summaryrefslogtreecommitdiffstats
path: root/io_uring
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2024-01-22 12:30:07 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2024-01-25 14:37:52 -0800
commit8c0b563e9b4d5a4bed51667816e487120d2eb696 (patch)
tree873bec05c98d3ed8db6c08ee8b4e944efd789fc7 /io_uring
parentdaa61bacd3b99e70b1259ef5075e9c2e8edf9a1f (diff)
downloadlinux-stable-8c0b563e9b4d5a4bed51667816e487120d2eb696.tar.gz
linux-stable-8c0b563e9b4d5a4bed51667816e487120d2eb696.tar.bz2
linux-stable-8c0b563e9b4d5a4bed51667816e487120d2eb696.zip
io_uring/rw: ensure io->bytes_done is always initialized
commit 0a535eddbe0dc1de4386046ab849f08aeb2f8faf upstream. If IOSQE_ASYNC is set and we fail importing an iovec for a readv or writev request, then we leave ->bytes_done uninitialized and hence the eventual failure CQE posted can potentially have a random res value rather than the expected -EINVAL. Setup ->bytes_done before potentially failing, so we have a consistent value if we fail the request early. Cc: stable@vger.kernel.org Reported-by: xingwei lee <xrivendell7@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'io_uring')
-rw-r--r--io_uring/io_uring.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index aa15e8d878a9..936abc6ee450 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -3485,14 +3485,17 @@ static inline int io_rw_prep_async(struct io_kiocb *req, int rw)
struct iovec *iov = iorw->fast_iov;
int ret;
+ iorw->bytes_done = 0;
+ iorw->free_iovec = NULL;
+
ret = io_import_iovec(rw, req, &iov, &iorw->iter, false);
if (unlikely(ret < 0))
return ret;
- iorw->bytes_done = 0;
- iorw->free_iovec = iov;
- if (iov)
+ if (iov) {
+ iorw->free_iovec = iov;
req->flags |= REQ_F_NEED_CLEANUP;
+ }
iov_iter_save_state(&iorw->iter, &iorw->iter_state);
return 0;
}