diff options
author | Jens Axboe <axboe@kernel.dk> | 2023-12-21 18:49:18 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2024-01-26 02:27:41 +0300 |
commit | d6cc8dd231b8f843217688a0cffd206d5140b0a6 (patch) | |
tree | ed8d18c05e7a8d25035aef53427ae201778f534e /io_uring | |
parent | c866866c795296d3637ab0d48a3d8a3ef5d6f4a3 (diff) | |
download | linux-d6cc8dd231b8f843217688a0cffd206d5140b0a6.tar.xz |
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/rw.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/io_uring/rw.c b/io_uring/rw.c index 0133db648d8e..038e6b13a749 100644 --- a/io_uring/rw.c +++ b/io_uring/rw.c @@ -534,15 +534,19 @@ static inline int io_rw_prep_async(struct io_kiocb *req, int rw) struct iovec *iov; int ret; + iorw->bytes_done = 0; + iorw->free_iovec = NULL; + /* submission path, ->uring_lock should already be taken */ ret = io_import_iovec(rw, req, &iov, &iorw->s, 0); 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; + } + return 0; } |