Skip to content

Commit fdacd09

Browse files
hagarhemgregkh
authored andcommitted
io_uring: fix possible deadlock in io_register_iowq_max_workers()
commit 73254a297c2dd094abec7c9efee32455ae875bdf upstream. The io_register_iowq_max_workers() function calls io_put_sq_data(), which acquires the sqd->lock without releasing the uring_lock. Similar to the commit 009ad9f ("io_uring: drop ctx->uring_lock before acquiring sqd->lock"), this can lead to a potential deadlock situation. To resolve this issue, the uring_lock is released before calling io_put_sq_data(), and then it is re-acquired after the function call. This change ensures that the locks are acquired in the correct order, preventing the possibility of a deadlock. Suggested-by: Maximilian Heyne <[email protected]> Signed-off-by: Hagar Hemdan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 9478355 commit fdacd09

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

io_uring/io_uring.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3921,8 +3921,10 @@ static __cold int io_register_iowq_max_workers(struct io_ring_ctx *ctx,
39213921
}
39223922

39233923
if (sqd) {
3924+
mutex_unlock(&ctx->uring_lock);
39243925
mutex_unlock(&sqd->lock);
39253926
io_put_sq_data(sqd);
3927+
mutex_lock(&ctx->uring_lock);
39263928
}
39273929

39283930
if (copy_to_user(arg, new_count, sizeof(new_count)))
@@ -3947,8 +3949,11 @@ static __cold int io_register_iowq_max_workers(struct io_ring_ctx *ctx,
39473949
return 0;
39483950
err:
39493951
if (sqd) {
3952+
mutex_unlock(&ctx->uring_lock);
39503953
mutex_unlock(&sqd->lock);
39513954
io_put_sq_data(sqd);
3955+
mutex_lock(&ctx->uring_lock);
3956+
39523957
}
39533958
return ret;
39543959
}

0 commit comments

Comments
 (0)