BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v2 05/13] bpf: Turn loads of __arena pointer members into arena pointers
Date: Tue, 13 Oct 2026 08:40:57 +0000	[thread overview]
Message-ID: <sashiko-outbox-169266@kernel.org> (raw)
In-Reply-To: <20261013082012.1107446-6-memxor@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] bpf: PROBE_MEM fault bypass via non-nullable __arena pointers
--

commit fdb573c7b91be34110bf569fb46f6159ad42b9b8
Author: Kumar Kartikeya Dwivedi <memxor@gmail.com>

bpf: Turn loads of __arena pointer members into arena pointers

This commit translates the loads of __arena tagged pointer members in
kernel structs into arena pointers during verification. If the member
is also tagged as __nullable, a NULL test is kept before subtracting
the arena base address.

> diff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c
> index b2fa7e8bedf3a..3c95b6c8bbbc5 100644
> --- a/kernel/bpf/fixups.c
> +++ b/kernel/bpf/fixups.c
[ ... ]
> @@ -870,6 +870,36 @@ int bpf_opt_subreg_zext_lo32_rnd_hi32(struct bpf_verifier_env *env,
>   *     struct __sk_buff    -> struct sk_buff
>   *     struct bpf_sock_ops -> struct sock
>   */
> +/*
> + * A load through an __arena pointer member of a kernel struct reads the kernel
> + * address of arena memory. Append the conversion to the arena pointer form,
[ ... ]
> +static int arena_member_fixup(struct bpf_verifier_env *env, int idx, struct bpf_insn *insn,
> +			      struct bpf_insn *buf)
> +{
> +	struct bpf_insn_aux_data *aux = &env->insn_aux_data[idx];
> +	int cnt = 0;
> +	u32 base;
> +
> +	if (!aux->arena_member)
> +		return 0;
> +	if (aux->non_arena_load) {
> +		verbose(env, "an insn loads an arena pointer member on one path and something else on another\n");
> +		return -EINVAL;
> +	}
> +
> +	base = bpf_arena_get_kern_vm_start(env->prog->aux->arena);
> +	buf[cnt++] = *insn;
> +	if (aux->arena_member_nullable)
> +		buf[cnt++] = BPF_JMP_IMM(BPF_JEQ, insn->dst_reg, 0, 1);
> +	buf[cnt++] = BPF_ALU32_IMM(BPF_SUB, insn->dst_reg, (s32)base);

[Severity: High]
Could this allow a bypass of the PROBE_MEM zeroing mechanism when a fault
occurs on a non-nullable arena pointer?

If a PROBE_MEM read of a non-nullable __arena pointer faults, the exception
handler zeroes the destination register and resumes execution at the next
instruction. Because the pointer lacks __nullable, the zero-check branch
is omitted and the BPF_SUB instruction executes unconditionally.

This executes on the zeroed register, changing its value to -(u32)base.
Since base (kern_vm_start) is page-aligned but shifted by GUARD_SZ / 2 (32KB),
the truncated 32-bit offset calculates to 4GB - (base % 4GB). This
consistently points to the next 4GB-aligned address in the kernel.

Because base % 4GB is at least 32KB, this mathematically guarantees the
address falls strictly within the 4GB valid, user-mapped bounds of the arena.
Could an attacker map this arena offset, populate it with a malicious
payload, and spoof the BPF program into using attacker-controlled data?

> +	return cnt;
> +}
> +

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261013082012.1107446-1-memxor@gmail.com?part=5

  reply	other threads:[~2026-10-13  8:40 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-13  8:19 [PATCH bpf-next v2 00/13] Fix some arena paper cuts Kumar Kartikeya Dwivedi
2026-10-13  8:19 ` [PATCH bpf-next v2 01/13] libbpf: Keep the fd_array fill index out of bpf_program__clone() Kumar Kartikeya Dwivedi
2026-10-13 13:00   ` Mykyta Yatsenko
2026-10-13  8:19 ` [PATCH bpf-next v2 02/13] selftests/bpf: Clone a program that calls a module kfunc Kumar Kartikeya Dwivedi
2026-10-13  8:19 ` [PATCH bpf-next v2 03/13] compiler_types: Add __arena and __nullable BTF type tag qualifiers Kumar Kartikeya Dwivedi
2026-10-13  8:19 ` [PATCH bpf-next v2 04/13] bpf: Recognize __nullable on pointer members of kernel structs Kumar Kartikeya Dwivedi
2026-10-13  8:52   ` sashiko-bot
2026-10-13  9:19     ` Kumar Kartikeya Dwivedi
2026-10-13  8:20 ` [PATCH bpf-next v2 05/13] bpf: Turn loads of __arena pointer members into arena pointers Kumar Kartikeya Dwivedi
2026-10-13  8:40   ` sashiko-bot [this message]
2026-10-13  9:04     ` Kumar Kartikeya Dwivedi
2026-10-13  8:20 ` [PATCH bpf-next v2 06/13] selftests/bpf: Test __nullable pointer members Kumar Kartikeya Dwivedi
2026-10-13  8:20 ` [PATCH bpf-next v2 07/13] selftests/bpf: Test __arena " Kumar Kartikeya Dwivedi
2026-10-13  9:14   ` bot+bpf-ci
2026-10-13  9:19     ` Kumar Kartikeya Dwivedi
2026-10-13  8:20 ` [PATCH bpf-next v2 08/13] libbpf: Bind the arena of an object to every program in it Kumar Kartikeya Dwivedi
2026-10-13  9:14   ` bot+bpf-ci
2026-10-13  8:20 ` [PATCH bpf-next v2 09/13] selftests/bpf: Test arena binding by libbpf Kumar Kartikeya Dwivedi
2026-10-13  8:20 ` [PATCH bpf-next v2 10/13] bpf: Set up the arena base only in functions that use it Kumar Kartikeya Dwivedi
2026-10-13  8:20 ` [PATCH bpf-next v2 11/13] libbpf: Render the arena type tag with its address space Kumar Kartikeya Dwivedi
2026-10-13  8:20 ` [PATCH bpf-next v2 12/13] selftests/bpf: Test the address space rendering of the arena type tag Kumar Kartikeya Dwivedi
2026-10-13  8:20 ` [PATCH bpf-next v2 13/13] selftests/bpf: Test an arena kfunc argument passed from a subprogram Kumar Kartikeya Dwivedi

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=sashiko-outbox-169266@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