mirror of
https://gitee.com/bianbu-linux/linux-6.6
synced 2025-04-24 14:07:52 -04:00
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>
This commit is contained in:
parent
2c487fbf22
commit
c239b77ea4
1 changed files with 7 additions and 3 deletions
|
@ -549,15 +549,19 @@ static inline int io_rw_prep_async(struct io_kiocb *req, int rw)
|
||||||
struct iovec *iov;
|
struct iovec *iov;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
iorw->bytes_done = 0;
|
||||||
|
iorw->free_iovec = NULL;
|
||||||
|
|
||||||
/* submission path, ->uring_lock should already be taken */
|
/* submission path, ->uring_lock should already be taken */
|
||||||
ret = io_import_iovec(rw, req, &iov, &iorw->s, 0);
|
ret = io_import_iovec(rw, req, &iov, &iorw->s, 0);
|
||||||
if (unlikely(ret < 0))
|
if (unlikely(ret < 0))
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
iorw->bytes_done = 0;
|
if (iov) {
|
||||||
iorw->free_iovec = iov;
|
iorw->free_iovec = iov;
|
||||||
if (iov)
|
|
||||||
req->flags |= REQ_F_NEED_CLEANUP;
|
req->flags |= REQ_F_NEED_CLEANUP;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue