Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1469910rdb; Mon, 19 Feb 2024 17:55:26 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXLxWlbTHdCzdgfSqF9l5iljjefe6HpYZqaO15d293XEEn2v5nI4QfJYBp0l2EbGDKTN1pCsIgcqoMTwQEMnKtGyw94BqiibQ8DIzkIkg== X-Google-Smtp-Source: AGHT+IHLJBJ5FGCo1GVdgmynZ1zI0kCVxdUfsJtNiwoC21VJ24gd9uFFadYXnDB6oFOJmjdOE7he X-Received: by 2002:a17:902:ce01:b0:1db:96d3:3608 with SMTP id k1-20020a170902ce0100b001db96d33608mr16606144plg.2.1708394126515; Mon, 19 Feb 2024 17:55:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708394126; cv=pass; d=google.com; s=arc-20160816; b=GQ5jIwDeKU5UYkhv9CBSz2BO9XmA67h7/ll391LhCOHSwcKYNfyGedGsCeDsYkEB6T vdZlvc8AwPlru4l4NaW3VDy7AUlylF67fDgU/6J/edc25RfR+x0BFy44e3GIjmfIxOW6 Vn5YEtjK3mf4l2Mx1QgwX0QZXx40h8/Uze/SBop4Ei/3bbYwzV/hRfDayqazD63I49XC qOmgsUCRDLYTAxfC0iLDcDxQw+CNUqex5PsyGjPCx5flOefGsnrRzuRt30OH7xnkRkVw 2g5gSFdNpdupWoJF64y1pX61hJjOZoHAzlAWMRaEsN7zAvWd9VpGDcDAvebmVwAkfHLa cFZA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:in-reply-to:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:user-agent:date :message-id:from:references:cc:to:subject; bh=JMczjjsQA58kSxMvBPP9iex461qZG5SH6ai3Rmu2kk4=; fh=H7l9Wh7MxDQOXtGqxsg755Ey4KVQgSPpTlcMeb4Nkc8=; b=r4dTvs3BjMVMafx8VjVsv/LGgqucQsX90HyhDKwsAGjsqSIaIYRAy3Wc0xnYp2z9Tw dWEhkWiwTkWMlEqfA0k+RU+ttVGugIWbFs81DZRpDIaR7QrRL8myKNOKu8qK5fq0ldQP RInbTbxWBtq7lHZjR1uNT83GIkQHu8sJ1oUs83bqzmfLvbZCuzi1pIthRO44ksCLZ+7O +7XTWUcftp53Vve9O9oGd+wDkjANb0TWdc9EwpYeuTfTrokNg1XufVaoA35Sr0UcZ4jY HHRuYTYmuALKSnijGorbefKCf4+19icglXA3nf/CAJP3hkX1dXr1RPNJxMC06I8V1sxI 8GXA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-ext4+bounces-1285-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1285-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id n18-20020a170902d2d200b001db5ee2a794si5409678plc.562.2024.02.19.17.55.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 17:55:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4+bounces-1285-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-ext4+bounces-1285-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1285-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id CA2F5B219A7 for ; Tue, 20 Feb 2024 01:55:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AAB73374EB; Tue, 20 Feb 2024 01:55:17 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ADC4612E5B for ; Tue, 20 Feb 2024 01:55:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708394117; cv=none; b=fWPSOLvJ1fVx04SfVKIDd0COxaxwnrVZ8hw3DZAwi9NniCJhY9rwepUGYGxOLHKXlCNdZxvYUnYUg0aGRz69nIzIUU9PTx4uqqTINpq36nmd0GWGTajZ/GlaQsbSaKJIylHlFA484d/a081wGBLIsi5BrArp1VRnLiYcghph/QA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708394117; c=relaxed/simple; bh=RCm5R+47q6RJzdnlRGItUunB0aZelJdUXLfSaQ+x3Po=; h=Subject:To:CC:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=l8cKcdByLvxdzOG7n6NsSANOS9JgS31dXudg5yDQjk3mnV5I/DAUkQae7o8b9SksouvRrV5MAc997jXiLiWOgGFsKO9hGpd+tO6UmUoNf7Z7Hi0N7IJ2GIqBPCugCkrVqKrg05Bml8/iavJ7zvPunZiDBSKAI42+B//dB0P43kI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Tf2WM1h9Pz1xnMy; Tue, 20 Feb 2024 09:53:51 +0800 (CST) Received: from canpemm500005.china.huawei.com (unknown [7.192.104.229]) by mail.maildlp.com (Postfix) with ESMTPS id 5F1FF140120; Tue, 20 Feb 2024 09:55:12 +0800 (CST) Received: from [10.174.176.34] (10.174.176.34) by canpemm500005.china.huawei.com (7.192.104.229) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 20 Feb 2024 09:55:12 +0800 Subject: Re: [PATCH v2] ext4: Verify s_clusters_per_group even without bigalloc To: Jan Kara CC: , Ted Tso References: <20240219171033.22882-1-jack@suse.cz> From: Zhang Yi Message-ID: Date: Tue, 20 Feb 2024 09:55:11 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: <20240219171033.22882-1-jack@suse.cz> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500005.china.huawei.com (7.192.104.229) On 2024/2/20 1:10, Jan Kara wrote: > Currently we ignore s_clusters_per_group field in the on-disk superblock > if bigalloc feature is not enabled. However e2fsprogs don't even open > the filesystem if s_clusters_per_group is invalid. This results in an > odd state where kernel happily works with the filesystem while even > e2fsck refuses to touch it. Verify that s_clusters_per_group is valid > even if bigalloc feature is not enabled to make things consistent. Due > to current e2fsprogs behavior it is unlikely there are filesystems out > in the wild (except for intentionally fuzzed ones) with invalid > s_clusters_per_group counts. > > Signed-off-by: Jan Kara Thanks, looks good to me. Reviewed-by: Zhang Yi > --- > fs/ext4/super.c | 30 +++++++++++++----------------- > 1 file changed, 13 insertions(+), 17 deletions(-) > > Changes since v1: > * share code checking s_clusters_per_group for !bigalloc & bigalloc configs > > diff --git a/fs/ext4/super.c b/fs/ext4/super.c > index 0f931d0c227d..0a34e0b23541 100644 > --- a/fs/ext4/super.c > +++ b/fs/ext4/super.c > @@ -4422,22 +4422,6 @@ static int ext4_handle_clustersize(struct super_block *sb) > } > sbi->s_cluster_bits = le32_to_cpu(es->s_log_cluster_size) - > le32_to_cpu(es->s_log_block_size); > - sbi->s_clusters_per_group = > - le32_to_cpu(es->s_clusters_per_group); > - if (sbi->s_clusters_per_group > sb->s_blocksize * 8) { > - ext4_msg(sb, KERN_ERR, > - "#clusters per group too big: %lu", > - sbi->s_clusters_per_group); > - return -EINVAL; > - } > - if (sbi->s_blocks_per_group != > - (sbi->s_clusters_per_group * (clustersize / sb->s_blocksize))) { > - ext4_msg(sb, KERN_ERR, "blocks per group (%lu) and " > - "clusters per group (%lu) inconsistent", > - sbi->s_blocks_per_group, > - sbi->s_clusters_per_group); > - return -EINVAL; > - } > } else { > if (clustersize != sb->s_blocksize) { > ext4_msg(sb, KERN_ERR, > @@ -4451,9 +4435,21 @@ static int ext4_handle_clustersize(struct super_block *sb) > sbi->s_blocks_per_group); > return -EINVAL; > } > - sbi->s_clusters_per_group = sbi->s_blocks_per_group; > sbi->s_cluster_bits = 0; > } > + sbi->s_clusters_per_group = le32_to_cpu(es->s_clusters_per_group); > + if (sbi->s_clusters_per_group > sb->s_blocksize * 8) { > + ext4_msg(sb, KERN_ERR, "#clusters per group too big: %lu", > + sbi->s_clusters_per_group); > + return -EINVAL; > + } > + if (sbi->s_blocks_per_group != > + (sbi->s_clusters_per_group * (clustersize / sb->s_blocksize))) { > + ext4_msg(sb, KERN_ERR, > + "blocks per group (%lu) and clusters per group (%lu) inconsistent", > + sbi->s_blocks_per_group, sbi->s_clusters_per_group); > + return -EINVAL; > + } > sbi->s_cluster_ratio = clustersize / sb->s_blocksize; > > /* Do we have standard group size of clustersize * 8 blocks ? */ >