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=1796384800; b=vIi8f+eoJuPLj/gBLYRFHgGApx1p4XEuQDCRf0Jeo5Q5UPtYZIFrNj83sEymfXHsrkIY akmpS803ymRxFd1mqmmmjjJzj6c0VGd7cmApDmwieiGbhEPaOtrlkK9vXWW2xWIBjVcL8 ElEATcVgt7MZxfdCMazxaPwYgt8QsTDgzFTjhSivZh4hli7pqsfwc4ObBe5W66o+ZT20a zDOzpn8L23R+7OMr1nBmnTn9QUn/pUVcP79QkAtB1US8YKJ07hwNC94nJmco6k1fLSCtk F+BNaaa8xxnMVkJlncl6ZXbFh/FmrsKZlPzAsSoAZdQy0ioMGj77oBsTFe+K6KPV/hw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384800; 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=7XmFKTxIaSg/iuft0NGp1gc/Vp1683aiXEnNVzVZnDM=; b=Az6QJzljEdkoeyY1uXM/rhKtbi7GerTx/q2UHMViEE/gcwx7FSh1HAMMlaadezBlFfqG 2S4uZYZX5Lg3kXrlz0ySjp1Vk+yWmh7JuMGGFIsm4htlnrbHkPAlw2ohwJLkJ9ueZfZMN AZkWQEpFB9tvBt+WcPGcvGoIk8Yjz+xCg04qVg9lx41xIjNd21M4ytH/RYZj6rqGNkKuL L9sejjPBsSHGOW5ZCesgSHBIZM5rr5TAFf1RfLvaUAKa81mJRNRfT2Sw/vhAVyYjrlvSa 0A7wm76ygaYaIgyTPoUc6OjCHFxAS4kH2MkqCULyxZ80Trmntgo3CWp96euCjt1wQ0A== 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=xZctKing; 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 D6B06606A32F; Fri, 4 Dec 2026 11:46:40 +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=xZctKing Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00B411F00897; Fri, 4 Dec 2026 11:46:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384800; bh=7XmFKTxIaSg/iuft0NGp1gc/Vp1683aiXEnNVzVZnDM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=xZctKingzlxCIrGN9Q+LDkDCBXg5j+o1pNqHgzX4FAm5rOOab9twhBV6kbDaqi9ax trXofIAam8aLhL91A2TFOakZbFMjAO9G7djV4GD4HTtS+A4i2CedJArHfWL82PjThE +XfdCqbg3X26a4fCb3dOTr3HSZxFdBpghmRhvi6w= 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.6 0299/1167] libbpf: Avoid overflow in BTF.ext bounds check Date: Fri, 4 Dec 2026 18:55:26 +0900 Message-ID: <20261204100709.819078844@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-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 "start of the info sec" comment from the void *info; declaration to above the info = ... assignment, since the function here is named btf_ext_setup_info() and the context differed. ] 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 54ad899a1e96c..78bc62be03fbd 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