Skip to content

Commit 40da553

Browse files
jankaratytso
authored andcommitted
ext4: verify s_clusters_per_group even without bigalloc
Currently we ignore s_clusters_per_group field in the on-disk superblock if bigalloc feature is not enabled. However e2fsprogs don't even open the filesystem if s_clusters_per_group is invalid. This results in an odd state where kernel happily works with the filesystem while even e2fsck refuses to touch it. Verify that s_clusters_per_group is valid even if bigalloc feature is not enabled to make things consistent. Due to current e2fsprogs behavior it is unlikely there are filesystems out in the wild (except for intentionally fuzzed ones) with invalid s_clusters_per_group counts. Signed-off-by: Jan Kara <[email protected]> Reviewed-by: Zhang Yi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent a6b3bfe commit 40da553

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

fs/ext4/super.c

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4422,22 +4422,6 @@ static int ext4_handle_clustersize(struct super_block *sb)
44224422
}
44234423
sbi->s_cluster_bits = le32_to_cpu(es->s_log_cluster_size) -
44244424
le32_to_cpu(es->s_log_block_size);
4425-
sbi->s_clusters_per_group =
4426-
le32_to_cpu(es->s_clusters_per_group);
4427-
if (sbi->s_clusters_per_group > sb->s_blocksize * 8) {
4428-
ext4_msg(sb, KERN_ERR,
4429-
"#clusters per group too big: %lu",
4430-
sbi->s_clusters_per_group);
4431-
return -EINVAL;
4432-
}
4433-
if (sbi->s_blocks_per_group !=
4434-
(sbi->s_clusters_per_group * (clustersize / sb->s_blocksize))) {
4435-
ext4_msg(sb, KERN_ERR, "blocks per group (%lu) and "
4436-
"clusters per group (%lu) inconsistent",
4437-
sbi->s_blocks_per_group,
4438-
sbi->s_clusters_per_group);
4439-
return -EINVAL;
4440-
}
44414425
} else {
44424426
if (clustersize != sb->s_blocksize) {
44434427
ext4_msg(sb, KERN_ERR,
@@ -4451,9 +4435,21 @@ static int ext4_handle_clustersize(struct super_block *sb)
44514435
sbi->s_blocks_per_group);
44524436
return -EINVAL;
44534437
}
4454-
sbi->s_clusters_per_group = sbi->s_blocks_per_group;
44554438
sbi->s_cluster_bits = 0;
44564439
}
4440+
sbi->s_clusters_per_group = le32_to_cpu(es->s_clusters_per_group);
4441+
if (sbi->s_clusters_per_group > sb->s_blocksize * 8) {
4442+
ext4_msg(sb, KERN_ERR, "#clusters per group too big: %lu",
4443+
sbi->s_clusters_per_group);
4444+
return -EINVAL;
4445+
}
4446+
if (sbi->s_blocks_per_group !=
4447+
(sbi->s_clusters_per_group * (clustersize / sb->s_blocksize))) {
4448+
ext4_msg(sb, KERN_ERR,
4449+
"blocks per group (%lu) and clusters per group (%lu) inconsistent",
4450+
sbi->s_blocks_per_group, sbi->s_clusters_per_group);
4451+
return -EINVAL;
4452+
}
44574453
sbi->s_cluster_ratio = clustersize / sb->s_blocksize;
44584454

44594455
/* Do we have standard group size of clustersize * 8 blocks ? */

0 commit comments

Comments
 (0)