• Y
    ext4: fix bug for rename with RENAME_WHITEOUT · e8025b2f
    yangerkun 提交于
    mainline inclusion
    from mainline-5.11-rc4
    commit 6b4b8e6b
    category: bugfix
    bugzilla: 46884
    CVE: NA
    ---------------------------
    
    We got a "deleted inode referenced" warning cross our fsstress test. The
    bug can be reproduced easily with following steps:
    
      cd /dev/shm
      mkdir test/
      fallocate -l 128M img
      mkfs.ext4 -b 1024 img
      mount img test/
      dd if=/dev/zero of=test/foo bs=1M count=128
      mkdir test/dir/ && cd test/dir/
      for ((i=0;i<1000;i++)); do touch file$i; done # consume all block
      cd ~ && renameat2(AT_FDCWD, /dev/shm/test/dir/file1, AT_FDCWD,
        /dev/shm/test/dir/dst_file, RENAME_WHITEOUT) # ext4_add_entry in
        ext4_rename will return ENOSPC!!
      cd /dev/shm/ && umount test/ && mount img test/ && ls -li test/dir/file1
      We will get the output:
      "ls: cannot access 'test/dir/file1': Structure needs cleaning"
      and the dmesg show:
      "EXT4-fs error (device loop0): ext4_lookup:1626: inode #2049: comm ls:
      deleted inode referenced: 139"
    
    ext4_rename will create a special inode for whiteout and use this 'ino'
    to replace the source file's dir entry 'ino'. Once error happens
    latter(the error above was the ENOSPC return from ext4_add_entry in
    ext4_rename since all space has been consumed), the cleanup do drop the
    nlink for whiteout, but forget to restore 'ino' with source file. This
    will trigger the bug describle as above.
    Signed-off-by: Nyangerkun <yangerkun@huawei.com>
    Reviewed-by: NJan Kara <jack@suse.cz>
    Cc: stable@vger.kernel.org
    Fixes: cd808dec ("ext4: support RENAME_WHITEOUT")
    Link: https://lore.kernel.org/r/20210105062857.3566-1-yangerkun@huawei.comSigned-off-by: NTheodore Ts'o <tytso@mit.edu>
    
    Conflicts:
    	fs/ext4/namei.c
    Signed-off-by: Nyangerkun <yangerkun@huawei.com>
    Reviewed-by: Nzhangyi (F) <yi.zhang@huawei.com>
    Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
    Signed-off-by: NCheng Jian <cj.chengjian@huawei.com>
    e8025b2f
namei.c 103.9 KB