Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3637762pxb; Mon, 24 Jan 2022 14:07:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJy4Nr/XCQKX4chrZqXU2iULKvJ6dKdlO1j4Lz2w7UgmbJIf79abLRTkBfdfWRdsJZZyj3ol X-Received: by 2002:a17:903:24d:b0:14a:677d:843a with SMTP id j13-20020a170903024d00b0014a677d843amr16057899plh.129.1643062031280; Mon, 24 Jan 2022 14:07:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643062031; cv=none; d=google.com; s=arc-20160816; b=JSoWNAQsqTlSkv1EJ21ZsvcZWEuqLehj1oGnQyVkrLmn+GZRFqxly1tqg+bQQsBjtp oOXn3fjctBraEPY2p8kzooH4X+1GkepCr8GsrKdvo/QHbUaJu2JBjdeGQSFnVasnqs9R ND57xlTE+DYuUDU1lGYqwWAfB+UcyBsILtDXVRaelpmQb1JUggikcWjuuTb+Zve1HVfp ZOUVPrpFDXyk3ewKMeo3SuSqSp886t7Tet+lRkH+Nf0WqbhunZyIAXPld4RxmumGScpN l2Jo3Qhdk2RsWT0M45/CUi5GKgeWm4rZ/pK8NGCexJPLsknu0Dznppx8bKEpwh36cAry LZZQ== 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=EKxDU65/fGTgXe5C6cOyVKb8JH4zQesDOllI8zKZnrA=; b=sVR7d92T3f/xufWvaD4jNjzlK9oTlMjTqvwSm32m6nGXULs6zewc4mRJM+ZyLvwEKq jIeBMDb1Cxjjb6TvEgwyRDxhacrBpkcMT3drNIEoB7ESuKQNivnaoRqF2qsMdZsBNQZ2 w00C8PHZ4rayFwOzKRKUwklJs6zT/yNL0F1s+g6bj536AhyrtA8BuCVOL0ay+xFmXlF8 NZynBbHj2lrXqw+JykRFTIELEgylF/4kwBNvTQLcU67xOtpMuAZMuwQR6pPNJpGPGuQ/ IwjOd6qXq5rDYzpuTz64Mun4Py9YHCrbFDRtMxdzTb8iUEAlqjai8OUox0w0AzaGx+oc 4CuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cB0GTfeQ; 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 u10si7791830ple.201.2022.01.24.14.06.57; Mon, 24 Jan 2022 14:07:11 -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=cB0GTfeQ; 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 S1379784AbiAXVyo (ORCPT + 99 others); Mon, 24 Jan 2022 16:54:44 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:43938 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1450803AbiAXVV1 (ORCPT ); Mon, 24 Jan 2022 16:21:27 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 81042614C9; Mon, 24 Jan 2022 21:21:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 699E4C340E4; Mon, 24 Jan 2022 21:21:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643059286; bh=qugYk4pDsPqpyUGAGLi31+juSnBWrfgIxERcbKmTZ94=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cB0GTfeQQzFjcG4ZjdqTbY2Vb8wtkd9SD7KhFa8OtEmdXFBLpOQaxlnT4pvoEzt3M RRwswxgWAMLPzEkVkYH7RXec2fXCrodDq2qm2mwj+2x7sCsE0sRDRtClC337pF1Ugi 5KfIAQcqE/7/lQlGYv8Nz6EEOMXn5xVISE13gnuA= 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 0548/1039] libbpf: Validate that .BTF and .BTF.ext sections contain data Date: Mon, 24 Jan 2022 19:38:57 +0100 Message-Id: <20220124184143.698193669@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 62554d52e71797eefa3fc15b54008038837bb2d4 ] .BTF and .BTF.ext ELF sections should have SHT_PROGBITS type and contain data. If they are not, ELF is invalid or corrupted, so bail out. Otherwise this can lead to data->d_buf being NULL and SIGSEGV later on. 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-4-andrii@kernel.org Signed-off-by: Sasha Levin --- tools/lib/bpf/libbpf.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index c7ba5e6ed9cfe..96cee9cd8c03c 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -3271,8 +3271,12 @@ static int bpf_object__elf_collect(struct bpf_object *obj) } else if (strcmp(name, MAPS_ELF_SEC) == 0) { obj->efile.btf_maps_shndx = idx; } else if (strcmp(name, BTF_ELF_SEC) == 0) { + if (sh->sh_type != SHT_PROGBITS) + return -LIBBPF_ERRNO__FORMAT; btf_data = data; } else if (strcmp(name, BTF_EXT_ELF_SEC) == 0) { + if (sh->sh_type != SHT_PROGBITS) + return -LIBBPF_ERRNO__FORMAT; btf_ext_data = data; } else if (sh->sh_type == SHT_SYMTAB) { /* already processed during the first pass above */ -- 2.34.1