Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1002317pxb; Wed, 6 Apr 2022 06:28:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwb+ecBuPl7suIifQLTZtBb7e8dU48ba1FsD1klLOI6Gh8bBIIT+sadGs24TCLIarj7oZvJ X-Received: by 2002:a63:1c5c:0:b0:398:f69b:1996 with SMTP id c28-20020a631c5c000000b00398f69b1996mr7136800pgm.370.1649251699280; Wed, 06 Apr 2022 06:28:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649251699; cv=none; d=google.com; s=arc-20160816; b=ZPO5XxNNYbpQE86dZNsxXj5tvYKQ902k08hyUFY2D0juqptSQTpSbulKiOFJzteg76 DK93FrDarG5Zyi6he9kEzfwWlpD1cqbtStYSDz2op2ACR5WWLPchIitA9rl5RFeb/aNp Q6FWmdl1BKKT2Z9QWirVuAbSIlgUIGjRwjyMXYUaanPVPj0wKce1CDGtqHRn7qrGWC3s 1kKiFcE5MHS1zjInZB3Yx/dAZnI+OvXhD2BMwMgAKNoPn8L3YCLZK91BerECeELdxOXB aDkJPRVbhzK8Wk5cOKqwqpX5g+gPIPrSJd0YT7MTVEqQ5kXZJ+cWDi2IHDFCp1Okzf59 ZT/Q== 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=xuuPO8Gu90hB7xRkEuJl4+cWaUKvu0YXuL7FWHgl6p8=; b=otepAkd//QnESE1aERF7b2HnMuAF5rk3HpBIP0HPItIJWhQb1bktskCSy3YPhs/uc+ hxKdkrDv1WJQBPkJvBZ+AoKkE4yDPebwWQcy02+/i9pNBHYJRFQtpiz3Ow+Qj+Shx/zK 7sbHVPpXGYrSPEXidzYHD5FGwrUq3KMTizrQ9zVVUcS7sqOTLtFhrZLt5uvy18V1cIGY FHk2AUQSjtaxGFDq1nMQTf+3/un7RCLyZBFOljvcIHPwedg3MLurHe/TnCOelh+h5EUV dsiByVUaRg++IfbWt7fvluSpGcrt6cgIXgTv4rB6WLN6JK4LiIfsHC4stPgzbPNV6ki+ Xbcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=geMa6udp; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id r16-20020aa79890000000b004fa599bcf9bsi14841453pfl.271.2022.04.06.06.28.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 06:28:19 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=geMa6udp; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 964C45CE507; Wed, 6 Apr 2022 04:09:40 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1579622AbiDEXcL (ORCPT + 99 others); Tue, 5 Apr 2022 19:32:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349156AbiDEJtP (ORCPT ); Tue, 5 Apr 2022 05:49:15 -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 91D345F6B; Tue, 5 Apr 2022 02:41:44 -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 303E061368; Tue, 5 Apr 2022 09:41:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41C5AC385A2; Tue, 5 Apr 2022 09:41:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649151703; bh=6EwFOGsPJ+YtAsXr+TGu5nCqNtOeBU5wO0bhRpAxWnE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=geMa6udp9ABrWr8UZNjjqpNy+ZEwqBJyEc8uDA5ow4REkIhNqlETRapxNFlDLzG/9 CYxlVNDqkTsDwUGDlYWro+58qhhmugivlebW7LI/eseVtr1t6bnPRFl/SOj+c1aqju 3dfAzMbWUiEUB82nsOpYrACm0FOf1pO97E49rRDA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhang Yi , Jan Kara , Sasha Levin Subject: [PATCH 5.15 494/913] ext2: correct max file size computing Date: Tue, 5 Apr 2022 09:25:56 +0200 Message-Id: <20220405070354.662664214@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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: Zhang Yi [ Upstream commit 50b3a818991074177a56c87124c7a7bdf5fa4f67 ] We need to calculate the max file size accurately if the total blocks that can address by block tree exceed the upper_limit. But this check is not correct now, it only compute the total data blocks but missing metadata blocks are needed. So in the case of "data blocks < upper_limit && total blocks > upper_limit", we will get wrong result. Fortunately, this case could not happen in reality, but it's confused and better to correct the computing. bits data blocks metadatablocks upper_limit 10 16843020 66051 2147483647 11 134480396 263171 1073741823 12 1074791436 1050627 536870911 (*) 13 8594130956 4198403 268435455 (*) 14 68736258060 16785411 134217727 (*) 15 549822930956 67125251 67108863 (*) 16 4398314962956 268468227 33554431 (*) [*] Need to calculate in depth. Fixes: 1c2d14212b15 ("ext2: Fix underflow in ext2_max_size()") Link: https://lore.kernel.org/r/20220212050532.179055-1-yi.zhang@huawei.com Signed-off-by: Zhang Yi Signed-off-by: Jan Kara Signed-off-by: Sasha Levin --- fs/ext2/super.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/ext2/super.c b/fs/ext2/super.c index d8d580b609ba..3d21279fe2cb 100644 --- a/fs/ext2/super.c +++ b/fs/ext2/super.c @@ -753,8 +753,12 @@ static loff_t ext2_max_size(int bits) res += 1LL << (bits-2); res += 1LL << (2*(bits-2)); res += 1LL << (3*(bits-2)); + /* Compute how many metadata blocks are needed */ + meta_blocks = 1; + meta_blocks += 1 + ppb; + meta_blocks += 1 + ppb + ppb * ppb; /* Does block tree limit file size? */ - if (res < upper_limit) + if (res + meta_blocks <= upper_limit) goto check_lfs; res = upper_limit; -- 2.34.1