Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3415881rwa; Tue, 23 Aug 2022 04:31:59 -0700 (PDT) X-Google-Smtp-Source: AA6agR5OmixmkX737poszP4EhB590pgEZcgXUeEoKpH7RsyIcG4wbT9gJAy5eXm+gA0PtupFmOYK X-Received: by 2002:a05:6402:2b8b:b0:43a:5475:f1ae with SMTP id fj11-20020a0564022b8b00b0043a5475f1aemr3291903edb.363.1661254236598; Tue, 23 Aug 2022 04:30:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661254236; cv=none; d=google.com; s=arc-20160816; b=ISxBNZ0Uqjkdw7w2n6o/9C/UUDqhKbqV6ZhJJdHGOnm98ll5Kzu8GG+58NrrqHH7vp Z6BhFW4wIpfVOa680c/l3uOxRkllNPocNX11RQiJuBxMTdTf4nSgo+rM7V02fX7LcIfv 5ey6FRQHtibVPGqol3kf6kmgTX1nQchfRTSbE03cx9Gndh9vIrmmaX/v4JEDhqLVmPSZ 0dbPp8RxfUujn2wYriiU7Y7KOLdV0FZcpsYZA9xhH6ltgSPliU+uO7MipU+M8e55Dwhy r+j8oMA5R3uB5xW5TXlvNmeWD0ezTPifdl4EDZbrpsrCB4hlCf8HgBNBXXmWfatcKRhF 11Ng== 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=dKyL3pgNTc6STdqN9DcbpmGKltVic47DMHLDyGpm7HI=; b=0f9xLLLm5SVl54cEqKTbc6CRrB2ORqnj9bXlngOwGcdV/WlF3U9sDlzCM5luwWpX2a qWCckw+xCa9jQr/FVnM3hrni9dByXr8blaGHswxPisWC9LY1ujyE1oUds8gfoQJ2ewIb YaoioAGyXnrJ8c9yK18PUAmI/YC31aob+b3O0GP2qlsQ4NPQrItnG6GYK1Rkt/JG1Gf4 rb9mmX8i0DsIG/jp/iFvpYXuD5lBkZ8lWC0oEaL3j74uc9xDqGfbkpKS0QQcJSTlxA2N bqbgSBV9pAuy8SJ58BbkKZnVb6fsNyb8+297mEAKS6xtMSYvND8lNBjvL/4iA7layWDW nrDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=t8XNS5v4; 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 25-20020a508e59000000b004468d4978cfsi1873396edx.341.2022.08.23.04.30.10; Tue, 23 Aug 2022 04:30:36 -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=t8XNS5v4; 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 S1356634AbiHWLDQ (ORCPT + 99 others); Tue, 23 Aug 2022 07:03:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357273AbiHWLBy (ORCPT ); Tue, 23 Aug 2022 07:01:54 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFBD2AF4BB; Tue, 23 Aug 2022 02:14:27 -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 ams.source.kernel.org (Postfix) with ESMTPS id 85930B81C85; Tue, 23 Aug 2022 09:14:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CEE4DC433B5; Tue, 23 Aug 2022 09:14:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661246041; bh=LIzfmA1mLukFGyq63niJTErm1FewG0B2a5QkgHosg7Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t8XNS5v4zHUPh6RlQdDsrXkOC/+SVsAnduS0AfDeLGgN/sJpLbKxN4+dNfrUQep2w mzz5MZ1f4bKba7k4ENZxkvafXxBEOQFmZKuJTtazz8VavxoJKOHWASfLduytpBOPqp xHcceM5OMYUV2Foa7TBoWSQUrvUNAjFzJZNPj3FU= 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 4.19 269/287] ext4: avoid resizing to a partial cluster size Date: Tue, 23 Aug 2022 10:27:18 +0200 Message-Id: <20220823080110.432124883@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080100.268827165@linuxfoundation.org> References: <20220823080100.268827165@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 88f9627225fc..dd23c97ae951 100644 --- a/fs/ext4/resize.c +++ b/fs/ext4/resize.c @@ -1981,6 +1981,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