Skip to content

Commit 3851d25

Browse files
committed
io_uring: check for rollover of buffer ID when providing buffers
We already check if the chosen starting offset for the buffer IDs fit within an unsigned short, as 65535 is the maximum value for a provided buffer. But if the caller asks to add N buffers at offset M, and M + N would exceed the size of the unsigned short, we simply add buffers with wrapping around the ID. This is not necessarily a bug and could in fact be a valid use case, but it seems confusing and inconsistent with the initial check for starting offset. Let's check for wrap consistently, and error the addition if we do need to wrap. Reported-by: Olivier Langlois <olivier@trillion01.com> Link: axboe/liburing#726 Cc: stable@vger.kernel.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 0fc8c2a commit 3851d25

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

io_uring/kbuf.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ int io_provide_buffers_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe
346346
tmp = READ_ONCE(sqe->off);
347347
if (tmp > USHRT_MAX)
348348
return -E2BIG;
349+
if (tmp + p->nbufs >= USHRT_MAX)
350+
return -EINVAL;
349351
p->bid = tmp;
350352
return 0;
351353
}

0 commit comments

Comments
 (0)