btrfs: handle invalid root reference found in may_destroy_subvol()

[ Upstream commit 6fbc6f4ac1f4907da4fc674251527e7dc79ffbf6 ]

The may_destroy_subvol() looks up a root by a key, allowing to do an
inexact search when key->offset is -1.  It's never expected to find such
item, as it would break the allowed range of a root id.

Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit ebce7d482d1a08392362ddf936ffdd9244fb1ece)
[Vegard: move changes to ioctl.c due to missing commit
 ec42f167348a1949ac309532aa34760cfc96c92f ("btrfs: Move
 may_destroy_subvol() from ioctl.c to inode.c").]
Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com>
This commit is contained in:
David Sterba
2024-01-24 22:58:01 +01:00
committed by Vegard Nossum
parent b52a80ebbf
commit 4ae1ece59e

View File

@@ -1953,9 +1953,14 @@ static noinline int may_destroy_subvol(struct btrfs_root *root)
key.offset = (u64)-1;
ret = btrfs_search_slot(NULL, fs_info->tree_root, &key, path, 0, 0);
if (ret < 0)
if (ret == 0) {
/*
* Key with offset -1 found, there would have to exist a root
* with such id, but this is out of valid range.
*/
ret = -EUCLEAN;
goto out;
BUG_ON(ret == 0);
}
ret = 0;
if (path->slots[0] > 0) {