Skip to content

Commit 76a9088

Browse files
axboeopsiff
authored andcommitted
io_uring/sqpoll: don't put task_struct on tctx setup failure
[ Upstream commit f2320f1 ] 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: ac0b8b3 ("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> (cherry picked from commit 6b358b3adfb9b20ac38b55e5eb42cac5c18d6baa)
1 parent 1765b58 commit 76a9088

1 file changed

Lines changed: 1 addition & 4 deletions

File tree

io_uring/sqpoll.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,6 @@ void io_sqpoll_wait_sq(struct io_ring_ctx *ctx)
426426
__cold int io_sq_offload_create(struct io_ring_ctx *ctx,
427427
struct io_uring_params *p)
428428
{
429-
struct task_struct *task_to_put = NULL;
430429
int ret;
431430

432431
/* Retain compatibility with failing for an invalid attach attempt */
@@ -510,7 +509,7 @@ __cold int io_sq_offload_create(struct io_ring_ctx *ctx,
510509
rcu_assign_pointer(sqd->thread, tsk);
511510
mutex_unlock(&sqd->lock);
512511

513-
task_to_put = get_task_struct(tsk);
512+
get_task_struct(tsk);
514513
ret = io_uring_alloc_task_context(tsk, ctx);
515514
wake_up_new_task(tsk);
516515
if (ret)
@@ -525,8 +524,6 @@ __cold int io_sq_offload_create(struct io_ring_ctx *ctx,
525524
complete(&ctx->sq_data->exited);
526525
err:
527526
io_sq_thread_finish(ctx);
528-
if (task_to_put)
529-
put_task_struct(task_to_put);
530527
return ret;
531528
}
532529

0 commit comments

Comments
 (0)