]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
io_uring/sqpoll: don't put task_struct on tctx setup failure
authorJens Axboe <axboe@kernel.dk>
Tue, 17 Jun 2025 12:43:18 +0000 (06:43 -0600)
committerJens Axboe <axboe@kernel.dk>
Tue, 17 Jun 2025 12:43:18 +0000 (06:43 -0600)
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>
io_uring/sqpoll.c

index fa5a6750ee524257e0d7cb525588d6c89cc9e5a2..a3f11349ce063e4fb5145f2fda937ff934cc3f9a 100644 (file)
@@ -420,7 +420,6 @@ void io_sqpoll_wait_sq(struct io_ring_ctx *ctx)
 __cold int io_sq_offload_create(struct io_ring_ctx *ctx,
                                struct io_uring_params *p)
 {
-       struct task_struct *task_to_put = NULL;
        int ret;
 
        /* Retain compatibility with failing for an invalid attach attempt */
@@ -499,7 +498,7 @@ __cold int io_sq_offload_create(struct io_ring_ctx *ctx,
                rcu_assign_pointer(sqd->thread, tsk);
                mutex_unlock(&sqd->lock);
 
-               task_to_put = get_task_struct(tsk);
+               get_task_struct(tsk);
                ret = io_uring_alloc_task_context(tsk, ctx);
                wake_up_new_task(tsk);
                if (ret)
@@ -514,8 +513,6 @@ err_sqpoll:
        complete(&ctx->sq_data->exited);
 err:
        io_sq_thread_finish(ctx);
-       if (task_to_put)
-               put_task_struct(task_to_put);
        return ret;
 }