提交 558f5b03 编写于 作者: Z Zhang Yi 提交者: Yang Yingliang

ext4: fix check to prevent false positive report of incorrect used inodes

mainline inclusion
from mainline-v5.13-rc1
commit a149d2a5
category: bugfix
bugzilla: 50787
CVE: NA
---------------------------

Commit <50122847> ("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: 50122847 ("ext4: fix check to prevent initializing reserved inodes")
Signed-off-by: NZhang Yi <yi.zhang@huawei.com>
Suggested-by: NJan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20210331121516.2243099-1-yi.zhang@huawei.comSigned-off-by: NTheodore Ts'o <tytso@mit.edu>
Reviewed-by: NZhang Xiaoxu <zhangxiaoxu5@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 e6a47cb4
...@@ -1356,6 +1356,7 @@ int ext4_init_inode_table(struct super_block *sb, ext4_group_t group, ...@@ -1356,6 +1356,7 @@ int ext4_init_inode_table(struct super_block *sb, ext4_group_t group,
handle_t *handle; handle_t *handle;
ext4_fsblk_t blk; ext4_fsblk_t blk;
int num, ret = 0, used_blks = 0; int num, ret = 0, used_blks = 0;
unsigned long used_inos = 0;
/* This should not happen, but just to be sure check this */ /* This should not happen, but just to be sure check this */
if (sb_rdonly(sb)) { if (sb_rdonly(sb)) {
...@@ -1386,22 +1387,37 @@ int ext4_init_inode_table(struct super_block *sb, ext4_group_t group, ...@@ -1386,22 +1387,37 @@ int ext4_init_inode_table(struct super_block *sb, ext4_group_t group,
* used inodes so we need to skip blocks with used inodes in * used inodes so we need to skip blocks with used inodes in
* inode table. * inode table.
*/ */
if (!(gdp->bg_flags & cpu_to_le16(EXT4_BG_INODE_UNINIT))) if (!(gdp->bg_flags & cpu_to_le16(EXT4_BG_INODE_UNINIT))) {
used_blks = DIV_ROUND_UP((EXT4_INODES_PER_GROUP(sb) - used_inos = EXT4_INODES_PER_GROUP(sb) -
ext4_itable_unused_count(sb, gdp)), ext4_itable_unused_count(sb, gdp);
sbi->s_inodes_per_block); used_blks = DIV_ROUND_UP(used_inos, sbi->s_inodes_per_block);
if ((used_blks < 0) || (used_blks > sbi->s_itb_per_group) || /* Bogus inode unused count? */
((group == 0) && ((EXT4_INODES_PER_GROUP(sb) - if (used_blks < 0 || used_blks > sbi->s_itb_per_group) {
ext4_itable_unused_count(sb, gdp)) < ext4_error(sb, "Something is wrong with group %u: "
EXT4_FIRST_INO(sb)))) { "used itable blocks: %d; "
ext4_error(sb, "Something is wrong with group %u: " "itable unused count: %u",
"used itable blocks: %d; " group, used_blks,
"itable unused count: %u", ext4_itable_unused_count(sb, gdp));
group, used_blks, ret = 1;
ext4_itable_unused_count(sb, gdp)); goto err_out;
ret = 1; }
goto err_out;
used_inos += group * EXT4_INODES_PER_GROUP(sb);
/*
* Are there some uninitialized inodes in the inode table
* before the first normal inode?
*/
if ((used_blks != sbi->s_itb_per_group) &&
(used_inos < EXT4_FIRST_INO(sb))) {
ext4_error(sb, "Something is wrong with group %u: "
"itable unused count: %u; "
"itables initialized count: %ld",
group, ext4_itable_unused_count(sb, gdp),
used_inos);
ret = 1;
goto err_out;
}
} }
blk = ext4_inode_table(sb, gdp) + used_blks; blk = ext4_inode_table(sb, gdp) + used_blks;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册