]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
btrfs: export: handle invalid inode or root reference in btrfs_get_parent()
authorDavid Sterba <dsterba@suse.com>
Fri, 19 Jan 2024 20:19:18 +0000 (21:19 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 13 Apr 2024 11:01:44 +0000 (13:01 +0200)
[ 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>
fs/btrfs/export.c

index fab7eb76e53b2a3e9b3f2508f4b7aa2ef9077c2f..58b0f04d7123f34537e97525a5cb5d33a7936843 100644 (file)
@@ -161,8 +161,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;