Skip to content

Commit 0fef948

Browse files
committed
io_uring: make offset == -1 consistent with preadv2/pwritev2
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>
1 parent 00d23d5 commit 0fef948

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

fs/io_uring.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2866,6 +2866,11 @@ static ssize_t io_import_iovec(int rw, struct io_kiocb *req,
28662866
return iov_iter_count(&req->io->rw.iter);
28672867
}
28682868

2869+
static inline loff_t *io_kiocb_ppos(struct kiocb *kiocb)
2870+
{
2871+
return kiocb->ki_filp->f_mode & FMODE_STREAM ? NULL : &kiocb->ki_pos;
2872+
}
2873+
28692874
/*
28702875
* For files that don't have ->read_iter() and ->write_iter(), handle them
28712876
* by looping over ->read() or ->write() manually.
@@ -2901,10 +2906,10 @@ static ssize_t loop_rw_iter(int rw, struct file *file, struct kiocb *kiocb,
29012906

29022907
if (rw == READ) {
29032908
nr = file->f_op->read(file, iovec.iov_base,
2904-
iovec.iov_len, &kiocb->ki_pos);
2909+
iovec.iov_len, io_kiocb_ppos(kiocb));
29052910
} else {
29062911
nr = file->f_op->write(file, iovec.iov_base,
2907-
iovec.iov_len, &kiocb->ki_pos);
2912+
iovec.iov_len, io_kiocb_ppos(kiocb));
29082913
}
29092914

29102915
if (iov_iter_is_bvec(iter))
@@ -3139,7 +3144,7 @@ static int io_read(struct io_kiocb *req, bool force_nonblock,
31393144
goto copy_iov;
31403145

31413146
iov_count = iov_iter_count(iter);
3142-
ret = rw_verify_area(READ, req->file, &kiocb->ki_pos, iov_count);
3147+
ret = rw_verify_area(READ, req->file, io_kiocb_ppos(kiocb), iov_count);
31433148
if (unlikely(ret))
31443149
goto out_free;
31453150

@@ -3262,7 +3267,7 @@ static int io_write(struct io_kiocb *req, bool force_nonblock,
32623267
goto copy_iov;
32633268

32643269
iov_count = iov_iter_count(iter);
3265-
ret = rw_verify_area(WRITE, req->file, &kiocb->ki_pos, iov_count);
3270+
ret = rw_verify_area(WRITE, req->file, io_kiocb_ppos(kiocb), iov_count);
32663271
if (unlikely(ret))
32673272
goto out_free;
32683273

0 commit comments

Comments
 (0)