Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp350542pxf; Wed, 31 Mar 2021 05:08:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRdJSKoqKsXm2BHPzDmVt8jyQjj33etUnN0XZPCTP/CbFdCfqJ2qnjnQdoXk/ZPBwBiKKc X-Received: by 2002:a17:906:f10c:: with SMTP id gv12mr3177369ejb.53.1617192513332; Wed, 31 Mar 2021 05:08:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617192513; cv=none; d=google.com; s=arc-20160816; b=Eu28n0RO8YDU5tbqmSHoilRsRYWTtayH3PLteL+YKtm1L6IzhD1EKTYi/vPKpvaCXk ofvad4RInqEUuM5fTz0xk70W7yvkKkGP3RMCaIHYetQDaYFeoqbiC4ATEBpSqfx1uuwJ Sa274hjrfBTQCypTe9GJ9LpSZMNvb6bTeib6M17uJh16nx4K13AZDclR/jKdiGoZjun2 VrF49+9mR6YsdyBKE/E9NEfmXu44YvqXyFSDv4SJ4SiAPCF3bzVod1lGpU/DGDfiZoAw KZY08yUsI2q4X8JzQVbPg4j+z3OpTKiF/bhlyka2SWDowsgHlZgVbTuSzkzjxiLYCzLI 5NjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=YExRiFTFU/IePE7yEmD8TJVK8vUgpTRrDnGUGaQ65ng=; b=G5l78vHyTMrGj1U2toCk9MvulsHfecGknL7Zk/Fr2GMHPISaRQWIoJpOAJuBfvFLPH xvjGEgLxN+uRfjDyk9G1VZhb+SvVf8FftYW8Zh8SD4c2zlX4LGQSm1QQVSLas0O9YlHA ggBqbaZ2PiHxiRdepydPBwIEHPCGLzMx8XyT85D8iExFNtG6JkKn+Qjh8rwa2n4EQUkY MklHnITLsOV+G/Z8/52D0wrtKxH+AgxadtrUD7J6MkJ6jSnk0OdYBcPSVu8GMNZ+JsbU Y00AgGQDnqtsn4yfi1H/o9zTx2T04sG8rQo8NG+drp0yGzShlDsYs6Tpdk9ucpskdvW+ 64dw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lr6si1739786ejb.9.2021.03.31.05.08.08; Wed, 31 Mar 2021 05:08:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235505AbhCaMHf (ORCPT + 99 others); Wed, 31 Mar 2021 08:07:35 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:15125 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234377AbhCaMH0 (ORCPT ); Wed, 31 Mar 2021 08:07:26 -0400 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4F9Q4H3cvDz1BFXb; Wed, 31 Mar 2021 20:05:19 +0800 (CST) Received: from huawei.com (10.175.127.227) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.498.0; Wed, 31 Mar 2021 20:07:15 +0800 From: Zhang Yi To: CC: , , , Subject: [PATCH v2] ext4: fix check to prevent false positive report of incorrect used inodes Date: Wed, 31 Mar 2021 20:15:16 +0800 Message-ID: <20210331121516.2243099-1-yi.zhang@huawei.com> X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.127.227] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org 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. Fixes: 50122847007 ("ext4: fix check to prevent initializing reserved inodes") Signed-off-by: Zhang Yi Suggested-by: Jan Kara --- Changes since v1: - Splict check of used_blks and used_inos to make code more comprehensible as Jan suggested. fs/ext4/ialloc.c | 48 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c index 633ae7becd61..5f0c7fe32672 100644 --- a/fs/ext4/ialloc.c +++ b/fs/ext4/ialloc.c @@ -1513,6 +1513,7 @@ int ext4_init_inode_table(struct super_block *sb, ext4_group_t group, handle_t *handle; ext4_fsblk_t blk; int num, ret = 0, used_blks = 0; + unsigned long used_inos = 0; /* This should not happen, but just to be sure check this */ if (sb_rdonly(sb)) { @@ -1543,22 +1544,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 * inode table. */ - if (!(gdp->bg_flags & cpu_to_le16(EXT4_BG_INODE_UNINIT))) - used_blks = DIV_ROUND_UP((EXT4_INODES_PER_GROUP(sb) - - ext4_itable_unused_count(sb, gdp)), - sbi->s_inodes_per_block); - - if ((used_blks < 0) || (used_blks > sbi->s_itb_per_group) || - ((group == 0) && ((EXT4_INODES_PER_GROUP(sb) - - ext4_itable_unused_count(sb, gdp)) < - EXT4_FIRST_INO(sb)))) { - ext4_error(sb, "Something is wrong with group %u: " - "used itable blocks: %d; " - "itable unused count: %u", - group, used_blks, - ext4_itable_unused_count(sb, gdp)); - ret = 1; - goto err_out; + if (!(gdp->bg_flags & cpu_to_le16(EXT4_BG_INODE_UNINIT))) { + used_inos = EXT4_INODES_PER_GROUP(sb) - + ext4_itable_unused_count(sb, gdp); + used_blks = DIV_ROUND_UP(used_inos, sbi->s_inodes_per_block); + + /* Bogus inode unused count? */ + if (used_blks < 0 || used_blks > sbi->s_itb_per_group) { + ext4_error(sb, "Something is wrong with group %u: " + "used itable blocks: %d; " + "itable unused count: %u", + group, used_blks, + ext4_itable_unused_count(sb, gdp)); + 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; -- 2.25.4