Skip to contentSkip to conversation

io_uring/timeout: multishot timeout rearms during cancel drain

BUG Cheng Yongkang 2 participants 2 messages Nov 15 io_uring

lore
Share & tools
lore
#0 lore raw

Hi Jens,

I hit a corner case in io_timeout_complete(). It only shows up when userspace sets the CQ head to a bogus value, so it may not be worth fixing. I am reporting it in case you want the check.

io_timeout_complete() does not look at tw.cancel, unlike io_poll_check_events(), io_req_task_submit() and the linked timeout handler in the same file. During io_cancel_local_task_work(), a zero-interval multishot timeout still posts a CQE and rearms its timer, which queues new task work. The drain keeps running it until CQE posting fails.

Normally the CQ fills up quickly and the request then completes. But if userspace sets the CQ head to cq.tail + 0x7fffffff, posting keeps succeeding for about 2^31 CQEs. On v7.3 with DEFER_TASKRUN and 4096 such timeouts, the ring was still not freed 5 seconds after close.

Skipping the rearm when tw.cancel is set fixes it:

  -		if (io_req_post_cqe(req, -ETIME, IORING_CQE_F_MORE)) {
  +		if (!tw.cancel &&
  +		    io_req_post_cqe(req, -ETIME, IORING_CQE_F_MORE)) {

With this change the same test frees the ring in about 300 ms, and normal multishot timeouts behave as before. The code is unchanged in next-20261113. I can send a patch if you want one.

Thanks,
Cheng Yongkang

maintainer
#1 lore raw
Quoted 6 lines · Cheng Yongkang

Hi Jens,

I hit a corner case in io_timeout_complete(). It only shows up when userspace sets the CQ head to a bogus value, so it may not be worth fixing. I am reporting it in case you want the check.

For this and the other one, please send an actual patch. You already did the work.

—
Jens Axboe