diff options
author | David Sterba <dsterba@suse.com> | 2024-01-25 00:58:01 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2024-09-04 14:17:37 +0300 |
commit | 94a7dff229b930e3323bea272f1973f9f7a42ea8 (patch) | |
tree | 69cd83a751d6ae52c0b061d9ba73e276c53ef838 | |
parent | 3dd13074e75e91ea3ae688de0959d9956675c17f (diff) | |
download | linux-94a7dff229b930e3323bea272f1973f9f7a42ea8.tar.xz |
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>
-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 1f99d7dced17..4bf28f74605f 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -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) { |