btrfs: qgroup: fix qgroup id collision across mounts
authorBoris Burkov <boris@bur.io>
Thu, 9 May 2024 22:34:40 +0000 (15:34 -0700)
committerDavid Sterba <dsterba@suse.com>
Wed, 15 May 2024 15:57:09 +0000 (17:57 +0200)
commit2b8aa78cf1279ec5e418baa26bfed5df682568d8
tree2bf02e8017b49a5d779303192b892a06689003ab
parent1fa7603d569b9e738e9581937ba8725cd7d39b48
btrfs: qgroup: fix qgroup id collision across mounts

If we delete subvolumes whose ID is the largest in the filesystem, then
unmount and mount again, then btrfs_init_root_free_objectid on the
tree_root will select a subvolid smaller than that one and thus allow
reusing it.

If we are also using qgroups (and particularly squotas) it is possible
to delete the subvol without deleting the qgroup. In that case, we will
be able to create a new subvol whose id already has a level 0 qgroup.
This will result in re-using that qgroup which would then lead to
incorrect accounting.

Fixes: 6ed05643ddb1 ("btrfs: create qgroup earlier in snapshot creation")
CC: stable@vger.kernel.org # 6.7+
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Boris Burkov <boris@bur.io>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/qgroup.c