1. 08 11月, 2022 1 次提交
  2. 07 11月, 2022 7 次提交
    • J
      btrfs: zoned: fix locking imbalance on scrub · c62f6bec
      Johannes Thumshirn 提交于
      If we're doing device replace on a zoned filesystem and discover in
      scrub_enumerate_chunks() that we don't have to copy the block group it is
      unlocked before it gets skipped.
      
      But as the block group hasn't yet been locked before it leads to a locking
      imbalance. To fix this simply remove the unlock.
      
      This was uncovered by fstests' testcase btrfs/163.
      
      Fixes: 9283b9e0 ("btrfs: remove lock protection for BLOCK_GROUP_FLAG_TO_COPY")
      Signed-off-by: NJohannes Thumshirn <johannes.thumshirn@wdc.com>
      Reviewed-by: NDavid Sterba <dsterba@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      c62f6bec
    • J
      btrfs: zoned: initialize device's zone info for seeding · a8d1b164
      Johannes Thumshirn 提交于
      When performing seeding on a zoned filesystem it is necessary to
      initialize each zoned device's btrfs_zoned_device_info structure,
      otherwise mounting the filesystem will cause a NULL pointer dereference.
      
      This was uncovered by fstests' testcase btrfs/163.
      
      CC: stable@vger.kernel.org # 5.15+
      Signed-off-by: NJohannes Thumshirn <johannes.thumshirn@wdc.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      a8d1b164
    • J
      btrfs: zoned: clone zoned device info when cloning a device · 21e61ec6
      Johannes Thumshirn 提交于
      When cloning a btrfs_device, we're not cloning the associated
      btrfs_zoned_device_info structure of the device in case of a zoned
      filesystem.
      
      Later on this leads to a NULL pointer dereference when accessing the
      device's zone_info for instance when setting a zone as active.
      
      This was uncovered by fstests' testcase btrfs/161.
      
      CC: stable@vger.kernel.org # 5.15+
      Signed-off-by: NJohannes Thumshirn <johannes.thumshirn@wdc.com>
      Reviewed-by: NDavid Sterba <dsterba@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      21e61ec6
    • Q
      Revert "btrfs: scrub: use larger block size for data extent scrub" · b75b51f8
      Qu Wenruo 提交于
      This reverts commit 786672e9.
      
      [BUG]
      Since commit 786672e9 ("btrfs: scrub: use larger block size for data
      extent scrub"), btrfs scrub no longer reports errors if the corruption
      is not in the first sector of a STRIPE_LEN.
      
      The following script can expose the problem:
      
        mkfs.btrfs -f $dev
        mount $dev $mnt
        xfs_io -f -c "pwrite -S 0xff 0 8k" $mnt/foobar
        umount $mnt
      
        # 13631488 is the logical bytenr of above 8K extent
        btrfs-map-logical -l 13631488 -b 4096 $dev
        mirror 1 logical 13631488 physical 13631488 device /dev/test/scratch1
      
        # Corrupt the 2nd sector of that extent
        xfs_io -f -c "pwrite -S 0x00 13635584 4k" $dev
      
        mount $dev $mnt
        btrfs scrub start -B $mnt
        scrub done for 54e63f9f-0c30-4c84-a33b-5c56014629b7
        Scrub started:    Mon Nov  7 07:18:27 2022
        Status:           finished
        Duration:         0:00:00
        Total to scrub:   536.00MiB
        Rate:             0.00B/s
        Error summary:    no errors found <<<
      
      [CAUSE]
      That offending commit enlarges the data extent scrub size from sector
      size to BTRFS_STRIPE_LEN, to avoid extra scrub_block to be allocated.
      
      But unfortunately the data extent scrub is still heavily relying on the
      fact that there is only one scrub_sector per scrub_block.
      
      Thus it will only check the first sector, and ignoring the remaining
      sectors.
      
      Furthermore the error reporting is not able to handle multiple sectors
      either.
      
      [FIX]
      For now just revert the offending commit.
      
      The consequence is just extra memory usage during scrub.
      We will need a proper change to make the remaining data scrub path to
      handle multiple sectors before we enlarging the data scrub size.
      Reported-by: NLi Zhang <zhanglikernel@gmail.com>
      Signed-off-by: NQu Wenruo <wqu@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      b75b51f8
    • D
      btrfs: don't print stack trace when transaction is aborted due to ENOMEM · 8bb808c6
      David Sterba 提交于
      Add ENOMEM among the error codes that don't print stack trace on
      transaction abort. We've got several reports from syzbot that detects
      stacks as errors but caused by limiting memory. As this is an artificial
      condition we don't need to know where exactly the error happens, the
      abort and error cleanup will continue like e.g. for EIO.
      
      As the transaction aborts code needs to be inline in a lot of code, the
      implementation cases about minimal bloat. The error codes are in a
      separate function and the WARN uses the condition directly. This
      increases the code size by 571 bytes on release build.
      
      Alternatives considered: add -ENOMEM among the errors, this increases
      size by 2340 bytes, various attempts to combine the WARN and helper
      calls, increase by 700 or more bytes.
      
      Example syzbot reports (error -12):
      
      - https://syzkaller.appspot.com/bug?extid=5244d35be7f589cf093e
      - https://syzkaller.appspot.com/bug?extid=9c37714c07194d816417Signed-off-by: NDavid Sterba <dsterba@suse.com>
      8bb808c6
    • Z
      btrfs: selftests: fix wrong error check in btrfs_free_dummy_root() · 9b2f2034
      Zhang Xiaoxu 提交于
      The btrfs_alloc_dummy_root() uses ERR_PTR as the error return value
      rather than NULL, if error happened, there will be a NULL pointer
      dereference:
      
        BUG: KASAN: null-ptr-deref in btrfs_free_dummy_root+0x21/0x50 [btrfs]
        Read of size 8 at addr 000000000000002c by task insmod/258926
      
        CPU: 2 PID: 258926 Comm: insmod Tainted: G        W          6.1.0-rc2+ #5
        Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-1.fc33 04/01/2014
        Call Trace:
         <TASK>
         dump_stack_lvl+0x34/0x44
         kasan_report+0xb7/0x140
         kasan_check_range+0x145/0x1a0
         btrfs_free_dummy_root+0x21/0x50 [btrfs]
         btrfs_test_free_space_cache+0x1a8c/0x1add [btrfs]
         btrfs_run_sanity_tests+0x65/0x80 [btrfs]
         init_btrfs_fs+0xec/0x154 [btrfs]
         do_one_initcall+0x87/0x2a0
         do_init_module+0xdf/0x320
         load_module+0x3006/0x3390
         __do_sys_finit_module+0x113/0x1b0
         do_syscall_64+0x35/0x80
       entry_SYSCALL_64_after_hwframe+0x46/0xb0
      
      Fixes: aaedb55b ("Btrfs: add tests for btrfs_get_extent")
      CC: stable@vger.kernel.org # 4.9+
      Reviewed-by: NAnand Jain <anand.jain@oracle.com>
      Signed-off-by: NZhang Xiaoxu <zhangxiaoxu5@huawei.com>
      Reviewed-by: NDavid Sterba <dsterba@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      9b2f2034
    • L
      btrfs: fix match incorrectly in dev_args_match_device · 0fca385d
      Liu Shixin 提交于
      syzkaller found a failed assertion:
      
        assertion failed: (args->devid != (u64)-1) || args->missing, in fs/btrfs/volumes.c:6921
      
      This can be triggered when we set devid to (u64)-1 by ioctl. In this
      case, the match of devid will be skipped and the match of device may
      succeed incorrectly.
      
      Patch 562d7b15 introduced this function which is used to match device.
      This function contains two matching scenarios, we can distinguish them by
      checking the value of args->missing rather than check whether args->devid
      and args->uuid is default value.
      
      Reported-by: syzbot+031687116258450f9853@syzkaller.appspotmail.com
      Fixes: 562d7b15 ("btrfs: handle device lookup with btrfs_dev_lookup_args")
      CC: stable@vger.kernel.org # 5.16+
      Reviewed-by: NNikolay Borisov <nborisov@suse.com>
      Signed-off-by: NLiu Shixin <liushixin2@huawei.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      0fca385d
  3. 06 11月, 2022 4 次提交
    • T
      ext4: fix fortify warning in fs/ext4/fast_commit.c:1551 · 0d043351
      Theodore Ts'o 提交于
      With the new fortify string system, rework the memcpy to avoid this
      warning:
      
      memcpy: detected field-spanning write (size 60) of single field "&raw_inode->i_generation" at fs/ext4/fast_commit.c:1551 (size 4)
      
      Cc: stable@kernel.org
      Fixes: 54d9469b ("fortify: Add run-time WARN for cross-field memcpy()")
      Signed-off-by: NTheodore Ts'o <tytso@mit.edu>
      0d043351
    • J
      ext4: fix wrong return err in ext4_load_and_init_journal() · 9f2a1d9f
      Jason Yan 提交于
      The return value is wrong in ext4_load_and_init_journal(). The local
      variable 'err' need to be initialized before goto out. The original code
      in __ext4_fill_super() is fine because it has two return values 'ret'
      and 'err' and 'ret' is initialized as -EINVAL. After we factor out
      ext4_load_and_init_journal(), this code is broken. So fix it by directly
      returning -EINVAL in the error handler path.
      
      Cc: stable@kernel.org
      Fixes: 9c1dd22d ("ext4: factor out ext4_load_and_init_journal()")
      Signed-off-by: NJason Yan <yanaijie@huawei.com>
      Reviewed-by: NJan Kara <jack@suse.cz>
      Link: https://lore.kernel.org/r/20221025040206.3134773-1-yanaijie@huawei.comSigned-off-by: NTheodore Ts'o <tytso@mit.edu>
      9f2a1d9f
    • Y
      ext4: fix warning in 'ext4_da_release_space' · 1b8f787e
      Ye Bin 提交于
      Syzkaller report issue as follows:
      EXT4-fs (loop0): Free/Dirty block details
      EXT4-fs (loop0): free_blocks=0
      EXT4-fs (loop0): dirty_blocks=0
      EXT4-fs (loop0): Block reservation details
      EXT4-fs (loop0): i_reserved_data_blocks=0
      EXT4-fs warning (device loop0): ext4_da_release_space:1527: ext4_da_release_space: ino 18, to_free 1 with only 0 reserved data blocks
      ------------[ cut here ]------------
      WARNING: CPU: 0 PID: 92 at fs/ext4/inode.c:1528 ext4_da_release_space+0x25e/0x370 fs/ext4/inode.c:1524
      Modules linked in:
      CPU: 0 PID: 92 Comm: kworker/u4:4 Not tainted 6.0.0-syzkaller-09423-g493ffd66 #0
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/22/2022
      Workqueue: writeback wb_workfn (flush-7:0)
      RIP: 0010:ext4_da_release_space+0x25e/0x370 fs/ext4/inode.c:1528
      RSP: 0018:ffffc900015f6c90 EFLAGS: 00010296
      RAX: 42215896cd52ea00 RBX: 0000000000000000 RCX: 42215896cd52ea00
      RDX: 0000000000000000 RSI: 0000000080000001 RDI: 0000000000000000
      RBP: 1ffff1100e907d96 R08: ffffffff816aa79d R09: fffff520002bece5
      R10: fffff520002bece5 R11: 1ffff920002bece4 R12: ffff888021fd2000
      R13: ffff88807483ecb0 R14: 0000000000000001 R15: ffff88807483e740
      FS:  0000000000000000(0000) GS:ffff8880b9a00000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 00005555569ba628 CR3: 000000000c88e000 CR4: 00000000003506f0
      DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
      DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
      Call Trace:
       <TASK>
       ext4_es_remove_extent+0x1ab/0x260 fs/ext4/extents_status.c:1461
       mpage_release_unused_pages+0x24d/0xef0 fs/ext4/inode.c:1589
       ext4_writepages+0x12eb/0x3be0 fs/ext4/inode.c:2852
       do_writepages+0x3c3/0x680 mm/page-writeback.c:2469
       __writeback_single_inode+0xd1/0x670 fs/fs-writeback.c:1587
       writeback_sb_inodes+0xb3b/0x18f0 fs/fs-writeback.c:1870
       wb_writeback+0x41f/0x7b0 fs/fs-writeback.c:2044
       wb_do_writeback fs/fs-writeback.c:2187 [inline]
       wb_workfn+0x3cb/0xef0 fs/fs-writeback.c:2227
       process_one_work+0x877/0xdb0 kernel/workqueue.c:2289
       worker_thread+0xb14/0x1330 kernel/workqueue.c:2436
       kthread+0x266/0x300 kernel/kthread.c:376
       ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:306
       </TASK>
      
      Above issue may happens as follows:
      ext4_da_write_begin
        ext4_create_inline_data
          ext4_clear_inode_flag(inode, EXT4_INODE_EXTENTS);
          ext4_set_inode_flag(inode, EXT4_INODE_INLINE_DATA);
      __ext4_ioctl
        ext4_ext_migrate -> will lead to eh->eh_entries not zero, and set extent flag
      ext4_da_write_begin
        ext4_da_convert_inline_data_to_extent
          ext4_da_write_inline_data_begin
            ext4_da_map_blocks
              ext4_insert_delayed_block
      	  if (!ext4_es_scan_clu(inode, &ext4_es_is_delonly, lblk))
      	    if (!ext4_es_scan_clu(inode, &ext4_es_is_mapped, lblk))
      	      ext4_clu_mapped(inode, EXT4_B2C(sbi, lblk)); -> will return 1
      	       allocated = true;
                ext4_es_insert_delayed_block(inode, lblk, allocated);
      ext4_writepages
        mpage_map_and_submit_extent(handle, &mpd, &give_up_on_write); -> return -ENOSPC
        mpage_release_unused_pages(&mpd, give_up_on_write); -> give_up_on_write == 1
          ext4_es_remove_extent
            ext4_da_release_space(inode, reserved);
              if (unlikely(to_free > ei->i_reserved_data_blocks))
      	  -> to_free == 1  but ei->i_reserved_data_blocks == 0
      	  -> then trigger warning as above
      
      To solve above issue, forbid inode do migrate which has inline data.
      
      Cc: stable@kernel.org
      Reported-by: syzbot+c740bb18df70ad00952e@syzkaller.appspotmail.com
      Signed-off-by: NYe Bin <yebin10@huawei.com>
      Reviewed-by: NJan Kara <jack@suse.cz>
      Link: https://lore.kernel.org/r/20221018022701.683489-1-yebin10@huawei.comSigned-off-by: NTheodore Ts'o <tytso@mit.edu>
      1b8f787e
    • L
      ext4: fix BUG_ON() when directory entry has invalid rec_len · 17a0bc9b
      Luís Henriques 提交于
      The rec_len field in the directory entry has to be a multiple of 4.  A
      corrupted filesystem image can be used to hit a BUG() in
      ext4_rec_len_to_disk(), called from make_indexed_dir().
      
       ------------[ cut here ]------------
       kernel BUG at fs/ext4/ext4.h:2413!
       ...
       RIP: 0010:make_indexed_dir+0x53f/0x5f0
       ...
       Call Trace:
        <TASK>
        ? add_dirent_to_buf+0x1b2/0x200
        ext4_add_entry+0x36e/0x480
        ext4_add_nondir+0x2b/0xc0
        ext4_create+0x163/0x200
        path_openat+0x635/0xe90
        do_filp_open+0xb4/0x160
        ? __create_object.isra.0+0x1de/0x3b0
        ? _raw_spin_unlock+0x12/0x30
        do_sys_openat2+0x91/0x150
        __x64_sys_open+0x6c/0xa0
        do_syscall_64+0x3c/0x80
        entry_SYSCALL_64_after_hwframe+0x46/0xb0
      
      The fix simply adds a call to ext4_check_dir_entry() to validate the
      directory entry, returning -EFSCORRUPTED if the entry is invalid.
      
      CC: stable@kernel.org
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=216540Signed-off-by: NLuís Henriques <lhenriques@suse.de>
      Link: https://lore.kernel.org/r/20221012131330.32456-1-lhenriques@suse.deSigned-off-by: NTheodore Ts'o <tytso@mit.edu>
      17a0bc9b
  4. 05 11月, 2022 3 次提交
    • C
      cifs: fix use-after-free on the link name · 542228db
      ChenXiaoSong 提交于
      xfstests generic/011 reported use-after-free bug as follows:
      
        BUG: KASAN: use-after-free in __d_alloc+0x269/0x859
        Read of size 15 at addr ffff8880078933a0 by task dirstress/952
      
        CPU: 1 PID: 952 Comm: dirstress Not tainted 6.1.0-rc3+ #77
        Call Trace:
         __dump_stack+0x23/0x29
         dump_stack_lvl+0x51/0x73
         print_address_description+0x67/0x27f
         print_report+0x3e/0x5c
         kasan_report+0x7b/0xa8
         kasan_check_range+0x1b2/0x1c1
         memcpy+0x22/0x5d
         __d_alloc+0x269/0x859
         d_alloc+0x45/0x20c
         d_alloc_parallel+0xb2/0x8b2
         lookup_open+0x3b8/0x9f9
         open_last_lookups+0x63d/0xc26
         path_openat+0x11a/0x261
         do_filp_open+0xcc/0x168
         do_sys_openat2+0x13b/0x3f7
         do_sys_open+0x10f/0x146
         __se_sys_creat+0x27/0x2e
         __x64_sys_creat+0x55/0x6a
         do_syscall_64+0x40/0x96
         entry_SYSCALL_64_after_hwframe+0x63/0xcd
      
        Allocated by task 952:
         kasan_save_stack+0x1f/0x42
         kasan_set_track+0x21/0x2a
         kasan_save_alloc_info+0x17/0x1d
         __kasan_kmalloc+0x7e/0x87
         __kmalloc_node_track_caller+0x59/0x155
         kstrndup+0x60/0xe6
         parse_mf_symlink+0x215/0x30b
         check_mf_symlink+0x260/0x36a
         cifs_get_inode_info+0x14e1/0x1690
         cifs_revalidate_dentry_attr+0x70d/0x964
         cifs_revalidate_dentry+0x36/0x62
         cifs_d_revalidate+0x162/0x446
         lookup_open+0x36f/0x9f9
         open_last_lookups+0x63d/0xc26
         path_openat+0x11a/0x261
         do_filp_open+0xcc/0x168
         do_sys_openat2+0x13b/0x3f7
         do_sys_open+0x10f/0x146
         __se_sys_creat+0x27/0x2e
         __x64_sys_creat+0x55/0x6a
         do_syscall_64+0x40/0x96
         entry_SYSCALL_64_after_hwframe+0x63/0xcd
      
        Freed by task 950:
         kasan_save_stack+0x1f/0x42
         kasan_set_track+0x21/0x2a
         kasan_save_free_info+0x1c/0x34
         ____kasan_slab_free+0x1c1/0x1d5
         __kasan_slab_free+0xe/0x13
         __kmem_cache_free+0x29a/0x387
         kfree+0xd3/0x10e
         cifs_fattr_to_inode+0xb6a/0xc8c
         cifs_get_inode_info+0x3cb/0x1690
         cifs_revalidate_dentry_attr+0x70d/0x964
         cifs_revalidate_dentry+0x36/0x62
         cifs_d_revalidate+0x162/0x446
         lookup_open+0x36f/0x9f9
         open_last_lookups+0x63d/0xc26
         path_openat+0x11a/0x261
         do_filp_open+0xcc/0x168
         do_sys_openat2+0x13b/0x3f7
         do_sys_open+0x10f/0x146
         __se_sys_creat+0x27/0x2e
         __x64_sys_creat+0x55/0x6a
         do_syscall_64+0x40/0x96
         entry_SYSCALL_64_after_hwframe+0x63/0xcd
      
      When opened a symlink, link name is from 'inode->i_link', but it may be
      reset to a new value when revalidate the dentry. If some processes get the
      link name on the race scenario, then UAF will happen on link name.
      
      Fix this by implementing 'get_link' interface to duplicate the link name.
      
      Fixes: 76894f3e ("cifs: improve symlink handling for smb2+")
      Signed-off-by: NChenXiaoSong <chenxiaosong2@huawei.com>
      Reviewed-by: NPaulo Alcantara (SUSE) <pc@cjr.nz>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      542228db
    • S
      cifs: avoid unnecessary iteration of tcp sessions · 23d9b9b7
      Shyam Prasad N 提交于
      In a few places, we do unnecessary iterations of
      tcp sessions, even when the server struct is provided.
      
      The change avoids it and uses the server struct provided.
      Signed-off-by: NShyam Prasad N <sprasad@microsoft.com>
      Reviewed-by: NPaulo Alcantara (SUSE) <pc@cjr.nz>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      23d9b9b7
    • S
      cifs: always iterate smb sessions using primary channel · 8abcaeae
      Shyam Prasad N 提交于
      smb sessions and tcons currently hang off primary channel only.
      Secondary channels have the lists as empty. Whenever there's a
      need to iterate sessions or tcons, we should use the list in the
      corresponding primary channel.
      Signed-off-by: NShyam Prasad N <sprasad@microsoft.com>
      Reviewed-by: NPaulo Alcantara (SUSE) <pc@cjr.nz>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      8abcaeae
  5. 03 11月, 2022 6 次提交
    • F
      btrfs: fix inode reserve space leak due to nowait buffered write · eb81b682
      Filipe Manana 提交于
      During a nowait buffered write, if we fail to balance dirty pages we exit
      btrfs_buffered_write() without releasing the delalloc space reserved for
      an extent, resulting in leaking space from the inode's block reserve.
      
      So fix that by releasing the delalloc space for the extent when balancing
      dirty pages fails.
      Reported-by: Nkernel test robot <yujie.liu@intel.com>
      Link: https://lore.kernel.org/all/202210111304.d369bc32-yujie.liu@intel.com
      Fixes: 965f47ae ("btrfs: make btrfs_buffered_write nowait compatible")
      Reviewed-by: NJosef Bacik <josef@toxicpanda.com>
      Signed-off-by: NFilipe Manana <fdmanana@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      eb81b682
    • F
      btrfs: fix nowait buffered write returning -ENOSPC · a348c8d4
      Filipe Manana 提交于
      If we are doing a buffered write in NOWAIT context and we can't reserve
      metadata space due to -ENOSPC, then we should return -EAGAIN so that we
      retry the write in a context allowed to block and do metadata reservation
      with flushing, which might succeed this time due to the allowed flushing.
      
      Returning -ENOSPC while in NOWAIT context simply makes some writes fail
      with -ENOSPC when they would likely succeed after switching from NOWAIT
      context to blocking context. That is unexpected behaviour and even fio
      complains about it with a warning like this:
      
        fio: io_u error on file /mnt/sdi/task_0.0.0: No space left on device: write offset=1535705088, buflen=65536
        fio: pid=592630, err=28/file:io_u.c:1846, func=io_u error, error=No space left on device
      
      The fio's job config is this:
      
         [global]
         bs=64K
         ioengine=io_uring
         iodepth=1
         size=2236962133
         nr_files=1
         filesize=2236962133
         direct=0
         runtime=10
         fallocate=posix
         io_size=2236962133
         group_reporting
         time_based
      
         [task_0]
         rw=randwrite
         directory=/mnt/sdi
         numjobs=4
      
      So fix this by returning -EAGAIN if we are in NOWAIT context and the
      metadata reservation failed with -ENOSPC.
      
      Fixes: 304e45ac ("btrfs: plumb NOWAIT through the write path")
      Reviewed-by: NJosef Bacik <josef@toxicpanda.com>
      Signed-off-by: NFilipe Manana <fdmanana@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      a348c8d4
    • F
      btrfs: remove pointless and double ulist frees in error paths of qgroup tests · d0ea17ae
      Filipe Manana 提交于
      Several places in the qgroup self tests follow the pattern of freeing the
      ulist pointer they passed to btrfs_find_all_roots() if the call to that
      function returned an error. That is pointless because that function always
      frees the ulist in case it returns an error.
      
      Also In some places like at test_multiple_refs(), after a call to
      btrfs_qgroup_account_extent() we also leave "old_roots" and "new_roots"
      pointing to ulists that were freed, because btrfs_qgroup_account_extent()
      has freed those ulists, and if after that the next call to
      btrfs_find_all_roots() fails, we call ulist_free() on the "old_roots"
      ulist again, resulting in a double free.
      
      So remove those calls to reduce the code size and avoid double ulist
      free in case of an error.
      Signed-off-by: NFilipe Manana <fdmanana@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      d0ea17ae
    • F
      btrfs: fix ulist leaks in error paths of qgroup self tests · d37de92b
      Filipe Manana 提交于
      In the test_no_shared_qgroup() and test_multiple_refs() qgroup self tests,
      if we fail to add the tree ref, remove the extent item or remove the
      extent ref, we are returning from the test function without freeing the
      "old_roots" ulist that was allocated by the previous calls to
      btrfs_find_all_roots(). Fix that by calling ulist_free() before returning.
      
      Fixes: 442244c9 ("btrfs: qgroup: Switch self test to extent-oriented qgroup mechanism.")
      Signed-off-by: NFilipe Manana <fdmanana@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      d37de92b
    • F
      btrfs: fix inode list leak during backref walking at find_parent_nodes() · 92876eec
      Filipe Manana 提交于
      During backref walking, at find_parent_nodes(), if we are dealing with a
      data extent and we get an error while resolving the indirect backrefs, at
      resolve_indirect_refs(), or in the while loop that iterates over the refs
      in the direct refs rbtree, we end up leaking the inode lists attached to
      the direct refs we have in the direct refs rbtree that were not yet added
      to the refs ulist passed as argument to find_parent_nodes(). Since they
      were not yet added to the refs ulist and prelim_release() does not free
      the lists, on error the caller can only free the lists attached to the
      refs that were added to the refs ulist, all the remaining refs get their
      inode lists never freed, therefore leaking their memory.
      
      Fix this by having prelim_release() always free any attached inode list
      to each ref found in the rbtree, and have find_parent_nodes() set the
      ref's inode list to NULL once it transfers ownership of the inode list
      to a ref added to the refs ulist passed to find_parent_nodes().
      
      Fixes: 86d5f994 ("btrfs: convert prelimary reference tracking to use rbtrees")
      Signed-off-by: NFilipe Manana <fdmanana@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      92876eec
    • F
      btrfs: fix inode list leak during backref walking at resolve_indirect_refs() · 5614dc3a
      Filipe Manana 提交于
      During backref walking, at resolve_indirect_refs(), if we get an error
      we jump to the 'out' label and call ulist_free() on the 'parents' ulist,
      which frees all the elements in the ulist - however that does not free
      any inode lists that may be attached to elements, through the 'aux' field
      of a ulist node, so we end up leaking lists if we have any attached to
      the unodes.
      
      Fix this by calling free_leaf_list() instead of ulist_free() when we exit
      from resolve_indirect_refs(). The static function free_leaf_list() is
      moved up for this to be possible and it's slightly simplified by removing
      unnecessary code.
      
      Fixes: 3301958b ("Btrfs: add inodes before dropping the extent lock in find_all_leafs")
      Signed-off-by: NFilipe Manana <fdmanana@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      5614dc3a
  6. 02 11月, 2022 1 次提交
  7. 31 10月, 2022 18 次提交