Skip to content

Commit 098b257

Browse files
zhangyi089gregkh
authored andcommitted
ext4: fix check to prevent false positive report of incorrect used inodes
commit a149d2a upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 3461909 commit 098b257

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
@@ -1512,6 +1512,7 @@ int ext4_init_inode_table(struct super_block *sb, ext4_group_t group,
15121512
handle_t *handle;
15131513
ext4_fsblk_t blk;
15141514
int num, ret = 0, used_blks = 0;
1515+
unsigned long used_inos = 0;
15151516

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

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

0 commit comments

Comments
 (0)