[PATCH] io_uring/timeout: don't rearm a multishot timeout on cancel
From: Cheng Yongkang
Date: Sun Nov 15 2026 - 23:45:33 EST
io_timeout_complete() does not check tw.cancel. When it runs from
io_cancel_local_task_work(), a multishot timeout that has not reached
its count still posts an IORING_CQE_F_MORE completion and rearms its
timer. With a zero interval the timer expires again right away and
queues new task work, so the drain keeps running it until posting a
CQE fails.
Normally the CQ fills up quickly and the request then completes. But
if userspace moves the CQ head far ahead of the tail, for example to
cq.tail + 0x7fffffff, posting keeps succeeding and ring teardown is
delayed for a long time.
Don't post another CQE or rearm the timer when tw.cancel is set, so
the request completes through io_req_task_complete(), like the poll and
linked timeout task work does when cancelled.
Fixes: ea97f6c8558e ("io_uring: add support for multishot timeouts")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Cheng Yongkang <teel4res@xxxxxxxxx>
---
Report: https://lore.kernel.org/io-uring/20261115163547.225149-1-teel4res@xxxxxxxxx/
Runtime-tested on v7.3 with the reproducer from the report.
io_timeout_complete() is the same in io_uring-7.4, where it is only
build-tested.
io_uring/timeout.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/io_uring/timeout.c b/io_uring/timeout.c
index fa7b0d9a81d6..db78059cfeab 100644
--- a/io_uring/timeout.c
+++ b/io_uring/timeout.c
@@ -115,7 +115,8 @@ static void io_timeout_complete(struct io_tw_req tw_req, io_tw_token_t tw)
struct io_ring_ctx *ctx = req->ctx;
if (!io_timeout_finish(timeout, data)) {
- if (io_req_post_cqe(req, -ETIME, IORING_CQE_F_MORE)) {
+ if (!tw.cancel &&
+ io_req_post_cqe(req, -ETIME, IORING_CQE_F_MORE)) {
/* re-arm timer */
raw_spin_lock_irq(&ctx->timeout_lock);
list_add(&timeout->list, ctx->timeout_list.prev);
--
2.34.1