diff mbox series

btrfs: warn on wrong dev_t in fs_devices cache

Message ID c07bfcf1ca8ec66b8cfd1c6afae0b755af655cd1.1709251888.git.boris@bur.io (mailing list archive)
State New, archived
Headers show
Series btrfs: warn on wrong dev_t in fs_devices cache | expand

Commit Message

Boris Burkov March 1, 2024, 12:11 a.m. UTC
We are trying to close up loopholes that can cause this, but until we
are sure they are gone, this feels like a good precaution.

There are lots of ways the device scanning code can end up masking this
condition in a way that doesn't immediately bite us, but could be a
timebomb for the future. Try to make it more obviously a problem by
WARNing on it.

Signed-off-by: Boris Burkov <boris@bur.io>
---
 fs/btrfs/volumes.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Anand Jain March 1, 2024, 1:59 a.m. UTC | #1
On 3/1/24 05:41, Boris Burkov wrote:
> We are trying to close up loopholes that can cause this, but until we
> are sure they are gone, this feels like a good precaution.
> 
> There are lots of ways the device scanning code can end up masking this
> condition in a way that doesn't immediately bite us, but could be a
> timebomb for the future. Try to make it more obviously a problem by
> WARNing on it.

Not exactly a warning, but we can fix it. And,
we don't need the btrfs-progs patch. I have
sent a patch for it.

   [PATCH] btrfs: validate device maj:min during open

Thanks, Anand


> Signed-off-by: Boris Burkov <boris@bur.io>
> ---
>   fs/btrfs/volumes.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 3cc947a42116..0d81ec3cadf6 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -690,6 +690,7 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices,
>   
>   	device->bdev_handle = bdev_handle;
>   	device->bdev = bdev_handle->bdev;
> +	WARN_ON(device->devt != device->bdev->bd_dev);
>   	clear_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state);
>   
>   	fs_devices->open_devices++;
diff mbox series

Patch

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 3cc947a42116..0d81ec3cadf6 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -690,6 +690,7 @@  static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices,
 
 	device->bdev_handle = bdev_handle;
 	device->bdev = bdev_handle->bdev;
+	WARN_ON(device->devt != device->bdev->bd_dev);
 	clear_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state);
 
 	fs_devices->open_devices++;