1 ext4: use more strict checks for inodes_per_block on mount
3 Centralize the checks for inodes_per_block and be more strict to make
4 sure the inodes_per_block_group can't end up being zero.
6 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
7 Reviewed-by: Andreas Dilger <adilger@dilger.ca>
8 Cc: stable@vger.kernel.org
10 fs/ext4/super.c | 15 ++++++---------
11 1 file changed, 6 insertions(+), 9 deletions(-)
13 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
14 index 404e6f3c1bed..689c02df1af4 100644
17 @@ -3668,12 +3668,16 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
19 sbi->s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group);
20 sbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group);
21 - if (EXT4_INODE_SIZE(sb) == 0 || EXT4_INODES_PER_GROUP(sb) == 0)
24 sbi->s_inodes_per_block = blocksize / EXT4_INODE_SIZE(sb);
25 if (sbi->s_inodes_per_block == 0)
27 + if (sbi->s_inodes_per_group < sbi->s_inodes_per_block ||
28 + sbi->s_inodes_per_group > blocksize * 8) {
29 + ext4_msg(sb, KERN_ERR, "invalid inodes per group: %lu\n",
30 + sbi->s_blocks_per_group);
33 sbi->s_itb_per_group = sbi->s_inodes_per_group /
34 sbi->s_inodes_per_block;
35 sbi->s_desc_per_block = blocksize / EXT4_DESC_SIZE(sb);
36 @@ -3756,13 +3760,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
38 sbi->s_cluster_ratio = clustersize / blocksize;
40 - if (sbi->s_inodes_per_group > blocksize * 8) {
41 - ext4_msg(sb, KERN_ERR,
42 - "#inodes per group too big: %lu",
43 - sbi->s_inodes_per_group);
47 /* Do we have standard group size of clustersize * 8 blocks ? */
48 if (sbi->s_blocks_per_group == clustersize << 3)
49 set_opt2(sb, STD_GROUP_SIZE);