Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp348528pxu; Thu, 7 Jan 2021 06:40:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJz0wFuhu+EB+9swwdePD3X0oTtFVaMrAvqyq/2VO2ge9daI2cWCuP2vz+yO4NoPLOKdDzcM X-Received: by 2002:a50:8387:: with SMTP id 7mr1804814edi.131.1610030400117; Thu, 07 Jan 2021 06:40:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610030400; cv=none; d=google.com; s=arc-20160816; b=DuEXCmoRr3atj0HA+KGuKnamGecW8KZDCrXrMpRZdK41gGmgD/KA5Jd5rHTmM5O/RX 0F5mYyc0E0Ogn7tmYyPUOKqwNfnhHE8fo5Wab6V6cGU4F1JDTh1fxkBrawGbuk2fdZgt YX2zrKvBrfEg3zU4JQ6fTxpOKlh4T/c/zhLHKbppFlbNJVyybHaTBVYRLGGBDv1e8jhq NQD1wBpkZF6XM7gEUCMKQQgyRc7NtMmDOA9empdp33usgbm7esqt4Zu01PR4nQquSTRo xgQkCmz/kOCwIcHeq7cV+M1fXYOwa91y68CcZKjwE/OMUzYqjA5x8KPETMTQIFc8aAJD GP7g== 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=hNB+ffd3nFhCPFv4Dfrnzp9zbmVnfJH/xeCMsh15buA=; b=qWYzFJPeptBlUw04SED0q5q7ca5Zs9RdvnSxfPhZ17fiuVwS8ApGrWR8lgOYk4Iqqi GOGViIiVr23mEJFgulU2EhFbD9oqEp7sQ1e7zvWY04KYOXkHzkTJkEkHJv0T9f5DPSZb 61tai0mSNH3vsMbA+3FhJX4ru9QYPmspjP3tBepndL4bFT3LmmMD9mF2S0eOQQls9u42 2AIGZgSoO+mMm6yeJDD6wmiIWKnfghWOKW+HHCeiYktIYbB4Ic3ufUvPFB1RLtX/arZQ UzIYXskMkJ4x/MAzoxHUOQA/fNhpiHN0PvKStJ6LZyXp9cNTwehjqmAjhus6qLShy//1 y8OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=F7fsngo3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id by23si2320822ejb.165.2021.01.07.06.39.36; Thu, 07 Jan 2021 06:40:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=F7fsngo3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1729795AbhAGOhu (ORCPT + 99 others); Thu, 7 Jan 2021 09:37:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:46228 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729147AbhAGOcD (ORCPT ); Thu, 7 Jan 2021 09:32:03 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 28AA72339D; Thu, 7 Jan 2021 14:31:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610029860; bh=3tqmlEopHF5693Gx9TDEZtslMfY3JJfYKPA1NqRF2r0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F7fsngo3BhMXFrd1lZZmCaHvcSi8cCzVtGfmsXrPQene4eeUJ6aPyMtQ5fed1M8i8 0R8E2Jrh1u/qCdeS2WVpbZA3nW3i0kLpIRU7S5FEbCDBQkvmqQAbv35M0/8ZEQHaW0 OaSGl5lJmYJu2nIbaUeQ7g9k1MF7wMggoeA4pGrg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andreas Dilger , Jan Kara , Sasha Levin Subject: [PATCH 4.14 21/29] quota: Dont overflow quota file offsets Date: Thu, 7 Jan 2021 15:31:36 +0100 Message-Id: <20210107143055.965897593@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210107143052.973437064@linuxfoundation.org> References: <20210107143052.973437064@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jan Kara [ Upstream commit 10f04d40a9fa29785206c619f80d8beedb778837 ] The on-disk quota format supports quota files with upto 2^32 blocks. Be careful when computing quota file offsets in the quota files from block numbers as they can overflow 32-bit types. Since quota files larger than 4GB would require ~26 millions of quota users, this is mostly a theoretical concern now but better be careful, fuzzers would find the problem sooner or later anyway... Reviewed-by: Andreas Dilger Signed-off-by: Jan Kara Signed-off-by: Sasha Levin --- fs/quota/quota_tree.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/quota/quota_tree.c b/fs/quota/quota_tree.c index bb3f59bcfcf5b..656f9ff63edda 100644 --- a/fs/quota/quota_tree.c +++ b/fs/quota/quota_tree.c @@ -61,7 +61,7 @@ static ssize_t read_blk(struct qtree_mem_dqinfo *info, uint blk, char *buf) memset(buf, 0, info->dqi_usable_bs); return sb->s_op->quota_read(sb, info->dqi_type, buf, - info->dqi_usable_bs, blk << info->dqi_blocksize_bits); + info->dqi_usable_bs, (loff_t)blk << info->dqi_blocksize_bits); } static ssize_t write_blk(struct qtree_mem_dqinfo *info, uint blk, char *buf) @@ -70,7 +70,7 @@ static ssize_t write_blk(struct qtree_mem_dqinfo *info, uint blk, char *buf) ssize_t ret; ret = sb->s_op->quota_write(sb, info->dqi_type, buf, - info->dqi_usable_bs, blk << info->dqi_blocksize_bits); + info->dqi_usable_bs, (loff_t)blk << info->dqi_blocksize_bits); if (ret != info->dqi_usable_bs) { quota_error(sb, "dquota write failed"); if (ret >= 0) @@ -283,7 +283,7 @@ static uint find_free_dqentry(struct qtree_mem_dqinfo *info, blk); goto out_buf; } - dquot->dq_off = (blk << info->dqi_blocksize_bits) + + dquot->dq_off = ((loff_t)blk << info->dqi_blocksize_bits) + sizeof(struct qt_disk_dqdbheader) + i * info->dqi_entry_size; kfree(buf); @@ -558,7 +558,7 @@ static loff_t find_block_dqentry(struct qtree_mem_dqinfo *info, ret = -EIO; goto out_buf; } else { - ret = (blk << info->dqi_blocksize_bits) + sizeof(struct + ret = ((loff_t)blk << info->dqi_blocksize_bits) + sizeof(struct qt_disk_dqdbheader) + i * info->dqi_entry_size; } out_buf: -- 2.27.0