Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1263732rdb; Mon, 19 Feb 2024 09:10:51 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV/zL9hh5cvfXrWqUtNs3Q23/jeI/jeT1uSsUjics8cLORRpjSw0yAQXWJ7EVwlkQTa7wznbIkHBtu5sD7pf4Yv9g+WBOF4PpHMpwsk1w== X-Google-Smtp-Source: AGHT+IG4IWDi8LsJH/lV4poEMYvtTvlCGu0/0H4QrKrA/wxmIBsN4g42zDJvAalcrhUq4/8sUAOV X-Received: by 2002:a17:906:2ada:b0:a3e:1aea:6643 with SMTP id m26-20020a1709062ada00b00a3e1aea6643mr4055382eje.29.1708362651212; Mon, 19 Feb 2024 09:10:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708362651; cv=pass; d=google.com; s=arc-20160816; b=EaRdYTmn4qZKaaAKNf9Aw+7q3HUIekVIOmu/aGxo00Q5vokOtO4t4+dMCmwdjz44kk io41ZL59tL7i+Kb0EevHJfSmuGE8xIq5A0SD0uULQjXhsxirobZjO6gbzWUPe/j5Z68M 0t+7hcfJ9oBrx1tNoXvhfggHhEvRHP+d0GBnyegKfalS2oNKIaLMJ3mm4Pqi87ci82aS 7Ci7EGZdjxR2lydoc2DSMx57A66HHbWjXKd2K/Vebn9l8mz7DerLSOf/Y6HJF/nj+ck3 ucoldIbFQO3BynU1POZUAt4Fsyiy/hwmpDkiiH6LxAxhRhKUPXG4U6Xs/krEkm+ym1dm d0Fg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature:dkim-signature:dkim-signature:dkim-signature; bh=iJ+/nNmhztD2mxNSusR0IJsWj0+7uBy6vvC4GbPwuWQ=; fh=WOImGjPdRM/SEk6UEYo4PzpanGYixNpogOavt9XFNnY=; b=o+dgtM2ouGRVWcU+j4Vn34QAo40FYNF3wxUvSgTguEhP0KV1jLJncZZek9AbaKcfBQ UKwo5Jt+prHLoosaPeBtiBgSVUpF3nGq7BmPatf8NOYq6MlckaKtEliQhUrmiwxaGZYL f7eCHlMav6Ubsxi/6NmbWXvYTvjB8xlbAlxDiyBTu5hFU1MfE4z9lZTg/AQpyeOzD+xC 0QCOjejEtkf0KB6UCdknlRRDhCbZOb4tzPAO5vSu/MWvyMz0V6ead/Y7fn/hQLxhwLLx XSFswX6R1DNJBa978HOeiddcU3cJ/vANgOxZ1o3/qW43EIuA7xXBNEDFuG31TBtyuQKW MGdQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=d45RFPsu; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=d45RFPsu; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.cz dkim=pass dkdomain=suse.cz dkim=pass dkdomain=suse.cz); spf=pass (google.com: domain of linux-ext4+bounces-1283-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1283-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id lv13-20020a170906bc8d00b00a3e847bbf80si1186967ejb.632.2024.02.19.09.10.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 09:10:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4+bounces-1283-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=d45RFPsu; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=d45RFPsu; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.cz dkim=pass dkdomain=suse.cz dkim=pass dkdomain=suse.cz); spf=pass (google.com: domain of linux-ext4+bounces-1283-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1283-linux.lists.archive=gmail.com@vger.kernel.org" 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 am.mirrors.kernel.org (Postfix) with ESMTPS id E80861F2146B for ; Mon, 19 Feb 2024 17:10:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B38C7446AD; Mon, 19 Feb 2024 17:10:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="d45RFPsu"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="/daxwwh5"; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="d45RFPsu"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="/daxwwh5" X-Original-To: linux-ext4@vger.kernel.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 81F5F3F8DA for ; Mon, 19 Feb 2024 17:10:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708362644; cv=none; b=ZDjbwl3WrzFnN9NmuV/0pzXZPYglS9iBhVWSvxsUg/bCqpq9a6z7A1VEOER3Ees5bDoAuvf+1EwfZow6EVeNZVsYBS4RVPXbL1+SLmzCSDLuBZwe1+38fieRYbM0kUXrmob3rV1htejIwFTVtPQ2Hqz37T45Br/3ouwkplbe7kI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708362644; c=relaxed/simple; bh=WKFiFr64CUB/1NasbChOmjnE/kI1Szel06Fw0y9b3l4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=dLcLWsYYS+2io4QePT2L99RaWXlYcOkmRD6To0nzO/1y3+DlFLb/KqTBDWnx4gUlLAU9h8wZP029sG2wt8DlPNVZpKTQT7WmbzRiYhpwZpd2AFsOXXl6SnIMFTz6kNNclHegbrBgGPY+Vf03WpA4mc5nxUDKxevJ6caTuLAoiuY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz; spf=pass smtp.mailfrom=suse.cz; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=d45RFPsu; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=/daxwwh5; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=d45RFPsu; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=/daxwwh5; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.cz Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 85F2F21F68; Mon, 19 Feb 2024 17:10:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1708362639; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=iJ+/nNmhztD2mxNSusR0IJsWj0+7uBy6vvC4GbPwuWQ=; b=d45RFPsuSWbxcqJRSgx0V1IwRo91wuipQpFGJS4+c8oeFdr3OzLR2AY5JKPswKocWKNxFK NawpNosH9BdQsW9/avKmtgZmuTit+6C8P7fs2sQy8Cbu29FHh+gmiqtcIIi2CbdEWwv/t6 i/1wCRjVq+3tP27r5AMgDYWYHmF6B7Y= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1708362639; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=iJ+/nNmhztD2mxNSusR0IJsWj0+7uBy6vvC4GbPwuWQ=; b=/daxwwh55SbZF++FFxRkeITg+96/LrCNGsPSCOlEAdvv2q+DUT9rsbuwQ7aKDF/m+Cz8+q d2IdT9jCbxPrtRCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1708362639; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=iJ+/nNmhztD2mxNSusR0IJsWj0+7uBy6vvC4GbPwuWQ=; b=d45RFPsuSWbxcqJRSgx0V1IwRo91wuipQpFGJS4+c8oeFdr3OzLR2AY5JKPswKocWKNxFK NawpNosH9BdQsW9/avKmtgZmuTit+6C8P7fs2sQy8Cbu29FHh+gmiqtcIIi2CbdEWwv/t6 i/1wCRjVq+3tP27r5AMgDYWYHmF6B7Y= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1708362639; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=iJ+/nNmhztD2mxNSusR0IJsWj0+7uBy6vvC4GbPwuWQ=; b=/daxwwh55SbZF++FFxRkeITg+96/LrCNGsPSCOlEAdvv2q+DUT9rsbuwQ7aKDF/m+Cz8+q d2IdT9jCbxPrtRCA== Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 70A06139C6; Mon, 19 Feb 2024 17:10:39 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id 1+N+G4+L02ULOQAAn2gu4w (envelope-from ); Mon, 19 Feb 2024 17:10:39 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 1652AA0807; Mon, 19 Feb 2024 18:10:35 +0100 (CET) From: Jan Kara To: Ted Tso Cc: , Zhang Yi , Jan Kara Subject: [PATCH v2] ext4: Verify s_clusters_per_group even without bigalloc Date: Mon, 19 Feb 2024 18:10:33 +0100 Message-Id: <20240219171033.22882-1-jack@suse.cz> X-Mailer: git-send-email 2.35.3 Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2750; i=jack@suse.cz; h=from:subject; bh=WKFiFr64CUB/1NasbChOmjnE/kI1Szel06Fw0y9b3l4=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBl04tzaDbKExYHf1lB0mzxBCe7oguVUBOSsAZgQiut tgU4ESmJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCZdOLcwAKCRCcnaoHP2RA2ScLCA CaWPwXteu3o6+QR/jo7/r4NrhPAd1GzqSRJ8ntaLzHEDgxf3OYX1qX7P2ekKpZ1n5U0oYNmYgXtYw+ VP3rKBHd2UqcEbMZPlCK4JCwlteBXIymPk4OQIM7Aa2feX/aQJSNyBFW/tt70v/dmgndPyGlot97pY Zx7P0p/rh869dhY0osNhcG+EaR+XtU9WFjO4eTwt8vivgH59U8x0JpgfQPL/CSiY/ixCX1nG1oZ93Y AzhAYDtBp1otgzoNOxDb6da4PICYRcFVxrTfMrqw3yCEkgr9IQ+RYQmIaH5djWiTEw0S4ouZOB7gVA KfHY9tYRizs/GA4/g+89SyBBBYrbp0 X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Content-Transfer-Encoding: 8bit Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: *** X-Spam-Score: 3.69 X-Spamd-Result: default: False [3.69 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; TO_DN_SOME(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.996]; MID_CONTAINS_FROM(1.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-0.01)[51.08%] X-Spam-Flag: NO 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 --- 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 ? */ -- 2.35.3