1. 12 Jun, 2020 2 commits
  2. 11 Jun, 2020 6 commits
    • Ritesh Harjani's avatar
      ext4: mballoc: Use this_cpu_read instead of this_cpu_ptr · 81198536
      Ritesh Harjani authored
      Simplify reading a seq variable by directly using this_cpu_read API
      instead of doing this_cpu_ptr and then dereferencing it.
      
      This also avoid the below kernel BUG: which happens when
      CONFIG_DEBUG_PREEMPT is enabled
      
      BUG: using smp_processor_id() in preemptible [00000000] code: syz-fuzzer/6927
      caller is ext4_mb_new_blocks+0xa4d/0x3b70 fs/ext4/mballoc.c:4711
      CPU: 1 PID: 6927 Comm: syz-fuzzer Not tainted 5.7.0-next-20200602-syzkaller #0
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
      Call Trace:
       __dump_stack lib/dump_stack.c:77 [inline]
       dump_stack+0x18f/0x20d lib/dump_stack.c:118
       check_preemption_disabled+0x20d/0x220 lib/smp_processor_id.c:48
       ext4_mb_new_blocks+0xa4d/0x3b70 fs/ext4/mballoc.c:4711
       ext4_ext_map_blocks+0x201b/0x33e0 fs/ext4/extents.c:4244
       ext4_map_blocks+0x4cb/0x1640 fs/ext4/inode.c:626
       ext4_getblk+0xad/0x520 fs/ext4/inode.c:833
       ext4_bread+0x7c/0x380 fs/ext4/inode.c:883
       ext4_append+0x153/0x360 fs/ext4/namei.c:67
       ext4_init_new_dir fs/ext4/namei.c:2757 [inline]
       ext4_mkdir+0x5e0/0xdf0 fs/ext4/namei.c:2802
       vfs_mkdir+0x419/0x690 fs/namei.c:3632
       do_mkdirat+0x21e/0x280 fs/namei.c:3655
       do_syscall_64+0x60/0xe0 arch/x86/entry/common.c:359
       entry_SYSCALL_64_after_hwframe+0x44/0xa9
      
      Fixes: 42f56b7a4a7d ("ext4: mballoc: introduce pcpu seqcnt for freeing PA
      to improve ENOSPC handling")
      Suggested-by: default avatarBorislav Petkov <bp@alien8.de>
      Tested-by: default avatarMarek Szyprowski <m.szyprowski@samsung.com>
      Signed-off-by: default avatarRitesh Harjani <riteshh@linux.ibm.com>
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Reported-by: syzbot+82f324bb69744c5f6969@syzkaller.appspotmail.com
      Link: https://lore.kernel.org/r/534f275016296996f54ecf65168bb3392b6f653d.1591699601.git.riteshh@linux.ibm.comSigned-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
      81198536
    • Eric Biggers's avatar
      ext4: avoid utf8_strncasecmp() with unstable name · 2ce3ee93
      Eric Biggers authored
      If the dentry name passed to ->d_compare() fits in dentry::d_iname, then
      it may be concurrently modified by a rename.  This can cause undefined
      behavior (possibly out-of-bounds memory accesses or crashes) in
      utf8_strncasecmp(), since fs/unicode/ isn't written to handle strings
      that may be concurrently modified.
      
      Fix this by first copying the filename to a stack buffer if needed.
      This way we get a stable snapshot of the filename.
      
      Fixes: b886ee3e ("ext4: Support case-insensitive file name lookups")
      Cc: <stable@vger.kernel.org> # v5.2+
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: Daniel Rosenberg <drosen@google.com>
      Cc: Gabriel Krisman Bertazi <krisman@collabora.co.uk>
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Reviewed-by: default avatarAndreas Dilger <adilger@dilger.ca>
      Link: https://lore.kernel.org/r/20200601200543.59417-1-ebiggers@kernel.orgSigned-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
      2ce3ee93
    • yangerkun's avatar
      ext4: stop overwrite the errcode in ext4_setup_super · 5adaccac
      yangerkun authored
      Now the errcode from ext4_commit_super will overwrite EROFS exists in
      ext4_setup_super. Actually, no need to call ext4_commit_super since we
      will return EROFS. Fix it by goto done directly.
      
      Fixes: c89128a0 ("ext4: handle errors on ext4_commit_super")
      Signed-off-by: default avataryangerkun <yangerkun@huawei.com>
      Reviewed-by: default avatarJan Kara <jack@suse.cz>
      Link: https://lore.kernel.org/r/20200601073404.3712492-1-yangerkun@huawei.comSigned-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
      5adaccac
    • Jeffle Xu's avatar
      ext4: fix partial cluster initialization when splitting extent · cfb3c85a
      Jeffle Xu authored
      Fix the bug when calculating the physical block number of the first
      block in the split extent.
      
      This bug will cause xfstests shared/298 failure on ext4 with bigalloc
      enabled occasionally. Ext4 error messages indicate that previously freed
      blocks are being freed again, and the following fsck will fail due to
      the inconsistency of block bitmap and bg descriptor.
      
      The following is an example case:
      
      1. First, Initialize a ext4 filesystem with cluster size '16K', block size
      '4K', in which case, one cluster contains four blocks.
      
      2. Create one file (e.g., xxx.img) on this ext4 filesystem. Now the extent
      tree of this file is like:
      
      ...
      36864:[0]4:220160
      36868:[0]14332:145408
      51200:[0]2:231424
      ...
      
      3. Then execute PUNCH_HOLE fallocate on this file. The hole range is
      like:
      
      ..
      ext4_ext_remove_space: dev 254,16 ino 12 since 49506 end 49506 depth 1
      ext4_ext_remove_space: dev 254,16 ino 12 since 49544 end 49546 depth 1
      ext4_ext_remove_space: dev 254,16 ino 12 since 49605 end 49607 depth 1
      ...
      
      4. Then the extent tree of this file after punching is like
      
      ...
      49507:[0]37:158047
      49547:[0]58:158087
      ...
      
      5. Detailed procedure of punching hole [49544, 49546]
      
      5.1. The block address space:
      ```
      lblk        ~49505  49506   49507~49543     49544~49546    49547~
      	  ---------+------+-------------+----------------+--------
      	    extent | hole |   extent	|	hole	 | extent
      	  ---------+------+-------------+----------------+--------
      pblk       ~158045  158046  158047~158083  158084~158086   158087~
      ```
      
      5.2. The detailed layout of cluster 39521:
      ```
      		cluster 39521
      	<------------------------------->
      
      		hole		  extent
      	<----------------------><--------
      
      lblk      49544   49545   49546   49547
      	+-------+-------+-------+-------+
      	|	|	|	|	|
      	+-------+-------+-------+-------+
      pblk     158084  1580845  158086  158087
      ```
      
      5.3. The ftrace output when punching hole [49544, 49546]:
      - ext4_ext_remove_space (start 49544, end 49546)
        - ext4_ext_rm_leaf (start 49544, end 49546, last_extent [49507(158047), 40], partial [pclu 39522 lblk 0 state 2])
          - ext4_remove_blocks (extent [49507(158047), 40], from 49544 to 49546, partial [pclu 39522 lblk 0 state 2]
            - ext4_free_blocks: (block 158084 count 4)
              - ext4_mballoc_free (extent 1/6753/1)
      
      5.4. Ext4 error message in dmesg:
      EXT4-fs error (device vdb): mb_free_blocks:1457: group 1, block 158084:freeing already freed block (bit 6753); block bitmap corrupt.
      EXT4-fs error (device vdb): ext4_mb_generate_buddy:747: group 1, block bitmap and bg descriptor inconsistent: 19550 vs 19551 free clusters
      
      In this case, the whole cluster 39521 is freed mistakenly when freeing
      pblock 158084~158086 (i.e., the first three blocks of this cluster),
      although pblock 158087 (the last remaining block of this cluster) has
      not been freed yet.
      
      The root cause of this isuue is that, the pclu of the partial cluster is
      calculated mistakenly in ext4_ext_remove_space(). The correct
      partial_cluster.pclu (i.e., the cluster number of the first block in the
      next extent, that is, lblock 49597 (pblock 158086)) should be 39521 rather
      than 39522.
      
      Fixes: f4226d9e ("ext4: fix partial cluster initialization")
      Signed-off-by: default avatarJeffle Xu <jefflexu@linux.alibaba.com>
      Reviewed-by: default avatarEric Whitney <enwlinux@gmail.com>
      Cc: stable@kernel.org # v3.19+
      Link: https://lore.kernel.org/r/1590121124-37096-1-git-send-email-jefflexu@linux.alibaba.comSigned-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
      cfb3c85a
    • Theodore Ts'o's avatar
      ext4: avoid race conditions when remounting with options that change dax · 829b37b8
      Theodore Ts'o authored
      Trying to change dax mount options when remounting could allow mount
      options to be enabled for a small amount of time, and then the mount
      option change would be reverted.
      
      In the case of "mount -o remount,dax", this can cause a race where
      files would temporarily treated as DAX --- and then not.
      
      Cc: stable@kernel.org
      Reported-by: syzbot+bca9799bf129256190da@syzkaller.appspotmail.com
      Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
      829b37b8
    • Theodore Ts'o's avatar
      Enable ext4 support for per-file/directory dax operations · 68cd4492
      Theodore Ts'o authored
      This adds the same per-file/per-directory DAX support for ext4 as was
      done for xfs, now that we finally have consensus over what the
      interface should be.
      68cd4492
  3. 04 Jun, 2020 32 commits