Skip to content

Commit f2320f1

Browse files
committed
io_uring/sqpoll: don't put task_struct on tctx setup failure
A recent commit moved the error handling of sqpoll thread and tctx failures into the thread itself, as part of fixing an issue. However, it missed that tctx allocation may also fail, and that io_sq_offload_create() does its own error handling for the task_struct in that case. Remove the manual task putting in io_sq_offload_create(), as io_sq_thread() will notice that the tctx did not get setup and hence it should put itself and exit. Reported-by: [email protected] Fixes: ac0b8b3 ("io_uring: fix use-after-free of sq->thread in __io_uring_show_fdinfo()") Signed-off-by: Jens Axboe <[email protected]>
1 parent 91a7703 commit f2320f1

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

io_uring/sqpoll.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,6 @@ void io_sqpoll_wait_sq(struct io_ring_ctx *ctx)
420420
__cold int io_sq_offload_create(struct io_ring_ctx *ctx,
421421
struct io_uring_params *p)
422422
{
423-
struct task_struct *task_to_put = NULL;
424423
int ret;
425424

426425
/* Retain compatibility with failing for an invalid attach attempt */
@@ -499,7 +498,7 @@ __cold int io_sq_offload_create(struct io_ring_ctx *ctx,
499498
rcu_assign_pointer(sqd->thread, tsk);
500499
mutex_unlock(&sqd->lock);
501500

502-
task_to_put = get_task_struct(tsk);
501+
get_task_struct(tsk);
503502
ret = io_uring_alloc_task_context(tsk, ctx);
504503
wake_up_new_task(tsk);
505504
if (ret)
@@ -514,8 +513,6 @@ __cold int io_sq_offload_create(struct io_ring_ctx *ctx,
514513
complete(&ctx->sq_data->exited);
515514
err:
516515
io_sq_thread_finish(ctx);
517-
if (task_to_put)
518-
put_task_struct(task_to_put);
519516
return ret;
520517
}
521518

0 commit comments

Comments
 (0)