Skip to contentSkip to conversation

bpf: Fix CFI mismatch in task work callback

PATCH Applied Mykyta Yatsenko 2 participants 2 messages Jul 24 BPF

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf: Fix CFI mismatch in task work callback

From: Mykyta Yatsenko <[email protected]>

BPF subprograms use the bpf_callback_t ABI, but task work invokes the callback through a three-argument function pointer. This trips kCFI.

Store and invoke the callback as bpf_callback_t.

Fixes 38aa7003e369 ("bpf: task work scheduling kfuncs")

---
The unpatched task_work selftest triggers a kCFI failure and kernel panic. With this patch, all task_work and task_work_stress subtests pass with CONFIG_CFI=y.

---
 kernel/bpf/helpers.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
kernel/bpf/helpers.c +5 -4
index c18f1e16edee..88b38db47de9 100644
@@ -4388,7 +4388,7 @@ struct bpf_task_work_ctx {
 	struct bpf_map *map;
 	void *map_val;
 	enum task_work_notify_mode mode;
-	bpf_task_work_callback_t callback_fn;
+	bpf_callback_t callback_fn;
 	struct rcu_head rcu;
 } __aligned(8);
 
@@ -4471,7 +4471,8 @@ static void bpf_task_work_callback(struct callback_head *cb)
 	key = (void *)map_key_from_value(ctx->map, ctx->map_val, &idx);
 
 	migrate_disable();
-	ctx->callback_fn(ctx->map, key, ctx->map_val);
+	ctx->callback_fn((u64)(long)ctx->map, (u64)(long)key,
+			 (u64)(long)ctx->map_val, 0, 0);
 	migrate_enable();
 
 	bpf_task_work_ctx_reset(ctx);
@@ -4594,7 +4595,7 @@ static struct bpf_task_work_ctx *bpf_task_work_acquire_ctx(struct bpf_task_work
 }
 
 static int bpf_task_work_schedule(struct task_struct *task, struct bpf_task_work *tw,
-				  struct bpf_map *map, bpf_task_work_callback_t callback_fn,
+				  struct bpf_map *map, void *callback_fn,
 				  struct bpf_prog_aux *aux, enum task_work_notify_mode mode)
 {
 	struct bpf_prog *prog;
@@ -4619,7 +4620,7 @@ static int bpf_task_work_schedule(struct task_struct *task, struct bpf_task_work
 	}
 
 	ctx->task = task;
-	ctx->callback_fn = callback_fn;
+	ctx->callback_fn = (bpf_callback_t)callback_fn;
 	ctx->prog = prog;
 	ctx->mode = mode;
 	ctx->map = map;

---
base-commit: c21669db988c8f7cc525198dd33941eec7f092fa
change-id: 20260724-task_work_cfi-5bd42ea2f62a

Best regards,

Signature · 1 line
Mykyta Yatsenko <[email protected]>
#1 lore raw
This patch was applied to bpf/bpf-next.git (master) by Kumar Kartikeya Dwivedi <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Kumar Kartikeya Dwivedi <[email protected]>:

Quoted 8 lines · On Fri, 24 Jul 2026 08:52:06 -0700 you wrote:

From: Mykyta Yatsenko <[email protected]>

BPF subprograms use the bpf_callback_t ABI, but task work invokes the callback through a three-argument function pointer. This trips kCFI.

Store and invoke the callback as bpf_callback_t.

[...]

Here is the summary with links:
- [bpf-next] bpf: Fix CFI mismatch in task work callback

    https://git.kernel.org/bpf/bpf-next/c/2805abd08957

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html