diff options
author | David Sterba <dsterba@suse.com> | 2024-01-24 22:58:01 +0100 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2024-03-04 16:24:51 +0100 |
commit | 6fbc6f4ac1f4907da4fc674251527e7dc79ffbf6 (patch) | |
tree | 385d038ce727b2dbf10df310a9b231e846bff73c /fs/btrfs/inode.c | |
parent | f626a0f5b85614609716d78b94e2e5795b915d92 (diff) |
btrfs: handle invalid root reference found in may_destroy_subvol()
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>
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r-- | fs/btrfs/inode.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index bda91f3100bd..1a527c7f383b 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -4412,7 +4412,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) { |