1 From b76765d691a79ce752f1ce2c6a2178ce44f18bb0 Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Fri, 19 Jan 2024 21:19:18 +0100
4 Subject: btrfs: export: handle invalid inode or root reference in
7 From: David Sterba <dsterba@suse.com>
9 [ Upstream commit 26b66d1d366a375745755ca7365f67110bbf6bd5 ]
11 The get_parent handler looks up a parent of a given dentry, this can be
12 either a subvolume or a directory. The search is set up with offset -1
13 but it's never expected to find such item, as it would break allowed
14 range of inode number or a root id. This means it's a corruption (ext4
15 also returns this error code).
17 Reviewed-by: Josef Bacik <josef@toxicpanda.com>
18 Reviewed-by: Anand Jain <anand.jain@oracle.com>
19 Signed-off-by: David Sterba <dsterba@suse.com>
20 Signed-off-by: Sasha Levin <sashal@kernel.org>
22 fs/btrfs/export.c | 9 ++++++++-
23 1 file changed, 8 insertions(+), 1 deletion(-)
25 diff --git a/fs/btrfs/export.c b/fs/btrfs/export.c
26 index fab7eb76e53b2..58b0f04d7123f 100644
27 --- a/fs/btrfs/export.c
28 +++ b/fs/btrfs/export.c
29 @@ -161,8 +161,15 @@ struct dentry *btrfs_get_parent(struct dentry *child)
30 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
35 + * Key with offset of -1 found, there would have to exist an
36 + * inode with such number or a root with such id.
42 - BUG_ON(ret == 0); /* Key with offset of -1 found */
43 if (path->slots[0] == 0) {