]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ext4: unmap metadata when zeroing blocks
authorJan Kara <jack@suse.cz>
Fri, 30 Sep 2016 06:02:29 +0000 (02:02 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 22 Oct 2016 10:06:49 +0000 (12:06 +0200)
commit 9b623df614576680cadeaa4d7e0b5884de8f7c17 upstream.

When zeroing blocks for DAX allocations, we also have to unmap aliases
in the block device mappings.  Otherwise writeback can overwrite zeros
with stale data from block device page cache.

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

index 19acefad10b288695df352c8ce86812ebaeff31d..8fa01cbd74b33dc575947c582df7faa190f0e218 100644 (file)
@@ -647,11 +647,19 @@ found:
                /*
                 * We have to zeroout blocks before inserting them into extent
                 * status tree. Otherwise someone could look them up there and
-                * use them before they are really zeroed.
+                * use them before they are really zeroed. We also have to
+                * unmap metadata before zeroing as otherwise writeback can
+                * overwrite zeros with stale data from block device.
                 */
                if (flags & EXT4_GET_BLOCKS_ZERO &&
                    map->m_flags & EXT4_MAP_MAPPED &&
                    map->m_flags & EXT4_MAP_NEW) {
+                       ext4_lblk_t i;
+
+                       for (i = 0; i < map->m_len; i++) {
+                               unmap_underlying_metadata(inode->i_sb->s_bdev,
+                                                         map->m_pblk + i);
+                       }
                        ret = ext4_issue_zeroout(inode, map->m_lblk,
                                                 map->m_pblk, map->m_len);
                        if (ret) {