Skip to content

Commit 44eff40

Browse files
isilenceaxboe
authored andcommitted
io_uring: fix io_prep_async_link locking
io_prep_async_link() may be called after arming a linked timeout, automatically making it unsafe to traverse the linked list. Guard with completion_lock if there was a linked timeout. Cc: [email protected] # 5.9+ Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/93f7c617e2b4f012a2a175b3dab6bc2f27cebc48.1627304436.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent 991468d commit 44eff40

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

fs/io_uring.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -1279,8 +1279,17 @@ static void io_prep_async_link(struct io_kiocb *req)
12791279
{
12801280
struct io_kiocb *cur;
12811281

1282-
io_for_each_link(cur, req)
1283-
io_prep_async_work(cur);
1282+
if (req->flags & REQ_F_LINK_TIMEOUT) {
1283+
struct io_ring_ctx *ctx = req->ctx;
1284+
1285+
spin_lock_irq(&ctx->completion_lock);
1286+
io_for_each_link(cur, req)
1287+
io_prep_async_work(cur);
1288+
spin_unlock_irq(&ctx->completion_lock);
1289+
} else {
1290+
io_for_each_link(cur, req)
1291+
io_prep_async_work(cur);
1292+
}
12841293
}
12851294

12861295
static void io_queue_async_work(struct io_kiocb *req)

0 commit comments

Comments
 (0)