From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB9DC3D3CE5; Wed, 30 Sep 2026 19:06:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790795200; cv=none; b=hKgz8yp6FkVsV/JnrJ6I9pRTrhevF8iU5QtrLNLDpJRTlTkWvXUfhDZjdap143OIvfkZL9IfQ/PZIO8NzIGpnqmKPiXlVCnnTukdH2T+xEYvq/KyEBEY9aASsVljcfwigP2OeAPlR+WHu4ANTzf83zBXSsJqVx/uuePE9lM6lbE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790795200; c=relaxed/simple; bh=1G6mOujUxk2qLYaPoSUZ0xC15fzCMMz3+MdtlJ3URkA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cSyp0/rTkGpQSBWkulJShsvXm7x4hdnlSp76hV3vh+RScyoSfRR/O+XLsVWSn2SVabv6aKBrAi/Jtg6HAyh0JO4Hl0ALSbPbdN/i5N8U1Mcl1uu6dfxsLRFOlJlA2n7aqmpeetfrnKMncgALeg4A2z+PuwyYUxswtNuCx/cMbKE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=AJCmlY4R; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="AJCmlY4R" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 300DE1F000FF; Wed, 30 Sep 2026 19:06:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1790795199; bh=tilDegIQULgaCb62oJaTHsdKJHmLimKyfZcjPpj5ZvE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=AJCmlY4RiLJv/ikq+yJgXtQsJgV3xopSMGfD0b/aOL/R9hpjycRGm7enFAAOyjM2t /ej6Hp8iFOPU79s5NKceIAZVvbC7n+uV0Cd0U+kyXi72inhjHRLLbV2id9jnW+YRR+ xcbwEW97XBwTuCNWP43ZaUsJxeCuyEdUJpEeAhdY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jiayuan Chen , Ihor Solodrai , Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.6 0479/1193] bpf: Fix NULL-ptr-deref in btf_var_show() Date: Wed, 30 Sep 2026 17:19:23 +0200 Message-ID: <20260930152444.802576771@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930152434.301151190@linuxfoundation.org> References: <20260930152434.301151190@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jiayuan Chen [ Upstream commit 5403a383f52fc0905703b488f7c3db4b2447dc58 ] btf_var_show() calls btf_type_id_resolve() unconditionally, which dereferences btf->resolved_ids. That is NULL for a base BTF - e.g. the vmlinux BTF that bpf_snprintf_btf() renders against - since base BTF is not resolved during parsing. btf_modifier_show() guards this with 'if (btf->resolved_ids)', but btf_var_show() does not. A BPF program that passes the type_id of a BTF_KIND_VAR from the vmlinux BTF to bpf_snprintf_btf() thus NULL-derefs: KASAN: probably user-memory-access in range [0x46638-0x4663f] RIP: 0010:btf_var_show (kernel/bpf/btf.c:2929) Call Trace: btf_type_show (kernel/bpf/btf.c:8259) btf_type_snprintf_show (kernel/bpf/btf.c:8329) bpf_snprintf_btf (kernel/trace/bpf_trace.c:1047) bpf_prog_test_run_raw_tp (net/bpf/test_run.c:829) __sys_bpf (kernel/bpf/syscall.c:4804) do_syscall_64 (arch/x86/entry/syscall_64.c:84) entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121) Resolve the var's type directly with btf_type_skip_modifiers() when resolved_ids is NULL, mirroring btf_modifier_show(). Fixes: c4d0bfb45068 ("bpf: Add bpf_snprintf_btf helper") Signed-off-by: Jiayuan Chen Acked-by: Ihor Solodrai Link: https://lore.kernel.org/r/20260901104924.346187-4-jiayuan.chen@linux.dev Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin --- kernel/bpf/btf.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index f913437e97b22..3ae36f9f6c303 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -2732,7 +2732,15 @@ static void btf_var_show(const struct btf *btf, const struct btf_type *t, u32 type_id, void *data, u8 bits_offset, struct btf_show *show) { - t = btf_type_id_resolve(btf, &type_id); + /* + * btf_type_id_resolve() dereferences btf->resolved_ids, which is NULL + * for a base BTF (e.g. the vmlinux BTF that bpf_snprintf_btf() uses). + * Resolve the var's type directly in that case. + */ + if (btf->resolved_ids) + t = btf_type_id_resolve(btf, &type_id); + else + t = btf_type_skip_modifiers(btf, t->type, &type_id); btf_type_ops(t)->show(btf, t, type_id, data, bits_offset, show); } -- 2.53.0