Skip to content

Commit cd6bb35

Browse files
committed
ext4: use more strict checks for inodes_per_block on mount
Centralize the checks for inodes_per_block and be more strict to make sure the inodes_per_block_group can't end up being zero. Signed-off-by: Theodore Ts'o <[email protected]> Reviewed-by: Andreas Dilger <[email protected]> Cc: [email protected]
1 parent 5aee0f8 commit cd6bb35

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

fs/ext4/super.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3668,12 +3668,16 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
36683668

36693669
sbi->s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group);
36703670
sbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group);
3671-
if (EXT4_INODE_SIZE(sb) == 0 || EXT4_INODES_PER_GROUP(sb) == 0)
3672-
goto cantfind_ext4;
36733671

36743672
sbi->s_inodes_per_block = blocksize / EXT4_INODE_SIZE(sb);
36753673
if (sbi->s_inodes_per_block == 0)
36763674
goto cantfind_ext4;
3675+
if (sbi->s_inodes_per_group < sbi->s_inodes_per_block ||
3676+
sbi->s_inodes_per_group > blocksize * 8) {
3677+
ext4_msg(sb, KERN_ERR, "invalid inodes per group: %lu\n",
3678+
sbi->s_blocks_per_group);
3679+
goto failed_mount;
3680+
}
36773681
sbi->s_itb_per_group = sbi->s_inodes_per_group /
36783682
sbi->s_inodes_per_block;
36793683
sbi->s_desc_per_block = blocksize / EXT4_DESC_SIZE(sb);
@@ -3756,13 +3760,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
37563760
}
37573761
sbi->s_cluster_ratio = clustersize / blocksize;
37583762

3759-
if (sbi->s_inodes_per_group > blocksize * 8) {
3760-
ext4_msg(sb, KERN_ERR,
3761-
"#inodes per group too big: %lu",
3762-
sbi->s_inodes_per_group);
3763-
goto failed_mount;
3764-
}
3765-
37663763
/* Do we have standard group size of clustersize * 8 blocks ? */
37673764
if (sbi->s_blocks_per_group == clustersize << 3)
37683765
set_opt2(sb, STD_GROUP_SIZE);

0 commit comments

Comments
 (0)