Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3707537pxb; Mon, 24 Jan 2022 15:58:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJyVjZK57QGyTUOTKOx8fU/StqYezRE1rjh9qbQMwtGJKTjeO/2woZjQLpfDw5fstSW1h62M X-Received: by 2002:a17:902:7681:b0:149:bb15:c53f with SMTP id m1-20020a170902768100b00149bb15c53fmr16510305pll.159.1643068682639; Mon, 24 Jan 2022 15:58:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643068682; cv=none; d=google.com; s=arc-20160816; b=agMqiD35NpJaRdXFVRh/1zYuDsp8qwsLszKiskrfQeEmDsD/yvaiBl3wAB/YMUxLgc wW3r4KLVooR8ybJeacKjgBXbfKz5LgytCb5C/sEMiX8M/wP7fhTZ/UiGND8avKlOu9O+ hfPeBZ+pSNk/Ghzi36Cx5tbzYE4k5QFUIIkfCba1rb2+6x9j08x1GXfhqQQc4ZnNHb1/ BFql6unEhJrwwWZ1KuFIQSEW52V5tj6qIw0MbRqY6T3rvOXecvTPoTjCjxEJFPE1C+SU B8XIp55nVDTIiskegx4aWapTzasZ3NL3DdhbZIW8OoPsTFmfEzhlHjPcbf3nM9vxdonB 6cbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=EOWe4U5Kjydop3LY3uervcNXf6WTZwz84OLtyg87lRo=; b=p704lKgBilFynaveq7dsBtJonHM0WnIsk8p2Tthb850UyJsD6U/f7ejXxjSJISVq35 8iWTOcLWmOAJnZah6rnGDSUGbC6QjmZ798ovhZUgMH14wWgYQw6/aZAiAE5RIfB7qpHU nX9xa8ntEJ0KZ50PpBBiq41Ad2xcqzqjY4NB0AQjfgOjumGotfGRQEeYP0x/tleZ5xPY toHXiIb6namOD9rT4erk49cWHsok4xNES30hpnooi6x2pHA7R2q8Rc/P6xOh+j5Zix2C TmvEnqDInmz95o87WNvrWhiiceMe03rKv1kmnyoQcbSDnnYmaYDtbDmOahK2bslcCEzW nUBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NJ68WdmN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r21si12842065pla.499.2022.01.24.15.57.50; Mon, 24 Jan 2022 15:58:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NJ68WdmN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2366479AbiAXXwy (ORCPT + 99 others); Mon, 24 Jan 2022 18:52:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1845986AbiAXXOJ (ORCPT ); Mon, 24 Jan 2022 18:14:09 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E03CC067A75; Mon, 24 Jan 2022 13:20:56 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 26744B81218; Mon, 24 Jan 2022 21:20:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F143C340E4; Mon, 24 Jan 2022 21:20:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643059253; bh=aVB5FviLglqF60loxM2XgzrRKvbq4BiXPpr7wIcCXXc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NJ68WdmNcWTP/dW1BOdHVYNjUqV3s29WirLRFwqHw2XYygQgZehBWuhcDI1mQ2EGx xRCPXtZBW5L7x3tbpeHbpucjnjexZqeWVpN7HVZLUnJcmoCmWIv01lL9Gn3wb2OfU3 Q1I5TToCin0D3ZXTuy/0wTVZFcTII8RIWQt9cs54= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrii Nakryiko , Alexei Starovoitov , Yonghong Song , Sasha Levin Subject: [PATCH 5.16 0547/1039] libbpf: Improve sanity checking during BTF fix up Date: Mon, 24 Jan 2022 19:38:56 +0100 Message-Id: <20220124184143.658837249@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrii Nakryiko [ Upstream commit 88918dc12dc357a06d8d722a684617b1c87a4654 ] If BTF is corrupted DATASEC's variable type ID might be incorrect. Prevent this easy to detect situation with extra NULL check. Reported by oss-fuzz project. Signed-off-by: Andrii Nakryiko Signed-off-by: Alexei Starovoitov Acked-by: Yonghong Song Link: https://lore.kernel.org/bpf/20211103173213.1376990-3-andrii@kernel.org Signed-off-by: Sasha Levin --- tools/lib/bpf/libbpf.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 1cc0383471f01..c7ba5e6ed9cfe 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -2753,13 +2753,12 @@ static int btf_fixup_datasec(struct bpf_object *obj, struct btf *btf, for (i = 0, vsi = btf_var_secinfos(t); i < vars; i++, vsi++) { t_var = btf__type_by_id(btf, vsi->type); - var = btf_var(t_var); - - if (!btf_is_var(t_var)) { + if (!t_var || !btf_is_var(t_var)) { pr_debug("Non-VAR type seen in section %s\n", name); return -EINVAL; } + var = btf_var(t_var); if (var->linkage == BTF_VAR_STATIC) continue; -- 2.34.1