]> git.itanic.dy.fi Git - linux-stable/commitdiff
io_uring/rw: ensure io->bytes_done is always initialized
authorJens Axboe <axboe@kernel.dk>
Thu, 21 Dec 2023 15:49:18 +0000 (08:49 -0700)
committerJens Axboe <axboe@kernel.dk>
Thu, 21 Dec 2023 15:49:18 +0000 (08:49 -0700)
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>
io_uring/rw.c

index 4943d683508b4d1502594ceb7e27cf9453d51532..0c856726b15db330daf6470d3e8baea4d90ad17b 100644 (file)
@@ -589,15 +589,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;
 }