Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Jiayuan Chen <jiayuan.chen@linux.dev>
To: bot+bpf-ci@kernel.org, bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	eddyz87@gmail.com, memxor@gmail.com, martin.lau@linux.dev,
	song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org,
	emil@etsalapatis.com, ihor.solodrai@linux.dev, shuah@kernel.org,
	yatsenko@meta.com, alan.maguire@oracle.com,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	martin.lau@kernel.org, mason@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 20:48:51 +0800	[thread overview]
Message-ID: <334976a1-b8f3-416d-b5c6-588c25ab5a03@linux.dev> (raw)
In-Reply-To: <116308d606e3bff21d07c01feb8741702547d1c32b1eafaad6f3628a776828fc@mail.kernel.org>


在 8/31/26 7:48 PM, bot+bpf-ci@kernel.org 写道:
>> bpf: Fix NULL-ptr-deref when showing a void BTF type
>>
>> 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:
> Is this statement about the map dump path accurate? Looking at
> map_check_btf() in kernel/bpf/syscall.c, a map key isn't required to
> have a size:
>
> 	/* Some maps allow key to be unspecified. */
> 	if (btf_key_id) {
> 		key_type = btf_type_id_size(btf, &btf_key_id, &key_size);
> 		if (!key_type || key_size != map->key_size)
> 			return -EINVAL;
> 	} else {
> 		key_type = btf_type_by_id(btf, 0);
> 		if (!map->ops->map_check_btf)
> 			return -EINVAL;
> 	}
>
> When btf_key_id is 0, key_type is set to the void type, and
> map->btf_key_type_id is stored as 0. array_map_check_btf() even has a
> dedicated keyless exception ("One exception for keyless BTF:
> .bss/.data/.rodata/.percpu map").
>
> The preceding patch in this series, commit 55f5ad8f45a5 ("bpf: Reject
> key-less BTF for hash maps"), documents a syzbot NULL-ptr-deref where a
> void key reached the map dump path through htab_map_seq_show_elem() ->
> btf_type_seq_show_flags() -> btf_type_show() -> kind_ops[BTF_KIND_UNKN]
> == NULL. That patch closed the path by adding btf_type_is_void(key_type)
> rejections in htab_map_check_btf() and rhtab_map_check_btf().
>
> Would it be more accurate to say the map dump path is closed by the
> preceding patch and by existing btf_key_type_id guards, rather than by
> a size requirement?



I still think I am correct.

A "const void" (a nonzero-id modifier) is rejected as key/value by 
map_check_btf()'s size check;
your key-less case is a bare void key (id 0) on a different path, 
already handled by
patch 1 — so the size reasoning holds here.



  reply	other threads:[~2026-08-31 12:49 UTC|newest]

Thread overview: 16+ 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:48   ` bot+bpf-ci
2026-08-31 12:48     ` Jiayuan Chen [this message]
2026-08-31 21:06   ` Ihor Solodrai
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=334976a1-b8f3-416d-b5c6-588c25ab5a03@linux.dev \
    --to=jiayuan.chen@linux.dev \
    --cc=alan.maguire@oracle.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bot+bpf-ci@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mason@kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox