Commit 75769e3f authored by Pavel Begunkov's avatar Pavel Begunkov Committed by Jens Axboe

io_uring: improve import_fixed overflow checks

Replace a hand-coded overflow check with a specialised function. Even
though compilers are smart enough to generate identical binary (i.e.
check carry bit), but it's more foolproof and conveys the intention
better.
Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/e437dcdc929bacbb6f11a4824ecbbf17225cb82a.1617287883.git.asml.silence@gmail.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 0aec38fd
...@@ -2785,8 +2785,8 @@ static int io_import_fixed(struct io_kiocb *req, int rw, struct iov_iter *iter) ...@@ -2785,8 +2785,8 @@ static int io_import_fixed(struct io_kiocb *req, int rw, struct iov_iter *iter)
size_t len = req->rw.len; size_t len = req->rw.len;
struct io_mapped_ubuf *imu; struct io_mapped_ubuf *imu;
u16 index, buf_index = req->buf_index; u16 index, buf_index = req->buf_index;
u64 buf_end, buf_addr = req->rw.addr;
size_t offset; size_t offset;
u64 buf_addr;
if (unlikely(buf_index >= ctx->nr_user_bufs)) if (unlikely(buf_index >= ctx->nr_user_bufs))
return -EFAULT; return -EFAULT;
...@@ -2794,11 +2794,10 @@ static int io_import_fixed(struct io_kiocb *req, int rw, struct iov_iter *iter) ...@@ -2794,11 +2794,10 @@ static int io_import_fixed(struct io_kiocb *req, int rw, struct iov_iter *iter)
imu = &ctx->user_bufs[index]; imu = &ctx->user_bufs[index];
buf_addr = req->rw.addr; buf_addr = req->rw.addr;
/* overflow */ if (unlikely(check_add_overflow(buf_addr, (u64)len, &buf_end)))
if (buf_addr + len < buf_addr)
return -EFAULT; return -EFAULT;
/* not inside the mapped region */ /* not inside the mapped region */
if (buf_addr < imu->ubuf || buf_addr + len > imu->ubuf + imu->len) if (buf_addr < imu->ubuf || buf_end > imu->ubuf + imu->len)
return -EFAULT; return -EFAULT;
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment