Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3305037rwa; Tue, 23 Aug 2022 02:23:43 -0700 (PDT) X-Google-Smtp-Source: AA6agR7dMJXWEzXCnF0+RGy3FK1/89nYVoAtkQqZ4AvBTCOv7EXPDLI4kD1FL9U/fmfwwz4ieXIr X-Received: by 2002:a05:6402:190d:b0:446:871c:b536 with SMTP id e13-20020a056402190d00b00446871cb536mr3028652edz.175.1661246623530; Tue, 23 Aug 2022 02:23:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661246623; cv=none; d=google.com; s=arc-20160816; b=bF3pRhG7vPoiPBysIyeIkHwNTUfGRNdcnyyDNxU2Frd6GzRIWMGpcel0wSeeKsWj+t e2Ducn3JBZpgLkEWMrkGfl1DX9BChejIkhg1wRDBpUcfRfx7DDe92Hv5/8LASHFrPaaT Un7r2EaysVYQyFSvICYmWGRJuJ3FX4gJ4t3jZgxr8jfnF6TI25vue41Us/icXqRZyRrB +5lAgHUh+mHx8+DLRHMSZ63wlRsf1kSbIPeOwbBVNTpGBRLiPoJWUBWtC0DOLq12ETuF 3uVz90xb95Qz0xbAwMCypYQ7/W0l+24ZpPuLpBw/qQv+tqSwttSjCdzpIAyn2YqMAJQZ syDQ== 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=OpZm328Kw5nymcSSuteCNQVdFCBiIlCN3kdjJQpRYuk=; b=DdhkifzqaotB+pjCzAvuQa/3eIOF+RV0DAwBest9IMHnIFwgYTkb4OyuZZLs0C8cvY sRpIKQFYNL/3ytn2LjsrkUpDW+ihaNHhe3UkJg2Sua75D6fTxA+1CzSAF5DXnnkUnyOc CVEcJ22N4s35m+9w8XwuGgLdMwhN0T/Ti/G91aQV8oJ+yOFzBqh5MWOjFhG8/L+HVuFs CfmTLdMUotfk1Q8zhaZuUrAEvzhCy/42mxUgoWpD8zr2BWe6S5yse7SZl4+U21wMiFZj tE0T9j18KkZGkStFtyKcXmHt+aStw8eLE0DjzkY0K4hstmFyKn5QAtkY2W6pKKAMfOYN iUTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xCo5W5p5; 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 eb6-20020a0564020d0600b004359f471717si1972845edb.0.2022.08.23.02.23.17; Tue, 23 Aug 2022 02:23:43 -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=xCo5W5p5; 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 S242568AbiHWJT1 (ORCPT + 99 others); Tue, 23 Aug 2022 05:19:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350278AbiHWJQv (ORCPT ); Tue, 23 Aug 2022 05:16:51 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94DCE895D2; Tue, 23 Aug 2022 01:33:05 -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 61E7DB81C29; Tue, 23 Aug 2022 08:32:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82D71C433C1; Tue, 23 Aug 2022 08:32:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661243567; bh=ho87OgdVd2lfgHZPkZVU6G4Js8hh1GLxQWbGPKq8aXE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xCo5W5p599fYskNkW9fPEJQ68bFA2IBKn/keqAhYrAw+zHwcWr0nuu7b3ZGX0JcBQ x8qUBIusIpqtrqQedLp7m0uV2NZhmNORtsiPBJhbx0/hF/MFtTsLCH/ebRnXWUuKcZ Kt21s8hEa1lR+E0MdToyLTOrflV9TXdiyYd4JUaY= 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.19 317/365] ext4: avoid resizing to a partial cluster size Date: Tue, 23 Aug 2022 10:03:38 +0200 Message-Id: <20220823080131.440477452@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080118.128342613@linuxfoundation.org> References: <20220823080118.128342613@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 e5c2713aa11a..cb5a64293881 100644 --- a/fs/ext4/resize.c +++ b/fs/ext4/resize.c @@ -1989,6 +1989,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