From: sashiko-bot@kernel.org
To: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [RFC PATCH bpf-next v1 06/16] bpf: Support special fields in typed arena objects
Date: Sat, 26 Sep 2026 23:59:34 +0000 [thread overview]
Message-ID: <20260926235934.B6C4E1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260926233503.3114147-7-memxor@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] bpf: bpf_kptr_xchg allows user-space to forge kernel pointers via typed arena memory
- [High] bpf: bpf_kptr_xchg on arena pointers causes kernel panic on archs lacking inline support
--
commit 2d0dbe5c6fd18e1e3096285d4ab48687f876b4ce
Author: Kumar Kartikeya Dwivedi <memxor@gmail.com>
bpf: Support special fields in typed arena objects
This commit allows bpf_kptr_xchg() to take a pointer to a kptr field of a
typed arena object. It modifies the verifier to permit objects in arena
memory to own references to kernel objects and program-allocated objects.
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 75697e52a2df6..f854d8419fff0 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
[ ... ]
> @@ -8063,7 +8063,7 @@ static int process_kptr_func(struct bpf_verifier_env *env, int regno,
> struct btf_record *rec;
> u32 kptr_off;
>
> - if (type_is_ptr_alloc_obj(reg->type)) {
> + if (type_is_ptr_alloc_obj(reg->type) || type_is_typed_arena_obj(reg->type)) {
> rec = reg_btf_record(reg);
[Severity: Critical]
Does this allow user-space to forge kernel pointers?
Because arena memory (BPF_MAP_TYPE_ARENA) is inherently shared between the
kernel and user-space, it can be mmapped with PROT_READ and PROT_WRITE.
Furthermore, arena maps lack a map-level btf_record (it is NULL), which
bypasses the standard check in bpf_map_mmap() that forbids mmapping maps
containing special fields.
Could a malicious user-space process mmap the arena, write an arbitrary
64-bit value to the offset of the kptr field, and then have the BPF program
call bpf_kptr_xchg() to read this user-supplied value? The verifier would
unconditionally track the returned value as a trusted kernel pointer.
Could this forged pointer then be dereferenced or passed to bpf_obj_drop(),
leading to memory corruption or KASLR bypass?
> } else { /* PTR_TO_MAP_VALUE */
> map_ptr = reg->map_ptr;
[ ... ]
> @@ -8834,6 +8834,7 @@ static const struct bpf_reg_types kptr_xchg_dest_types = {
> PTR_TO_BTF_ID | MEM_ALLOC,
> PTR_TO_BTF_ID | MEM_ALLOC | NON_OWN_REF,
> PTR_TO_BTF_ID | MEM_ALLOC | NON_OWN_REF | MEM_RCU,
> + PTR_TO_BTF_ID | MEM_ARENA,
[Severity: High]
Could this cause a kernel panic on architectures that lack inline support
for ptr_xchg?
On architectures that support arenas but do not override
bpf_jit_supports_ptr_xchg() to return true (e.g., PowerPC and s390x), the JIT
will fall back to calling the bpf_kptr_xchg() C kernel helper.
The bpf_kptr_xchg() helper uses the raw xchg() macro on the provided pointer,
which resides in demand-paged arena memory:
kernel/bpf/helpers.c:bpf_kptr_xchg() {
...
return xchg(kptr, (unsigned long)ptr);
}
If the accessed arena page is unmapped, a kernel page fault occurs. Because
bpf_arena_handle_page_fault() is only wired up in the architecture-specific
fault handlers for arm64 and x86, it is completely ignored on PowerPC and
s390x.
Since the xchg() macro lacks an exception table entry inside the helper,
wouldn't an unmapped arena page result in an unhandled fault and a direct
kernel panic?
> }
> };
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260926233503.3114147-1-memxor@gmail.com?part=6
next prev parent reply other threads:[~2026-09-26 23:59 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-26 23:34 [RFC PATCH bpf-next v1 00/16] BPF typed arenas Kumar Kartikeya Dwivedi
2026-09-26 23:34 ` [RFC PATCH bpf-next v1 01/16] mm/vmalloc: Add get_vm_area_align() Kumar Kartikeya Dwivedi
2026-09-26 23:42 ` sashiko-bot
2026-09-26 23:34 ` [RFC PATCH bpf-next v1 02/16] bpf: Introduce BPF typed arenas Kumar Kartikeya Dwivedi
2026-09-26 23:34 ` [RFC PATCH bpf-next v1 03/16] bpf: Back typed arena chunks with scratch on demand Kumar Kartikeya Dwivedi
2026-09-26 23:56 ` sashiko-bot
2026-09-26 23:34 ` [RFC PATCH bpf-next v1 04/16] bpf: Add the typed_arena_cast instruction Kumar Kartikeya Dwivedi
2026-09-26 23:55 ` sashiko-bot
2026-09-26 23:34 ` [RFC PATCH bpf-next v1 05/16] bpf: Allow scalar and atomic access to typed arena objects Kumar Kartikeya Dwivedi
2026-09-26 23:34 ` [RFC PATCH bpf-next v1 06/16] bpf: Support special fields in " Kumar Kartikeya Dwivedi
2026-09-26 23:59 ` sashiko-bot [this message]
2026-09-26 23:34 ` [RFC PATCH bpf-next v1 07/16] bpf: Trust typed pointer fields of " Kumar Kartikeya Dwivedi
2026-09-27 0:03 ` sashiko-bot
2026-09-26 23:34 ` [RFC PATCH bpf-next v1 08/16] bpf: Canonicalize loaded typed arena pointers where they are used Kumar Kartikeya Dwivedi
2026-09-26 23:34 ` [RFC PATCH bpf-next v1 09/16] bpf: Add typed arena page allocation and release kfuncs Kumar Kartikeya Dwivedi
2026-09-26 23:55 ` sashiko-bot
2026-09-26 23:34 ` [RFC PATCH bpf-next v1 10/16] bpf: Let typed_arena_cast copy pointers the verifier already trusts Kumar Kartikeya Dwivedi
2026-09-26 23:49 ` sashiko-bot
2026-09-26 23:34 ` [RFC PATCH bpf-next v1 11/16] libbpf: Support the typed_arena_cast instruction Kumar Kartikeya Dwivedi
2026-09-26 23:34 ` [RFC PATCH bpf-next v1 12/16] selftests/bpf: Build BPF objects with compiler-inserted typed arena casts Kumar Kartikeya Dwivedi
2026-09-26 23:46 ` sashiko-bot
2026-09-26 23:34 ` [RFC PATCH bpf-next v1 13/16] selftests/bpf: Test typed arena casts and registration Kumar Kartikeya Dwivedi
2026-09-26 23:34 ` [RFC PATCH bpf-next v1 14/16] selftests/bpf: Test typed arena object access, kptrs and typed pointer fields Kumar Kartikeya Dwivedi
2026-09-26 23:34 ` [RFC PATCH bpf-next v1 15/16] selftests/bpf: Test typed arena page allocation and release Kumar Kartikeya Dwivedi
2026-09-26 23:46 ` sashiko-bot
2026-09-26 23:34 ` [RFC PATCH bpf-next v1 16/16] selftests/bpf: Exercise typed arenas at run time Kumar Kartikeya Dwivedi
2026-09-26 23:50 ` sashiko-bot
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=20260926235934.B6C4E1F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=memxor@gmail.com \
--cc=sashiko-reviews@lists.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