public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] btrfs: validate device maj:min during open
@ 2024-03-08  2:45 Anand Jain
  2024-03-08 15:48 ` Christoph Hellwig
  2024-03-08 17:41 ` Boris Burkov
  0 siblings, 2 replies; 13+ messages in thread
From: Anand Jain @ 2024-03-08  2:45 UTC (permalink / raw)
  To: boris, dsterba, linux-btrfs; +Cc: Anand Jain, stable

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 tempfsid 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 tempfsid 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: stable@vger.kernel.org # 6.7+
Fixes: a5b8a5f9f835 ("btrfs: support cloned-device mount capability")
Reported-by: Boris Burkov <boris@bur.io>
Co-developed-by: Boris Burkov <boris@bur.io>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2:
Drop using lookup_bdev() instead, get it from device->bdev->bd_dev.

v1:
https://lore.kernel.org/linux-btrfs/752b8526be21d984e0ee58c7f66d312664ff5ac5.1709256891.git.anand.jain@oracle.com/

 fs/btrfs/volumes.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index e49935a54da0..c318640b4472 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -692,6 +692,16 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices,
 	device->bdev = bdev_handle->bdev;
 	clear_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state);
 
+	if (device->devt != device->bdev->bd_dev) {
+		btrfs_warn(NULL,
+			   "device %s maj:min changed from %d:%d to %d:%d",
+			   device->name->str, MAJOR(device->devt),
+			   MINOR(device->devt), MAJOR(device->bdev->bd_dev),
+			   MINOR(device->bdev->bd_dev));
+
+		device->devt = device->bdev->bd_dev;
+	}
+
 	fs_devices->open_devices++;
 	if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state) &&
 	    device->devid != BTRFS_DEV_REPLACE_DEVID) {
-- 
2.38.1


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

end of thread, other threads:[~2024-03-13 16:25 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-08  2:45 [PATCH v2] btrfs: validate device maj:min during open Anand Jain
2024-03-08 15:48 ` Christoph Hellwig
2024-03-08 16:04   ` Anand Jain
2024-03-08 16:10     ` Christoph Hellwig
2024-03-08 16:23       ` Anand Jain
2024-03-08 17:23         ` Christoph Hellwig
2024-03-08 17:32           ` Boris Burkov
2024-03-08 17:42             ` Christoph Hellwig
2024-03-08 17:51               ` Boris Burkov
2024-03-13 16:24                 ` Anand Jain
2024-03-08 17:41 ` Boris Burkov
2024-03-12 19:17   ` Boris Burkov
2024-03-13 10:25     ` Anand Jain

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