From nobody Fri Sep 5 20:05:13 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A600C49EC5 for ; Tue, 23 Aug 2022 12:03:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244555AbiHWMDf (ORCPT ); Tue, 23 Aug 2022 08:03:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359654AbiHWMCG (ORCPT ); Tue, 23 Aug 2022 08:02:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A17597D61; Tue, 23 Aug 2022 02:36:19 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1C32B61460; Tue, 23 Aug 2022 09:35:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0D962C433C1; Tue, 23 Aug 2022 09:35:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661247346; bh=ZfhN6gBPas6paF0r6SYHnlPxLeobyhbICE7aQpwDZpg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PtCqT7DkzmTUcJ9ZAKZRmjI0WGpRMN6Phi/BUDrVFYDyLcyl23J3nkRKfBVWvcjnk ZJhn/CtJDthJrHW/xB267/ofs+W9EjJB7TuaUo5l1tB7eA3oE3e2/i/vwhuQHwED4l LNVmf0DW6FCQW7tkfkenPWRaRwO11CdyRzGPegto= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Oleg Kiselev , Theodore Tso , Sasha Levin Subject: [PATCH 5.4 368/389] ext4: avoid resizing to a partial cluster size Date: Tue, 23 Aug 2022 10:27:26 +0200 Message-Id: <20220823080130.902458340@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080115.331990024@linuxfoundation.org> References: <20220823080115.331990024@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kiselev, Oleg [ Upstream commit 69cb8e9d8cd97cdf5e293b26d70a9dee3e35e6bd ] This patch avoids an attempt to resize the filesystem to an unaligned cluster boundary. An online resize to a size that is not integral to cluster size results in the last iteration attempting to grow the fs by a negative amount, which trips a BUG_ON and leaves the fs with a corrupted in-memory superblock. Signed-off-by: Oleg Kiselev Link: https://lore.kernel.org/r/0E92A0AB-4F16-4F1A-94B7-702CC6504FDE@amazon= .com Signed-off-by: Theodore Ts'o Signed-off-by: Sasha Levin --- fs/ext4/resize.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c index 306003e29c4c..f0fc7fc579e6 100644 --- a/fs/ext4/resize.c +++ b/fs/ext4/resize.c @@ -1979,6 +1979,16 @@ int ext4_resize_fs(struct super_block *sb, ext4_fsbl= k_t n_blocks_count) } brelse(bh); =20 + /* + * For bigalloc, trim the requested size to the nearest cluster + * boundary to avoid creating an unusable filesystem. We do this + * silently, instead of returning an error, to avoid breaking + * callers that blindly resize the filesystem to the full size of + * the underlying block device. + */ + if (ext4_has_feature_bigalloc(sb)) + n_blocks_count &=3D ~((1 << EXT4_CLUSTER_BITS(sb)) - 1); + retry: o_blocks_count =3D ext4_blocks_count(es); =20 --=20 2.35.1