public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v6 0/8] btrfs: use fs_holder_ops for btrfs
@ 2025-06-30  5:29 Qu Wenruo
  2025-06-30  5:29 ` [PATCH v6 1/8] btrfs: always open the device read-only in btrfs_scan_one_device Qu Wenruo
                   ` (9 more replies)
  0 siblings, 10 replies; 13+ messages in thread
From: Qu Wenruo @ 2025-06-30  5:29 UTC (permalink / raw)
  To: linux-btrfs

[CHANGELOG]
v6:
- Fix an error handling bug that can lead to use-after-free
  Reported by syzbot, that inside btrfs_get_tree_super() that if we
  didn't open the devices, there are corner cases that
  fs_info->fs_devices can be freed twice, causing use-after-free bug.

  This one fixed two error paths:
  * sget_fc() failure
    Which is not the one reported by syzbot, but still possible to hit.

  * btrfs_open_devices() failure
    Which I believe is the one reported by syzbot.

  There is a dedicated fix pushed into linux-next.

  This refreshed series is for the proper merge into our for-next
  branch.

v5:
- Fix a tailing whitespace
  This introduced by patch "btrfs: add comments to make super block
  creation more clear", and that patch is created during a small
  window where my commit checkpatch hook is broken.

  And unfortunately that comment is also later updated by several
  patches, causing several conflicts with that whitespace error fixed.

v4:
- Fix a lockdep error
  In the patch "btrfs: delay btrfs_open_devices() until super block is
  created", we call sget_fc() with uuid_mutex locked.
  But during fs closing, we also try to lock uuid_mutex with s_umount
  locked.

  This leads to a reserved lock sequence and resuled a lockdep warning.

  Fix it by introducing btrfs_fs_devices::holding (aka, the old solution
  introduced by Christoph), but this time with no extra bugs during
  fstests.

- Add the patch to use fs_holder_ops
  This patch is small and properly tested, it's more situable to include
  this one here, other than delaying it to the next devloss feature.

- Add the missing patch to always open device-readonly when scanning
  My bad, there are a little too many patches pending, and I forgot to
  include the first patch.

v3:
- Drop the btrfs_fs_devices::opened split
  It turns out to cause problems during tests.

- Extra cleanup related to the btrfs_get_tree_*()
  Now the re-entry through vfs_get_tree() is completely dropped.

- Extra comments explaining the sget_fc() behavior

- Call bdev_fput() instead of fput()
  This alignes us to all the other fses.

- Updated patch to delay btrfs_open_devices() until sget_fc()
  Instead of relying on the previous solution (split
  btrfs_open_devices::opened), just expand the uuid_mutex critical
  section.


Christoph Hellwig (3):
  btrfs: always open the device read-only in btrfs_scan_one_device
  btrfs: call btrfs_close_devices from ->kill_sb
  btrfs: use the super_block as holder when mounting file systems

Qu Wenruo (5):
  btrfs: get rid of the re-entry of btrfs_get_tree()
  btrfs: add comments to make super block creation more clear
  btrfs: call bdev_fput() to reclaim the blk_holder immediately
  btrfs: delay btrfs_open_devices() until super block is created
  btrfs: use fs_holder_ops for all opened devices

 fs/btrfs/dev-replace.c |   4 +-
 fs/btrfs/disk-io.c     |   4 +-
 fs/btrfs/fs.h          |   2 -
 fs/btrfs/ioctl.c       |   4 +-
 fs/btrfs/super.c       | 129 ++++++++++++++++++++++-------------------
 fs/btrfs/volumes.c     |  33 ++++++-----
 fs/btrfs/volumes.h     |  27 ++++++++-
 7 files changed, 119 insertions(+), 84 deletions(-)

-- 
2.50.0


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2025-07-01 14:38 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-30  5:29 [PATCH v6 0/8] btrfs: use fs_holder_ops for btrfs Qu Wenruo
2025-06-30  5:29 ` [PATCH v6 1/8] btrfs: always open the device read-only in btrfs_scan_one_device Qu Wenruo
2025-06-30  5:29 ` [PATCH v6 2/8] btrfs: get rid of the re-entry of btrfs_get_tree() Qu Wenruo
2025-06-30  5:29 ` [PATCH v6 3/8] btrfs: add comments to make super block creation more clear Qu Wenruo
2025-06-30  5:29 ` [PATCH v6 4/8] btrfs: call btrfs_close_devices from ->kill_sb Qu Wenruo
2025-06-30  5:29 ` [PATCH v6 5/8] btrfs: call bdev_fput() to reclaim the blk_holder immediately Qu Wenruo
2025-06-30  5:29 ` [PATCH v6 6/8] btrfs: delay btrfs_open_devices() until super block is created Qu Wenruo
2025-06-30  5:29 ` [PATCH v6 7/8] btrfs: use the super_block as holder when mounting file systems Qu Wenruo
2025-06-30  5:29 ` [PATCH v6 8/8] btrfs: use fs_holder_ops for all opened devices Qu Wenruo
2025-06-30  5:40 ` [PATCH v6 0/8] btrfs: use fs_holder_ops for btrfs Christoph Hellwig
2025-06-30  5:43   ` Qu Wenruo
2025-06-30  5:49     ` Christoph Hellwig
2025-07-01 14:38 ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox