BPF List
 help / color / mirror / Atom feed
* [PATCH bpf] bpf: Reject kernel threads in bpf_task_work_schedule()
@ 2026-11-26  5:30 Sechang Lim
  2026-11-26  5:40 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Sechang Lim @ 2026-11-26  5:30 UTC (permalink / raw)
  To: bpf
  Cc: ast, daniel, andrii, eddyz87, memxor, martin.lau, song,
	yonghong.song, jolsa, emil, ihor.solodrai, yatsenko

bpf_task_work_schedule_signal() on a kernel thread sets
TIF_NOTIFY_SIGNAL, but the thread never returns to user space, so
nothing clears it and signal_pending() stays true. Interruptible sleeps
in the thread return immediately.

For kthreadd this means spinning at 100% CPU. io_ring_exit_work() waits
on ctx->ref_comp interruptibly, assuming a kworker gets no signals. If a
prog running in that kworker schedules task work on current, the wait
returns -ERESTARTSYS and the ctx is freed while ctx->refs is still
switching to atomic:

  WARNING: lib/percpu-refcount.c:114 at __percpu_ref_exit+0x77/0x110
  Workqueue: iou_exit io_ring_exit_work
  ...
  BUG: KASAN: slab-use-after-free in rcu_cblist_dequeue+0xd3/0x120

The callback can't run before the thread exits anyway. Reject kernel
threads with -EPERM, as bpf_send_signal() does.

Fixes: 38aa7003e369 ("bpf: task work scheduling kfuncs")
Signed-off-by: Sechang Lim <rhkrqnwk98@gmail.com>
---
 kernel/bpf/helpers.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
index bc0dd36a2799..42f3f7599567 100644
--- a/kernel/bpf/helpers.c
+++ b/kernel/bpf/helpers.c
@@ -4806,6 +4806,9 @@ static int bpf_task_work_schedule(struct task_struct *task, struct bpf_task_work
 
 	BTF_TYPE_EMIT(struct bpf_task_work);
 
+	if (task->flags & PF_KTHREAD)
+		return -EPERM;
+
 	prog = bpf_prog_inc_not_zero(aux->prog);
 	if (IS_ERR(prog))
 		return -EBADF;
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-26  5:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26  5:30 [PATCH bpf] bpf: Reject kernel threads in bpf_task_work_schedule() Sechang Lim
2026-11-26  5:40 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox