BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v1 2/9] bpf: Support __arena and __arena_nullable on struct_ops stub arguments
Date: Wed, 15 Jul 2026 22:22:19 +0000	[thread overview]
Message-ID: <20260715222220.194631F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260715220052.1590783-3-memxor@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] EXT (freplace) and TRACING (fentry/fexit) programs attached to struct_ops programs bypass defensive checks and `ctx_arg_info` inheritance, causing them to incorrectly verify arena pointers as trusted kernel pointers (`PTR_TO_BTF_ID`).
--

--- Patch [2]: [PATCH bpf-next v1 2/9] bpf: Support __arena and __arena_nullable on struct_ops stub arguments ---
commit 592a1abca0acd2ddc98e47619cf772faa71d7c0d
Author: Tejun Heo <tj@kernel.org>

bpf: Support __arena and __arena_nullable on struct_ops stub arguments

This patch adds support for the __arena and __arena_nullable suffixes on
struct_ops callback arguments. The trampoline automatically converts the
kernel pointer to an arena pointer when saving arguments, allowing the BPF
program to dereference it directly.

> diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c
> index 6eadf64f7ec90..56759891eab79 100644
> --- a/kernel/bpf/trampoline.c
> +++ b/kernel/bpf/trampoline.c

[ ... ]

> @@ -688,6 +736,22 @@ static int bpf_trampoline_update(struct bpf_trampoline *tr, bool lock_direct_mut
>  		goto out;
>  	}
>  
> +	/*
> +	 * Arena ctx args are converted only by the struct_ops indirect
> +	 * trampoline, which dispatches to a single known prog. Generic
> +	 * trampolines can mix progs with different arenas, so no conversion
> +	 * is possible here. Not reachable today: only struct_ops progs get
> +	 * arena ctx args and they never ride generic trampolines.
> +	 */
> +	for (kind = 0; kind < BPF_TRAMP_MAX; kind++) {
> +		for (i = 0; i < tnodes[kind].nr_nodes; i++) {
> +			if (bpf_prog_has_arena_ctx_arg(tnodes[kind].nodes[i]->link->prog)) {
> +				err = -ENOTSUPP;
> +				goto out;
> +			}
> +		}
> +	}

[Severity: Critical]
Will this defensive check be bypassed for FENTRY/EXT programs attached to
struct_ops programs?

When an FENTRY or EXT program attaches to a struct_ops program, it does not
inherit ctx_arg_info from its target in bpf_check_attach_target(). Because
the attaching program lacks ctx_arg_info, bpf_prog_has_arena_ctx_arg()
would return false here, allowing the attachment to proceed instead of
returning -ENOTSUPP.

If this check is bypassed, could the attaching FENTRY/EXT program evaluate
the argument as a standard PTR_TO_BTF_ID? Since the generic FENTRY
trampoline receives the already-converted, user-controlled arena offset from
the struct_ops caller, this might allow an attaching program to treat an
untrusted offset as a trusted kernel pointer.

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

  reply	other threads:[~2026-07-15 22:22 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-15 22:00 [PATCH bpf-next v1 0/9] Add arena argument support to kfuncs and struct_ops Kumar Kartikeya Dwivedi
2026-07-15 22:00 ` [PATCH bpf-next v1 1/9] bpf: Support __arena and __arena_nullable kfunc argument suffixes Kumar Kartikeya Dwivedi
2026-07-15 23:05   ` bot+bpf-ci
2026-07-16 11:31     ` Kumar Kartikeya Dwivedi
2026-07-15 22:00 ` [PATCH bpf-next v1 2/9] bpf: Support __arena and __arena_nullable on struct_ops stub arguments Kumar Kartikeya Dwivedi
2026-07-15 22:22   ` sashiko-bot [this message]
2026-07-15 22:00 ` [PATCH bpf-next v1 3/9] bpf, x86: JIT __arena kfunc argument rebasing Kumar Kartikeya Dwivedi
2026-07-15 22:00 ` [PATCH bpf-next v1 4/9] bpf, x86: Convert struct_ops arena arguments in the trampoline Kumar Kartikeya Dwivedi
2026-07-15 22:00 ` [PATCH bpf-next v1 5/9] selftests/bpf: Add kfunc __arena and __arena_nullable argument tests Kumar Kartikeya Dwivedi
2026-07-15 22:00 ` [PATCH bpf-next v1 6/9] selftests/bpf: Add JIT-sequence tests for __arena kfunc arguments Kumar Kartikeya Dwivedi
2026-07-15 22:00 ` [PATCH bpf-next v1 7/9] selftests/bpf: Add struct_ops __arena and __arena_nullable argument tests Kumar Kartikeya Dwivedi
2026-07-15 22:00 ` [PATCH bpf-next v1 8/9] bpf, x86: Fix stack-passed arguments for indirect trampolines Kumar Kartikeya Dwivedi
2026-07-15 22:14   ` sashiko-bot
2026-07-16 11:32     ` Kumar Kartikeya Dwivedi
2026-07-15 22:51   ` bot+bpf-ci
2026-07-15 22:00 ` [PATCH bpf-next v1 9/9] selftests/bpf: Test stack-passed struct_ops arena arguments 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=20260715222220.194631F000E9@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