Skip to content

Commit 447c19f

Browse files
isilenceaxboe
authored andcommitted
io_uring: fix ltout double free on completion race
Always remove linked timeout on io_link_timeout_fn() from the master request link list, otherwise we may get use-after-free when first io_link_timeout_fn() puts linked timeout in the fail path, and then will be found and put on master's free. Cc: [email protected] # 5.10+ Fixes: 90cd7e4 ("io_uring: track link timeout's master explicitly") Reported-and-tested-by: [email protected] Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/69c46bf6ce37fec4fdcd98f0882e18eb07ce693a.1620990121.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent a298232 commit 447c19f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

fs/io_uring.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6354,10 +6354,11 @@ static enum hrtimer_restart io_link_timeout_fn(struct hrtimer *timer)
63546354
* We don't expect the list to be empty, that will only happen if we
63556355
* race with the completion of the linked work.
63566356
*/
6357-
if (prev && req_ref_inc_not_zero(prev))
6357+
if (prev) {
63586358
io_remove_next_linked(prev);
6359-
else
6360-
prev = NULL;
6359+
if (!req_ref_inc_not_zero(prev))
6360+
prev = NULL;
6361+
}
63616362
spin_unlock_irqrestore(&ctx->completion_lock, flags);
63626363

63636364
if (prev) {

0 commit comments

Comments
 (0)