From: Jens Axboe <axboe@kernel.dk>
To: io-uring@vger.kernel.org
Cc: Chris Mason <mason@kernel.org>, Jens Axboe <axboe@kernel.dk>
Subject: [PATCH 06/10] io_uring/timeout: hold timeout_lock for the link splice
Date: Wed, 25 Nov 2026 11:43:15 -0700 [thread overview]
Message-ID: <20261125184439.58077-7-axboe@kernel.dk> (raw)
In-Reply-To: <20261125184439.58077-1-axboe@kernel.dk>
From: Chris Mason <mason@kernel.org>
The exit of a single thread that races with the close of its
IORING_SETUP_DEFER_TASKRUN ring can cause a use-after-free of a linked
timeout that has fired.
io-wq calls its match function under raw spinlocks, so there
io_match_task_safe() walks the link chain without ->uring_lock. It holds
->timeout_lock, which is enough only if a linked timeout leaves the
chain under that lock. But io_req_task_link_timeout() does the splice
under ->uring_lock alone. Once the ring is closed, the closing task runs
that task_work, and with a drain active the flush frees the request:
io_match_task_safe() io_cancel_local_task_work()
==================== ===========================
lock ->timeout_lock
io_match_linked()
req = head->link
lock ->uring_lock
io_req_task_link_timeout()
prev->link = req->link
io_req_task_complete()
io_submit_flush_completions()
io_free_batch_list()
io_queue_deferred()
__io_req_caches_free()
req = req->link
The fix used here is to hold ->timeout_lock as well for the splice,
which stays in task_work and under ->uring_lock.
Fixes: 49ae66eb8c27 ("io_uring: defer linked-timeout chain splice out of hrtimer context")
Signed-off-by: Chris Mason <mason@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
io_uring/timeout.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/io_uring/timeout.c b/io_uring/timeout.c
index db78059cfeab..46c01704b58f 100644
--- a/io_uring/timeout.c
+++ b/io_uring/timeout.c
@@ -392,11 +392,14 @@ static void io_req_task_link_timeout(struct io_tw_req tw_req, io_tw_token_t tw)
if (prev) {
/*
* splice the linked timeout out of prev's chain if the regular
- * completion path didn't already do it.
+ * completion path didn't already do it. io-wq cancellation
+ * walks the chain with only ->timeout_lock held.
*/
+ raw_spin_lock_irq(&req->ctx->timeout_lock);
if (prev->link == req)
prev->link = req->link;
req->link = NULL;
+ raw_spin_unlock_irq(&req->ctx->timeout_lock);
if (!tw.cancel) {
struct io_cancel_data cd = {
--
2.55.0
next prev parent reply other threads:[~2026-11-25 18:44 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 18:43 [PATCHSET 0/10] Various fixes Jens Axboe
2026-11-25 18:43 ` [PATCH 01/10] io_uring/net: don't copy msg_name on a recvmsg retry Jens Axboe
2026-11-25 18:43 ` [PATCH 02/10] io_uring/kbuf: clear REQ_F_BL_NO_RECYCLE on buffer put Jens Axboe
2026-11-25 18:43 ` [PATCH 03/10] io_uring: free the ring after a grace period Jens Axboe
2026-11-25 18:43 ` [PATCH 04/10] io_uring: free the ring from an RCU work Jens Axboe
2026-11-25 18:43 ` [PATCH 05/10] io_uring/filetable: don't install O_PATH files Jens Axboe
2026-11-25 18:43 ` Jens Axboe [this message]
2026-11-25 18:43 ` [PATCH 07/10] io_uring/cancel: always walk links under timeout_lock Jens Axboe
2026-11-25 18:43 ` [PATCH 08/10] io_uring/net: don't count the buffers of a send bundle Jens Axboe
2026-11-25 18:43 ` [PATCH 09/10] io_uring: drop cached task refs on ring release Jens Axboe
2026-11-25 18:43 ` [PATCH 10/10] io_uring/net: restore the cmsg buffer on recvmsg retry Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261125184439.58077-7-axboe@kernel.dk \
--to=axboe@kernel.dk \
--cc=io-uring@vger.kernel.org \
--cc=mason@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox