Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp3248470pxb; Mon, 18 Apr 2022 20:34:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw76+Xn5K9HCZoB1Dh9O5cPyXJ7hHw0SY/+bJRKBK23VCijXAldWhIU8xnzZvh+UJY/dA0a X-Received: by 2002:a17:902:8e82:b0:151:777b:6d7 with SMTP id bg2-20020a1709028e8200b00151777b06d7mr13452022plb.172.1650339240892; Mon, 18 Apr 2022 20:34:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650339240; cv=none; d=google.com; s=arc-20160816; b=Me8pf+PqB3e1D812olrrTUee1Pcyd7yE+cJD/XcUgpGNkEh3yZX/p13JtWFFKSpXnE xgkapezIt4UL37sN0PYHuR1WuYfIdKIsM+Ltz/quhi4Fo7qP3LyQWXyKAvvwqY1aKQnn GeqPCnKOuoUhGaMm6hkFhwEKC3iVce6pE4WpxSuzkcGotgfBDuoeMd+bOXcqQWsYUEhK wI2ETo1bp2RDyMvjifQMl2p4zxLoPi0KEXK2ucyOgDWmuAmZTJpmHo+xpbfJ+xnJt8gl AWxBKIJpOUE7syeQhUV9CN7VubPAQ2oKMeJqbdyhnrNMoLZuQvXFu0xbkmn8yJGiuGd9 dZow== 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=0d1HOPBCxSNCBQrzOQldo72zZ+sIqN7FvzpQGZinVAU=; b=I/AcfenOE2HslqM1zLd0divWG4bzYWlRnX/FKKK8eZ1NvHX/V+DAqnVEEUcbz9nkvL CDV2mycGYUtP2K1yJ2IoDchQ5XFy9wgn/h1IXD2CRtnFtn8lFiSwvr2HJYWs7QiohcV2 YWnNVvwGRxJbmrb0/CzRlV2X3b3MY3Mm7eJtKGCE//fwDVst8KIHa2/IWeQSQpfp0oD+ FixkZ3EYbwwALH4WSOZCi2J3PoC1YM6X0e+Bh+xdxEHoisNoyeDytR/LFaF+UO2fjhw9 pN0jwfUL3KNDVzKOr7DH3UIdFiiGjEzDVvUqHxoJIPscBV5QCDVKp1TYdOwxs142zeRj +uhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1GcqsVvA; 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 a6-20020a17090ae20600b001cb62eaf933si887325pjz.71.2022.04.18.20.33.45; Mon, 18 Apr 2022 20:34:00 -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=1GcqsVvA; 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 S1343777AbiDROPI (ORCPT + 99 others); Mon, 18 Apr 2022 10:15:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244643AbiDRN5J (ORCPT ); Mon, 18 Apr 2022 09:57:09 -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 31BBE2AC70; Mon, 18 Apr 2022 06:06:43 -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 C239060F09; Mon, 18 Apr 2022 13:06:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B08DAC385A1; Mon, 18 Apr 2022 13:06:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650287202; bh=sIlGPuICAm1ZU+WN1JUAVEk1pJn9L2Hov/TGqQ4r7CY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1GcqsVvAEXrgu/B9kwZdmHaq+StuX0k+CwKU1AaPTzCS8U9X39TJ9app/4BGyYoot /XTd9WJXDFB3YA394iyGvQbGaMI4t8OS6Hh3pwxJHavHj0nhDHFNtpJMAnFH2WsHo4 NHWN+ZeRDW3XXHYj/3NnRbTT6MH4k3u4RyFgIKXs= 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.9 089/218] ext2: correct max file size computing Date: Mon, 18 Apr 2022 14:12:35 +0200 Message-Id: <20220418121202.154103461@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121158.636999985@linuxfoundation.org> References: <20220418121158.636999985@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=-7.7 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: 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 186912c9bf56..5ca1f73958b0 100644 --- a/fs/ext2/super.c +++ b/fs/ext2/super.c @@ -743,8 +743,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