io_uring: kiocb_done() should *not* trust ->ki_pos if ->{read,write}_iter() failed
authorAl Viro <viro@zeniv.linux.org.uk>
Mon, 28 Aug 2023 22:47:31 +0000 (18:47 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 8 Nov 2023 13:11:02 +0000 (14:11 +0100)
commit9eab5008db6c98273acaa0e0dde0fdb25848217e
treeb8ba762ca7287e2d0f7c2a673be9c28dbcddfdb5
parented0ba37e7b9b2f9669d3ed0634356aef04ee0ef1
io_uring: kiocb_done() should *not* trust ->ki_pos if ->{read,write}_iter() failed

[ Upstream commit 1939316bf988f3e49a07d9c4dd6f660bf4daa53d ]

->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 <brauner@kernel.org>
Reviewed-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
io_uring/rw.c