Re: [PATCH] btrfs: Added null check to extent_root variable

From: Qu Wenruo
Date: Wed Sep 04 2024 - 01:51:58 EST




在 2024/9/4 12:07, Ghanshyam Agrawal 写道:
Reported-by: syzbot+9c3e0cdfbfe351b0bc0e@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes:https://syzkaller.appspot.com/bug?extid=9c3e0cdfbfe351b0bc0e
Signed-off-by: Ghanshyam Agrawal <ghanshyam1898@xxxxxxxxx>
---
fs/btrfs/ref-verify.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/fs/btrfs/ref-verify.c b/fs/btrfs/ref-verify.c
index 9522a8b79d22..4e98ddf5e8df 100644
--- a/fs/btrfs/ref-verify.c
+++ b/fs/btrfs/ref-verify.c
@@ -1002,6 +1002,9 @@ int btrfs_build_ref_tree(struct btrfs_fs_info *fs_info)
return -ENOMEM;

extent_root = btrfs_extent_root(fs_info, 0);
+ if (!extent_root)
+ return -EIO;
+

Can you reproduce the original bug and are sure it's an NULL extent tree
causing the problem?

At least a quick glance into the console output shows there is no
special handling like rescue=ibadroots to ignore extent root, nor any
obvious corruption in the extent tree.

If extent root is really empty, we should error out way earlier.

Mind to explain the crash with more details?

Thanks,
Qu

eb = btrfs_read_lock_root_node(extent_root);
level = btrfs_header_level(eb);
path->nodes[level] = eb;