[PATCH bpf-next v4 3/6] bpf: Link the async run context without writing to it
From: Mike Bazov via B4 Relay
Date: Mon Nov 30 2026 - 06:54:30 EST
From: Mike Bazov <mikeba@xxxxxxxxxxxxxxx>
bpf_run_async_cb() links bpf_async_run_ctx with bpf_set_run_ctx(). All
CPUs share that one frame. The next patch makes bpf_set_run_ctx() write
the outer frame into the frame it links, so callbacks that run on two
CPUs at once would overwrite each other's link, and a program that runs
inside a callback would follow it into another task's stack.
Set current->bpf_ctx directly instead, so that the frame is never
written. No functional change.
Signed-off-by: Mike Bazov <mikeba@xxxxxxxxxxxxxxx>
---
kernel/bpf/helpers.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
index f7ff82548f38..7156b4f41f43 100644
--- a/kernel/bpf/helpers.c
+++ b/kernel/bpf/helpers.c
@@ -1228,9 +1228,11 @@ struct bpf_run_ctx bpf_async_run_ctx;
static void bpf_run_async_cb(struct bpf_prog *prog, bpf_callback_t callback_fn,
struct bpf_map *map, void *key, void *value)
{
- struct bpf_run_ctx *old_ctx = bpf_set_run_ctx(&bpf_async_run_ctx);
+ struct bpf_run_ctx *old_ctx = READ_ONCE(current->bpf_ctx);
struct bpf_timed_may_goto saved;
+ /* All CPUs share bpf_async_run_ctx, so link it without writing to it */
+ WRITE_ONCE(current->bpf_ctx, &bpf_async_run_ctx);
bpf_timed_may_goto_save(prog, &saved);
callback_fn((u64)(long)map, (u64)(long)key, (u64)(long)value, 0, 0);
bpf_timed_may_goto_restore(prog, &saved);
--
2.43.0