Skip to contentSkip to conversation

io_uring/kbuf: align legacy buffer add limit with MAX_BIDS_PER_BGID

PATCH Applied [email protected] 2 participants 2 messages May 28 io_uring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 io_uring/kbuf: align legacy buffer add limit with MAX_BIDS_PER_BGID

From: liyouhong <[email protected]>

io_provide_buffers_prep() accepts nbufs up to MAX_BIDS_PER_BGID, but io_add_buffers() stops when bl->nbufs reaches USHRT_MAX. This makes the effective add limit one lower than the validated limit.

Use MAX_BIDS_PER_BGID in the add-side boundary check so validation and execution use the same limit, and update the comment to refer to the actual limit constant.

---
 io_uring/kbuf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
io_uring/kbuf.c +2 -2
index 63061aa1cab9..6a619dee21c1 100644
@@ -541,11 +541,11 @@ static int io_add_buffers(struct io_ring_ctx *ctx, struct io_provide_buf *pbuf,
 
 	for (i = 0; i < pbuf->nbufs; i++) {
 		/*
-		 * Nonsensical to have more than sizeof(bid) buffers in a
+		 * Nonsensical to have more than MAX_BIDS_PER_BGID buffers in a
 		 * buffer list, as the application then has no way of knowing
 		 * which duplicate bid refers to what buffer.
 		 */
-		if (bl->nbufs == USHRT_MAX) {
+		if (bl->nbufs == MAX_BIDS_PER_BGID) {
 			ret = -EOVERFLOW;
 			break;
 		}
Signature · 1 line
2.25.1
maintainer Applied
#1 lore raw
Quoted 9 lines · On Thu, 28 May 2026 10:49:36 +0800, [email protected] wrote:

io_provide_buffers_prep() accepts nbufs up to MAX_BIDS_PER_BGID, but io_add_buffers() stops when bl->nbufs reaches USHRT_MAX. This makes the effective add limit one lower than the validated limit.

Use MAX_BIDS_PER_BGID in the add-side boundary check so validation and execution use the same limit, and update the comment to refer to the actual limit constant.

[...]

Applied, thanks!

[1/1] io_uring/kbuf: align legacy buffer add limit with MAX_BIDS_PER_BGID

      commit: ca55f98d6ff1ecb31a07b668a8d105b4e0829c6a

Best regards,

Signature · 1 line
Jens Axboe