Skip to content

Commit aefd7f7

Browse files
lorddoskiaskdave
authored andcommitted
btrfs: promote debugging asserts to full-fledged checks in validate_super
Syzbot managed to trigger this assert while performing its fuzzing. Turns out it's better to have those asserts turned into full-fledged checks so that in case buggy btrfs images are mounted the users gets an error and mounting is stopped. Alternatively with CONFIG_BTRFS_ASSERT disabled such image would have been erroneously allowed to be mounted. Reported-by: [email protected] CC: [email protected] # 5.4+ Reviewed-by: Johannes Thumshirn <[email protected]> Reviewed-by: Qu Wenruo <[email protected]> Signed-off-by: Nikolay Borisov <[email protected]> Reviewed-by: David Sterba <[email protected]> [ add uuids to the messages ] Signed-off-by: David Sterba <[email protected]>
1 parent e7b2ec3 commit aefd7f7

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

fs/btrfs/disk-io.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2648,6 +2648,24 @@ static int validate_super(struct btrfs_fs_info *fs_info,
26482648
ret = -EINVAL;
26492649
}
26502650

2651+
if (memcmp(fs_info->fs_devices->fsid, fs_info->super_copy->fsid,
2652+
BTRFS_FSID_SIZE)) {
2653+
btrfs_err(fs_info,
2654+
"superblock fsid doesn't match fsid of fs_devices: %pU != %pU",
2655+
fs_info->super_copy->fsid, fs_info->fs_devices->fsid);
2656+
ret = -EINVAL;
2657+
}
2658+
2659+
if (btrfs_fs_incompat(fs_info, METADATA_UUID) &&
2660+
memcmp(fs_info->fs_devices->metadata_uuid,
2661+
fs_info->super_copy->metadata_uuid, BTRFS_FSID_SIZE)) {
2662+
btrfs_err(fs_info,
2663+
"superblock metadata_uuid doesn't match metadata uuid of fs_devices: %pU != %pU",
2664+
fs_info->super_copy->metadata_uuid,
2665+
fs_info->fs_devices->metadata_uuid);
2666+
ret = -EINVAL;
2667+
}
2668+
26512669
if (memcmp(fs_info->fs_devices->metadata_uuid, sb->dev_item.fsid,
26522670
BTRFS_FSID_SIZE) != 0) {
26532671
btrfs_err(fs_info,
@@ -3279,14 +3297,6 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
32793297

32803298
disk_super = fs_info->super_copy;
32813299

3282-
ASSERT(!memcmp(fs_info->fs_devices->fsid, fs_info->super_copy->fsid,
3283-
BTRFS_FSID_SIZE));
3284-
3285-
if (btrfs_fs_incompat(fs_info, METADATA_UUID)) {
3286-
ASSERT(!memcmp(fs_info->fs_devices->metadata_uuid,
3287-
fs_info->super_copy->metadata_uuid,
3288-
BTRFS_FSID_SIZE));
3289-
}
32903300

32913301
features = btrfs_super_flags(disk_super);
32923302
if (features & BTRFS_SUPER_FLAG_CHANGING_FSID_V2) {

0 commit comments

Comments
 (0)