Skip to contentSkip to conversation

io_uring: check for user passing 0 nr_submit

PATCH Applied Pavel Begunkov 3 participants 5 messages Oct 16, 2025 – Oct 22, 2025 io_uring

v2 of 3 Applied Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 io_uring: check for user passing 0 nr_submit

io_submit_sqes() shouldn't be stepping into its main loop when there is nothing to submit, i.e. nr=0. Fix 0 submission queue entries checks, which should follow after all user input truncations.

Fixes 6962980947e2b ("io_uring: restructure submit sqes to_submit checks")

---

v2: split out of the series with extra tags, no functional changes

 io_uring/io_uring.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
io_uring/io_uring.c +3 -2
index 820ef0527666..ee04ab9bf968 100644
@@ -2422,10 +2422,11 @@ int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr)
 	unsigned int left;
 	int ret;
 
+	entries = min(nr, entries);
 	if (unlikely(!entries))
 		return 0;
-	/* make sure SQ entry isn't read before tail */
-	ret = left = min(nr, entries);
+
+	ret = left = entries;
 	io_get_task_refs(left);
 	io_submit_state_start(&ctx->submit_state, left);
 
Signature · 1 line
2.49.0
#1 lore raw
Quoted 3 lines · Pavel Begunkov

io_submit_sqes() shouldn't be stepping into its main loop when there is nothing to submit, i.e. nr=0. Fix 0 submission queue entries checks, which should follow after all user input truncations.

I see two callers of io_submit_sqes, and neither of them will pass 0 for nr. What am I missing?

-Jeff

Quoted 28 lines
Fixes 6962980947e2b ("io_uring: restructure submit sqes to_submit checks")

---

v2: split out of the series with extra tags, no functional changes

 io_uring/io_uring.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
io_uring/io_uring.c +3 -2
index 820ef0527666..ee04ab9bf968 100644
@@ -2422,10 +2422,11 @@ int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr)
 	unsigned int left;
 	int ret;
 
+	entries = min(nr, entries);
 	if (unlikely(!entries))
 		return 0;
-	/* make sure SQ entry isn't read before tail */
-	ret = left = min(nr, entries);
+
+	ret = left = entries;
 	io_get_task_refs(left);
 	io_submit_state_start(&ctx->submit_state, left);
#2 lore raw
Quoted 8 lines · Jeff Moyer
Quoted 3 lines · Pavel Begunkov

io_submit_sqes() shouldn't be stepping into its main loop when there is nothing to submit, i.e. nr=0. Fix 0 submission queue entries checks, which should follow after all user input truncations.

I see two callers of io_submit_sqes, and neither of them will pass 0 for nr. What am I missing?

You're right, we can drop the fixes/stable part. It's still good to have as it's handled not in the best way.

Quoted 28 lines
Quoted 27 lines
Fixes 6962980947e2b ("io_uring: restructure submit sqes to_submit checks")

---

v2: split out of the series with extra tags, no functional changes

  io_uring/io_uring.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
io_uring/io_uring.c +3 -2
index 820ef0527666..ee04ab9bf968 100644
@@ -2422,10 +2422,11 @@ int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr)
  	unsigned int left;
  	int ret;
 
+	entries = min(nr, entries);
  	if (unlikely(!entries))
  		return 0;
-	/* make sure SQ entry isn't read before tail */
-	ret = left = min(nr, entries);
+
+	ret = left = entries;
  	io_get_task_refs(left);
  	io_submit_state_start(&ctx->submit_state, left);
Signature · 1 line
Pavel Begunkov
#3 lore raw
Quoted 6 lines · Pavel Begunkov
Quoted 5 lines · Jeff Moyer
Quoted 3 lines · Pavel Begunkov

io_submit_sqes() shouldn't be stepping into its main loop when there is nothing to submit, i.e. nr=0. Fix 0 submission queue entries checks, which should follow after all user input truncations.

Quoted 6 lines
Quoted 3 lines

I see two callers of io_submit_sqes, and neither of them will pass 0 for
nr. What am I missing?

You're right, we can drop the fixes/stable part. It's still good to have as it's handled not in the best way.

Agreed.

Cheers,
Jeff

Quoted 29 lines
Quoted 29 lines
Quoted 28 lines
Fixes 6962980947e2b ("io_uring: restructure submit sqes to_submit checks")

---

v2: split out of the series with extra tags, no functional changes

  io_uring/io_uring.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
io_uring/io_uring.c +2 -2
index 820ef0527666..ee04ab9bf968 100644
@@ -2422,10 +2422,11 @@ int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr)
  	unsigned int left;
  	int ret;
  +	entries = min(nr, entries);
  	if (unlikely(!entries))
  		return 0;
-	/* make sure SQ entry isn't read before tail */
-	ret = left = min(nr, entries);
+
+	ret = left = entries;
  	io_get_task_refs(left);
  	io_submit_state_start(&ctx->submit_state, left);
maintainer Applied
#4 lore raw
In reply to Pavel Begunkov
Quoted 5 lines · Pavel Begunkov

io_submit_sqes() shouldn't be stepping into its main loop when there is nothing to submit, i.e. nr=0. Fix 0 submission queue entries checks, which should follow after all user input truncations.

Applied, thanks!

[1/1] io_uring: check for user passing 0 nr_submit

      commit: dde92a5026d81df1a146e9c243d09b27d1bf04bf

Best regards,

Signature · 1 line
Jens Axboe