[syzbot] [btrfs?] general protection fault in btrfs_root_node

38 views
Skip to first unread message

syzbot

unread,
Sep 3, 2024, 7:42:27 PM9/3/24
Hello,

syzbot found the following issue on:

HEAD commit: 20371ba12063 Merge tag 'drm-fixes-2024-08-30' of https://g..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=16206c53980000
kernel config: https://syzkaller.appspot.com/x/.config?x=996585887acdadb3
dashboard link: https://syzkaller.appspot.com/bug?extid=9c3e0cdfbfe351b0bc0e
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=16778a63980000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=14924339980000

Downloadable assets:
disk image (non-bootable): https://storage.googleapis.com/syzbot-assets/7bc7510fe41f/non_bootable_disk-20371ba1.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/35987fde8063/vmlinux-20371ba1.xz
kernel image: https://storage.googleapis.com/syzbot-assets/1012e3751087/bzImage-20371ba1.xz
mounted in repro: https://storage.googleapis.com/syzbot-assets/892f30044c3a/mount_0.gz

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: [email protected]

BTRFS info (device loop0): using crc32c (crc32c-intel) checksum algorithm
BTRFS info (device loop0): using free-space-tree
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000003: 0000 [#1] PREEMPT SMP KASAN NOPTI
KASAN: null-ptr-deref in range [0x0000000000000018-0x000000000000001f]
CPU: 0 UID: 0 PID: 5105 Comm: syz-executor368 Not tainted 6.11.0-rc5-syzkaller-00176-g20371ba12063 #0
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2~bpo12+1 04/01/2014
RIP: 0010:btrfs_root_node+0x86/0x3b0 fs/btrfs/ctree.c:260
Code: a0 aa c8 fd 48 83 c4 08 e8 47 80 12 08 89 c3 31 ff 89 c6 e8 4c 6f ec fd 85 db 74 17 e8 33 a1 d2 fd 84 c0 74 1c e8 fa 6a ec fd <43> 80 3c 3c 00 75 4b eb 51 e8 ec 6a ec fd 43 80 3c 3c 00 75 3d eb
RSP: 0018:ffffc90000e376c0 EFLAGS: 00010293
RAX: ffffffff83a72136 RBX: 0000000000000001 RCX: ffff888000784880
RDX: 0000000000000000 RSI: ffffffff8c608d20 RDI: ffffffff8c608ce0
RBP: ffffc90000e378b0 R08: ffffffff83a72124 R09: 1ffffffff283c908
R10: dffffc0000000000 R11: fffffbfff283c909 R12: 0000000000000003
R13: dffffc0000000000 R14: 0000000000000018 R15: dffffc0000000000
FS: 0000555578f7a380(0000) GS:ffff88801fe00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f674dc59068 CR3: 0000000034fa8000 CR4: 0000000000350ef0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
<TASK>
btrfs_read_lock_root_node+0x27/0xd0 fs/btrfs/locking.c:279
btrfs_build_ref_tree+0x112/0x16f0 fs/btrfs/ref-verify.c:1005
open_ctree+0x1fea/0x2a10 fs/btrfs/disk-io.c:3533
btrfs_fill_super fs/btrfs/super.c:965 [inline]
btrfs_get_tree_super fs/btrfs/super.c:1888 [inline]
btrfs_get_tree+0xe7a/0x1920 fs/btrfs/super.c:2114
vfs_get_tree+0x90/0x2b0 fs/super.c:1800
fc_mount+0x1b/0xb0 fs/namespace.c:1231
btrfs_get_tree_subvol fs/btrfs/super.c:2077 [inline]
btrfs_get_tree+0x652/0x1920 fs/btrfs/super.c:2115
vfs_get_tree+0x90/0x2b0 fs/super.c:1800
do_new_mount+0x2be/0xb40 fs/namespace.c:3472
do_mount fs/namespace.c:3812 [inline]
__do_sys_mount fs/namespace.c:4020 [inline]
__se_sys_mount+0x2d6/0x3c0 fs/namespace.c:3997
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f3e4d3e7eea
Code: d8 64 89 02 48 c7 c0 ff ff ff ff eb a6 e8 5e 04 00 00 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 49 89 ca b8 a5 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffcc9f71558 EFLAGS: 00000282 ORIG_RAX: 00000000000000a5
RAX: ffffffffffffffda RBX: 00007ffcc9f71560 RCX: 00007f3e4d3e7eea
RDX: 0000000020005100 RSI: 0000000020000040 RDI: 00007ffcc9f71560
RBP: 0000000000000004 R08: 00007ffcc9f715a0 R09: 0000000000005110
R10: 0000000000a08811 R11: 0000000000000282 R12: 00007ffcc9f715a0
R13: 0000000000000003 R14: 0000000001000000 R15: 00007f3e4d42f03b
</TASK>
Modules linked in:
---[ end trace 0000000000000000 ]---
RIP: 0010:btrfs_root_node+0x86/0x3b0 fs/btrfs/ctree.c:260
Code: a0 aa c8 fd 48 83 c4 08 e8 47 80 12 08 89 c3 31 ff 89 c6 e8 4c 6f ec fd 85 db 74 17 e8 33 a1 d2 fd 84 c0 74 1c e8 fa 6a ec fd <43> 80 3c 3c 00 75 4b eb 51 e8 ec 6a ec fd 43 80 3c 3c 00 75 3d eb
RSP: 0018:ffffc90000e376c0 EFLAGS: 00010293
RAX: ffffffff83a72136 RBX: 0000000000000001 RCX: ffff888000784880
RDX: 0000000000000000 RSI: ffffffff8c608d20 RDI: ffffffff8c608ce0
RBP: ffffc90000e378b0 R08: ffffffff83a72124 R09: 1ffffffff283c908
R10: dffffc0000000000 R11: fffffbfff283c909 R12: 0000000000000003
R13: dffffc0000000000 R14: 0000000000000018 R15: dffffc0000000000
FS: 0000555578f7a380(0000) GS:ffff88801fe00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00005610c6449d38 CR3: 0000000034fa8000 CR4: 0000000000350ef0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
----------------
Code disassembly (best guess):
0: a0 aa c8 fd 48 83 c4 movabs 0xe808c48348fdc8aa,%al
7: 08 e8
9: 47 80 12 08 rex.RXB adcb $0x8,(%r10)
d: 89 c3 mov %eax,%ebx
f: 31 ff xor %edi,%edi
11: 89 c6 mov %eax,%esi
13: e8 4c 6f ec fd call 0xfdec6f64
18: 85 db test %ebx,%ebx
1a: 74 17 je 0x33
1c: e8 33 a1 d2 fd call 0xfdd2a154
21: 84 c0 test %al,%al
23: 74 1c je 0x41
25: e8 fa 6a ec fd call 0xfdec6b24
* 2a: 43 80 3c 3c 00 cmpb $0x0,(%r12,%r15,1) <-- trapping instruction
2f: 75 4b jne 0x7c
31: eb 51 jmp 0x84
33: e8 ec 6a ec fd call 0xfdec6b24
38: 43 80 3c 3c 00 cmpb $0x0,(%r12,%r15,1)
3d: 75 3d jne 0x7c
3f: eb .byte 0xeb


---
This report is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at [email protected].

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.

If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title

If you want syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.

If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)

