Skip to content

Commit e0ee967

Browse files
committed
io_uring/kbuf: sanitize peek buffer setup
Harden the buffer peeking a bit, by adding a sanity check for it having a valid size. Outside of that, arg->max_len is a size_t, though it's only ever set to a 32-bit value (as it's governed by MAX_RW_COUNT). Bump our needed check to a size_t so we know it fits. Finally, cap the calculated needed iov value to the PEEK_MAX_IMPORT, which is the maximum number of segments that should be peeked. Fixes: 35c8711 ("io_uring/kbuf: add helpers for getting/peeking multiple buffers") Signed-off-by: Jens Axboe <[email protected]>
1 parent 1fc2ac4 commit e0ee967

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

io_uring/kbuf.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,13 @@ static int io_ring_buffers_peek(struct io_kiocb *req, struct buf_sel_arg *arg,
218218

219219
buf = io_ring_head_to_buf(br, head, bl->mask);
220220
if (arg->max_len) {
221-
int needed;
221+
u32 len = READ_ONCE(buf->len);
222+
size_t needed;
222223

223-
needed = (arg->max_len + buf->len - 1) / buf->len;
224-
needed = min(needed, PEEK_MAX_IMPORT);
224+
if (unlikely(!len))
225+
return -ENOBUFS;
226+
needed = (arg->max_len + len - 1) / len;
227+
needed = min_not_zero(needed, (size_t) PEEK_MAX_IMPORT);
225228
if (nr_avail > needed)
226229
nr_avail = needed;
227230
}

0 commit comments

Comments
 (0)