1. 29 3月, 2023 2 次提交
  2. 22 3月, 2023 1 次提交
    • D
      ext4: fix another off-by-one fsmap error on 1k block filesystems · 9c07e0e5
      Darrick J. Wong 提交于
      mainline inclusion
      from mainline-v6.3-rc2
      commit c993799b
      category: bugfix
      bugzilla: 188522,https://gitee.com/openeuler/kernel/issues/I6N7ZP
      CVE: NA
      
      Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c993799baf9c5861f8df91beb80e1611b12efcbd
      
      --------------------------------
      
      Apparently syzbot figured out that issuing this FSMAP call:
      
      struct fsmap_head cmd = {
      	.fmh_count	= ...;
      	.fmh_keys	= {
      		{ .fmr_device = /* ext4 dev */, .fmr_physical = 0, },
      		{ .fmr_device = /* ext4 dev */, .fmr_physical = 0, },
      	},
      ...
      };
      ret = ioctl(fd, FS_IOC_GETFSMAP, &cmd);
      
      Produces this crash if the underlying filesystem is a 1k-block ext4
      filesystem:
      
      kernel BUG at fs/ext4/ext4.h:3331!
      invalid opcode: 0000 [#1] PREEMPT SMP
      CPU: 3 PID: 3227965 Comm: xfs_io Tainted: G        W  O       6.2.0-rc8-achx
      Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.15.0-1 04/01/2014
      RIP: 0010:ext4_mb_load_buddy_gfp+0x47c/0x570 [ext4]
      RSP: 0018:ffffc90007c03998 EFLAGS: 00010246
      RAX: ffff888004978000 RBX: ffffc90007c03a20 RCX: ffff888041618000
      RDX: 0000000000000000 RSI: 00000000000005a4 RDI: ffffffffa0c99b11
      RBP: ffff888012330000 R08: ffffffffa0c2b7d0 R09: 0000000000000400
      R10: ffffc90007c03950 R11: 0000000000000000 R12: 0000000000000001
      R13: 00000000ffffffff R14: 0000000000000c40 R15: ffff88802678c398
      FS:  00007fdf2020c880(0000) GS:ffff88807e100000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 00007ffd318a5fe8 CR3: 000000007f80f001 CR4: 00000000001706e0
      Call Trace:
       <TASK>
       ext4_mballoc_query_range+0x4b/0x210 [ext4 dfa189daddffe8fecd3cdfd00564e0f265a8ab80]
       ext4_getfsmap_datadev+0x713/0x890 [ext4 dfa189daddffe8fecd3cdfd00564e0f265a8ab80]
       ext4_getfsmap+0x2b7/0x330 [ext4 dfa189daddffe8fecd3cdfd00564e0f265a8ab80]
       ext4_ioc_getfsmap+0x153/0x2b0 [ext4 dfa189daddffe8fecd3cdfd00564e0f265a8ab80]
       __ext4_ioctl+0x2a7/0x17e0 [ext4 dfa189daddffe8fecd3cdfd00564e0f265a8ab80]
       __x64_sys_ioctl+0x82/0xa0
       do_syscall_64+0x2b/0x80
       entry_SYSCALL_64_after_hwframe+0x46/0xb0
      RIP: 0033:0x7fdf20558aff
      RSP: 002b:00007ffd318a9e30 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
      RAX: ffffffffffffffda RBX: 00000000000200c0 RCX: 00007fdf20558aff
      RDX: 00007fdf1feb2010 RSI: 00000000c0c0583b RDI: 0000000000000003
      RBP: 00005625c0634be0 R08: 00005625c0634c40 R09: 0000000000000001
      R10: 0000000000000000 R11: 0000000000000246 R12: 00007fdf1feb2010
      R13: 00005625be70d994 R14: 0000000000000800 R15: 0000000000000000
      
      For GETFSMAP calls, the caller selects a physical block device by
      writing its block number into fsmap_head.fmh_keys[01].fmr_device.
      To query mappings for a subrange of the device, the starting byte of the
      range is written to fsmap_head.fmh_keys[0].fmr_physical and the last
      byte of the range goes in fsmap_head.fmh_keys[1].fmr_physical.
      
      IOWs, to query what mappings overlap with bytes 3-14 of /dev/sda, you'd
      set the inputs as follows:
      
      	fmh_keys[0] = { .fmr_device = major(8, 0), .fmr_physical = 3},
      	fmh_keys[1] = { .fmr_device = major(8, 0), .fmr_physical = 14},
      
      Which would return you whatever is mapped in the 12 bytes starting at
      physical offset 3.
      
      The crash is due to insufficient range validation of keys[1] in
      ext4_getfsmap_datadev.  On 1k-block filesystems, block 0 is not part of
      the filesystem, which means that s_first_data_block is nonzero.
      ext4_get_group_no_and_offset subtracts this quantity from the blocknr
      argument before cracking it into a group number and a block number
      within a group.  IOWs, block group 0 spans blocks 1-8192 (1-based)
      instead of 0-8191 (0-based) like what happens with larger blocksizes.
      
      The net result of this encoding is that blocknr < s_first_data_block is
      not a valid input to this function.  The end_fsb variable is set from
      the keys that are copied from userspace, which means that in the above
      example, its value is zero.  That leads to an underflow here:
      
      	blocknr = blocknr - le32_to_cpu(es->s_first_data_block);
      
      The division then operates on -1:
      
      	offset = do_div(blocknr, EXT4_BLOCKS_PER_GROUP(sb)) >>
      		EXT4_SB(sb)->s_cluster_bits;
      
      Leaving an impossibly large group number (2^32-1) in blocknr.
      ext4_getfsmap_check_keys checked that keys[0].fmr_physical and
      keys[1].fmr_physical are in increasing order, but
      ext4_getfsmap_datadev adjusts keys[0].fmr_physical to be at least
      s_first_data_block.  This implies that we have to check it again after
      the adjustment, which is the piece that I forgot.
      
      Reported-by: syzbot+6be2b977c89f79b6b153@syzkaller.appspotmail.com
      Fixes: 4a495624 ("ext4: fix off-by-one fsmap error on 1k block filesystems")
      Link: https://syzkaller.appspot.com/bug?id=79d5768e9bfe362911ac1a5057a36fc6b5c30002
      Cc: stable@vger.kernel.org
      Signed-off-by: NDarrick J. Wong <djwong@kernel.org>
      Link: https://lore.kernel.org/r/Y+58NPTH7VNGgzdd@magnoliaSigned-off-by: NTheodore Ts'o <tytso@mit.edu>
      Signed-off-by: NBaokun Li <libaokun1@huawei.com>
      Reviewed-by: NZhihao Cheng <chengzhihao1@huawei.com>
      Reviewed-by: NZhang Yi <yi.zhang@huawei.com>
      Signed-off-by: NJialin Zhang <zhangjialin11@huawei.com>
      9c07e0e5
  3. 15 3月, 2023 2 次提交
    • Y
      ext4: fix WARNING in mb_find_extent · 7dec118b
      Ye Bin 提交于
      maillist inclusion
      category: bugfix
      bugzilla: https://gitee.com/src-openeuler/kernel/issues/I6K53I
      
      Reference: https://patchwork.ozlabs.org/project/linux-ext4/patch/20230116020015.1506120-1-yebin@huaweicloud.com/
      
      --------------------------------
      
      Syzbot found the following issue:
      
      EXT4-fs: Warning: mounting with data=journal disables delayed allocation, dioread_nolock, O_DIRECT and fast_commit support!
      EXT4-fs (loop0): orphan cleanup on readonly fs
      ------------[ cut here ]------------
      WARNING: CPU: 1 PID: 5067 at fs/ext4/mballoc.c:1869 mb_find_extent+0x8a1/0xe30
      Modules linked in:
      CPU: 1 PID: 5067 Comm: syz-executor307 Not tainted 6.2.0-rc1-syzkaller #0
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/26/2022
      RIP: 0010:mb_find_extent+0x8a1/0xe30 fs/ext4/mballoc.c:1869
      RSP: 0018:ffffc90003c9e098 EFLAGS: 00010293
      RAX: ffffffff82405731 RBX: 0000000000000041 RCX: ffff8880783457c0
      RDX: 0000000000000000 RSI: 0000000000000041 RDI: 0000000000000040
      RBP: 0000000000000040 R08: ffffffff82405723 R09: ffffed10053c9402
      R10: ffffed10053c9402 R11: 1ffff110053c9401 R12: 0000000000000000
      R13: ffffc90003c9e538 R14: dffffc0000000000 R15: ffffc90003c9e2cc
      FS:  0000555556665300(0000) GS:ffff8880b9900000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 000056312f6796f8 CR3: 0000000022437000 CR4: 00000000003506e0
      DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
      DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
      Call Trace:
       <TASK>
       ext4_mb_complex_scan_group+0x353/0x1100 fs/ext4/mballoc.c:2307
       ext4_mb_regular_allocator+0x1533/0x3860 fs/ext4/mballoc.c:2735
       ext4_mb_new_blocks+0xddf/0x3db0 fs/ext4/mballoc.c:5605
       ext4_ext_map_blocks+0x1868/0x6880 fs/ext4/extents.c:4286
       ext4_map_blocks+0xa49/0x1cc0 fs/ext4/inode.c:651
       ext4_getblk+0x1b9/0x770 fs/ext4/inode.c:864
       ext4_bread+0x2a/0x170 fs/ext4/inode.c:920
       ext4_quota_write+0x225/0x570 fs/ext4/super.c:7105
       write_blk fs/quota/quota_tree.c:64 [inline]
       get_free_dqblk+0x34a/0x6d0 fs/quota/quota_tree.c:130
       do_insert_tree+0x26b/0x1aa0 fs/quota/quota_tree.c:340
       do_insert_tree+0x722/0x1aa0 fs/quota/quota_tree.c:375
       do_insert_tree+0x722/0x1aa0 fs/quota/quota_tree.c:375
       do_insert_tree+0x722/0x1aa0 fs/quota/quota_tree.c:375
       dq_insert_tree fs/quota/quota_tree.c:401 [inline]
       qtree_write_dquot+0x3b6/0x530 fs/quota/quota_tree.c:420
       v2_write_dquot+0x11b/0x190 fs/quota/quota_v2.c:358
       dquot_acquire+0x348/0x670 fs/quota/dquot.c:444
       ext4_acquire_dquot+0x2dc/0x400 fs/ext4/super.c:6740
       dqget+0x999/0xdc0 fs/quota/dquot.c:914
       __dquot_initialize+0x3d0/0xcf0 fs/quota/dquot.c:1492
       ext4_process_orphan+0x57/0x2d0 fs/ext4/orphan.c:329
       ext4_orphan_cleanup+0xb60/0x1340 fs/ext4/orphan.c:474
       __ext4_fill_super fs/ext4/super.c:5516 [inline]
       ext4_fill_super+0x81cd/0x8700 fs/ext4/super.c:5644
       get_tree_bdev+0x400/0x620 fs/super.c:1282
       vfs_get_tree+0x88/0x270 fs/super.c:1489
       do_new_mount+0x289/0xad0 fs/namespace.c:3145
       do_mount fs/namespace.c:3488 [inline]
       __do_sys_mount fs/namespace.c:3697 [inline]
       __se_sys_mount+0x2d3/0x3c0 fs/namespace.c:3674
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd
      
      Add some debug information:
      mb_find_extent: mb_find_extent block=41, order=0 needed=64 next=0 ex=0/41/1@3735929054 64 64 7
      block_bitmap: ff 3f 0c 00 fc 01 00 00 d2 3d 00 00 00 00 00 00 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
      
      Acctually, blocks per group is 64, but block bitmap indicate at least has
      128 blocks. Now, ext4_validate_block_bitmap() didn't check invalid block's
      bitmap if set.
      To resolve above issue, add check like fsck "Padding at end of block bitmap is
      not set".
      
      Reported-by: syzbot+68223fe9f6c95ad43bed@syzkaller.appspotmail.com
      Signed-off-by: NYe Bin <yebin10@huawei.com>
      Reviewed-by: NJan Kara <jack@suse.cz>
      Signed-off-by: NZhihao Cheng <chengzhihao1@huawei.com>
      Reviewed-by: NYang Erkun <yangerkun@huawei.com>
      Reviewed-by: NHou Tao <houtao1@huawei.com>
      Signed-off-by: NJialin Zhang <zhangjialin11@huawei.com>
      7dec118b
    • Z
      ext4: fix incorrect options show of original mount_opt and extend mount_opt2 · 2b59ae5e
      Zhang Yi 提交于
      maillist inclusion
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I6D5XF
      
      Reference: https://lore.kernel.org/linux-ext4/20230130111138.76tp6pij3yhh4brh@quack3/T/#t
      
      --------------------------------
      
      Current _ext4_show_options() do not distinguish MOPT_2 flag, so it mixed
      extend sbi->s_mount_opt2 options with sbi->s_mount_opt, it could lead to
      show incorrect options, e.g. show fc_debug_force if we mount with
      errors=continue mode and miss it if we set.
      
        $ mkfs.ext4 /dev/pmem0
        $ mount -o errors=remount-ro /dev/pmem0 /mnt
        $ cat /proc/fs/ext4/pmem0/options | grep fc_debug_force
          #empty
        $ mount -o remount,errors=continue /mnt
        $ cat /proc/fs/ext4/pmem0/options | grep fc_debug_force
          fc_debug_force
        $ mount -o remount,errors=remount-ro,fc_debug_force /mnt
        $ cat /proc/fs/ext4/pmem0/options | grep fc_debug_force
          #empty
      
      Fixes: 995a3ed6 ("ext4: add fast_commit feature and handling for extended mount options")
      Signed-off-by: NZhang Yi <yi.zhang@huawei.com>
      
      Conflict:
        fs/ext4/super.c
      Reviewed-by: NZhihao Cheng <chengzhihao1@huawei.com>
      Reviewed-by: NZhang Xiaoxu <zhangxiaoxu5@huawei.com>
      Signed-off-by: NJialin Zhang <zhangjialin11@huawei.com>
      2b59ae5e
  4. 08 2月, 2023 2 次提交
  5. 11 1月, 2023 1 次提交
  6. 07 12月, 2022 2 次提交
  7. 26 11月, 2022 2 次提交
  8. 18 11月, 2022 3 次提交
  9. 07 11月, 2022 1 次提交
    • Y
      ext4: record error information when insert extent failed in 'ext4_split_extent_at' · 7425f87b
      Ye Bin 提交于
      hulk inclusion
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I5ZHOZ
      CVE: NA
      
      --------------------------------
      
      There's issue as follows when do test with memory fault injection:
      [localhost]# fsck.ext4 -a image
      image: clean, 45595/655360 files, 466841/2621440 blocks
      [localhost]# fsck.ext4 -fn image
      Pass 1: Checking inodes, blocks, and sizes
      Pass 2: Checking directory structure
      Pass 3: Checking directory connectivity
      Pass 4: Checking reference counts
      Pass 5: Checking group summary information
      Block bitmap differences:  -(1457230--1457256)
      Fix? no
      
      image: ********** WARNING: Filesystem still has errors **********
      
      image: 45595/655360 files (12.4% non-contiguous), 466841/2621440 blocks
      
      Inject context:
       -----------------------------------------------------------
       Inject function:kmem_cache_alloc (pid:177858) (return: 0)
       Calltrace Context:
       mem_cache_allock+0x73/0xcc
       ext4_mb_new_blocks+0x32e/0x540 [ext4]
       ext4_new_meta_blocks+0xc4/0x110 [ext4]
       ext4_ext_grow_indepth+0x68/0x250 [ext4]
       ext4_ext_create_new_leaf+0xc5/0x120 [ext4]
       ext4_ext_insert_extent+0x1bf/0x670 [ext4]
       ext4_split_extent_at+0x212/0x530 [ext4]
       ext4_split_extent+0x13a/0x1a0 [ext4]
       ext4_ext_handle_unwritten_extents+0x13d/0x240 [ext4]
       ext4_ext_map_blocks+0x459/0x8f0 [ext4]
       ext4_map_blocks+0x18e/0x5a0 [ext4]
       ext4_iomap_alloc+0xb0/0x1b0 [ext4]
       ext4_iomap_begin+0xb0/0x130 [ext4]
       iomap_apply+0x95/0x2e0
       __iomap_dio_rw+0x1cc/0x4b0
       iomap_dio_rw+0xe/0x40
       ext4_dio_write_iter+0x1a9/0x390 [ext4]
       new_sync_write+0x113/0x1b0
       vfs_write+0x1b7/0x250
       ksys_write+0x5f/0xe0
       do_syscall_64+0x33/0x40
       entry_SYSCALL_64_after_hwframe+0x61/0xc6
      
      Compare extent change in journal:
      Start:
      ee_block      ee_len        ee_start
      75            32798         1457227  -> unwritten len=30
      308           12            434489
      355           5             442492
      =>
      ee_block      ee_len        ee_start
      11            2             951584
      74            32769         951647   -> unwritten  len=1
      75            32771         1457227  -> unwritten  len=3
      211           15            960906
      308           12            434489
      355           5             442492
      
      Acctually, above issue can repaired by 'fsck -fa'. But file system is 'clean',
      'fsck' will not do deep repair.
      Obviously, final lost 27 blocks. Above issue may happens as follows:
      ext4_split_extent_at
      ...
      err = ext4_ext_insert_extent(handle, inode, ppath, &newex, flags); -> return -ENOMEM
      if (err != -ENOSPC && err != -EDQUOT)
      	goto out; -> goto 'out' will not fix extent length, will
      ...
      fix_extent_len:
              ex->ee_len = orig_ex.ee_len;
              /*
               * Ignore ext4_ext_dirty return value since we are already in error path
               * and err is a non-zero error code.
               */
              ext4_ext_dirty(handle, inode, path + path->p_depth);
              return err;
      out:
              ext4_ext_show_leaf(inode, path);
              return err;
      If 'ext4_ext_insert_extent' return '-ENOMEM' which will not fix 'ex->ee_len' by
      old length. 'ext4_ext_insert_extent' will trigger extent tree merge, fix like
      'ex->ee_len = orig_ex.ee_len' may lead to new issues.
      To solve above issue, record error messages when 'ext4_ext_insert_extent' return
      'err' not equal '(-ENOSPC && -EDQUOT)'. If filesysten is mounted with 'errors=continue'
      as filesystem is not clean 'fsck' will repair issue. If filesystem is mounted with
      'errors=remount-ro' filesystem will be remounted by read-only.
      Signed-off-by: NYe Bin <yebin10@huawei.com>
      Reviewed-by: NZhang Yi <yi.zhang@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      7425f87b
  10. 02 11月, 2022 4 次提交
    • B
      ext4: fix bug_on in __es_tree_search caused by bad boot loader inode · 08d24e76
      Baokun Li 提交于
      hulk inclusion
      category: bugfix
      bugzilla: 187821,https://gitee.com/openeuler/kernel/issues/I5X9U0
      CVE: NA
      
      --------------------------------
      
      We got a issue as fllows:
      
      ==================================================================
       kernel BUG at fs/ext4/extents_status.c:203!
       invalid opcode: 0000 [#1] PREEMPT SMP
       CPU: 1 PID: 945 Comm: cat Not tainted 6.0.0-next-20221007-dirty #349
       RIP: 0010:ext4_es_end.isra.0+0x34/0x42
       RSP: 0018:ffffc9000143b768 EFLAGS: 00010203
       RAX: 0000000000000000 RBX: ffff8881769cd0b8 RCX: 0000000000000000
       RDX: 0000000000000000 RSI: ffffffff8fc27cf7 RDI: 00000000ffffffff
       RBP: ffff8881769cd0bc R08: 0000000000000000 R09: ffffc9000143b5f8
       R10: 0000000000000001 R11: 0000000000000001 R12: ffff8881769cd0a0
       R13: ffff8881768e5668 R14: 00000000768e52f0 R15: 0000000000000000
       FS: 00007f359f7f05c0(0000)GS:ffff88842fd00000(0000)knlGS:0000000000000000
       CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
       CR2: 00007f359f5a2000 CR3: 000000017130c000 CR4: 00000000000006e0
       DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
       DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
       Call Trace:
        <TASK>
        __es_tree_search.isra.0+0x6d/0xf5
        ext4_es_cache_extent+0xfa/0x230
        ext4_cache_extents+0xd2/0x110
        ext4_find_extent+0x5d5/0x8c0
        ext4_ext_map_blocks+0x9c/0x1d30
        ext4_map_blocks+0x431/0xa50
        ext4_mpage_readpages+0x48e/0xe40
        ext4_readahead+0x47/0x50
        read_pages+0x82/0x530
        page_cache_ra_unbounded+0x199/0x2a0
        do_page_cache_ra+0x47/0x70
        page_cache_ra_order+0x242/0x400
        ondemand_readahead+0x1e8/0x4b0
        page_cache_sync_ra+0xf4/0x110
        filemap_get_pages+0x131/0xb20
        filemap_read+0xda/0x4b0
        generic_file_read_iter+0x13a/0x250
        ext4_file_read_iter+0x59/0x1d0
        vfs_read+0x28f/0x460
        ksys_read+0x73/0x160
        __x64_sys_read+0x1e/0x30
        do_syscall_64+0x35/0x80
        entry_SYSCALL_64_after_hwframe+0x63/0xcd
        </TASK>
      ==================================================================
      
      In the above issue, ioctl invokes the swap_inode_boot_loader function to
      swap inode<5> and inode<12>. However, inode<5> contain incorrect imode and
      disordered extents, and i_nlink is set to 1. The extents check for inode in
      the ext4_iget function can be bypassed bacause 5 is EXT4_BOOT_LOADER_INO.
      While links_count is set to 1, the extents are not initialized in
      swap_inode_boot_loader. After the ioctl command is executed successfully,
      the extents are swapped to inode<12>, in this case, run the `cat` command
      to view inode<12>. And Bug_ON is triggered due to the incorrect extents.
      
      When the boot loader inode is not initialized, its imode can be one of the
      following:
      1) the imode is a bad type, which is marked as bad_inode in ext4_iget and
         set to S_IFREG.
      2) the imode is good type but not S_IFREG.
      3) the imode is S_IFREG.
      
      The BUG_ON may be triggered by bypassing the check in cases 1 and 2.
      Therefore, when the boot loader inode is bad_inode or its imode is not
      S_IFREG, initialize the inode to avoid triggering the BUG.
      Signed-off-by: NBaokun Li <libaokun1@huawei.com>
      Reviewed-by: NZhang Yi <yi.zhang@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      08d24e76
    • B
      ext4: add EXT4_IGET_BAD flag to prevent unexpected bad inode · 0cc9ff5e
      Baokun Li 提交于
      hulk inclusion
      category: bugfix
      bugzilla: 187821,https://gitee.com/openeuler/kernel/issues/I5X9U0
      CVE: NA
      
      --------------------------------
      
      There are many places that will get unhappy (and crash) when ext4_iget()
      returns a bad inode. However, if iget the boot loader inode, allows a bad
      inode to be returned, because the inode may not be initialized. This
      mechanism can be used to bypass some checks and cause panic. To solve this
      problem, we add a special iget flag EXT4_IGET_BAD. Only with this flag
      we'd be returning bad inode from ext4_iget(), otherwise we always return
      the error code if the inode is bad inode.(suggested by Jan Kara)
      Signed-off-by: NBaokun Li <libaokun1@huawei.com>
      Reviewed-by: NZhang Yi <yi.zhang@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      0cc9ff5e
    • B
      ext4: add helper to check quota inums · 931dd258
      Baokun Li 提交于
      hulk inclusion
      category: bugfix
      bugzilla: 187821,https://gitee.com/openeuler/kernel/issues/I5X9U0
      CVE: NA
      
      --------------------------------
      
      Before quota is enabled, a check on the preset quota inums in
      ext4_super_block is added to prevent wrong quota inodes from being loaded.
      In addition, when the quota fails to be enabled, the quota type and quota
      inum are printed to facilitate fault locating.
      Signed-off-by: NBaokun Li <libaokun1@huawei.com>
      Reviewed-by: NZhang Yi <yi.zhang@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      931dd258
    • B
      ext4: fix race condition between ext4_write and ext4_convert_inline_data · 7dd8c6c8
      Baokun Li 提交于
      stable inclusion
      from stable-v5.10.132
      commit 91f90b571f1a23f5b8a9c2b68a9aa5d6981a3c3d
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I5YS3T
      
      Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=91f90b571f1a23f5b8a9c2b68a9aa5d6981a3c3d
      
      --------------------------------
      
      commit f87c7a4b upstream.
      
      Hulk Robot reported a BUG_ON:
       ==================================================================
       EXT4-fs error (device loop3): ext4_mb_generate_buddy:805: group 0,
       block bitmap and bg descriptor inconsistent: 25 vs 31513 free clusters
       kernel BUG at fs/ext4/ext4_jbd2.c:53!
       invalid opcode: 0000 [#1] SMP KASAN PTI
       CPU: 0 PID: 25371 Comm: syz-executor.3 Not tainted 5.10.0+ #1
       RIP: 0010:ext4_put_nojournal fs/ext4/ext4_jbd2.c:53 [inline]
       RIP: 0010:__ext4_journal_stop+0x10e/0x110 fs/ext4/ext4_jbd2.c:116
       [...]
       Call Trace:
        ext4_write_inline_data_end+0x59a/0x730 fs/ext4/inline.c:795
        generic_perform_write+0x279/0x3c0 mm/filemap.c:3344
        ext4_buffered_write_iter+0x2e3/0x3d0 fs/ext4/file.c:270
        ext4_file_write_iter+0x30a/0x11c0 fs/ext4/file.c:520
        do_iter_readv_writev+0x339/0x3c0 fs/read_write.c:732
        do_iter_write+0x107/0x430 fs/read_write.c:861
        vfs_writev fs/read_write.c:934 [inline]
        do_pwritev+0x1e5/0x380 fs/read_write.c:1031
       [...]
       ==================================================================
      
      Above issue may happen as follows:
                 cpu1                     cpu2
      __________________________|__________________________
      do_pwritev
       vfs_writev
        do_iter_write
         ext4_file_write_iter
          ext4_buffered_write_iter
           generic_perform_write
            ext4_da_write_begin
                                 vfs_fallocate
                                  ext4_fallocate
                                   ext4_convert_inline_data
                                    ext4_convert_inline_data_nolock
                                     ext4_destroy_inline_data_nolock
                                      clear EXT4_STATE_MAY_INLINE_DATA
                                     ext4_map_blocks
                                      ext4_ext_map_blocks
                                       ext4_mb_new_blocks
                                        ext4_mb_regular_allocator
                                         ext4_mb_good_group_nolock
                                          ext4_mb_init_group
                                           ext4_mb_init_cache
                                            ext4_mb_generate_buddy  --> error
             ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA)
                                      ext4_restore_inline_data
                                       set EXT4_STATE_MAY_INLINE_DATA
             ext4_block_write_begin
            ext4_da_write_end
             ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA)
             ext4_write_inline_data_end
              handle=NULL
              ext4_journal_stop(handle)
               __ext4_journal_stop
                ext4_put_nojournal(handle)
                 ref_cnt = (unsigned long)handle
                 BUG_ON(ref_cnt == 0)  ---> BUG_ON
      
      The lock held by ext4_convert_inline_data is xattr_sem, but the lock
      held by generic_perform_write is i_rwsem. Therefore, the two locks can
      be concurrent.
      
      To solve above issue, we add inode_lock() for ext4_convert_inline_data().
      At the same time, move ext4_convert_inline_data() in front of
      ext4_punch_hole(), remove similar handling from ext4_punch_hole().
      
      Fixes: 0c8d414f ("ext4: let fallocate handle inline data correctly")
      Cc: stable@vger.kernel.org
      Reported-by: NHulk Robot <hulkci@huawei.com>
      Signed-off-by: NBaokun Li <libaokun1@huawei.com>
      Reviewed-by: NJan Kara <jack@suse.cz>
      Link: https://lore.kernel.org/r/20220428134031.4153381-1-libaokun1@huawei.comSigned-off-by: NTheodore Ts'o <tytso@mit.edu>
      Signed-off-by: NTadeusz Struk <tadeusz.struk@linaro.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
      7dd8c6c8
  11. 26 10月, 2022 1 次提交
  12. 18 10月, 2022 1 次提交
  13. 13 10月, 2022 5 次提交
  14. 27 9月, 2022 6 次提交
  15. 02 8月, 2022 3 次提交
  16. 26 7月, 2022 4 次提交