From: Ihor Solodrai <ihor.solodrai@linux.dev>
To: Jiayuan Chen <jiayuan.chen@linux.dev>, bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Jiri Olsa <jolsa@kernel.org>,
Emil Tsalapatis <emil@etsalapatis.com>,
Shuah Khan <shuah@kernel.org>,
Mykyta Yatsenko <yatsenko@meta.com>,
Alan Maguire <alan.maguire@oracle.com>,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH bpf v3 2/5] bpf: Fix NULL-ptr-deref when showing a void BTF type
Date: Mon, 31 Aug 2026 14:06:40 -0700 [thread overview]
Message-ID: <99f0921c-0cf9-48a8-a84f-3b888988eb33@linux.dev> (raw)
In-Reply-To: <20260831110314.150870-3-jiayuan.chen@linux.dev>
On 8/31/26 4:01 AM, Jiayuan Chen wrote:
> btf_modifier_show() resolves the modifier and then calls
> btf_type_ops(t)->show() unconditionally. For the void type (type_id 0,
> BTF_KIND_UNKN) kind_ops[] has no entry, so ->show is NULL.
>
> The map dump path cannot reach a void type (a map key/value must have a
> size and void has none), but bpf_snprintf_btf() takes a type_id straight
> from the BPF program, and a "const void" (a modifier that resolves to
> void, present in the vmlinux BTF) NULL-derefs there:
>
> KASAN: null-ptr-deref in range [0x0000000000000028-0x000000000000002f]
> RIP: 0010:btf_modifier_show (kernel/bpf/btf.c:2914)
> Call Trace:
> <TASK>
> btf_type_show (kernel/bpf/btf.c:8251)
> btf_type_snprintf_show (kernel/bpf/btf.c:8321)
> 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:94)
> entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121)
> </TASK>
>
> void has no size, so there is nothing to render - not even a byte length
> to fall back to dumping as raw hex. btf_df_show() is already the ->show
> for the other kinds that carry no value to print - FWD, FUNC, FUNC_PROTO,
> FLOAT and DECL_TAG - and emits an "<unsupported kind:N>" placeholder;
> void belongs to the same group and only lacks a show op because it has
> no kind_ops[] entry at all. Fall back to btf_df_show() in
> btf_modifier_show() when the resolved type has no show op, so a void type
> prints that placeholder instead of crashing; bpf_snprintf_btf() then
> returns the length as usual.
nit: The explanation is a bit too verbose, I'd try simplifying. And the
comment in the code as well.
>
> Fixes: c4d0bfb45068 ("bpf: Add bpf_snprintf_btf helper")
> Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
> ---
> 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 91b8ce77f699..6e267c4c4e1f 100644
> --- a/kernel/bpf/btf.c
> +++ b/kernel/bpf/btf.c
> @@ -2911,7 +2911,15 @@ static void btf_modifier_show(const struct btf *btf,
> else
> t = btf_type_skip_modifiers(btf, type_id, NULL);
>
> - btf_type_ops(t)->show(btf, t, type_id, data, bits_offset, show);
> + /*
> + * A modifier can resolve to the void type (e.g. "const void"), which
> + * has no show op (kind_ops[BTF_KIND_UNKN] is NULL). Print a placeholder
> + * instead of dereferencing NULL.
> + */
> + if (!btf_type_ops(t))
> + btf_df_show(btf, t, type_id, data, bits_offset, show);
> + else
> + btf_type_ops(t)->show(btf, t, type_id, data, bits_offset, show);
Acked-by: Ihor Solodrai <ihor.solodrai@linux.dev>
> }
>
> static void btf_var_show(const struct btf *btf, const struct btf_type *t,
next prev parent reply other threads:[~2026-08-31 21:06 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 11:01 [PATCH bpf v3 0/5] bpf: Fix NULL-ptr-derefs when showing a void BTF type Jiayuan Chen
2026-08-31 11:01 ` [PATCH bpf v3 1/5] bpf: Reject key-less BTF for hash maps Jiayuan Chen
2026-08-31 12:05 ` bot+bpf-ci
2026-08-31 12:27 ` Jiayuan Chen
2026-08-31 21:01 ` Ihor Solodrai
2026-08-31 11:01 ` [PATCH bpf v3 2/5] bpf: Fix NULL-ptr-deref when showing a void BTF type Jiayuan Chen
2026-08-31 11:35 ` sashiko-bot
2026-08-31 12:23 ` Jiayuan Chen
2026-08-31 11:48 ` bot+bpf-ci
2026-08-31 12:48 ` Jiayuan Chen
2026-08-31 21:06 ` Ihor Solodrai [this message]
2026-08-31 11:01 ` [PATCH bpf v3 3/5] bpf: Fix NULL-ptr-deref in btf_var_show() Jiayuan Chen
2026-08-31 21:08 ` Ihor Solodrai
2026-08-31 11:01 ` [PATCH bpf v3 4/5] selftests/bpf: Add test for key-less BTF hash map Jiayuan Chen
2026-08-31 11:48 ` bot+bpf-ci
2026-08-31 12:54 ` Jiayuan Chen
2026-08-31 21:12 ` Ihor Solodrai
2026-08-31 11:01 ` [PATCH bpf v3 5/5] selftests/bpf: Add test for showing a void BTF type Jiayuan Chen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=99f0921c-0cf9-48a8-a84f-3b888988eb33@linux.dev \
--to=ihor.solodrai@linux.dev \
--cc=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=jiayuan.chen@linux.dev \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=yatsenko@meta.com \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.