Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3468758rwa; Tue, 23 Aug 2022 05:23:28 -0700 (PDT) X-Google-Smtp-Source: AA6agR4mIRxxhxc0C+HxJUjUMK9lUhwckdvOn+TGowdmQh10i0lOAQ3pQCP2YHoyIgDJ9v37UVL+ X-Received: by 2002:a63:205e:0:b0:42a:98c6:182a with SMTP id r30-20020a63205e000000b0042a98c6182amr9925115pgm.482.1661257407898; Tue, 23 Aug 2022 05:23:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661257407; cv=none; d=google.com; s=arc-20160816; b=bHYuGIU07sYBBw2KContJmpujoVNM4Y6gtWr4uGpfwpLSg+9DAp0Gw/phX2feQSveT WSDxZ1H5eJv1RDe6nto97V0lov7lWkyK95CcWq8mqRwkOOSsv+jFrjbzckZb1XBtAsqF fN+pMyw/i3aq8nhqdE75qfLzXyLrmCQRj0HR2H4vSqeC33tOGV8ni451WkLXfz/FDZ+k 7Se5TK9M2K0IzbrI+huFhsNTmETZ2kqzJhm617d+p8Fte0l+w9+BysBQzmO6TKNSbsR7 wrT4pjoLx+fX6o/AjC2WfhGpspIPSj7J41An8zxtRLlWSzMivek9/7FF+ABuGXe7JPpM h7tA== 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=qvlcBP8dBVy460vV67p3EQWaY/6KLNWaHqjCnCWaMYM=; b=Gow07R/1iwshdNRe6THe/mbgVTJHbfFUuh78c6lX1yM+9c16GdjCYT3sZULctZa4PL 8N66Ix/XGzxN+8UPh6jaEpFkPG4FJKnloa8wm3d4nu6h4owwnKus/x3hret5JKOWxAk+ w8026stEC3Fk0nbd5NG3o8i0FVG05JM6oTGQkPHHfLBz7IAwK0LwxFkVQJH/AxgP+K1Q Tf+phhq0A6gH6Gpej/NoDIaN8Ywc7xgc7k95liczRc8gs3+Pw6c/CijTzd5hfdIlnlFA jbm5znyKqhE300dH6qVQ+SnP/WU+YehudCq2n9pnbgj0CcZczYK8XaQcxoBg63pgRihn fwrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kLCJqtps; 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 k127-20020a636f85000000b0041b8696d9e2si13854151pgc.88.2022.08.23.05.23.17; Tue, 23 Aug 2022 05:23:27 -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=kLCJqtps; 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 S1355080AbiHWKWt (ORCPT + 99 others); Tue, 23 Aug 2022 06:22:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353286AbiHWKLM (ORCPT ); Tue, 23 Aug 2022 06:11:12 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DADF87E83D; Tue, 23 Aug 2022 01:56:23 -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 8B835B81C3E; Tue, 23 Aug 2022 08:56:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C256BC433C1; Tue, 23 Aug 2022 08:56:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661244981; bh=EKvWYv2oRvwWVhIgF6Am3ZkEka/EGkblTHkR/o9hnYc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kLCJqtpsf9rymknU6mpEGEka4n/vvo5m5hRLXdoJweM7ojHO8hBvKXXdaZX8Z1Bst RfrUvtnBhlnqiRKvATzGLSYGzEO4Q2ugw9PTatnZeAmH0YXsM8cd3YTQwsBlDgcMd+ 3Ce2nrEXHeZQGyPJ93luzNLAQAn5fEv33wrd/HSA= 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.14 220/229] ext4: avoid resizing to a partial cluster size Date: Tue, 23 Aug 2022 10:26:21 +0200 Message-Id: <20220823080101.500040103@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080053.202747790@linuxfoundation.org> References: <20220823080053.202747790@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 a50eabffa411..30b2798244fa 100644 --- a/fs/ext4/resize.c +++ b/fs/ext4/resize.c @@ -1951,6 +1951,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