Skip to content

Commit

Permalink
io_uring: make offset == -1 consistent with preadv2/pwritev2
Browse files Browse the repository at this point in the history
[ Upstream commit 0fef948 ]

The man page for io_uring generally claims were consistent with what
preadv2 and pwritev2 accept, but turns out there's a slight discrepancy
in how offset == -1 is handled for pipes/streams. preadv doesn't allow
it, but preadv2 does. This currently causes io_uring to return -EINVAL
if that is attempted, but we should allow that as documented.

This change makes us consistent with preadv2/pwritev2 for just passing
in a NULL ppos for streams if the offset is -1.

Cc: stable@vger.kernel.org # v5.7+
Reported-by: Benedikt Ames <wisp3rwind@posteo.eu>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
axboe authored and gregkh committed Sep 3, 2020
1 parent 9ab83e1 commit e93fd7a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions fs/io_uring.c
Expand Up @@ -2518,6 +2518,11 @@ static ssize_t io_import_iovec(int rw, struct io_kiocb *req,
return import_iovec(rw, buf, sqe_len, UIO_FASTIOV, iovec, iter);
}

static inline loff_t *io_kiocb_ppos(struct kiocb *kiocb)
{
return kiocb->ki_filp->f_mode & FMODE_STREAM ? NULL : &kiocb->ki_pos;
}

/*
* For files that don't have ->read_iter() and ->write_iter(), handle them
* by looping over ->read() or ->write() manually.
Expand Down Expand Up @@ -2553,10 +2558,10 @@ static ssize_t loop_rw_iter(int rw, struct file *file, struct kiocb *kiocb,

if (rw == READ) {
nr = file->f_op->read(file, iovec.iov_base,
iovec.iov_len, &kiocb->ki_pos);
iovec.iov_len, io_kiocb_ppos(kiocb));
} else {
nr = file->f_op->write(file, iovec.iov_base,
iovec.iov_len, &kiocb->ki_pos);
iovec.iov_len, io_kiocb_ppos(kiocb));
}

if (iov_iter_is_bvec(iter))
Expand Down Expand Up @@ -2681,7 +2686,7 @@ static int io_read(struct io_kiocb *req, bool force_nonblock)
goto copy_iov;

iov_count = iov_iter_count(&iter);
ret = rw_verify_area(READ, req->file, &kiocb->ki_pos, iov_count);
ret = rw_verify_area(READ, req->file, io_kiocb_ppos(kiocb), iov_count);
if (!ret) {
ssize_t ret2;

Expand Down Expand Up @@ -2780,7 +2785,7 @@ static int io_write(struct io_kiocb *req, bool force_nonblock)
goto copy_iov;

iov_count = iov_iter_count(&iter);
ret = rw_verify_area(WRITE, req->file, &kiocb->ki_pos, iov_count);
ret = rw_verify_area(WRITE, req->file, io_kiocb_ppos(kiocb), iov_count);
if (!ret) {
ssize_t ret2;

Expand Down

0 comments on commit e93fd7a

Please sign in to comment.