Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp510141pxb; Wed, 3 Mar 2021 08:33:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJzrQkodrB5a6ko9mEcD/48nJ2dH1JCDl2tB3m46CP/y/Zis4n+pffZ30lwHeNcbfLvQ4t/+ X-Received: by 2002:aa7:cd6a:: with SMTP id ca10mr83525edb.7.1614789223997; Wed, 03 Mar 2021 08:33:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614789223; cv=none; d=google.com; s=arc-20160816; b=g9unKyVFVcCwbUxQrjjDgGl7wJA5nBdhnB8Bs2TP6CAGbYQpnfWxSqAp+wyRkOrUSQ YqIxwGNcPLFexCnW6vIS0tWZq0ev+iusuCjwKXLHKkapHf4viKc9cHpiGiuNCOP6ClVr fF3cAcHQfL3YDY2ay6NNxFp2KtQRqHrfbfgCtZnGqRLDNvQ1yfgrK6ZqR1rPvA6qpIRY 6OBLxircZ+y5n+Yv+yPRx1ZNK5rDhAkmpkfgQ2VMEM5xpTOx2yqMyaE1HATVUW2LhtYe 8YJZz0BE6JF3RAp0IDjXKy8BH5DTrqZL2uzkkPJk6eqM2wVxW4mqI/x69bfa2f583xAc YKUw== 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=RShMt1Fx2axsDKcNDnzTLsNL1tEt4f9mFNRR0x1/JoI=; b=sYyV7GN92a4e5bDFB8BYRPIiLWyS2rwz0KHWuRmoA74IoA4URt3J531bqETQLiaFCm zSz/MvO83RIKT1MK/+LFCwU+yN+JP3SSVL+7b9r4zB4OYSNuM77CrsbqLLbFH/dXb9+T IjbV75LnnBC6W7xUTh7Y5dYQlXC3LagmV58jnaKb38G+Fh7wGKuI+FNhuXAQ9AjMPQZE qh9JrUnEs1j5MaN5UYnv2D3KrgAAEQoHMMTK0AxTe4N2Wu6HcYQJOV2CmRrOcfkQniNK TBdEynVTQAx5eA0DBZsl+99vJTYGbIGM36yrYSW7Y1UznJYQPeOebKbKaYXA9gtfjxrn Pa/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vqz8LaUk; 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 t14si1766276ejr.191.2021.03.03.08.32.51; Wed, 03 Mar 2021 08:33:43 -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=vqz8LaUk; 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 S238828AbhCAX7O (ORCPT + 99 others); Mon, 1 Mar 2021 18:59:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:39686 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239516AbhCASTI (ORCPT ); Mon, 1 Mar 2021 13:19:08 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2A762651C2; Mon, 1 Mar 2021 17:16:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614619003; bh=SOuethk+Lvc1B4JliQnmJZw9lJz2/4JjD2WjtCynslo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vqz8LaUkvcb82sUZTEfvVTg8FN9lo+NX4War9HkE/VW9np39dWVpjfCVJg4Ptl34I PGTk9ZnpV6ZEK21lZSll4jk3XaOJ2c/cyZSCe/hjBRqVuPcCXCcR3X5ROfWUZZuYAK AXr9jpriZMoY/a6g6GEKNJ7D7dmLrBfjwqrih7fQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+77779c9b52ab78154b08@syzkaller.appspotmail.com, Jan Kara , Sasha Levin Subject: [PATCH 5.10 266/663] quota: Fix memory leak when handling corrupted quota file Date: Mon, 1 Mar 2021 17:08:34 +0100 Message-Id: <20210301161154.974457068@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161141.760350206@linuxfoundation.org> References: <20210301161141.760350206@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 a4db1072e1a3bd7a8d9c356e1902b13ac5deb8ef ] When checking corrupted quota file we can bail out and leak allocated info structure. Properly free info structure on error return. Reported-by: syzbot+77779c9b52ab78154b08@syzkaller.appspotmail.com Fixes: 11c514a99bb9 ("quota: Sanity-check quota file headers on load") Signed-off-by: Jan Kara Signed-off-by: Sasha Levin --- fs/quota/quota_v2.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/fs/quota/quota_v2.c b/fs/quota/quota_v2.c index c21106557a37e..b1467f3921c28 100644 --- a/fs/quota/quota_v2.c +++ b/fs/quota/quota_v2.c @@ -164,19 +164,24 @@ static int v2_read_file_info(struct super_block *sb, int type) quota_error(sb, "Number of blocks too big for quota file size (%llu > %llu).", (loff_t)qinfo->dqi_blocks << qinfo->dqi_blocksize_bits, i_size_read(sb_dqopt(sb)->files[type])); - goto out; + goto out_free; } if (qinfo->dqi_free_blk >= qinfo->dqi_blocks) { quota_error(sb, "Free block number too big (%u >= %u).", qinfo->dqi_free_blk, qinfo->dqi_blocks); - goto out; + goto out_free; } if (qinfo->dqi_free_entry >= qinfo->dqi_blocks) { quota_error(sb, "Block with free entry too big (%u >= %u).", qinfo->dqi_free_entry, qinfo->dqi_blocks); - goto out; + goto out_free; } ret = 0; +out_free: + if (ret) { + kfree(info->dqi_priv); + info->dqi_priv = NULL; + } out: up_read(&dqopt->dqio_sem); return ret; -- 2.27.0