Skip to contentSkip to conversation

Oversight in generic_file_aio_write_nolock

PATCH In review Oleg Drokin 2 participants 2 messages Apr 7, 2009 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Oversight in generic_file_aio_write_nolock

Hello!

There seems to be an oversight in generic_file_aio_write_nolock where when we open inode with O_SYNC and O_APPEND, then after we are done the writing, we flush wrong byterange from the file, from original offset for number of bytes written, instead from the actual oppended offset. This can lead to an unexpected data loss should the crash happen soon after such a write was performed.

Here is a simple fix, though perhaps we can just throw away the pos argument from the ->aio_write prototype eventually.

Bye,
Oleg

 filemap.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
filemap.c renamed from filemap.c.orig +2 -1
@@ -2420,7 +2420,8 @@
 	if (ret > 0 && ((file->f_flags & O_SYNC) || IS_SYNC(inode))) {
 		ssize_t err;
 
-		err = sync_page_range_nolock(inode, mapping, pos, ret);
+		err = sync_page_range_nolock(inode, mapping, iocb->ki_pos - ret,
+					     ret);
 		if (err < 0)
 			ret = err;
 	}
#1 lore raw
Quoted 11 lines · Oleg Drokin

Hello!

There seems to be an oversight in generic_file_aio_write_nolock where when we open inode with O_SYNC and O_APPEND, then after we are done the writing, we flush wrong byterange from the file, from original offset for number of bytes written, instead from the actual oppended offset. This can lead to an unexpected data loss should the crash happen soon after such a write was performed.

Here is a simple fix, though perhaps we can just throw away the pos argument from the ->aio_write prototype eventually.

Could I ask that you CC patches like this to linux-kernel also?

Jeff