Skip to content

Commit 0a535ed

Browse files
committed
io_uring/rw: ensure io->bytes_done is always initialized
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: [email protected] Reported-by: xingwei lee <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 6e5e6d2 commit 0a535ed

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

io_uring/rw.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -589,15 +589,19 @@ static inline int io_rw_prep_async(struct io_kiocb *req, int rw)
589589
struct iovec *iov;
590590
int ret;
591591

592+
iorw->bytes_done = 0;
593+
iorw->free_iovec = NULL;
594+
592595
/* submission path, ->uring_lock should already be taken */
593596
ret = io_import_iovec(rw, req, &iov, &iorw->s, 0);
594597
if (unlikely(ret < 0))
595598
return ret;
596599

597-
iorw->bytes_done = 0;
598-
iorw->free_iovec = iov;
599-
if (iov)
600+
if (iov) {
601+
iorw->free_iovec = iov;
600602
req->flags |= REQ_F_NEED_CLEANUP;
603+
}
604+
601605
return 0;
602606
}
603607

0 commit comments

Comments
 (0)