Skip to content

Commit 826ce37

Browse files
isilencegregkh
authored andcommitted
io_uring: fix regbuf vector size truncation
commit 146eb58629f45f8297e83d69e64d4eea4b28d972 upstream. There is a report of io_estimate_bvec_size() truncating the calculated number of segments that leads to corruption issues. Check it doesn't overflow "int"s used later. Rough but simple, can be improved on top. Cc: [email protected] Fixes: 9ef4cbb ("io_uring: add infra for importing vectored reg buffers") Reported-by: Google Big Sleep <[email protected]> Signed-off-by: Pavel Begunkov <[email protected]> Reviewed-by: Günther Noack <[email protected]> Tested-by: Günther Noack <[email protected]> Signed-off-by: Jens Axboe <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c43fe1e commit 826ce37

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

io_uring/rsrc.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,8 +1402,11 @@ static int io_estimate_bvec_size(struct iovec *iov, unsigned nr_iovs,
14021402
size_t max_segs = 0;
14031403
unsigned i;
14041404

1405-
for (i = 0; i < nr_iovs; i++)
1405+
for (i = 0; i < nr_iovs; i++) {
14061406
max_segs += (iov[i].iov_len >> shift) + 2;
1407+
if (max_segs > INT_MAX)
1408+
return -EOVERFLOW;
1409+
}
14071410
return max_segs;
14081411
}
14091412

@@ -1509,7 +1512,11 @@ int io_import_reg_vec(int ddir, struct iov_iter *iter,
15091512
if (unlikely(ret))
15101513
return ret;
15111514
} else {
1512-
nr_segs = io_estimate_bvec_size(iov, nr_iovs, imu);
1515+
int ret = io_estimate_bvec_size(iov, nr_iovs, imu);
1516+
1517+
if (ret < 0)
1518+
return ret;
1519+
nr_segs = ret;
15131520
}
15141521

15151522
if (sizeof(struct bio_vec) > sizeof(struct iovec)) {

0 commit comments

Comments
 (0)