Skip to content

Commit bfe0a5f

Browse files
committed
ext4: add more mount time checks of the superblock
The kernel's ext4 mount-time checks were more permissive than e2fsprogs's libext2fs checks when opening a file system. The superblock is considered too insane for debugfs or e2fsck to operate on it, the kernel has no business trying to mount it. This will make file system fuzzing tools work harder, but the failure cases that they find will be more useful and be easier to evaluate. Signed-off-by: Theodore Ts'o <tytso@mit.edu> Cc: stable@kernel.org
1 parent c37e9e0 commit bfe0a5f

1 file changed

Lines changed: 26 additions & 11 deletions

File tree

‎fs/ext4/super.c‎

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3793,6 +3793,13 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
37933793
le32_to_cpu(es->s_log_block_size));
37943794
goto failed_mount;
37953795
}
3796+
if (le32_to_cpu(es->s_log_cluster_size) >
3797+
(EXT4_MAX_CLUSTER_LOG_SIZE - EXT4_MIN_BLOCK_LOG_SIZE)) {
3798+
ext4_msg(sb, KERN_ERR,
3799+
"Invalid log cluster size: %u",
3800+
le32_to_cpu(es->s_log_cluster_size));
3801+
goto failed_mount;
3802+
}
37963803

37973804
if (le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) > (blocksize / 4)) {
37983805
ext4_msg(sb, KERN_ERR,
@@ -3939,13 +3946,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
39393946
"block size (%d)", clustersize, blocksize);
39403947
goto failed_mount;
39413948
}
3942-
if (le32_to_cpu(es->s_log_cluster_size) >
3943-
(EXT4_MAX_CLUSTER_LOG_SIZE - EXT4_MIN_BLOCK_LOG_SIZE)) {
3944-
ext4_msg(sb, KERN_ERR,
3945-
"Invalid log cluster size: %u",
3946-
le32_to_cpu(es->s_log_cluster_size));
3947-
goto failed_mount;
3948-
}
39493949
sbi->s_cluster_bits = le32_to_cpu(es->s_log_cluster_size) -
39503950
le32_to_cpu(es->s_log_block_size);
39513951
sbi->s_clusters_per_group =
@@ -3966,10 +3966,10 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
39663966
}
39673967
} else {
39683968
if (clustersize != blocksize) {
3969-
ext4_warning(sb, "fragment/cluster size (%d) != "
3970-
"block size (%d)", clustersize,
3971-
blocksize);
3972-
clustersize = blocksize;
3969+
ext4_msg(sb, KERN_ERR,
3970+
"fragment/cluster size (%d) != "
3971+
"block size (%d)", clustersize, blocksize);
3972+
goto failed_mount;
39733973
}
39743974
if (sbi->s_blocks_per_group > blocksize * 8) {
39753975
ext4_msg(sb, KERN_ERR,
@@ -4023,6 +4023,13 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
40234023
ext4_blocks_count(es));
40244024
goto failed_mount;
40254025
}
4026+
if ((es->s_first_data_block == 0) && (es->s_log_block_size == 0) &&
4027+
(sbi->s_cluster_ratio == 1)) {
4028+
ext4_msg(sb, KERN_WARNING, "bad geometry: first data "
4029+
"block is 0 with a 1k block and cluster size");
4030+
goto failed_mount;
4031+
}
4032+
40264033
blocks_count = (ext4_blocks_count(es) -
40274034
le32_to_cpu(es->s_first_data_block) +
40284035
EXT4_BLOCKS_PER_GROUP(sb) - 1);
@@ -4058,6 +4065,14 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
40584065
ret = -ENOMEM;
40594066
goto failed_mount;
40604067
}
4068+
if (((u64)sbi->s_groups_count * sbi->s_inodes_per_group) !=
4069+
le32_to_cpu(es->s_inodes_count)) {
4070+
ext4_msg(sb, KERN_ERR, "inodes count not valid: %u vs %llu",
4071+
le32_to_cpu(es->s_inodes_count),
4072+
((u64)sbi->s_groups_count * sbi->s_inodes_per_group));
4073+
ret = -EINVAL;
4074+
goto failed_mount;
4075+
}
40614076

40624077
bgl_lock_init(sbi->s_blockgroup_lock);
40634078

0 commit comments

Comments
 (0)