Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp13959383pxu; Mon, 4 Jan 2021 09:01:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJy+YQaHxmjqPTm0Np+jKJH0q971Afi7nlXgn9KWQ1cqMGL/xlVrtxXks1dTNS90G0RYiwhH X-Received: by 2002:a05:6402:a53:: with SMTP id bt19mr73095716edb.104.1609779711989; Mon, 04 Jan 2021 09:01:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609779711; cv=none; d=google.com; s=arc-20160816; b=A7jCpj0NvRn4M+rpQy6ennKsVEASb1DcuM4R/Wxl9JrAJ+gaEgtfzuCu+IZdD0sb3M M9V7wN+BrnIfcP63HHk5vsjXznFnuKhQhEFRxYucBMouqzpkL8Kfb0KZU49vfnmQqVSx jYgFcRUmDTOP0TycFTFJJJzc+aOYlHxCAXsEXnw03i4kFACPdCdphElXje0f1DjBIUBK vfZQ+IkNwFojN4nUZaXewHdZW/9B/llKlePHhNDeilO2Ea//Hevi2KZMP62MfnCFvJsI T+cbga27BVusjv4qeWpVtVG8VaOBeCSt/627e/rDBZg+X4WVxAqb+tPgP5aeFX9k2ka2 xBEw== 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=RecYx1bVzYCKUOofVSYfjVm8sJgNILpv7zKVr9yU5X8=; b=BJXLzkCf+v/A1Ub0zyoRc7l9N5lnifayQwiCyCu7hySsh4A5u2aZ8b5t6Pik4PHEyK QWRDnFVdS5AOT8TAvs72MmI/QOAwkryjlZTe46rePXJejxGIAkbTahZuSBkajhrKYDtN JYRav+TS01/vqZCqNPI5j2s4g/acTznvf2PTyA1bpgzTqtaz5U1UGGxGbu2kbiPeqOHs 6zLvrzFnYwBAdRSLOTjE6IvJamZ0zUyJzaBhahulvqNGUvapoS5btztzuuos416es2nC VDhnoJaK5TewgLbgwHOlu4E3Sy47EnmfLMp+2JJyvGti6BqKpFlsvHyu3B6vi5/O49lm Zpsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1Wrzli67; 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 gb7si26211972ejc.460.2021.01.04.09.01.27; Mon, 04 Jan 2021 09:01:51 -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=1Wrzli67; 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 S1727630AbhADQJ7 (ORCPT + 99 others); Mon, 4 Jan 2021 11:09:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:37174 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728416AbhADQAm (ORCPT ); Mon, 4 Jan 2021 11:00:42 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id BA25F22473; Mon, 4 Jan 2021 16:00:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609776027; bh=Rpl5XNX4S2+Z7AcpERuwFeSEjczuuFk6ejVvwNWPCVI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1Wrzli67HbZF0xtjBjoNHSp9JH9LZwBfzN7yTdNtzoWNjIT0nSVMC2ZBCdiZx7z49 2V8FC4WOzRekVr5mGD/OPa9/5DwbGT1bjJLEX52awHJmvHi0LZZNcR3eHiMJeKpEnR kTuriLusYuJtxJ70WqfrlEFdUvdkapPpy7G6+fSk= 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 5.4 36/47] quota: Dont overflow quota file offsets Date: Mon, 4 Jan 2021 16:57:35 +0100 Message-Id: <20210104155707.481231084@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210104155705.740576914@linuxfoundation.org> References: <20210104155705.740576914@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 a6f856f341dc7..c5562c871c8be 100644 --- a/fs/quota/quota_tree.c +++ b/fs/quota/quota_tree.c @@ -62,7 +62,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) @@ -71,7 +71,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) @@ -284,7 +284,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); @@ -559,7 +559,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