Re: [syzbot] [btrfs?] general protection fault in btrfs_search_slot

From: Lizhi Xu
Date: Thu Oct 24 2024 - 22:24:14 EST


use the input logical can't find the extent root, so add sanity check for
extent root before search slot.

#syz test

diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index f8e1d5b2c512..87eaf5dd2d5d 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -2213,6 +2213,9 @@ int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical,
key.objectid = logical;
key.offset = (u64)-1;

+ if (!extent_root)
+ return -ENOENT;
+
ret = btrfs_search_slot(NULL, extent_root, &key, path, 0, 0);
if (ret < 0)
return ret;