]> www.infradead.org Git - nvme.git/commit
btrfs: qgroup: fix quota root leak after quota disable failure
authorFilipe Manana <fdmanana@suse.com>
Thu, 20 Jun 2024 11:32:00 +0000 (12:32 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 24 Jun 2024 22:35:50 +0000 (00:35 +0200)
commita7e4c6a3031c74078dba7fa36239d0f4fe476c53
treebd503c82ea48883722ded42cbce0fd5fe4f37f9d
parent2c49908634a2b97b1c3abe0589be2739ac5e7fd5
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 bed92eae26cc ("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 <boris@bur.io>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/qgroup.c