]> www.infradead.org Git - users/hch/xfstests-dev.git/commit
btrfs: new test for devt change between mounts
authorBoris Burkov <boris@bur.io>
Mon, 11 Mar 2024 19:13:44 +0000 (12:13 -0700)
committerZorro Lang <zlang@kernel.org>
Sun, 28 Apr 2024 11:08:22 +0000 (19:08 +0800)
commitbc9debb83c9867b2cdfd19e3a304616749f1912c
tree5460d1a6b85b3dd3d9cf42b8081d04fc012f6b64
parentb9785de77fcb7b4c9f58d6d7178a0ef63a059b84
btrfs: new test for devt change between mounts

It is possible to confuse the btrfs device cache (fs_devices) by
starting with a multi-device filesystem, then removing and re-adding a
device in a way which changes its dev_t while the filesystem is
unmounted. After this procedure, if we remount, then we are in a funny
state where struct btrfs_device's "devt" field does not match the bd_dev
of the "bdev" field. I would say this is bad enough, as we have violated
a pretty clear invariant.

But for style points, we can then remove the extra device from the fs,
making it a single device fs, which enables the "temp_fsid" feature,
which permits multiple separate mounts of different devices with the
same fsid. Since btrfs is confused and *thinks* there are different
devices (based on device->devt), it allows a second redundant mount of
the same device (not a bind mount!). This then allows us to corrupt the
original mount by doing stuff to the one that should be a bind mount.

Reviewed-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Boris Burkov <boris@bur.io>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
[ use _create_loop_device, renamed $MNT $BIND and rm them before mkdir ]
Signed-off-by: Zorro Lang <zlang@kernel.org>
[ update the commit id of _fixed_by_kernel_commit ]
common/config
tests/btrfs/318 [new file with mode: 0755]
tests/btrfs/318.out [new file with mode: 0644]