Skip to content

Commit 146eb58

Browse files
isilenceaxboe
authored andcommitted
io_uring: fix regbuf vector size truncation
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: stable@vger.kernel.org Fixes: 9ef4cbb ("io_uring: add infra for importing vectored reg buffers") Reported-by: Google Big Sleep <big-sleep-vuln-reports+bigsleep-458654612@google.com> Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Reviewed-by: Günther Noack <gnoack@google.com> Tested-by: Günther Noack <gnoack@google.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 1fd5367 commit 146eb58

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
@@ -1403,8 +1403,11 @@ static int io_estimate_bvec_size(struct iovec *iov, unsigned nr_iovs,
14031403
size_t max_segs = 0;
14041404
unsigned i;
14051405

1406-
for (i = 0; i < nr_iovs; i++)
1406+
for (i = 0; i < nr_iovs; i++) {
14071407
max_segs += (iov[i].iov_len >> shift) + 2;
1408+
if (max_segs > INT_MAX)
1409+
return -EOVERFLOW;
1410+
}
14081411
return max_segs;
14091412
}
14101413

@@ -1510,7 +1513,11 @@ int io_import_reg_vec(int ddir, struct iov_iter *iter,
15101513
if (unlikely(ret))
15111514
return ret;
15121515
} else {
1513-
nr_segs = io_estimate_bvec_size(iov, nr_iovs, imu);
1516+
int ret = io_estimate_bvec_size(iov, nr_iovs, imu);
1517+
1518+
if (ret < 0)
1519+
return ret;
1520+
nr_segs = ret;
15141521
}
15151522

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

0 commit comments

Comments
 (0)