Re: [syzbot] [btrfs?] KASAN: slab-use-after-free Read in add_delayed_ref

From: syzbot
Date: Tue Oct 15 2024 - 06:15:12 EST


Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
BUG: sleeping function called from invalid context in ulist_alloc

BTRFS info (device loop0): first mount of filesystem 395ef67a-297e-477c-816d-cd80a5b93e5d
BTRFS info (device loop0): using sha256 (sha256-avx2) checksum algorithm
BTRFS info (device loop0): using free-space-tree
BUG: sleeping function called from invalid context at include/linux/sched/mm.h:321
in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 6014, name: syz.0.15
preempt_count: 1, expected: 0
RCU nest depth: 0, expected: 0
8 locks held by syz.0.15/6014:
#0: ffff888032202420 (sb_writers#13){.+.+}-{0:0}, at: mnt_want_write+0x3f/0x90 fs/namespace.c:515
#1: ffff888066478d90 (&type->i_mutex_dir_key#8/1){+.+.}-{3:3}, at: inode_lock_nested include/linux/fs.h:851 [inline]
#1: ffff888066478d90 (&type->i_mutex_dir_key#8/1){+.+.}-{3:3}, at: filename_create+0x260/0x540 fs/namei.c:4026
#2: ffff888032202610 (sb_internal#2){.+.+}-{0:0}, at: btrfs_create_common+0x1b2/0x2e0 fs/btrfs/inode.c:6572
#3: ffff88802e9ce458 (btrfs_trans_num_writers){++++}-{0:0}, at: join_transaction+0x15e/0xd70 fs/btrfs/transaction.c:313
#4: ffff88802e9ce480 (btrfs_trans_num_extwriters){++++}-{0:0}, at: join_transaction+0x15e/0xd70 fs/btrfs/transaction.c:313
#5: ffff888078a220f8 (btrfs-tree-01){++++}-{3:3}, at: btrfs_tree_lock_nested+0x2f/0x250 fs/btrfs/locking.c:189
#6: ffff8880302980f8 (btrfs-tree-01/1){+.+.}-{3:3}, at: btrfs_tree_lock_nested+0x2f/0x250 fs/btrfs/locking.c:189
#7: ffff88802174d388 (&cur_trans->delayed_refs.lock){+.+.}-{2:2}, at: spin_lock include/linux/spinlock.h:351 [inline]
#7: ffff88802174d388 (&cur_trans->delayed_refs.lock){+.+.}-{2:2}, at: add_delayed_ref+0x6e6/0x1e70 fs/btrfs/delayed-ref.c:1045
Preemption disabled at:
[<0000000000000000>] 0x0
CPU: 0 UID: 0 PID: 6014 Comm: syz.0.15 Not tainted 6.12.0-rc3-next-20241015-syzkaller-04439-gb852e1e7a038-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:94 [inline]
dump_stack_lvl+0x241/0x360 lib/dump_stack.c:120
__might_resched+0x5d4/0x780 kernel/sched/core.c:8653
might_alloc include/linux/sched/mm.h:321 [inline]
slab_pre_alloc_hook mm/slub.c:4045 [inline]
slab_alloc_node mm/slub.c:4123 [inline]
__kmalloc_cache_noprof+0x61/0x390 mm/slub.c:4299
kmalloc_noprof include/linux/slab.h:879 [inline]
ulist_alloc+0x6e/0x140 fs/btrfs/ulist.c:101
btrfs_find_all_roots_safe+0xf3/0x4c0 fs/btrfs/backref.c:1748
btrfs_find_all_roots+0x84/0xf0 fs/btrfs/backref.c:1799
btrfs_qgroup_trace_extent_post+0x1cd/0x2e0 fs/btrfs/qgroup.c:2105
add_delayed_ref+0x131c/0x1e70 fs/btrfs/delayed-ref.c:1076
btrfs_alloc_tree_block+0xdfb/0x1440 fs/btrfs/extent-tree.c:5209
btrfs_force_cow_block+0x526/0x1da0 fs/btrfs/ctree.c:573
btrfs_cow_block+0x35e/0xa40 fs/btrfs/ctree.c:754
btrfs_search_slot+0xbdd/0x30d0 fs/btrfs/ctree.c:2116
btrfs_insert_empty_items+0x9c/0x1a0 fs/btrfs/ctree.c:4314
btrfs_create_new_inode+0xe27/0x1f60 fs/btrfs/inode.c:6344
btrfs_create_common+0x1d4/0x2e0 fs/btrfs/inode.c:6578
vfs_mkdir+0x2f9/0x4f0 fs/namei.c:4257
do_mkdirat+0x264/0x3a0 fs/namei.c:4280
__do_sys_mkdirat fs/namei.c:4295 [inline]
__se_sys_mkdirat fs/namei.c:4293 [inline]
__x64_sys_mkdirat+0x87/0xa0 fs/namei.c:4293
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:0x7f8dcbd7dff9
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f8dccb5c038 EFLAGS: 00000246 ORIG_RAX: 0000000000000102
RAX: ffffffffffffffda RBX: 00007f8dcbf35f80 RCX: 00007f8dcbd7dff9
RDX: 0000000000000000 RSI: 0000000020000200 RDI: 0000000000000005
RBP: 00007f8dcbdf0296 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 0000000000000000 R14: 00007f8dcbf35f80 R15: 00007ffe00c6dd48
</TASK>


Tested on:

commit: b852e1e7 Add linux-next specific files for 20241015
git tree: linux-next
console output: https://syzkaller.appspot.com/x/log.txt?x=1186d727980000
kernel config: https://syzkaller.appspot.com/x/.config?x=3cb0191818709a2b
dashboard link: https://syzkaller.appspot.com/bug?extid=c3a3a153f0190dca5be9
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=12c2045f980000