From: sashiko-bot@kernel.org
To: "Mike Bazov" <mikeba@sentinelone.com>, bpf@vger.kernel.org
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH bpf-next v5 3/5] bpf: Check program recursion per task via bpf_ctx
Date: Tue, 01 Dec 2026 16:05:49 +0000 [thread overview]
Message-ID: <sashiko-outbox-243640@kernel.org> (raw)
In-Reply-To: <20261201-bpf-preempt-v2-r2-v5-3-a6bb30daae35@sentinelone.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] bpf: per-CPU private stack corruption in tail-called struct_ops
progs
--
commit 2791d0c4355e1253047a56e8095c3bf4c6c3cf5f
Author: Mike Bazov <mikeba@sentinelone.com>
bpf: Check program recursion per task via bpf_ctx
This commit replaces per-CPU, per-program recursion counters with per-task
recursion tracking through current->bpf_ctx, while disabling preemption for
non-sleepable programs with prog->percpu_state set.
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index dd35abb37a236..2e3be7c112213 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -5434,7 +5434,8 @@ static enum priv_stack_mode bpf_enable_priv_stack(struct bpf_prog *prog)
> * program attached to both a syscall and a regular tracepoint. They always
> * use the task's kernel stack. Kprobe multi, kprobe session and perf_event
> * programs are serialized per CPU by bpf_prog_active, and struct_ops
> - * programs that request a private stack keep per-CPU recursion protection.
> + * programs that get a private stack run with preemption disabled, see
> + * bpf_prog_enter_run_ctx(). A sleepable one can't, so it gets none.
> */
> switch (prog->type) {
> case BPF_PROG_TYPE_KPROBE:
> @@ -5450,7 +5451,7 @@ static enum priv_stack_mode bpf_enable_priv_stack(struct bpf_prog *prog)
> case BPF_PROG_TYPE_PERF_EVENT:
> return PRIV_STACK_ADAPTIVE;
> case BPF_PROG_TYPE_STRUCT_OPS:
> - if (prog->aux->priv_stack_requested)
> + if (prog->aux->priv_stack_requested && !prog->sleepable)
> return PRIV_STACK_ADAPTIVE;
> fallthrough;
> default:
[Severity: High]
Can a tail-called struct_ops program run on its per-CPU private stack
without preemption disabled or recursion tracking, allowing two runs on
the same CPU to overwrite prog->aux->priv_stack_ptr?
When an entry struct_ops program calls bpf_tail_call,
check_max_stack_depth() disables its private stack (jits_use_priv_stack =
false) while check_helper_call() sets prog->percpu_state = true. However,
bpf_trampoline_enter() checks bpf_prog_check_recur(), which for
BPF_PROG_TYPE_STRUCT_OPS only tests prog->aux->jits_use_priv_stack:
include/linux/bpf_verifier.h:bpf_prog_check_recur() {
...
case BPF_PROG_TYPE_STRUCT_OPS:
return prog->aux->jits_use_priv_stack;
...
}
As a result, the entry program uses __bpf_prog_enter() instead of
__bpf_prog_enter_recur(), calling bpf_set_run_ctx() rather than
bpf_prog_enter_run_ctx(). If it tail-calls a second struct_ops program
that has no tail calls of its own and was allocated a per-CPU private
stack, the target executes on prog->aux->priv_stack_ptr with preemption
enabled and with run_ctx.prog left NULL (and even under
__bpf_prog_enter_recur(), run_ctx.prog records only the entry program, not
the tail-call target). Preemption or nested re-entry on the same CPU can
then enter the target program a second time and corrupt its active private
stack.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201-bpf-preempt-v2-r2-v5-0-a6bb30daae35@sentinelone.com?part=3
next prev parent reply other threads:[~2026-12-01 16:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 15:32 [PATCH bpf-next v5 0/5] bpf: Check recursion per task for preemptible programs Mike Bazov via B4 Relay
2026-12-01 15:32 ` [PATCH bpf-next v5 1/5] bpf: Avoid per-CPU private stack in preemptible tracing progs Mike Bazov via B4 Relay
2026-12-01 15:46 ` sashiko-bot
2026-12-01 15:32 ` [PATCH bpf-next v5 2/5] bpf: Mark programs that keep per-CPU state Mike Bazov via B4 Relay
2026-12-01 15:32 ` [PATCH bpf-next v5 3/5] bpf: Check program recursion per task via bpf_ctx Mike Bazov via B4 Relay
2026-12-01 16:05 ` sashiko-bot [this message]
2026-12-01 15:32 ` [PATCH bpf-next v5 4/5] bpf: Remove the per-CPU recursion counter of programs Mike Bazov via B4 Relay
2026-12-01 15:32 ` [PATCH bpf-next v5 5/5] selftests/bpf: Add preemption recursion test for tracing programs Mike Bazov via B4 Relay
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-243640@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mikeba@sentinelone.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