]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
io_uring/rw: ensure io->bytes_done is always initialized
authorJens Axboe <axboe@kernel.dk>
Mon, 22 Jan 2024 19:30:07 +0000 (12:30 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 25 Jan 2024 22:52:48 +0000 (14:52 -0800)
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>
io_uring/io_uring.c

index 30535d4edee7529da865c942234d83458411e4ce..55fd6d98fe121fcd04a7ba0770cec2ad402f4efa 100644 (file)
@@ -3490,14 +3490,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;
 }