Linux Btrfs filesystem development
 help / color / mirror / Atom feed
* [PATCH] btrfs: qgroup: Fix possible leak in btrfs_add_qgroup_relation()
@ 2015-05-02 15:19 Christian Engelmayer
  2015-05-05  0:27 ` Qu Wenruo
  2015-05-05 13:20 ` David Sterba
  0 siblings, 2 replies; 3+ messages in thread
From: Christian Engelmayer @ 2015-05-02 15:19 UTC (permalink / raw)
  To: linux-btrfs; +Cc: quwenruo, clm, jbacik, dsterba, Christian Engelmayer

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) {
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs: qgroup: Fix possible leak in btrfs_add_qgroup_relation()
  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
  2015-05-05 13:20 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: Qu Wenruo @ 2015-05-05  0:27 UTC (permalink / raw)
  To: Christian Engelmayer, linux-btrfs; +Cc: clm, jbacik, dsterba



-------- 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs: qgroup: Fix possible leak in btrfs_add_qgroup_relation()
  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
@ 2015-05-05 13:20 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2015-05-05 13:20 UTC (permalink / raw)
  To: Christian Engelmayer; +Cc: linux-btrfs, quwenruo, clm, jbacik

On Sat, May 02, 2015 at 05:19:55PM +0200, Christian Engelmayer wrote:
> 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>
Reviewed-by: David Sterba <dsterba@suse.cz>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-05-05 13:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2015-05-05 13:20 ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox