Message ID | fb42141d2569bf25642b8e953810e590cff97e87.1695089790.git.wqu@suse.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | btrfs: reduce the width of devices counter | expand |
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 163f37ad1b27..beb35a0187f4 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2431,7 +2431,8 @@ int btrfs_validate_super(struct btrfs_fs_info *fs_info, btrfs_super_stripesize(sb)); ret = -EINVAL; } - if (btrfs_super_num_devices(sb) > (1UL << 31)) + /* 65536 devices already doesn't sound sane. */ + if (btrfs_super_num_devices(sb) > U16_MAX) btrfs_warn(fs_info, "suspicious number of devices: %llu", btrfs_super_num_devices(sb)); if (btrfs_super_num_devices(sb) == 0) {
The btrfs superblock uses u64 for num_devices (including both read-write and read-only devices). The real-world value should be way smaller, dozens of devices would already be a little too many, not to mention anything beyond U16_MAX (65535). So here we just reject any superblock with a num_devices beyond U16_MAX. Signed-off-by: Qu Wenruo <wqu@suse.com> --- fs/btrfs/disk-io.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)