Skip to content

Commit 9f7eb84

Browse files
asjkdave
authored andcommitted
btrfs: validate device maj:min during open
Boris managed to create a device capable of changing its maj:min without altering its device path. Only multi-devices can be scanned. A device that gets scanned and remains in the btrfs kernel cache might end up with an incorrect maj:min. Despite the temp-fsid feature patch did not introduce this bug, it could lead to issues if the above multi-device is converted to a single device with a stale maj:min. Subsequently, attempting to mount the same device with the correct maj:min might mistake it for another device with the same fsid, potentially resulting in wrongly auto-enabling the temp-fsid feature. To address this, this patch validates the device's maj:min at the time of device open and updates it if it has changed since the last scan. CC: [email protected] # 6.7+ Fixes: a5b8a5f ("btrfs: support cloned-device mount capability") Reported-by: Boris Burkov <[email protected]> Co-developed-by: Boris Burkov <[email protected]> Reviewed-by: Boris Burkov <[email protected]># Signed-off-by: Anand Jain <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 1ec17ef commit 9f7eb84

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

fs/btrfs/volumes.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,16 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices,
692692
device->bdev = bdev_handle->bdev;
693693
clear_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state);
694694

695+
if (device->devt != device->bdev->bd_dev) {
696+
btrfs_warn(NULL,
697+
"device %s maj:min changed from %d:%d to %d:%d",
698+
device->name->str, MAJOR(device->devt),
699+
MINOR(device->devt), MAJOR(device->bdev->bd_dev),
700+
MINOR(device->bdev->bd_dev));
701+
702+
device->devt = device->bdev->bd_dev;
703+
}
704+
695705
fs_devices->open_devices++;
696706
if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state) &&
697707
device->devid != BTRFS_DEV_REPLACE_DEVID) {

0 commit comments

Comments
 (0)