diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2014-02-09 15:18:09 -0500 |
---|---|---|
committer | Jiri Slaby <jslaby@suse.cz> | 2014-12-03 11:58:41 +0100 |
commit | 79a423edd0ce526b6a28fd1fed4478d0ecda03e0 (patch) | |
tree | 4746b0e55a311b6cfe274b262534f70a1543348c /mm | |
parent | f39a6f3d592372cd369b6a04a8562f3e6f41ee47 (diff) |
fix O_SYNC|O_APPEND syncing the wrong range on write()
commit d311d79de305f1ada47cadd672e6ed1b28a949eb upstream.
It actually goes back to 2004 ([PATCH] Concurrent O_SYNC write support)
when sync_page_range() had been introduced; generic_file_write{,v}() correctly
synced
pos_after_write - written .. pos_after_write - 1
but generic_file_aio_write() synced
pos_before_write .. pos_before_write + written - 1
instead. Which is not the same thing with O_APPEND, obviously.
A couple of years later correct variant had been killed off when
everything switched to use of generic_file_aio_write().
All users of generic_file_aio_write() are affected, and the same bug
has been copied into other instances of ->aio_write().
The fix is trivial; the only subtle point is that generic_write_sync()
ought to be inlined to avoid calculations useless for the majority of
calls.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Diffstat (limited to 'mm')
-rw-r--r-- | mm/filemap.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/mm/filemap.c b/mm/filemap.c index b012daefc2d7..e94c70380deb 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2723,8 +2723,8 @@ ssize_t generic_file_aio_write(struct kiocb *iocb, const struct iovec *iov, if (ret > 0) { ssize_t err; - err = generic_write_sync(file, pos, ret); - if (err < 0 && ret > 0) + err = generic_write_sync(file, iocb->ki_pos - ret, ret); + if (err < 0) ret = err; } return ret; |