Commit 9dcb6ed9 authored by David Sterba's avatar David Sterba

btrfs: handle invalid root reference found in btrfs_find_root()

The btrfs_find_root() 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 allowed the range of a root id.
Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
Reviewed-by: default avatarAnand Jain <anand.jain@oracle.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 0fe29838
...@@ -81,7 +81,14 @@ int btrfs_find_root(struct btrfs_root *root, const struct btrfs_key *search_key, ...@@ -81,7 +81,14 @@ int btrfs_find_root(struct btrfs_root *root, const struct btrfs_key *search_key,
if (ret > 0) if (ret > 0)
goto out; goto out;
} else { } else {
BUG_ON(ret == 0); /* Logical error */ /*
* Key with offset -1 found, there would have to exist a root
* with such id, but this is out of the valid range.
*/
if (ret == 0) {
ret = -EUCLEAN;
goto out;
}
if (path->slots[0] == 0) if (path->slots[0] == 0)
goto out; goto out;
path->slots[0]--; path->slots[0]--;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment