Skip to content

Commit 20fb0dc

Browse files
axboegregkh
authored andcommitted
io_uring: zero iocb->ki_pos for stream file types
[ Upstream commit 7b9762a ] io_uring supports using offset == -1 for using the current file position, and we read that in as part of read/write command setup. For the non-iter read/write types we pass in NULL for the position pointer, but for the iter types we should not be passing any anything but 0 for the position for a stream. Clear kiocb->ki_pos if the file is a stream, don't leave it as -1. If we do, then the request will error with -ESPIPE. Fixes: ba04291 ("io_uring: allow use of offset == -1 to mean file position") Link: axboe/liburing#501 Reported-by: Samuel Williams <samuel.williams@oriontransfer.co.nz> Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 5cf0397 commit 20fb0dc

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

fs/io_uring.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2879,9 +2879,13 @@ static int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe,
28792879
req->flags |= REQ_F_ISREG;
28802880

28812881
kiocb->ki_pos = READ_ONCE(sqe->off);
2882-
if (kiocb->ki_pos == -1 && !(file->f_mode & FMODE_STREAM)) {
2883-
req->flags |= REQ_F_CUR_POS;
2884-
kiocb->ki_pos = file->f_pos;
2882+
if (kiocb->ki_pos == -1) {
2883+
if (!(file->f_mode & FMODE_STREAM)) {
2884+
req->flags |= REQ_F_CUR_POS;
2885+
kiocb->ki_pos = file->f_pos;
2886+
} else {
2887+
kiocb->ki_pos = 0;
2888+
}
28852889
}
28862890
kiocb->ki_hint = ki_hint_validate(file_write_hint(kiocb->ki_filp));
28872891
kiocb->ki_flags = iocb_flags(kiocb->ki_filp);

0 commit comments

Comments
 (0)