io_uring/rw: fix unexpected link breakage
authorPavel Begunkov <asml.silence@gmail.com>
Mon, 26 Sep 2022 23:44:39 +0000 (00:44 +0100)
committerJens Axboe <axboe@kernel.dk>
Tue, 27 Sep 2022 00:44:15 +0000 (18:44 -0600)
req->cqe.res is set in io_read() to the amount of bytes left to be done,
which is used to figure out whether to fail a read or not. However,
io_read() may do another without returning, and we stash the previous
value into ->bytes_done but forget to update cqe.res. Then we ask a read
to do strictly less than cqe.res but expect the return to be exactly
cqe.res.

Fix the bug by updating cqe.res for retries.

Cc: stable@vger.kernel.org
Reported-and-Tested-by: Beld Zhang <beldzhang@gmail.com>
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/3a1088440c7be98e5800267af922a67da0ef9f13.1664235732.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_uring/rw.c

index 59c92a4..ed14322 100644 (file)
@@ -793,6 +793,7 @@ int io_read(struct io_kiocb *req, unsigned int issue_flags)
                        return -EAGAIN;
                }
 
+               req->cqe.res = iov_iter_count(&s->iter);
                /*
                 * Now retry read with the IOCB_WAITQ parts set in the iocb. If
                 * we get -EIOCBQUEUED, then we'll get a notification when the