summaryrefslogtreecommitdiffstats
path: root/fs/btrfs/root-tree.c
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2024-01-23 23:28:24 +0100
committerDavid Sterba <dsterba@suse.com>2024-03-04 16:24:47 +0100
commit9dcb6ed9ce53d24e7b7fba7e02512787cd4dfa72 (patch)
tree997c9f57a794c40de59ac4460f11b6f7327f0700 /fs/btrfs/root-tree.c
parent0fe29838ba0aee39a7bca46bb47e7ca348a9e161 (diff)
downloadlinux-9dcb6ed9ce53d24e7b7fba7e02512787cd4dfa72.tar.gz
linux-9dcb6ed9ce53d24e7b7fba7e02512787cd4dfa72.tar.bz2
linux-9dcb6ed9ce53d24e7b7fba7e02512787cd4dfa72.zip
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: Josef Bacik <josef@toxicpanda.com> Reviewed-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/root-tree.c')
-rw-r--r--fs/btrfs/root-tree.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c
index ce831660550b..4bb538a372ce 100644
--- a/fs/btrfs/root-tree.c
+++ b/fs/btrfs/root-tree.c
@@ -81,7 +81,14 @@ int btrfs_find_root(struct btrfs_root *root, const struct btrfs_key *search_key,
if (ret > 0)
goto out;
} 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)
goto out;
path->slots[0]--;