]> git.ipfire.org Git - thirdparty/kernel/stable.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)
committerBen Hutchings <ben@decadent.org.uk>
Tue, 28 Apr 2020 18:02:20 +0000 (19:02 +0100)
commit8a76993a673d694c17cd6fd6d7d9fc323fe224d4
tree2220617b26d5c774387b636426cbf4dcba13a761
parent5c72decb78daa9e21cf0cc4d00c1fdfa70233719
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>
[bwh: Backported to 3.16: drop changes in ext4_insert_range()]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
fs/ext4/extents.c