From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796387447; b=0ySdt9jEZNHi12x8kDwo6n5W0vkZ39JwaOMzC21+nnwq6746McQaRKsHzNYJ8H0EPabs qWYKjRzOI3hrP0yllb2IFg9v5poOuVcQHqwv2y9aIBiDKQU/ZzhmTNduNaG2xobTgL5K+ BOi/ho0qTeuoZxyGqy08RQ+gcboYVxU40M7RyccMl93a4tzuR/sorUjJ/9UsM02JLLLYs Yk8wt/0hA1NNE6Ip05awEZmxi4Feb5gYSS9OIkbZaUKMklPSwEe9QuhLJvPuxdeM1rcaL oLEyOeFztYTJqTTEufQIQ7DqjmDarznv+5mrYJhbHWAU0zVCZXql5fsX8fM08dpiQGw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387447; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=MOktdbGE3ww6m0Z7I61fIsO3WJVA0NulXy7EOnHP/yk=; b=ZAu9ugkZz+VtGmLItaeIIfJ2Zy6KG+ucbMJKFK3Ih0K6+DkHmXcwWl5wyVhgfw22WBKe AHUGaK44sqCeTQUpTQAHS8BYBUCEL8HRmrqOK4BOSgi4u9+BUGpxCuECSFX6mqp8afmAg Wt7bk68+Iu1Yvz219Yr1QpCrFxhwXxS/nTNnMcFxRL3SE5Q5n7t0Sz9T4evvV+Bf3IwiF /WnKPWbbaOTXLAcBTDJf6vmKKyWyi1vMRVzNmbGa9HvmU/SWPNs4wlDNyc3TJKqLq3Gew NY9rSLzqKnbtJr0IqV+gHr7hPeKa8WW32l4HOfenTGEs742mNoDXaPtHsvvsfARlTtA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=pKMgncQK; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 757A8606A32C; Fri, 4 Dec 2026 12:30:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=pKMgncQK Received: by smtp.kernel.org (Postfix) with ESMTPSA id E06491F000C2; Fri, 4 Dec 2026 12:30:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387447; bh=MOktdbGE3ww6m0Z7I61fIsO3WJVA0NulXy7EOnHP/yk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=pKMgncQKuNm0SGd4ZbpeS/KCx0ndrlZIh/t6RwYyToPq3YKSjTW6fizQ9/ce3+d7R aNB7UjYTNY6ab5BTqTdTybIGUYvdb+xDpw+zb2bPohZrL2qThmvkmZw+h+9uzGa3i8 AGFOzmW1w8XelXguSh0jPnpIYTjQw1g/mENbWuto= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Darren Carreras , Andrii Nakryiko , Sasha Levin Subject: [PATCH 6.1 0248/1059] libbpf: Avoid overflow in BTF.ext bounds check Date: Fri, 4 Dec 2026 18:56:19 +0900 Message-ID: <20261204100650.697709765@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Darren Carreras [ Upstream commit e40f61a31688898e7cf81e91074a42f805883e4d ] A malformed BTF.ext subsection length in an ELF input can wrap the pointer addition used by btf_ext_parse_sec_info() on 32-bit builds. The wrapped pointer passes the bounds check and parsing then reads beyond the copied BTF.ext data. Ensure the header fits in the copied data, then validate the subsection offset and length with subtraction before forming its pointer. Fixes: ae4ab4b4117d ("btf: expose API to work with raw btf_ext data") Closes: https://issues.oss-fuzz.com/issues/477315119 Signed-off-by: Darren Carreras Signed-off-by: Andrii Nakryiko Link: https://lore.kernel.org/bpf/20260813-b4-libbpf-v6-send-20260813-v6-1-56be61c52758@gmail.com [ sashal: Moved the info pointer and comment below the new bounds check, and kept the older function name, with the comment placed on the declaration originally. ] Signed-off-by: Sasha Levin --- tools/lib/bpf/btf.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index df3f001dfeec7..8df51b51354eb 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c @@ -2657,9 +2657,8 @@ static int btf_ext_setup_info(struct btf_ext *btf_ext, { const struct btf_ext_info_sec *sinfo; struct btf_ext_info *ext_info; - __u32 info_left, record_size; + __u32 data_left, info_left, record_size; size_t sec_cnt = 0; - /* The start of the info sec (including the __u32 record_size). */ void *info; if (ext_sec->len == 0) @@ -2671,15 +2670,20 @@ static int btf_ext_setup_info(struct btf_ext *btf_ext, return -EINVAL; } - info = btf_ext->data + btf_ext->hdr->hdr_len + ext_sec->off; - info_left = ext_sec->len; + if (btf_ext->hdr->hdr_len > btf_ext->data_size) + return -EINVAL; - if (btf_ext->data + btf_ext->data_size < info + ext_sec->len) { + data_left = btf_ext->data_size - btf_ext->hdr->hdr_len; + if (ext_sec->off > data_left || ext_sec->len > data_left - ext_sec->off) { pr_debug("%s section (off:%u len:%u) is beyond the end of the ELF section .BTF.ext\n", ext_sec->desc, ext_sec->off, ext_sec->len); return -EINVAL; } + /* The start of the info sec (including the __u32 record_size). */ + info = btf_ext->data + btf_ext->hdr->hdr_len + ext_sec->off; + info_left = ext_sec->len; + /* At least a record size */ if (info_left < sizeof(__u32)) { pr_debug(".BTF.ext %s record size not found\n", ext_sec->desc); -- 2.53.0