Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3383947pxb; Mon, 17 Jan 2022 19:13:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJwBuQjz0SKGlRVS0ZvIherE9zRkPSEJA6fnlGzPVfVlPhP4DspAnRfSiAxQoyLKzzuvX81E X-Received: by 2002:a63:7110:: with SMTP id m16mr21325574pgc.621.1642475598938; Mon, 17 Jan 2022 19:13:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642475598; cv=none; d=google.com; s=arc-20160816; b=H5DL88IBZY4bximU44AY8Z1NFf4aE4GU994uR6rDSJTRPwqVhs1NVhct+BXWEZXv0y J+jXMMXpnFXIazX2PfvFA6qQLEC0anpxjhufF9cp2OnTqTZ8E9IWJmxEOBv0QLLCS8ef zLArnGKUp7TM93tC1YpB9cUpJAU+5TW5Nx1oth5KKLFW5F8Ar3IdZS4Peb/yn1V7iNnh 8pLSfPxFNYoNzC2GvwIQBK2Q6EU/82pOBkAPmdFMYnd2EJNN9/ztbt8+/Is2odimy9E1 Cnwj2414lwMKX6fkFCYuw5r1Pliq9mNZ8SZfdTk1NioQvd7e7YcxDvimFPly4juK2IfG vEnQ== 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=XmBwRcgYIqZKaBkBaR7i6FUn6n5Bh6wp0O5b1RCfQS8=; b=yGN/XnnuG7yxOV5v8THaP9Xa+5FD3lYJnUOxU4Z/hgjRYlZCOqQYvQKRh/zxGLup/Z hBfu86OOga/14LOtgKMddhqafjAaD4YelrtdclTar00sXbbjSL1pk2mMsdaCxSpISN7i /YTJ1SSTHqsJJ50THkz/ws76u0LBUYodWc2+sX0oyOSSMxA6Ny8anZrRPNsD/OwmlQ7E wPaSUC3Uk52ej8bh+vxNDZdYzn7j/kfqVjRR/AcmPMO1DRXxVSAnIK2FpMifHVX4jt1u 76ZvhYHvLXhsW/NkJdjVbP8kcvtLpBefrKSQ4tmZyytLJ6sN+PG90Sb2ron2sK7eWnXA T4JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OV6Gj9A9; 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 p7si13846059plo.589.2022.01.17.19.13.07; Mon, 17 Jan 2022 19:13:18 -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=OV6Gj9A9; 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 S244509AbiARCUX (ORCPT + 99 others); Mon, 17 Jan 2022 21:20:23 -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 S244343AbiARCT7 (ORCPT ); Mon, 17 Jan 2022 21:19:59 -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 7F18DB811FF; Tue, 18 Jan 2022 02:19:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A8E8C36AE3; Tue, 18 Jan 2022 02:19:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642472397; bh=xhoC9JEsQkh2x4CVlOItxInWCYdd7RSZiQ/yq62fugw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OV6Gj9A9LcbnoRB8JnFSXZKYD24Dw/lSjKfiZwxoL3gHSg5CFJA26c5vj6uUq1Os4 /OZNzdh1ygTs1lKv6i7LO0ia752HFQNLTMlYrFrXDOnR++cI2CmNqdP1fZKLkGXUgI SE04RRfJUQPubjBxnsRMvDunvcAHrSrx+/KSl30Ukrhb2afQnBxRf3G5CDKO2QvVqS oVNS5WAcggVBdumqK+eT1FD35nN1ytHcpK3M5xa4zPed9LMx8xLgtDlWnBS939FkDw xGRlKs/3QEesW3WyVdx8x4q2eA5kno3c2SfE2cBNpRW8EaHyBgn3Dkft0gTiH/iBlh OWpyDqrzWgLqg== 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 010/217] libbpf: Validate that .BTF and .BTF.ext sections contain data Date: Mon, 17 Jan 2022 21:16:13 -0500 Message-Id: <20220118021940.1942199-10-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 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 18651e11b9ba3..7d27152dfb3a6 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -3270,8 +3270,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