Re: [PATCH bpf-next v12 2/6] bpf: Add bpf_prog_run_array_sleepable()

sashiko-bot
2026-04-22T22:02:31Z

Sashiko AI review found 1 potential issue(s):
- [Critical] Inverted RCU lock logic in bpf_prog_run_array_sleepable() causes use-after-free and 'sleeping in atomic' panics
--

commit bed1594e26a509b74cbf793566b3e03eca1cc31d
Author: Mykyta Yatsenko <yatsenko@meta.com>

bpf: Add bpf_prog_run_array_sleepable()

This commit adds a new function to run BPF program arrays on faultable
tracepoints. It includes per-program recursion checking for private stack
safety and identifies dummy placeholder programs by checking if the length
is zero.

> diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> index b4b703c90ca94..c909fee369c2d 100644
> --- a/include/linux/bpf.h
> +++ b/include/linux/bpf.h

[ ... ]

> @@ -3079,6 +3079,56 @@ void bpf_dynptr_set_null(struct bpf_dynptr_kern *ptr);
> void bpf_dynptr_set_rdonly(struct bpf_dynptr_kern *ptr);
> void bpf_prog_report_arena_violation(bool write, unsigned long addr, unsigned long fault_ip);
>
> +static __always_inline u32
> +bpf_prog_run_array_sleepable(const struct bpf_prog_array *array,
> + const void *ctx, bpf_prog_run_fn run_prog)
> +{

[ ... ]

> + run_ctx.bpf_cookie = item->bpf_cookie;
> +
> + if (prog->sleepable) {
> + guard(rcu)();
> + ret &= run_prog(prog, ctx);
> + } else {
> + ret &= run_prog(prog, ctx);
> + }

Should the guard(rcu)() logic be inverted here?

Sleepable BPF programs are permitted to block and sleep to handle page
faults, but holding the RCU read lock while sleeping is generally not
permitted and can lead to scheduling while atomic panics.

Conversely, executing non-sleepable BPF programs without the RCU read lock
could lead to use-after-free regressions, as they rely on the execution
environment holding the RCU lock to safely access RCU-protected memory and
dynamically sized maps.

Could this be changed to if (!prog->sleepable) to match the pattern used in
bpf_prog_run_array_uprobe()?

> +
> + bpf_prog_put_recursion_context(prog);
> + item++;
> + }
> + bpf_reset_run_ctx(old_run_ctx);
> + migrate_enable();
> + return ret;
> +}

--
Sashiko AI review · https://sashiko.dev/#/patchset/20260422-sleepable_tracepoints-v12-0-744bf0e3b311@meta.com?part=2