Skip to content

Commit 1939316

Browse files
author
Al Viro
committed
io_uring: kiocb_done() should *not* trust ->ki_pos if ->{read,write}_iter() failed
->ki_pos value is unreliable in such cases. For an obvious example, consider O_DSYNC write - we feed the data to page cache and start IO, then we make sure it's completed. Update of ->ki_pos is dealt with by the first part; failure in the second ends up with negative value returned _and_ ->ki_pos left advanced as if sync had been successful. In the same situation write(2) does not advance the file position at all. Reviewed-by: Christian Brauner <[email protected]> Reviewed-by: Jens Axboe <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 1f36cd0 commit 1939316

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

io_uring/rw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ static int kiocb_done(struct io_kiocb *req, ssize_t ret,
339339
struct io_rw *rw = io_kiocb_to_cmd(req, struct io_rw);
340340
unsigned final_ret = io_fixup_rw_res(req, ret);
341341

342-
if (req->flags & REQ_F_CUR_POS)
342+
if (ret >= 0 && req->flags & REQ_F_CUR_POS)
343343
req->file->f_pos = rw->kiocb.ki_pos;
344344
if (ret >= 0 && (rw->kiocb.ki_complete == io_complete_rw)) {
345345
if (!__io_complete_rw_common(req, ret)) {

0 commit comments

Comments
 (0)