Patch "ext4: fix data corruption for mmap writes" has been added to the 4.4-stable tree
Subsystems (2)
This is a note to let you know that I've just added the patch titled
ext4: fix data corruption for mmap writes
to the 4.4-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
ext4-fix-data-corruption-for-mmap-writes.patch
and it can be found in the queue-4.4 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From
a056bdaae7a181f7dcc876cfab2f94538e508709Mon Sep 17 00:00:00 2001
From: Jan Kara <[email protected]>
Date: Fri, 26 May 2017 17:45:45 -0400
Subject: ext4: fix data corruption for mmap writes
From: Jan Kara <[email protected]>
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.
--- fs/ext4/inode.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)
fs/ext4/inode.c +19 -5
@@ -1946,15 +1946,29 @@ static int ext4_writepage(struct page *pstatic int mpage_submit_page (struct mpage_da_data *mpd,struct page *page) {int len; -loff_t size =i_size_read (mpd->inode); +loff_t size;int err;BUG_ON (page->index != mpd->first_page); -if (page->index == size >>PAGE_CACHE_SHIFT ) - len = size & ~PAGE_CACHE_MASK ; -else - len =PAGE_CACHE_SIZE ;clear_page_dirty_for_io (page); +/* +* We have to be very careful here! Nothing protects writeback path +* against i_size changes and the page can be writeably mapped into +* page tables. So an application can be growing i_size and writing +* data through mmap while writeback runs. clear_page_dirty_for_io() +* write-protects our page in page tables and the page cannot get +* written to again until we release page lock. So only after +* clear_page_dirty_for_io() we are safe to sample i_size for +* ext4_bio_write_page() to zero-out tail of the written page. We rely +* on the barrier provided by TestClearPageDirty in +* clear_page_dirty_for_io() to make sure i_size is really sampled only +* after page tables are updated. +*/ + size =i_size_read (mpd->inode); +if (page->index == size >>PAGE_SHIFT ) + len = size & ~PAGE_MASK ; +else + len =PAGE_SIZE ; err =ext4_bio_write_page (&mpd->io_submit, page, len, mpd->wbc, false);if (!err) mpd->wbc->nr_to_write--;
Patches currently in stable-queue which might be from [email protected] are
queue-4.4/ext4-fix-data-corruption-for-mmap-writes.patch queue-4.4/ext4-don-t-clear-sgid-when-inheriting-acls.patch