Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp395441pxb; Wed, 3 Mar 2021 06:08:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJxYwqPFW88bgSFyiSD5DUmYDE4iXMXW7jGsgGuw+41fi04WDMVvFLrXD0JYmbZnBIbn+wj6 X-Received: by 2002:a19:3f04:: with SMTP id m4mr14941184lfa.395.1614780481300; Wed, 03 Mar 2021 06:08:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614780481; cv=none; d=google.com; s=arc-20160816; b=gb7vOOKuhbGAK2VGyamoFvlwXO7P+OYGWucUCNH94VZQfncfN6kP/uatqBHBxo55M2 FMCId643IXM4IXQlsGanV9PmG7a+lwmgiB0tHZL3JDpvz4eOVAFyi8rajCtv63NOMTy+ eWZjZVWKnFBQkN/9ULQG4YhDVyM/NG8RUtsQOX2ofVt6rqHs25BWzkWa2pBk23GEu4SR xKLjqvIPtkT+I9ujr8ydh6+/BKOL5FCoVLiyotr4pmeIOaH/bUMiC5K8fC+7Kpbf49fm etf/PmhAgzqpjSFp3OQm9CDTbRwWf3OIPzWiRidfSXBsans2FKcuLpwN+rYhqmHS56Qc d0HQ== 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=vOTHBjzy0/tkzInkyCnvWPvku4LxUPPiAColi2P3yMw=; b=OV4YdN0C0YmxDJkb/InJU1/u9Ckr+gNu+DtuVmatZuyIjF9UT+AGAdsNg2xVgEaXGc OsHT4yuk819pZans7I6AqzStXQD11njtWMdj/8d48W2+vP4O9RFrUT3IV6bVkUU1x4Qf XG1mn/22epTuUjMfLilpWEkQdEPooyOnYmcpWaa577TgzPl2IVRw8Xz5X0V67/eVDSXX oGDyQyrbvuhBW/DUAoHwL5MuTxDiJuZRKzCBf/R0leAEele0QsEtuKX8LSftadGuX5tp pkxf3EwxJVTsEyVrku+gUP5Pp3iFSc/0sV0RbLBrPpgTU/+IJobFnEP5iOupaDaZ2O/w KOQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PaQk5BPo; 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 x11si2490144edd.560.2021.03.03.06.07.01; Wed, 03 Mar 2021 06:08:01 -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=PaQk5BPo; 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 S243287AbhCAUbF (ORCPT + 99 others); Mon, 1 Mar 2021 15:31:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:35292 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237076AbhCARGv (ORCPT ); Mon, 1 Mar 2021 12:06:51 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 283E264F32; Mon, 1 Mar 2021 16:40:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614616827; bh=tEhdxp0bf97jK5Xbg7ROvByaEMNGg7BVNmSgnPjs+8M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PaQk5BPon+71b0Lzvu8tAAlpTSjBQ2xGJWBTPqF58rM50HHXfVdy3svIyzoHYesE5 ZTgCOvn4b45F5EGXLNRBH0fXACnWDZhV5eTCmhZoHpodQ8I3gbgedmyv57dKg2y915 PWR+wELQr3ZULzDbQcpdGOPy9oPLnbgpJKYyfpa0= 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 4.19 109/247] quota: Fix memory leak when handling corrupted quota file Date: Mon, 1 Mar 2021 17:12:09 +0100 Message-Id: <20210301161037.010491421@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161031.684018251@linuxfoundation.org> References: <20210301161031.684018251@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 d99710270a373..addfaae8decfd 100644 --- a/fs/quota/quota_v2.c +++ b/fs/quota/quota_v2.c @@ -165,19 +165,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