* [PATCH] io_uring: kiocb_done() should *not* trust ->ki_pos if ->{read,write}_iter() failed
@ 2023-10-26 2:18 Al Viro
2023-10-26 11:55 ` Christian Brauner
2023-10-26 13:46 ` Jens Axboe
0 siblings, 2 replies; 3+ messages in thread
From: Al Viro @ 2023-10-26 2:18 UTC (permalink / raw)
To: linux-fsdevel; +Cc: Jens Axboe, Christian Brauner
[in viro/vfs.git#fixes at the moment]
->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.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
io_uring/rw.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/io_uring/rw.c b/io_uring/rw.c
index c8c822fa7980..08d94fb972f0 100644
--- a/io_uring/rw.c
+++ b/io_uring/rw.c
@@ -339,7 +339,7 @@ static int kiocb_done(struct io_kiocb *req, ssize_t ret,
struct io_rw *rw = io_kiocb_to_cmd(req, struct io_rw);
unsigned final_ret = io_fixup_rw_res(req, ret);
- if (req->flags & REQ_F_CUR_POS)
+ if (ret >= 0 && req->flags & REQ_F_CUR_POS)
req->file->f_pos = rw->kiocb.ki_pos;
if (ret >= 0 && (rw->kiocb.ki_complete == io_complete_rw)) {
if (!__io_complete_rw_common(req, ret)) {
--
2.39.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] io_uring: kiocb_done() should *not* trust ->ki_pos if ->{read,write}_iter() failed
2023-10-26 2:18 [PATCH] io_uring: kiocb_done() should *not* trust ->ki_pos if ->{read,write}_iter() failed Al Viro
@ 2023-10-26 11:55 ` Christian Brauner
2023-10-26 13:46 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Christian Brauner @ 2023-10-26 11:55 UTC (permalink / raw)
To: Al Viro; +Cc: linux-fsdevel, Jens Axboe, Christian Brauner
On Thu, Oct 26, 2023 at 03:18:40AM +0100, Al Viro wrote:
> [in viro/vfs.git#fixes at the moment]
> ->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.
>
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
> ---
Looks good to me,
Reviewed-by: Christian Brauner <brauner@kernel.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] io_uring: kiocb_done() should *not* trust ->ki_pos if ->{read,write}_iter() failed
2023-10-26 2:18 [PATCH] io_uring: kiocb_done() should *not* trust ->ki_pos if ->{read,write}_iter() failed Al Viro
2023-10-26 11:55 ` Christian Brauner
@ 2023-10-26 13:46 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2023-10-26 13:46 UTC (permalink / raw)
To: Al Viro, linux-fsdevel; +Cc: Christian Brauner
On 10/25/23 8:18 PM, Al Viro wrote:
> [in viro/vfs.git#fixes at the moment]
> ->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.
Looks good, thanks Al:
Reviewed-by: Jens Axboe <axboe@kernel.dk>
or let me know if you want me to pick it up.
--
Jens Axboe
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-10-26 13:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-26 2:18 [PATCH] io_uring: kiocb_done() should *not* trust ->ki_pos if ->{read,write}_iter() failed Al Viro
2023-10-26 11:55 ` Christian Brauner
2023-10-26 13:46 ` Jens Axboe
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).