[PATCH bpf v3 1/2] bpf: disable private stack for sleepable programs
Christian Simon <[email protected]>
| Newsgroups | org.kernel.vger.bpf,org.kernel.vger.stable |
|---|---|
| Message-ID | <[email protected]> |
A JITed BPF program can use one private stack per program and CPU.
Sleepable programs can be preempted, allowing another task to run the
same program on the same CPU. The second invocation then reuses and can
overwrite the first invocation's private stack.
Disable private stack for sleepable programs so they use the regular kernel
stack, which handles preemption correctly. This change is intentionally
limited to programs marked sleepable; preemptible non-sleepable dispatch
paths require separate protection.
Fixes: 7d1cd70d4b16 ("bpf, x86: Support private stack in jit")
Fixes: 6c17a882d380 ("bpf, arm64: JIT support for private stack")
Fixes: 156d985123b6 ("powerpc64/bpf: Implement JIT support for private stack")
Cc: [email protected]
Signed-off-by: Christian Simon <[email protected]>
---
kernel/bpf/verifier.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 5e37ca75e5c4..038753ef07a9 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -5237,6 +5237,15 @@ static enum priv_stack_mode bpf_enable_priv_stack(struct bpf_prog *prog)
if (!bpf_jit_supports_private_stack())
return NO_PRIV_STACK;
+ /*
+ * Sleepable programs can be preempted, allowing another task to run
+ * the same program on the same CPU. Since private stack is per-CPU
+ * and per-program, the second invocation would corrupt the first's
+ * stack. Disable private stack for sleepable programs.
+ */
+ if (prog->sleepable)
+ return NO_PRIV_STACK;
+
/* bpf_prog_check_recur() checks all prog types that use bpf trampoline
* while kprobe/tp/perf_event/raw_tp don't use trampoline hence checked
* explicitly.
--
2.54.0