Skip to contentSkip to conversation

io_uring: fix ltout double free on completion race

PATCH Applied Pavel Begunkov 2 participants 2 messages May 14, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

Fixes 90cd7e424969d ("io_uring: track link timeout's master explicitly")
Reported-and-tested-by [email protected]
---
 fs/io_uring.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
fs/io_uring.c +4 -3
index 9ac5e278a91e..599102cc6dfc 100644
@@ -6354,10 +6354,11 @@ static enum hrtimer_restart io_link_timeout_fn(struct hrtimer *timer)
 	 * We don't expect the list to be empty, that will only happen if we
 	 * race with the completion of the linked work.
 	 */
-	if (prev && req_ref_inc_not_zero(prev))
+	if (prev) {
 		io_remove_next_linked(prev);
-	else
-		prev = NULL;
+		if (!req_ref_inc_not_zero(prev))
+			prev = NULL;
+	}
 	spin_unlock_irqrestore(&ctx->completion_lock, flags);
 
 	if (prev) {
Signature · 1 line
2.31.1
maintainer Applied
#1 lore raw
Quoted 4 lines · Pavel Begunkov

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.

Applied, thanks.

Signature · 1 line
Jens Axboe