Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3383881pxb; Mon, 17 Jan 2022 19:13:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJwKTqpGSbb7OwTmQBOrb7GMnIkqteQaqpvGw6p36jLokQ5G96gt2+HEB7gmB1/jjgEMymTK X-Received: by 2002:a63:115c:: with SMTP id 28mr13256385pgr.382.1642475592968; Mon, 17 Jan 2022 19:13:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642475592; cv=none; d=google.com; s=arc-20160816; b=d84PxlMkqn/i6IFGyDhpCYYhq/slu/u3zHTRxmKNe2z3lRpfXBvv99yZkt4ZhW3vv6 S3CiBs07ZWsE8kXmfG3eHDrhX68SJ/WZV27U5pofjlOnkfTMUGFDcSyAkNyXoXrXBx/I 2sR0/ydFhz6psyXpgG46N9estDjAolEqvLiPaQQe5rF0v89TS+oIQzYVF9wFUwLBWb8o oCxRG6XXtGydS46EC8kdX4pe3oOSRWeMicF9rHSyxXvqq3A9aH8nGKaGB8fra4ogQxp6 ZumS7A5tx6xAaTf5ayzQwb/xbN0lfR+JsZ0MYj8AOKq5nrHRGV5FGXV2/y3s/UKvtYlj Qjhg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=hSeJKJLe8NfhBd7oYLIUFG11WiMFgzZGFOmPJ1sMq5k=; b=SdjaX54X/+JV5FUQBX0GspZV/z38CsL6UVVhlAFpqrGP41GFUizyGtb4IXaBbfwjpJ J6HNuynyCp+nk2qqJfBg5IMLMtziuJowdVCxr57DWMPx7C8L5UouGXJvTnoSu5GH+Hp3 h6ZSScgywkwOOp460GjgeIgWVTZnz2U+830vvb6hnJovhuXDVQ5ow04vUvpIb6Aq/elp ZIOQTgHI5Yu3RuVRbxlZWk+uMo79WM9hzplX4bywtadVh0MbeUtjlkMQB370GqbyWYXx UT5XRdr/5p4B/LD+d0vI1EmdIcFCy1Ivqq7DKA17Y/KEArcsC1V/XSJLlxBF0ZJ72Ika QjWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=G0JMM8Ht; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n8si18071269plh.596.2022.01.17.19.13.01; Mon, 17 Jan 2022 19:13:12 -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=@kernel.org header.s=k20201202 header.b=G0JMM8Ht; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244576AbiARCUO (ORCPT + 99 others); Mon, 17 Jan 2022 21:20:14 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:34802 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244399AbiARCT5 (ORCPT ); Mon, 17 Jan 2022 21:19:57 -0500 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 BE56CB811FF; Tue, 18 Jan 2022 02:19:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B021BC36AEB; Tue, 18 Jan 2022 02:19:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642472394; bh=D2F65sZ8+SV9pkPLBU9T9VYQyZJtdJT8brhvmr+qFZo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G0JMM8HtWyOGSaDPtHkPGvf49tiMZtL8JymoI/Vf74ALq73JbgmvzfaVTRaMSNM6b nwZJ1aWyjRYfdaoVwZ5UfBF0Lg+iZckKLJeBpTR8QzPWY8ZnFwGMsTMJgrprXmG9aC Xnt0mK9bhLxGPFU5EpiLZBPh4D1bwbDcp7F0RkJ0kMs4icwsTmFpMf+SOShZNc4rA+ TV1JHYu33wPjhmct4Dn0JEQAmwz8S7dyVLYoEtaR1KNQOeL79yZheRQRp/wxH2M1/u FbI32OZtsZSDpsqTIGS+UGlwhM2Dl/WSfgaHKSVSIQ6++tjEmm1hY47UB406QS9Xkx EOA++R8E2Ybkw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Andrii Nakryiko , Alexei Starovoitov , Yonghong Song , Sasha Levin , daniel@iogearbox.net, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH AUTOSEL 5.16 008/217] libbpf: Detect corrupted ELF symbols section Date: Mon, 17 Jan 2022 21:16:11 -0500 Message-Id: <20220118021940.1942199-8-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220118021940.1942199-1-sashal@kernel.org> References: <20220118021940.1942199-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrii Nakryiko [ Upstream commit 833907876be55205d0ec153dcd819c014404ee16 ] Prevent divide-by-zero if ELF is corrupted and has zero sh_entsize. 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-2-andrii@kernel.org Signed-off-by: Sasha Levin --- tools/lib/bpf/libbpf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 7c74342bb6680..b5bf1c074832e 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -3555,7 +3555,7 @@ static int bpf_object__collect_externs(struct bpf_object *obj) scn = elf_sec_by_idx(obj, obj->efile.symbols_shndx); sh = elf_sec_hdr(obj, scn); - if (!sh) + if (!sh || sh->sh_entsize != sizeof(Elf64_Sym)) return -LIBBPF_ERRNO__FORMAT; dummy_var_btf_id = add_dummy_ksym_var(obj->btf); -- 2.34.1