Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3359099pxf; Sun, 28 Mar 2021 23:13:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZSma+IlCEKBs22YI29ZA2GKANAZ+ouSO/lCGszujgaQgSnJvQNWIHbVdTTh3M7DpbhGgd X-Received: by 2002:a17:906:ecb8:: with SMTP id qh24mr27830646ejb.162.1616998408074; Sun, 28 Mar 2021 23:13:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616998408; cv=none; d=google.com; s=arc-20160816; b=aDOiCR4hNkF7QeA4qn3dBRpMV/BQ8aDSyjxPrwuL77vkzn/amBjrot5schRTTCGP6k f6IBy109rwVBBfwqlWPm5TpG8SfZojCmomcm3TuWtEYg2PAwQ2b1xQKYmaKhNlgiMsLw prJofR1uJHdpsIspDTpgCZrlVu60arWAPgt4GHwP8P1V1dqwnoLoRvyXy7KgYE/Hnuq+ JEYE1CV/zBO7k5qG7dsGcSizNlnmNelocM3fi8om6NSATF+a/avmTXlZg+at9vTZp1WA mymMQBw/YSGM2xS7bcIqmnNn25fncOE4QG3DdO16/tSfMCcMn++aoZU/+0+9NmsAploI FioQ== 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=S8N3O3LLuxhI1gTIu5xFNGxSp3MJ6XKQsRwRQIYCi+c=; b=P46l6hJ1C+7LUzHBjnR/qYzL+ZbJXnEYqbKcFBfmv3eZrqgDJCj5okqK5KJowRfyTT iBHwDakthVbtgfwH37TP5KGLRmn8tHqOJe5cm5wN1fpQ1X5sG+Pwv5z7qYQJ/SDddsow DoPDVzOoZlHLInoLCuQ+uQ8rioWVzC8GVkP0P26IQtfsR+DHFZV7LiujIYFWvECsvGrj YLXVu8a48zpm81ogzjh3Ajq77yN8j1xneNShxZG+Cmu4bCysC68lLTWUrhZY5UNPznc9 ApGqWuYTBmv6xDqfc+ogC1ImWIMxuuCsjL82KNJObeL2uHqCTpehhCex/ftQhLcqigvD 8VxQ== 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 bt14si11123879edb.466.2021.03.28.23.12.59; Sun, 28 Mar 2021 23:13:28 -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 S229884AbhC2GM1 (ORCPT + 99 others); Mon, 29 Mar 2021 02:12:27 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:14941 "EHLO szxga06-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229502AbhC2GMC (ORCPT ); Mon, 29 Mar 2021 02:12:02 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4F82Hc0sjrzkgGj; Mon, 29 Mar 2021 14:10:20 +0800 (CST) Received: from huawei.com (10.175.127.227) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.498.0; Mon, 29 Mar 2021 14:11:54 +0800 From: Zhang Yi To: CC: , , , Subject: [PATCH] ext4: fix check to prevent false positive report of incorrect used inodes Date: Mon, 29 Mar 2021 14:19:55 +0800 Message-ID: <20210329061955.2437573-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 --- fs/ext4/ialloc.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c index 633ae7becd61..2eab813b690b 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,25 @@ 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); + + if (used_blks >= 0 && used_blks <= sbi->s_itb_per_group) + used_inos += group * EXT4_INODES_PER_GROUP(sb); + + if ((used_blks < 0) || (used_blks > sbi->s_itb_per_group) || + ((used_blks != sbi->s_itb_per_group) && + (used_inos < 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; + } } blk = ext4_inode_table(sb, gdp) + used_blks; -- 2.25.4