Skip to contentSkip to conversation

io_uring/wait: clamp min_events as unsigned

PATCH New Yichong Chen 1 participant 1 message Nov 24 io_uring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 io_uring/wait: clamp min_events as unsigned

io_cqring_wait() clamps min_events with min_t(int, ...), but io_uring_enter() passes the u32 min_complete straight in. Anything above INT_MAX is negative by then, so the clamp is a no-op and io_should_wake() reads cq.tail + min_events as a positive distance from cq.tail. The wait returns 0 with no events available instead of blocking for the clamped count; min_complete = 0xffffffff returns immediately, while 1 and INT_MAX block for the timeout as expected. Clamp as unsigned, as io_iopoll_check() already does.

Fixes 816619782bdc ("io_uring: move min_events sanitisation")
---
 io_uring/wait.c | 4 ++--
 io_uring/wait.h | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
io_uring/wait.c +2 -2
index fb1c082993a7..074cdf073ca7 100644
@@ -204,7 +204,7 @@ static inline int io_cqring_wait_schedule(struct io_ring_ctx *ctx,
  * Wait until events become available, if we don't already have some. The
  * application must reap them itself, as they reside on the shared cq ring.
  */
-int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, u32 flags,
+int io_cqring_wait(struct io_ring_ctx *ctx, unsigned int min_events, u32 flags,
 		   struct ext_arg *ext_arg)
 {
 	struct io_wait_queue iowq;
@@ -212,7 +212,7 @@ int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, u32 flags,
 	ktime_t start_time;
 	int ret, nr_wait;
 
-	min_events = min_t(int, min_events, ctx->cq_entries);
+	min_events = min(min_events, ctx->cq_entries);
 
 	if (!io_allowed_run_tw(ctx))
 		return -EEXIST;
io_uring/wait.h +1 -1
index eb5ae8a6fc94..07e1e9ea03cd 100644
@@ -38,7 +38,7 @@ struct ext_arg {
 	bool iowait;
 };
 
-int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, u32 flags,
+int io_cqring_wait(struct io_ring_ctx *ctx, unsigned int min_events, u32 flags,
 		   struct ext_arg *ext_arg);
 int io_run_task_work_sig(struct io_ring_ctx *ctx);
 void io_cqring_do_overflow_flush(struct io_ring_ctx *ctx);
Signature · 1 line
2.51.0