Re: [PATCH bpf-next v2 2/5] bpf: Check program recursion per task via bpf_ctx
From: Alexei Starovoitov
Date: Wed Nov 11 2026 - 20:12:04 EST
On Wed, Nov 11, 2026 at 11:39 AM Mike Bazov via B4 Relay <devnull+mikeba.sentinelone.com@xxxxxxxxxx> wrote:
> As a result, the same program can now run in two tasks at once on one
> CPU. Programs that use a per-CPU map as scratch space across helper
> calls may see another run's data, where the run was dropped before.
The kernel has such scratch space too: bpf_raw_tp_regs.
bpf_get_stack(), bpf_get_stackid() and bpf_perf_event_output() of fentry,
raw_tp and tp_btf progs take a slot of it with get_bpf_raw_tp_regs().
It doesn't disable preemption. Three tasks on one cpu:
task A task B task C
level 1, regs[0]
<preempted>
level 2, regs[1]
<preempted>
put: level 1
level 2, regs[1]
uses the regs of C
B sends a sample or a stack trace with the regs of C.
This is an existing bug. Today it takes two or more progs.
With this patch A, B and C can be in one prog.
Doesn't hold the series, but I had to mention.
> Fixes: ca06f55b9002 ("bpf: Add per-program recursion prevention mechanism")
> Fixes: a46023d5616e ("tracing: Guard __DECLARE_TRACE() use of __DO_TRACE_CALL() with SRCU-fast")
> Fixes: 439ebd5b5708 ("bpf: Add sleepable support for raw tracepoint programs")
I don't think we will be sending them to stable soon.
This is a big behavior change.
Backports only after next merge window.