Skip to content

Commit

Permalink
btrfs: qgroup: Fix possible leak in btrfs_add_qgroup_relation()
Browse files Browse the repository at this point in the history
Commit 9c8b35b ("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>
Signed-off-by: Chris Mason <clm@fb.com>
  • Loading branch information
Christian Engelmayer authored and Chris Mason committed Jun 3, 2015
1 parent 35c7664 commit ab3680d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions fs/btrfs/qgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit ab3680d

Please sign in to comment.