If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report

If you want to undo deduplication, reply with:
#syz undup

Ghanshyam Agrawal

unread,
Sep 4, 2024, 12:23:28 AM9/4/24
to syzkaller-bugs
Added a check for the nullability of the extent_root variable.

I am not sure what error code I should return when the variable is null. Can someone help me with this? Thank you very much.

#syz test

diff --git a/fs/btrfs/ref-verify.c b/fs/btrfs/ref-verify.c
index 9522a8b79d22..e613420cb079 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 -EBADF;
+
  eb = btrfs_read_lock_root_node(extent_root);
  level = btrfs_header_level(eb);
  path->nodes[level] = eb;

Ghanshyam Agrawal

unread,
Sep 4, 2024, 12:23:28 AM9/4/24
to syzkaller-bugs
The extent_root variable may be obtained as null in which case, it later throws a null pointer error. We can add a check for the null-ness of this variable.

I am still not sure though, what error should be returned when the variable is null. Can someone please help me with this. Thank you very much.

#syz test
diff --git a/fs/btrfs/ref-verify.c b/fs/btrfs/ref-verify.c
index 9522a8b79d22..e613420cb079 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 -EBADF;
+
  eb = btrfs_read_lock_root_node(extent_root);
  level = btrfs_header_level(eb);
  path->nodes[level] = eb;

