[PATCH] io_uring/rsrc: reject overflowing regvec bvec byte counts
Jérémy Jean <[email protected]>
| Newsgroups | org.kernel.vger.io-uring |
|---|---|
| Message-ID | <[email protected]> |
io_import_reg_vec() converts the estimated number of bio_vec entries
into iovec-sized storage when struct bio_vec is larger than struct
iovec. The conversion still multiplies nr_segs by sizeof(struct
bio_vec) in size_t without checking for overflow.
On 32-bit kernels, a registered buffer large enough to make
io_estimate_bvec_size() return 357913942 segments wraps the byte count
from 0x100000008 to 8. io_vec_realloc() then reserves only the input
iovecs plus one extra slot while io_vec_fill_bvec() writes the full
bio_vec array.
Check both the multiplication and the rounding addition before
deriving the replacement iovec count.
Fixes: b4e41050b212 ("io_uring/rsrc: raise registered buffer 1GB limit")
Assisted-by: Codex:gpt-5
Signed-off-by: Jérémy Jean <[email protected]>
---
io_uring/rsrc.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
index 8d0f2ee24e0c..98dccefd801b 100644
--- a/io_uring/rsrc.c
+++ b/io_uring/rsrc.c
@@ -1653,8 +1653,12 @@ int io_import_reg_vec(int ddir, struct iov_iter *iter,
if (sizeof(struct bio_vec) > sizeof(struct iovec)) {
size_t bvec_bytes;
- bvec_bytes = nr_segs * sizeof(struct bio_vec);
- nr_segs = (bvec_bytes + sizeof(*iov) - 1) / sizeof(*iov);
+ if (check_mul_overflow((size_t)nr_segs, sizeof(struct bio_vec),
+ &bvec_bytes) ||
+ check_add_overflow(bvec_bytes, sizeof(*iov) - 1,
+ &bvec_bytes))
+ return -EOVERFLOW;
+ nr_segs = bvec_bytes / sizeof(*iov);
nr_segs += nr_iovs;
}
--
2.47.3