Skip to content

Commit a7e4c6a

Browse files
fdmananakdave
authored andcommitted
btrfs: qgroup: fix quota root leak after quota disable failure
If during the quota disable we fail when cleaning the quota tree or when deleting the root from the root tree, we jump to the 'out' label without ever dropping the reference on the quota root, resulting in a leak of the root since fs_info->quota_root is no longer pointing to the root (we have set it to NULL just before those steps). Fix this by always doing a btrfs_put_root() call under the 'out' label. This is a problem that exists since qgroups were first added in 2012 by commit bed92ea ("Btrfs: qgroup implementation and prototypes"), but back then we missed a kfree on the quota root and free_extent_buffer() calls on its root and commit root nodes, since back then roots were not yet reference counted. Reviewed-by: Boris Burkov <[email protected]> Reviewed-by: Qu Wenruo <[email protected]> Signed-off-by: Filipe Manana <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 2c49908 commit a7e4c6a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

fs/btrfs/qgroup.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,7 @@ static int flush_reservations(struct btrfs_fs_info *fs_info)
13511351

13521352
int btrfs_quota_disable(struct btrfs_fs_info *fs_info)
13531353
{
1354-
struct btrfs_root *quota_root;
1354+
struct btrfs_root *quota_root = NULL;
13551355
struct btrfs_trans_handle *trans = NULL;
13561356
int ret = 0;
13571357

@@ -1449,9 +1449,9 @@ int btrfs_quota_disable(struct btrfs_fs_info *fs_info)
14491449
btrfs_free_tree_block(trans, btrfs_root_id(quota_root),
14501450
quota_root->node, 0, 1);
14511451

1452-
btrfs_put_root(quota_root);
14531452

14541453
out:
1454+
btrfs_put_root(quota_root);
14551455
mutex_unlock(&fs_info->qgroup_ioctl_lock);
14561456
if (ret && trans)
14571457
btrfs_end_transaction(trans);

0 commit comments

Comments
 (0)