summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2024-01-19 21:19:18 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2024-04-13 12:50:15 +0200
commit8b11774810aadeda80d4eb54f648eaf88f369d22 (patch)
tree779d7d2a2567df2b8cdea53ed1f92138249c559a
parentbebd9e0ff90034875c5dfe4bd514fd7055fc7a89 (diff)
downloadlinux-stable-8b11774810aadeda80d4eb54f648eaf88f369d22.tar.gz
linux-stable-8b11774810aadeda80d4eb54f648eaf88f369d22.tar.bz2
linux-stable-8b11774810aadeda80d4eb54f648eaf88f369d22.zip
btrfs: export: handle invalid inode or root reference in btrfs_get_parent()
[ Upstream commit 26b66d1d366a375745755ca7365f67110bbf6bd5 ] The get_parent handler looks up a parent of a given dentry, this can be either a subvolume or a directory. The search is set up with offset -1 but it's never expected to find such item, as it would break allowed range of inode number or a root id. This means it's a corruption (ext4 also returns this error code). Reviewed-by: Josef Bacik <josef@toxicpanda.com> Reviewed-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--fs/btrfs/export.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/fs/btrfs/export.c b/fs/btrfs/export.c
index ecc33e3a3c06..01e9a5afc33b 100644
--- a/fs/btrfs/export.c
+++ b/fs/btrfs/export.c
@@ -182,8 +182,15 @@ struct dentry *btrfs_get_parent(struct dentry *child)
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
if (ret < 0)
goto fail;
+ if (ret == 0) {
+ /*
+ * Key with offset of -1 found, there would have to exist an
+ * inode with such number or a root with such id.
+ */
+ ret = -EUCLEAN;
+ goto fail;
+ }
- BUG_ON(ret == 0); /* Key with offset of -1 found */
if (path->slots[0] == 0) {
ret = -ENOENT;
goto fail;