add patch fix-potential-use-after-free-after-remounting-with-noblock_validity
[ext4-patch-queue.git] / fix-punch-hole-for-inline_data
blob6c38c619ae0ddc10dcd044d8099e290fd166e57a
1 ext4: fix punch hole for inline_data file systems
3 If a program attempts to punch a hole on an inline data file, we need
4 to convert it to a normal file first.
6 This was detected using ext4/032 using the adv configuration.  Simple
7 reproducer:
9 mke2fs -Fq -t ext4 -O inline_data /dev/vdc
10 mount /vdc
11 echo "" > /vdc/testfile
12 xfs_io -c 'truncate 33554432' /vdc/testfile
13 xfs_io -c 'fpunch 0 1048576' /vdc/testfile
14 umount /vdc
15 e2fsck -fy /dev/vdc
17 Cc: stable@vger.kernel.org
18 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
19 ---
20  fs/ext4/inode.c | 9 +++++++++
21  1 file changed, 9 insertions(+)
23 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
24 index 2b1c58da8d1e..e567f0229d4e 100644
25 --- a/fs/ext4/inode.c
26 +++ b/fs/ext4/inode.c
27 @@ -4236,6 +4236,15 @@ int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length)
29         trace_ext4_punch_hole(inode, offset, length, 0);
31 +       ext4_clear_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA);
32 +       if (ext4_has_inline_data(inode)) {
33 +               down_write(&EXT4_I(inode)->i_mmap_sem);
34 +               ret = ext4_convert_inline_data(inode);
35 +               up_write(&EXT4_I(inode)->i_mmap_sem);
36 +               if (ret)
37 +                       return ret;
38 +       }
40         /*
41          * Write out all dirty pages to avoid race conditions
42          * Then release them.