Received: by 2002:a19:f614:0:0:0:0:0 with SMTP id x20csp63663lfe; Fri, 15 Apr 2022 19:40:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfKAWj0PABJHIuP8YsVaX9uvbuC2Qq/Mw89pnagl79XvqwYZ6RtoAhW8ORclxT7ZtRP7R0 X-Received: by 2002:a05:6a00:2310:b0:4fa:7eb1:e855 with SMTP id h16-20020a056a00231000b004fa7eb1e855mr1773133pfh.14.1650076849735; Fri, 15 Apr 2022 19:40:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650076849; cv=none; d=google.com; s=arc-20160816; b=pD+yutHjpLyhdq/AGIanffo9cLYH67s4IuQJkvCamwKV4kW0IlJqZmTFf3m+kEB7pH LapklOXocxy5MV1bQP+RdqfVw253lCUoeBm7ynxfB+pm6UjVErnbCkjsvbOZ/xZ7p5NJ b8Y4VIokkfUXI9j9olgtPUfIkx+BSMt47qBU0m8W8CV4NFnZEHx2DifFwNGX056aDjMK IjWkmxI9WEzFFsoHS24U8X87E4pPA1p9og9wko/LC+nfL1izxAOzQ7gPGKYUzuPHqho8 ApldUZPaXOUoAa3dfSXhMLt9e0F+o7fbMva0a37iemp3ZW/Zt2e3yZHLuGHMdCHlOJG5 wxnA== 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=eQkSV1QraaDOdNPzvjVkOc/vPkXO+nB9CMtPEoEPK80=; b=zxKO0TihT/SrvQmY/Py2TYK2OItNbZAs9ibW0pvdUpFDWliAHUB7IC7G82J9wXKx8j 8H3dfVkLpazrUVOoGW6V1PoECnZXOjl6ymSsi3/X/aVKWB3Xuld7FEDeVZwzA7NtXLcu 1LeuSiYZ818QU3Fbn5UZXXZnsZoCnJWetz53RJcvA94ChP6fgubNZ0RDGpOqq+snB7QB 3ayP/r33+CyC15D4M1Sa8tlBq68DDb0B037jMazkEd13O3wcxJ9LoZgQd94HGKXAmrhy XJszgaMS/JMIc8Au4+stYI9BOiYCvnAAUnyJElkb26iq3DzAyw1dzeAud4i1+pcXyOfU FtoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=H9Yo7hxW; 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 i62-20020a638741000000b0039f0abb51a1si2807809pge.1.2022.04.15.19.40.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 19:40:49 -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=H9Yo7hxW; 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 2D28118205D; Fri, 15 Apr 2022 18:48:11 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245106AbiDNNiM (ORCPT + 99 others); Thu, 14 Apr 2022 09:38:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244604AbiDNN1t (ORCPT ); Thu, 14 Apr 2022 09:27:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10F7CA147B; Thu, 14 Apr 2022 06:20:33 -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 3FD23618F8; Thu, 14 Apr 2022 13:20:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4CB78C385A5; Thu, 14 Apr 2022 13:20:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649942432; bh=+pom7rYuiu1GHH2u/bfaDM5Mokwk4HiMpu7sSxFzKzc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H9Yo7hxWtXZGzlJ4rGCfU13+VSymLwoFECkS/NX+1M3Kj9XokE2OKko7gzIWwcE0O tsMGyWTumI4DU12q2A6qaFvT7zKcs0uDp0qxfALxuE4JOwCI1Gt0jWTkwAho0rxGCW DzAJzUE4nsAIkmY6Ie1pqjkK+RVS4aXlixKrNodg= 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 4.19 134/338] ext2: correct max file size computing Date: Thu, 14 Apr 2022 15:10:37 +0200 Message-Id: <20220414110842.713711498@linuxfoundation.org> X-Mailer: git-send-email 2.35.2 In-Reply-To: <20220414110838.883074566@linuxfoundation.org> References: <20220414110838.883074566@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 80a3038e0e46..ad9fd08f66ba 100644 --- a/fs/ext2/super.c +++ b/fs/ext2/super.c @@ -780,8 +780,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