On Tuesday, September 3, 2024 at 10:12:27 PM UTC+5:30 syzbot wrote:

Ghanshyam Agrawal

unread,
Sep 4, 2024, 4:39:00 AM9/4/24
Added a check for the nullability of the extent_root variable.

I am not sure what error code I should return when the variable is
null. Can someone help me with this? Thank you very much.

syzbot

unread,
Sep 4, 2024, 4:40:04 AM9/4/24
Hello,

syzbot tried to test the proposed patch but the build/boot failed:

failed to apply patch:
checking file fs/btrfs/ref-verify.c
patch: **** unexpected end of file in patch



Tested on:

commit: 88fac175 Merge tag 'fuse-fixes-6.11-rc7' of git://git...
git tree: upstream
patch: https://syzkaller.appspot.com/x/patch.diff?x=12c4531f980000

Ghanshyam Agrawal

unread,
Sep 4, 2024, 4:43:56 AM9/4/24

syzbot

unread,
Sep 4, 2024, 4:45:04 AM9/4/24
Hello,

syzbot tried to test the proposed patch but the build/boot failed:

failed to apply patch:
checking file fs/btrfs/ref-verify.c
Hunk #1 FAILED at 1002.
1 out of 1 hunk FAILED



Tested on:

commit: 88fac175 Merge tag 'fuse-fixes-6.11-rc7' of git://git...
git tree: upstream
kernel config: https://syzkaller.appspot.com/x/.config?x=996585887acdadb3
dashboard link: https://syzkaller.appspot.com/bug?extid=9c3e0cdfbfe351b0bc0e
compiler:
patch: https://syzkaller.appspot.com/x/patch.diff?x=124b14ab980000

Ghanshyam Agrawal

unread,
Sep 4, 2024, 4:49:35 AM9/4/24
0001-btrfs-fix-bug-when-extent_buffer-root-node-is-not-fo.patch

Ghanshyam Agrawal

unread,
Sep 4, 2024, 5:12:51 AM9/4/24
Added a check for the nullability of the extent_root variable.

I am not sure what error code I should return when the variable is
null. Can someone help me with this? Thank you very much.

#syz test
0001-btrfs-Added-null-check-to-extent_root-variable.patch

syzbot

unread,
Sep 4, 2024, 5:33:04 AM9/4/24
Hello,

syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Reported-by: [email protected]
Tested-by: [email protected]

Tested on:

commit: 88fac175 Merge tag 'fuse-fixes-6.11-rc7' of git://git...
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=178609eb980000
kernel config: https://syzkaller.appspot.com/x/.config?x=660f6eb11f9c7dc5
dashboard link: https://syzkaller.appspot.com/bug?extid=9c3e0cdfbfe351b0bc0e
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=14e24deb980000

Note: testing is done by a robot and is best-effort only.

syzbot

unread,
Nov 12, 2024, 1:47:06 PM11/12/24
syzbot has bisected this issue to:

commit 42437a6386ffeaaf200731e73d723ea491f3fe7d
Author: Josef Bacik <[email protected]>
Date: Fri Oct 16 15:29:18 2020 +0000

btrfs: introduce mount option rescue=ignorebadroots

bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=16ef335f980000
start commit: 2d5404caa8c7 Linux 6.12-rc7
git tree: upstream
final oops: https://syzkaller.appspot.com/x/report.txt?x=15ef335f980000
console output: https://syzkaller.appspot.com/x/log.txt?x=11ef335f980000
kernel config: https://syzkaller.appspot.com/x/.config?x=1503500c6f615d24
dashboard link: https://syzkaller.appspot.com/bug?extid=9c3e0cdfbfe351b0bc0e
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=15a1935f980000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=158934e8580000

Reported-by: [email protected]
Fixes: 42437a6386ff ("btrfs: introduce mount option rescue=ignorebadroots")

For information about bisection process see: https://goo.gl/tpsmEJ#bisection
Reply all
Reply to author
Forward
0 new messages