From: David Laight <David.Laight@ACULAB.COM>
To: "'axboe@kernel.dk'" <axboe@kernel.dk>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] Fix io_read() and io_write() when io_import_fixed() is used.
Date: Tue, 4 Feb 2020 11:20:11 +0000 [thread overview]
Message-ID: <0cf51853bebe4c889e4d00e4bbc61fb3@AcuMS.aculab.com> (raw)
io_import_fixed() returns 0 on success so io_import_iovec() may
not return the length of the transfer.
Instead always use the value from iov_iter_count()
(Which is called at the same place.)
Fixes 9d93a3f5a (modded by 491381ce0) and 9e645e110.
Signed-off-by: David Laight <david.laight@aculab.com>
---
Spotted while working on another patch to change the return value
of import_iovec() to be the address of the memory to kfree().
fs/io_uring.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index bde73b1..28128aa 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -1376,7 +1376,7 @@ static int io_read(struct io_kiocb *req, const struct sqe_submit *s,
struct iov_iter iter;
struct file *file;
size_t iov_count;
- ssize_t read_size, ret;
+ ssize_t ret;
ret = io_prep_rw(req, s, force_nonblock);
if (ret)
@@ -1390,11 +1390,10 @@ static int io_read(struct io_kiocb *req, const struct sqe_submit *s,
if (ret < 0)
return ret;
- read_size = ret;
+ iov_count = iov_iter_count(&iter);
if (req->flags & REQ_F_LINK)
- req->result = read_size;
+ req->result = iov_count;
- iov_count = iov_iter_count(&iter);
ret = rw_verify_area(READ, file, &kiocb->ki_pos, iov_count);
if (!ret) {
ssize_t ret2;
@@ -1414,7 +1413,7 @@ static int io_read(struct io_kiocb *req, const struct sqe_submit *s,
*/
if (force_nonblock && !(req->flags & REQ_F_NOWAIT) &&
(req->flags & REQ_F_ISREG) &&
- ret2 > 0 && ret2 < read_size)
+ ret2 > 0 && ret2 < iov_count)
ret2 = -EAGAIN;
/* Catch -EAGAIN return for forced non-blocking submission */
if (!force_nonblock || ret2 != -EAGAIN) {
@@ -1455,10 +1454,9 @@ static int io_write(struct io_kiocb *req, const struct sqe_submit *s,
if (ret < 0)
return ret;
- if (req->flags & REQ_F_LINK)
- req->result = ret;
-
iov_count = iov_iter_count(&iter);
+ if (req->flags & REQ_F_LINK)
+ req->result = iov_count;
ret = -EAGAIN;
if (force_nonblock && !(kiocb->ki_flags & IOCB_DIRECT)) {
--
1.8.1.2
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next reply other threads:[~2020-02-04 11:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-04 11:20 David Laight [this message]
2020-02-04 14:01 ` [PATCH] Fix io_read() and io_write() when io_import_fixed() is used Jens Axboe
2020-02-04 14:05 ` David Laight
2020-02-04 14:07 ` Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0cf51853bebe4c889e4d00e4bbc61fb3@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=axboe@kernel.dk \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).