Skip to content

Commit a149d2a

Browse files
zhangyi089tytso
authored andcommitted
ext4: fix check to prevent false positive report of incorrect used inodes
Commit <50122847007> ("ext4: fix check to prevent initializing reserved inodes") check the block group zero and prevent initializing reserved inodes. But in some special cases, the reserved inode may not all belong to the group zero, it may exist into the second group if we format filesystem below. mkfs.ext4 -b 4096 -g 8192 -N 1024 -I 4096 /dev/sda So, it will end up triggering a false positive report of a corrupted file system. This patch fix it by avoid check reserved inodes if no free inode blocks will be zeroed. Cc: stable@kernel.org Fixes: 5012284 ("ext4: fix check to prevent initializing reserved inodes") Signed-off-by: Zhang Yi <yi.zhang@huawei.com> Suggested-by: Jan Kara <jack@suse.cz> Link: https://lore.kernel.org/r/20210331121516.2243099-1-yi.zhang@huawei.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent d556435 commit a149d2a

1 file changed

Lines changed: 32 additions & 16 deletions

File tree

‎fs/ext4/ialloc.c‎

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,6 +1513,7 @@ int ext4_init_inode_table(struct super_block *sb, ext4_group_t group,
15131513
handle_t *handle;
15141514
ext4_fsblk_t blk;
15151515
int num, ret = 0, used_blks = 0;
1516+
unsigned long used_inos = 0;
15161517

15171518
/* This should not happen, but just to be sure check this */
15181519
if (sb_rdonly(sb)) {
@@ -1543,22 +1544,37 @@ int ext4_init_inode_table(struct super_block *sb, ext4_group_t group,
15431544
* used inodes so we need to skip blocks with used inodes in
15441545
* inode table.
15451546
*/
1546-
if (!(gdp->bg_flags & cpu_to_le16(EXT4_BG_INODE_UNINIT)))
1547-
used_blks = DIV_ROUND_UP((EXT4_INODES_PER_GROUP(sb) -
1548-
ext4_itable_unused_count(sb, gdp)),
1549-
sbi->s_inodes_per_block);
1550-
1551-
if ((used_blks < 0) || (used_blks > sbi->s_itb_per_group) ||
1552-
((group == 0) && ((EXT4_INODES_PER_GROUP(sb) -
1553-
ext4_itable_unused_count(sb, gdp)) <
1554-
EXT4_FIRST_INO(sb)))) {
1555-
ext4_error(sb, "Something is wrong with group %u: "
1556-
"used itable blocks: %d; "
1557-
"itable unused count: %u",
1558-
group, used_blks,
1559-
ext4_itable_unused_count(sb, gdp));
1560-
ret = 1;
1561-
goto err_out;
1547+
if (!(gdp->bg_flags & cpu_to_le16(EXT4_BG_INODE_UNINIT))) {
1548+
used_inos = EXT4_INODES_PER_GROUP(sb) -
1549+
ext4_itable_unused_count(sb, gdp);
1550+
used_blks = DIV_ROUND_UP(used_inos, sbi->s_inodes_per_block);
1551+
1552+
/* Bogus inode unused count? */
1553+
if (used_blks < 0 || used_blks > sbi->s_itb_per_group) {
1554+
ext4_error(sb, "Something is wrong with group %u: "
1555+
"used itable blocks: %d; "
1556+
"itable unused count: %u",
1557+
group, used_blks,
1558+
ext4_itable_unused_count(sb, gdp));
1559+
ret = 1;
1560+
goto err_out;
1561+
}
1562+
1563+
used_inos += group * EXT4_INODES_PER_GROUP(sb);
1564+
/*
1565+
* Are there some uninitialized inodes in the inode table
1566+
* before the first normal inode?
1567+
*/
1568+
if ((used_blks != sbi->s_itb_per_group) &&
1569+
(used_inos < EXT4_FIRST_INO(sb))) {
1570+
ext4_error(sb, "Something is wrong with group %u: "
1571+
"itable unused count: %u; "
1572+
"itables initialized count: %ld",
1573+
group, ext4_itable_unused_count(sb, gdp),
1574+
used_inos);
1575+
ret = 1;
1576+
goto err_out;
1577+
}
15621578
}
15631579

15641580
blk = ext4_inode_table(sb, gdp) + used_blks;

0 commit comments

Comments
 (0)