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=1795022028; b=bJszoPirwmD1q850L4cc8AaS6IzzA4R5PCM5jh1+xP8g2reHJdv8Cu0A6bbkBuVJuhrq 09PUR+wXkfPPuSitZEnvNTAjkak3M4n1oMOUH9ZSsj2nQSxACylc9zxfdhaltVrkGynMY g+gwUd5PZxLYGiEKi4w75NwcAM5wIMs1bzxOlaO8xF8nPdlAYOBKj9MwK7wTA/LxGFXRf rFlvrp/teT+hDfzkpnDDCAIlahVyoIwAGJJK6tcmmM8eCSGDlZPiXSByFSur9sv1x/god kgLIIs5dolNTIaWbGEDxFdoDqWVx3HWTVYGBeR4EYldOodTx85XYMsZf+vQlPGKKhBA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795022028; 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=7gPQUffiEay5DLz4ajYie/YfJlwUHJWUScvfXZ0SsTI=; b=IH+3YEZBvYp21HPl8s3a/5uGimARRskX/kyq+PkBs9yyQcFq3IG4m8THpsFrQoAxtii+ x8xbM2xY2lEeIfzsBzOLaffln+ymqSnotZJ7swcYJzPebSIsDYq/XOJIPvD8qoHzApwDt wf+yeW8TCmSOZnKmxt4HdL9Pcf2OYZl0n4Sxt6piGACOUMXiwaGc+wBorlpyQ1H+oJghG z5RRtS6SRsTfyB3viS+UkLbbgBD3F6hZSXD2yLNRduegDyR637N1rE4nf/BXPcRHGZGlD nG6mciACmNs/UfueA8eB/9ENEoP2NDpRzTCpV1Pay8kLLpogS5tRfTSqXBa9JrX5WTQ== 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=lvcBwWXT; 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 190A8606A338; Wed, 18 Nov 2026 17:13:48 +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=lvcBwWXT Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BF8E1F000C5; Wed, 18 Nov 2026 17:13:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795022028; bh=7gPQUffiEay5DLz4ajYie/YfJlwUHJWUScvfXZ0SsTI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=lvcBwWXTX7eS6FJT1LmuX80jBbtvkr2DzGsZoW4C0IDyci7ZqZXTWwUt9fL0VBsSG HmTSM4nF/Qeru7uNJDQCpoPlIHFJ4OB029CHpUgdDxjXwnJnYcpdNr0u+nOt31Qdcg RWms5w44YB8Uw4ytKhP08/rmM68zreXYK5QOPi4U= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Feng Yang , Alexei Starovoitov , Mahe Tardy , Ihor Solodrai , Sasha Levin Subject: [PATCH 7.3 2516/2651] bpf: Fix out-of-bounds btf->types write for split BTF Date: Wed, 18 Nov 2026 16:02:36 +0100 Message-ID: <20261118150415.289460800@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150247.972732815@linuxfoundation.org> References: <20261118150247.972732815@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 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Feng Yang [ Upstream commit 6c476d2b73056ed151c3f8b884c627c75999ed7c ] btf_add_type() stores the types of a BTF in btf->types[], which can hold at most BTF_MAX_TYPE entries. The types of a split BTF get IDs start_id .. start_id + nr_types - 1, so only BTF_MAX_TYPE - start_id of them fit, but neither the limit check nor the size used to grow the array accounts for start_id: the check is an equality test against BTF_MAX_TYPE ('start_id + btf->types_size == BTF_MAX_TYPE') and the new size is clamped to BTF_MAX_TYPE. The check therefore only fires if the array happens to grow to exactly BTF_MAX_TYPE - start_id entries. Otherwise, if the module has more than BTF_MAX_TYPE types, the array is filled up to BTF_MAX_TYPE entries. The next type that needs to be added reallocates the array to the same size, after which btf->types_size no longer equals btf->nr_types and the growth path is not taken anymore, so every following type is written past the end of the array: BUG: unable to handle page fault for address: ffffc90006200000 RIP: 0010:btf_add_type+0x74/0x270 Call Trace: btf_check_all_metas btf_parse_module Bound both the array size and the limit check by BTF_MAX_TYPE - start_id. Base BTF (start_id == 0) is unaffected. Fixes: 951bb64621b8 ("bpf: Add in-kernel split BTF support") Signed-off-by: Feng Yang Signed-off-by: Alexei Starovoitov Reviewed-by: Mahe Tardy Acked-by: Ihor Solodrai Link: https://patch.msgid.link/20261028031933.277550-1-yangfeng59949@163.com Signed-off-by: Sasha Levin --- kernel/bpf/btf.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index bf731bf9e0a57..b13302f33ff5c 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -1736,15 +1736,16 @@ static int btf_add_type(struct btf_verifier_env *env, struct btf_type *t) /* Expand 'types' array */ struct btf_type **new_types; - u32 expand_by, new_size; + u32 expand_by, new_size, max_size; - if (btf->start_id + btf->types_size == BTF_MAX_TYPE) { + if (btf->start_id + btf->types_size >= BTF_MAX_TYPE) { btf_verifier_log(env, "Exceeded max num of types"); return -E2BIG; } + max_size = BTF_MAX_TYPE - btf->start_id; expand_by = max_t(u32, btf->types_size >> 2, 16); - new_size = min_t(u32, BTF_MAX_TYPE, + new_size = min_t(u32, max_size, btf->types_size + expand_by); new_types = kvzalloc_objs(*new_types, new_size, -- 2.53.0