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 --- 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