cifs: fix writeback race with file that is growing
authorJeff Layton <jlayton@redhat.com>
Mon, 26 Nov 2012 14:48:41 +0000 (09:48 -0500)
committerSteve French <smfrench@gmail.com>
Tue, 27 Nov 2012 19:46:12 +0000 (13:46 -0600)
commit3a98b8614312026d489e56c1d0e294a68e2aad77
tree19230b635db898db1ca0661cbc4170fca9bccade
parent5e351cdc998db82935d1248a053a1be37d1160fd
cifs: fix writeback race with file that is growing

Commit eddb079deb4 created a regression in the writepages codepath.
Previously, whenever it needed to check the size of the file, it did so
by consulting the inode->i_size field directly. With that patch, the
i_size was fetched once on entry into the writepages code and that value
was used henceforth.

If the file is changing size though (for instance, if someone is writing
to it or has truncated it), then that value is likely to be wrong. This
can lead to data corruption. Pages past the EOF at the time that the
writepages call was issued may be silently dropped and ignored because
cifs_writepages wrongly assumes that the file must have been truncated
in the interim.

Fix cifs_writepages to properly fetch the size from the inode->i_size
field instead to properly account for this possibility.

Original bug report is here:

    https://bugzilla.kernel.org/show_bug.cgi?id=50991

Reported-and-Tested-by: Maxim Britov <ungifted01@gmail.com>
Reviewed-by: Suresh Jayaraman <sjayaraman@suse.com>
Signed-off-by: Jeff Layton <jlayton@redhat.com>
Signed-off-by: Steve French <smfrench@gmail.com>
fs/cifs/file.c