Skip to content

Commit 80120bb

Browse files
isilencegregkh
authored andcommitted
io_uring/sqpoll: fix sqpoll error handling races
commit e33ac68 upstream. BUG: KASAN: slab-use-after-free in __lock_acquire+0x370b/0x4a10 kernel/locking/lockdep.c:5089 Call Trace: <TASK> ... _raw_spin_lock_irqsave+0x3d/0x60 kernel/locking/spinlock.c:162 class_raw_spinlock_irqsave_constructor include/linux/spinlock.h:551 [inline] try_to_wake_up+0xb5/0x23c0 kernel/sched/core.c:4205 io_sq_thread_park+0xac/0xe0 io_uring/sqpoll.c:55 io_sq_thread_finish+0x6b/0x310 io_uring/sqpoll.c:96 io_sq_offload_create+0x162/0x11d0 io_uring/sqpoll.c:497 io_uring_create io_uring/io_uring.c:3724 [inline] io_uring_setup+0x1728/0x3230 io_uring/io_uring.c:3806 ... Kun Hu reports that the SQPOLL creating error path has UAF, which happens if io_uring_alloc_task_context() fails and then io_sq_thread() manages to run and complete before the rest of error handling code, which means io_sq_thread_finish() is looking at already killed task. Note that this is mostly theoretical, requiring fault injection on the allocation side to trigger in practice. Cc: [email protected] Reported-by: Kun Hu <[email protected]> Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/0f2f1aa5729332612bd01fe0f2f385fd1f06ce7c.1735231717.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 03041e4 commit 80120bb

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

io_uring/sqpoll.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ void io_sqpoll_wait_sq(struct io_ring_ctx *ctx)
352352
__cold int io_sq_offload_create(struct io_ring_ctx *ctx,
353353
struct io_uring_params *p)
354354
{
355+
struct task_struct *task_to_put = NULL;
355356
int ret;
356357

357358
/* Retain compatibility with failing for an invalid attach attempt */
@@ -432,6 +433,7 @@ __cold int io_sq_offload_create(struct io_ring_ctx *ctx,
432433
}
433434

434435
sqd->thread = tsk;
436+
task_to_put = get_task_struct(tsk);
435437
ret = io_uring_alloc_task_context(tsk, ctx);
436438
wake_up_new_task(tsk);
437439
if (ret)
@@ -442,11 +444,15 @@ __cold int io_sq_offload_create(struct io_ring_ctx *ctx,
442444
goto err;
443445
}
444446

447+
if (task_to_put)
448+
put_task_struct(task_to_put);
445449
return 0;
446450
err_sqpoll:
447451
complete(&ctx->sq_data->exited);
448452
err:
449453
io_sq_thread_finish(ctx);
454+
if (task_to_put)
455+
put_task_struct(task_to_put);
450456
return ret;
451457
}
452458

0 commit comments

Comments
 (0)