Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3412138rwa; Tue, 23 Aug 2022 04:28:19 -0700 (PDT) X-Google-Smtp-Source: AA6agR7DS0+3IE7OpMMlgx6iXuZmZtV3QyDptPsGuqUhs/PP8rkQ8b1qsZA8jT1yXU4uRwce7tji X-Received: by 2002:a17:90a:4801:b0:1fa:98ec:fa2 with SMTP id a1-20020a17090a480100b001fa98ec0fa2mr2805053pjh.41.1661254098979; Tue, 23 Aug 2022 04:28:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661254098; cv=none; d=google.com; s=arc-20160816; b=iQnwVxoJOxCBkxr9TKEZlqmcKgHEl7/RN1v9puFq64eGrx+qRBpqQsyNhsvaV8Bxvf v209DJ1GGJBuKRHHYFxf7PBQm6SBlh1HQmU6Y9kqnw/4M4w98O+zIP2aC/YG8gKgoOvc 0hfUWz7Gyf2BdtcpG/vdnqmeClRyMFWrCkym7x7YeZ7TXy2xowLikGpCPQjxWiV7cgLL 9xYetPirnoSzwTXsRX+ryVs/jUjrd6dxyfpRRQTM0vhFQaiAxf4SUrIT0OsgBsPdFGn2 upOGnifrqlKt15tKCfDjv9ALHDO0kwcTedLBV8V0T/D7Ten1bwfW4a6CFIVsRBrQP2KT iKIw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=UqPwQK//JpTRf8Y72d8AOR7sdXydO5y4bwshzMvHqLw=; b=tegdSwpSlMwIvzrA6xKjdicHJXwTMCROIlwcaTmWcZIFSl5z/gM8+KAxxb05DtGbBY nzPGgsMQWCSbu2L1cuLvrlOk+yDcAqulh56SlDJPMaGC7xbUKiS4DBQwhnI3xioaw5vT NdR2EreHu6E55ShtrYEJlSfJ+K3YVa01JAKNLozvDqe3dAAKFwZpinDzzX74RieXj1rU 9KY1mY/KNIJqzKaXnq8XKMX4bdZbX6otbwSu+LmRySBJQdw/hES3qFfHNngVS4WmxE1h ZV1M2j9kGQsH2vQwiun1B5IMttDITsiDjGg+6Tu6c4+eRnf1PxCwe2fEwFO6tHHUeth7 z0sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CSYd3+ZC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g21-20020a056a000b9500b005289aef5ec5si14387962pfj.311.2022.08.23.04.28.07; Tue, 23 Aug 2022 04:28:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CSYd3+ZC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353603AbiHWK0x (ORCPT + 99 others); Tue, 23 Aug 2022 06:26:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353639AbiHWKLq (ORCPT ); Tue, 23 Aug 2022 06:11:46 -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 26792719AF; Tue, 23 Aug 2022 01:57:53 -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 494436153F; Tue, 23 Aug 2022 08:57:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52F7EC433C1; Tue, 23 Aug 2022 08:57:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661245071; bh=IYZO8npxWKcX2UbrOdmes4WW/OzWUgGzMI1e69PPBiI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CSYd3+ZCaSeBuDk5PzoBbHUl2ixMv5erPpclvp5CrvcJtycFzhu2vccmFcmaqETkp I4b+ECD68Nde1CwgkK0i8Hel0sv4vba82TGSrQKarLZQbleDTX0M+10eAi34J2DpOV SRTN/rCuGKNldahLsip9/EAMxErtYHNHfIZxspnA= 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.15 205/244] ext4: avoid resizing to a partial cluster size Date: Tue, 23 Aug 2022 10:26:04 +0200 Message-Id: <20220823080106.344497069@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080059.091088642@linuxfoundation.org> References: <20220823080059.091088642@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 fa3c854125bb..862cbbc01d6e 100644 --- a/fs/ext4/resize.c +++ b/fs/ext4/resize.c @@ -1977,6 +1977,16 @@ int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count) } brelse(bh); + /* + * 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 &= ~((1 << EXT4_CLUSTER_BITS(sb)) - 1); + retry: o_blocks_count = ext4_blocks_count(es); -- 2.35.1