* [PATCH] io_uring/timeout: don't rearm a multishot timeout on cancel
@ 2026-11-16 4:45 Cheng Yongkang
2026-11-17 2:41 ` Jens Axboe
2026-11-17 2:49 ` Jens Axboe
0 siblings, 2 replies; 5+ messages in thread
From: Cheng Yongkang @ 2026-11-16 4:45 UTC (permalink / raw)
To: Jens Axboe; +Cc: David Wei, io-uring, linux-kernel
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@vger.kernel.org
Signed-off-by: Cheng Yongkang <teel4res@gmail.com>
---
Report: https://lore.kernel.org/io-uring/20261115163547.225149-1-teel4res@gmail.com/
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
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] io_uring/timeout: don't rearm a multishot timeout on cancel
2026-11-16 4:45 [PATCH] io_uring/timeout: don't rearm a multishot timeout on cancel Cheng Yongkang
@ 2026-11-17 2:41 ` Jens Axboe
2026-11-17 2:46 ` Cheng Yongkang
2026-11-17 2:49 ` Jens Axboe
1 sibling, 1 reply; 5+ messages in thread
From: Jens Axboe @ 2026-11-17 2:41 UTC (permalink / raw)
To: Cheng Yongkang; +Cc: David Wei, io-uring, linux-kernel
On 11/15/26 9:45 PM, Cheng Yongkang wrote:
> 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.
But why would the app do that, to shoot itself in the foot?
I think the fix is fine, but the premise of it is very odd.
--
Jens Axboe
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] io_uring/timeout: don't rearm a multishot timeout on cancel
2026-11-17 2:41 ` Jens Axboe
@ 2026-11-17 2:46 ` Cheng Yongkang
2026-11-17 2:48 ` Jens Axboe
0 siblings, 1 reply; 5+ messages in thread
From: Cheng Yongkang @ 2026-11-17 2:46 UTC (permalink / raw)
To: Jens Axboe; +Cc: David Wei, io-uring, linux-kernel
On 11/16/26 7:41 PM, Jens Axboe wrote:
> But why would the app do that, to shoot itself in the foot?
>
> I think the fix is fine, but the premise of it is very odd.
Agreed, no sane app would do that. The only thing that made it look
worth fixing to me is where the cost lands. The drain runs from
io_ring_exit_work() after the task has closed the ring, so the time is
spent in a kworker holding uring_lock, and the app can no longer stop
it by being killed.
Without the bogus CQ head the timeout is still rearmed during cancel,
it just stops once the CQ is full, so the change mostly makes the
timeout handler skip the rearm like the other cancel paths do.
I can reword the commit message to lead with that instead, if you
prefer.
Thanks,
Cheng Yongkang
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] io_uring/timeout: don't rearm a multishot timeout on cancel
2026-11-17 2:46 ` Cheng Yongkang
@ 2026-11-17 2:48 ` Jens Axboe
0 siblings, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2026-11-17 2:48 UTC (permalink / raw)
To: Cheng Yongkang; +Cc: David Wei, io-uring, linux-kernel
On 11/16/26 7:46 PM, Cheng Yongkang wrote:
> On 11/16/26 7:41 PM, Jens Axboe wrote:
>> But why would the app do that, to shoot itself in the foot?
>>
>> I think the fix is fine, but the premise of it is very odd.
>
> Agreed, no sane app would do that. The only thing that made it look
> worth fixing to me is where the cost lands. The drain runs from
> io_ring_exit_work() after the task has closed the ring, so the time is
> spent in a kworker holding uring_lock, and the app can no longer stop
> it by being killed.
>
> Without the bogus CQ head the timeout is still rearmed during cancel,
> it just stops once the CQ is full, so the change mostly makes the
> timeout handler skip the rearm like the other cancel paths do.
>
> I can reword the commit message to lead with that instead, if you
> prefer.
No it's fine, I already queued it up. But it really reeks of odd
and bogus syzbot test case, it's most certainly not something
that any normal application would see.
--
Jens Axboe
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] io_uring/timeout: don't rearm a multishot timeout on cancel
2026-11-16 4:45 [PATCH] io_uring/timeout: don't rearm a multishot timeout on cancel Cheng Yongkang
2026-11-17 2:41 ` Jens Axboe
@ 2026-11-17 2:49 ` Jens Axboe
1 sibling, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2026-11-17 2:49 UTC (permalink / raw)
To: Cheng Yongkang; +Cc: David Wei, io-uring, linux-kernel
On Sun, 15 Nov 2026 20:45:19 -0800, Cheng Yongkang wrote:
> 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.
>
> [...]
Applied, thanks!
[1/1] io_uring/timeout: don't rearm a multishot timeout on cancel
(no commit info)
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-17 2:49 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16 4:45 [PATCH] io_uring/timeout: don't rearm a multishot timeout on cancel Cheng Yongkang
2026-11-17 2:41 ` Jens Axboe
2026-11-17 2:46 ` Cheng Yongkang
2026-11-17 2:48 ` Jens Axboe
2026-11-17 2:49 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®