]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
btrfs: handle invalid root reference found in may_destroy_subvol()
authorDavid Sterba <dsterba@suse.com>
Wed, 24 Jan 2024 21:58:01 +0000 (22:58 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 4 Sep 2024 11:17:37 +0000 (13:17 +0200)
[ 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>
fs/btrfs/inode.c

index 1f99d7dced17a2f57ed8f28048da8b9bfac4b812..4bf28f74605fd764a068336afe1e8ff724c49648 100644 (file)
@@ -3918,7 +3918,14 @@ static noinline int may_destroy_subvol(struct btrfs_root *root)
        ret = btrfs_search_slot(NULL, fs_info->tree_root, &key, path, 0, 0);
        if (ret < 0)
                goto out;
-       BUG_ON(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;
+       }
 
        ret = 0;
        if (path->slots[0] > 0) {