Skip to content

btrfs: use fs_holder_ops for btrfs

Qu Wenruo linux-btrfs 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v6 Latest8 patches 4 repliesIn review
  2. v58 patches 1 replySuperseded
  3. v48 patches 3 repliesSuperseded

Changes in v6 from the cover letter

- 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.

Patches in v6 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/8btrfs: always open the device read-only in btrfs_scan_one_devicefs/btrfs/super.c fs/btrfs/volumes.c fs/btrfs/volumes.h+7 -80 replies
2/8btrfs: get rid of the re-entry of btrfs_get_tree()fs/btrfs/super.c+3 -240 replies
3/8btrfs: add comments to make super block creation more clearfs/btrfs/super.c+21 -90 replies
4/8btrfs: call btrfs_close_devices from ->kill_sbfs/btrfs/disk-io.c fs/btrfs/super.c+11 -210 replies
5/8btrfs: call bdev_fput() to reclaim the blk_holder immediatelyfs/btrfs/dev-replace.c fs/btrfs/ioctl.c fs/btrfs/volumes.c+12 -120 replies
6/8btrfs: delay btrfs_open_devices() until super block is createdfs/btrfs/super.c fs/btrfs/volumes.c fs/btrfs/volumes.h+74 -160 replies
7/8btrfs: use the super_block as holder when mounting file systemsfs/btrfs/dev-replace.c fs/btrfs/fs.h fs/btrfs/super.c +1 more+4 -70 replies
8/8btrfs: use fs_holder_ops for all opened devicesfs/btrfs/dev-replace.c fs/btrfs/volumes.c+3 -30 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v6 yet.

Read the v6 thread

Cover letter [PATCH v6 0/8] btrfs: use fs_holder_ops for 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(-)
Signature · 1 line
2.50.0