io_uring: revert consumed iov_iter bytes on error
authorJens Axboe <axboe@kernel.dk>
Mon, 24 Aug 2020 23:04:12 +0000 (17:04 -0600)
committerJens Axboe <axboe@kernel.dk>
Mon, 24 Aug 2020 23:05:36 +0000 (17:05 -0600)
commitb5ddc6a9b603eb4588e885b03e565e5df1d0a09d
tree44331f4d6312caa31278e33d9169a97570c84099
parent13dd21a7461a137c741e48582a7ddb7c7152078d
io_uring: revert consumed iov_iter bytes on error

Some consumers of the iov_iter will return an error, but still have
bytes consumed in the iterator. This is an issue for -EAGAIN, since we
rely on a sane iov_iter state across retries.

Fix this by ensuring that we revert consumed bytes, if any, if the file
operations have consumed any bytes from iterator. This is similar to what
generic_file_read_iter() does, and is always safe as we have the previous
bytes count handy already.

Fixes: ff6165b2d7f6 ("io_uring: retain iov_iter state over io_read/io_write calls")
Reported-by: Dmitry Shulyak <yashulyak@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
fs/io_uring.c