Skip to content

Commit 50e932d

Browse files
axboesmb49
authored andcommitted
io_uring/sqpoll: don't put task_struct on tctx setup failure
BugLink: https://bugs.launchpad.net/bugs/2120812 [ Upstream commit f2320f1dd6f6f82cb2c7aff23a12bab537bdea89 ] 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: syzbot+763e12bbf004fb1062e4@syzkaller.appspotmail.com Fixes: ac0b8b327a56 ("io_uring: fix use-after-free of sq->thread in __io_uring_show_fdinfo()") Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Noah Wager <noah.wager@canonical.com> Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
1 parent a669138 commit 50e932d

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
@@ -419,7 +419,6 @@ void io_sqpoll_wait_sq(struct io_ring_ctx *ctx)
419419
__cold int io_sq_offload_create(struct io_ring_ctx *ctx,
420420
struct io_uring_params *p)
421421
{
422-
struct task_struct *task_to_put = NULL;
423422
int ret;
424423

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

501-
task_to_put = get_task_struct(tsk);
500+
get_task_struct(tsk);
502501
ret = io_uring_alloc_task_context(tsk, ctx);
503502
wake_up_new_task(tsk);
504503
if (ret)
@@ -513,8 +512,6 @@ __cold int io_sq_offload_create(struct io_ring_ctx *ctx,
513512
complete(&ctx->sq_data->exited);
514513
err:
515514
io_sq_thread_finish(ctx);
516-
if (task_to_put)
517-
put_task_struct(task_to_put);
518515
return ret;
519516
}
520517

0 commit comments

Comments
 (0)