All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: Christian Engelmayer <cengelma@gmx.at>, <linux-btrfs@vger.kernel.org>
Cc: <clm@fb.com>, <jbacik@fb.com>, <dsterba@suse.cz>
Subject: Re: [PATCH] btrfs: qgroup: Fix possible leak in btrfs_add_qgroup_relation()
Date: Tue, 5 May 2015 08:27:32 +0800	[thread overview]
Message-ID: <55480E74.80404@cn.fujitsu.com> (raw)
In-Reply-To: <1430579995-24551-1-git-send-email-cengelma@gmx.at>



-------- Original Message  --------
Subject: [PATCH] btrfs: qgroup: Fix possible leak in 
btrfs_add_qgroup_relation()
From: Christian Engelmayer <cengelma@gmx.at>
To: <linux-btrfs@vger.kernel.org>
Date: 2015年05月02日 23:19

> Commit 9c8b35b1ba21 ("btrfs: quota: Automatically update related qgroups or
> mark INCONSISTENT flags when assigning/deleting a qgroup relations.")
> introduced the allocation of a temporary ulist in function
> btrfs_add_qgroup_relation() and added the corresponding cleanup to the out
> path. However, the allocation was introduced before the src/dst level check
> that directly returns. Fix the possible leakage of the ulist by moving the
> allocation after the input validation. Detected by Coverity CID 1295988.
>
> Signed-off-by: Christian Engelmayer <cengelma@gmx.at>
> ---
> Compile tested only. Applies against linux-next.
> ---
>   fs/btrfs/qgroup.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
> index 3d6546581bb9..842ff86d4ae8 100644
> --- a/fs/btrfs/qgroup.c
> +++ b/fs/btrfs/qgroup.c
> @@ -1115,14 +1115,14 @@ int btrfs_add_qgroup_relation(struct btrfs_trans_handle *trans,
>   	struct ulist *tmp;
>   	int ret = 0;
>
> -	tmp = ulist_alloc(GFP_NOFS);
> -	if (!tmp)
> -		return -ENOMEM;
> -
>   	/* Check the level of src and dst first */
>   	if (btrfs_qgroup_level(src) >= btrfs_qgroup_level(dst))
>   		return -EINVAL;
>
> +	tmp = ulist_alloc(GFP_NOFS);
> +	if (!tmp)
> +		return -ENOMEM;
> +
>   	mutex_lock(&fs_info->qgroup_ioctl_lock);
>   	quota_root = fs_info->quota_root;
>   	if (!quota_root) {
>
Oh, my fault.
Thanks for catching it.

Qu

  reply	other threads:[~2015-05-05  0:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-02 15:19 [PATCH] btrfs: qgroup: Fix possible leak in btrfs_add_qgroup_relation() Christian Engelmayer
2015-05-05  0:27 ` Qu Wenruo [this message]
2015-05-05 13:20 ` David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55480E74.80404@cn.fujitsu.com \
    --to=quwenruo@cn.fujitsu.com \
    --cc=cengelma@gmx.at \
    --cc=clm@fb.com \
    --cc=dsterba@suse.cz \
    --cc=jbacik@fb.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.