]> git.kernelconcepts.de Git - karo-tx-linux.git/commit
ext4: fix races between buffered IO and collapse / insert range
authorJan Kara <jack@suse.com>
Mon, 7 Dec 2015 19:31:11 +0000 (14:31 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 4 May 2016 21:48:53 +0000 (14:48 -0700)
commit1f7b7e9a4ba3d60af27c78a149743d269e6fb848
treecb9ee904e0acda006be5403c3a51d6beb6e835d1
parente096ade68c13011ba6548a542c1fc00e14555f5c
ext4: fix races between buffered IO and collapse / insert range

commit 32ebffd3bbb4162da5ff88f9a35dd32d0a28ea70 upstream.

Current code implementing FALLOC_FL_COLLAPSE_RANGE and
FALLOC_FL_INSERT_RANGE is prone to races with buffered writes and page
faults. If buffered write or write via mmap manages to squeeze between
filemap_write_and_wait_range() and truncate_pagecache() in the fallocate
implementations, the written data is simply discarded by
truncate_pagecache() although it should have been shifted.

Fix the problem by moving filemap_write_and_wait_range() call inside
i_mutex and i_mmap_sem. That way we are protected against races with
both buffered writes and page faults.

Signed-off-by: Jan Kara <jack@suse.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/ext4/extents.c