ext4: fix data corruption for mmap writes
authorJan Kara <jack@suse.cz>
Fri, 26 May 2017 21:45:45 +0000 (17:45 -0400)
committerBen Hutchings <ben@decadent.org.uk>
Fri, 15 Sep 2017 17:30:48 +0000 (18:30 +0100)
commit793736b192ee397205c24a424b3a5fa2ec82086b
treecc84d22ba0e2ac62c9c999b5e76cfee8f9362fa5
parent69615f190d3124cc5bf4cecbbfcb59e342572f26
ext4: fix data corruption for mmap writes

commit a056bdaae7a181f7dcc876cfab2f94538e508709 upstream.

mpage_submit_page() can race with another process growing i_size and
writing data via mmap to the written-back page. As mpage_submit_page()
samples i_size too early, it may happen that ext4_bio_write_page()
zeroes out too large tail of the page and thus corrupts user data.

Fix the problem by sampling i_size only after the page has been
write-protected in page tables by clear_page_dirty_for_io() call.

Reported-by: Michael Zimmer <michael@swarm64.com>
Fixes: cb20d5188366f04d96d2e07b1240cc92170ade40
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
[bwh: Backported to 3.2: The writeback path is very different here and
 it needs to read i_size long before calling clear_page_dirty_for_io().
 So read it twice and skip the page if it changed.]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
fs/ext4/inode.c