[v5.15] possible deadlock in btrfs_dirty_inode (3)

0 views
Skip to first unread message

syzbot

unread,
Dec 9, 2024, 2:33:27 PM12/9/24
Hello,

syzbot found the following issue on:

HEAD commit: 0a51d2d4527b Linux 5.15.173
git tree: linux-5.15.y
console output: https://syzkaller.appspot.com/x/log.txt?x=11d7c8f8580000
kernel config: https://syzkaller.appspot.com/x/.config?x=48dad5136d11d5fc
dashboard link: https://syzkaller.appspot.com/bug?extid=30f24026dfac984b80fc
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40

Unfortunately, I don't have any reproducer for this issue yet.

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/df502ed32946/disk-0a51d2d4.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/a6f49f24ceaa/vmlinux-0a51d2d4.xz
kernel image: https://storage.googleapis.com/syzbot-assets/f45db4b68abf/bzImage-0a51d2d4.xz

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

BTRFS info (device loop0): clearing compat-ro feature flag for FREE_SPACE_TREE (0x1)
BTRFS info (device loop0): clearing compat-ro feature flag for FREE_SPACE_TREE_VALID (0x2)
======================================================
WARNING: possible circular locking dependency detected
5.15.173-syzkaller #0 Not tainted
------------------------------------------------------
syz.0.18/4343 is trying to acquire lock:
ffff88807b248650 (sb_internal#3){.+.+}-{0:0}, at: btrfs_dirty_inode+0xcc/0x1c0 fs/btrfs/inode.c:6436

but task is already holding lock:
ffff88805e473720 (&type->i_mutex_dir_key#8){++++}-{3:3}, at: inode_lock include/linux/fs.h:789 [inline]
ffff88805e473720 (&type->i_mutex_dir_key#8){++++}-{3:3}, at: chown_common+0x499/0x890 fs/open.c:674

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #3 (&type->i_mutex_dir_key#8){++++}-{3:3}:
lock_acquire+0x1db/0x4f0 kernel/locking/lockdep.c:5623
down_read+0x45/0x2e0 kernel/locking/rwsem.c:1498
inode_lock_shared include/linux/fs.h:799 [inline]
lookup_slow+0x45/0x70 fs/namei.c:1679
walk_component+0x48c/0x610 fs/namei.c:1976
lookup_last fs/namei.c:2431 [inline]
path_lookupat+0x16f/0x450 fs/namei.c:2455
filename_lookup+0x230/0x5c0 fs/namei.c:2484
kern_path+0x37/0x180 fs/namei.c:2582
lookup_bdev+0xc1/0x280 block/bdev.c:979
device_matched fs/btrfs/volumes.c:568 [inline]
btrfs_free_stale_devices+0x71f/0xb00 fs/btrfs/volumes.c:608
btrfs_forget_devices+0x52/0x80 fs/btrfs/volumes.c:1395
btrfs_control_ioctl+0x108/0x210 fs/btrfs/super.c:2451
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:874 [inline]
__se_sys_ioctl+0xf1/0x160 fs/ioctl.c:860
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x3b/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x66/0xd0

-> #2 (&fs_devs->device_list_mutex){+.+.}-{3:3}:
lock_acquire+0x1db/0x4f0 kernel/locking/lockdep.c:5623
__mutex_lock_common+0x1da/0x25a0 kernel/locking/mutex.c:596
__mutex_lock kernel/locking/mutex.c:729 [inline]
mutex_lock_nested+0x17/0x20 kernel/locking/mutex.c:743
btrfs_run_dev_stats+0xeb/0xfd0 fs/btrfs/volumes.c:7949
commit_cowonly_roots+0x1cb/0x9d0 fs/btrfs/transaction.c:1290
btrfs_commit_transaction+0x13af/0x3800 fs/btrfs/transaction.c:2392
btrfs_clear_free_space_tree+0x755/0xbd0 fs/btrfs/free-space-tree.c:1264
btrfs_start_pre_rw_mount+0x2b0/0x680 fs/btrfs/disk-io.c:3079
open_ctree+0x2dcf/0x3500 fs/btrfs/disk-io.c:3634
btrfs_fill_super+0x1c7/0x2d0 fs/btrfs/super.c:1387
btrfs_mount_root+0x803/0x930 fs/btrfs/super.c:1752
legacy_get_tree+0xeb/0x180 fs/fs_context.c:611
vfs_get_tree+0x88/0x270 fs/super.c:1530
fc_mount fs/namespace.c:1000 [inline]
vfs_kern_mount+0xb8/0x150 fs/namespace.c:1030
btrfs_mount+0x395/0xb40 fs/btrfs/super.c:1812
legacy_get_tree+0xeb/0x180 fs/fs_context.c:611
vfs_get_tree+0x88/0x270 fs/super.c:1530
do_new_mount+0x2ba/0xb40 fs/namespace.c:3012
do_mount fs/namespace.c:3355 [inline]
__do_sys_mount fs/namespace.c:3563 [inline]
__se_sys_mount+0x2d5/0x3c0 fs/namespace.c:3540
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x3b/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x66/0xd0

-> #1 (&fs_info->tree_log_mutex){+.+.}-{3:3}:
reacquire_held_locks+0x3a2/0x660 kernel/locking/lockdep.c:5150
__lock_release kernel/locking/lockdep.c:5339 [inline]
lock_release+0x369/0x9a0 kernel/locking/lockdep.c:5643
__mutex_unlock_slowpath+0xde/0x750 kernel/locking/mutex.c:851
btrfs_commit_transaction+0x1e34/0x3800 fs/btrfs/transaction.c:2439
btrfs_clear_free_space_tree+0x755/0xbd0 fs/btrfs/free-space-tree.c:1264
btrfs_start_pre_rw_mount+0x2b0/0x680 fs/btrfs/disk-io.c:3079
open_ctree+0x2dcf/0x3500 fs/btrfs/disk-io.c:3634
btrfs_fill_super+0x1c7/0x2d0 fs/btrfs/super.c:1387
btrfs_mount_root+0x803/0x930 fs/btrfs/super.c:1752
legacy_get_tree+0xeb/0x180 fs/fs_context.c:611
vfs_get_tree+0x88/0x270 fs/super.c:1530
fc_mount fs/namespace.c:1000 [inline]
vfs_kern_mount+0xb8/0x150 fs/namespace.c:1030
btrfs_mount+0x395/0xb40 fs/btrfs/super.c:1812
legacy_get_tree+0xeb/0x180 fs/fs_context.c:611
vfs_get_tree+0x88/0x270 fs/super.c:1530
do_new_mount+0x2ba/0xb40 fs/namespace.c:3012
do_mount fs/namespace.c:3355 [inline]
__do_sys_mount fs/namespace.c:3563 [inline]
__se_sys_mount+0x2d5/0x3c0 fs/namespace.c:3540
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x3b/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x66/0xd0

-> #0 (sb_internal#3){.+.+}-{0:0}:
check_prev_add kernel/locking/lockdep.c:3053 [inline]
check_prevs_add kernel/locking/lockdep.c:3172 [inline]
validate_chain+0x1649/0x5930 kernel/locking/lockdep.c:3788
__lock_acquire+0x1295/0x1ff0 kernel/locking/lockdep.c:5012
lock_acquire+0x1db/0x4f0 kernel/locking/lockdep.c:5623
percpu_down_read include/linux/percpu-rwsem.h:51 [inline]
__sb_start_write include/linux/fs.h:1813 [inline]
sb_start_intwrite include/linux/fs.h:1930 [inline]
start_transaction+0x5a8/0x11a0 fs/btrfs/transaction.c:678
btrfs_dirty_inode+0xcc/0x1c0 fs/btrfs/inode.c:6436
btrfs_setattr+0x2d0/0xf70 fs/btrfs/inode.c:5495
notify_change+0xc6d/0xf50 fs/attr.c:505
chown_common+0x592/0x890 fs/open.c:680
do_fchownat+0x169/0x240 fs/open.c:711
__do_sys_lchown fs/open.c:736 [inline]
__se_sys_lchown fs/open.c:734 [inline]
__x64_sys_lchown+0x81/0x90 fs/open.c:734
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x3b/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x66/0xd0

other info that might help us debug this:

Chain exists of:
sb_internal#3 --> &fs_devs->device_list_mutex --> &type->i_mutex_dir_key#8

Possible unsafe locking scenario:

CPU0 CPU1
---- ----
lock(&type->i_mutex_dir_key#8);
lock(&fs_devs->device_list_mutex);
lock(&type->i_mutex_dir_key#8);
lock(sb_internal#3);

*** DEADLOCK ***

2 locks held by syz.0.18/4343:
#0: ffff88807b248460 (sb_writers#19){.+.+}-{0:0}, at: mnt_want_write+0x3b/0x80 fs/namespace.c:377
#1: ffff88805e473720 (&type->i_mutex_dir_key#8){++++}-{3:3}, at: inode_lock include/linux/fs.h:789 [inline]
#1: ffff88805e473720 (&type->i_mutex_dir_key#8){++++}-{3:3}, at: chown_common+0x499/0x890 fs/open.c:674

stack backtrace:
CPU: 0 PID: 4343 Comm: syz.0.18 Not tainted 5.15.173-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0x1e3/0x2d0 lib/dump_stack.c:106
check_noncircular+0x2f8/0x3b0 kernel/locking/lockdep.c:2133
check_prev_add kernel/locking/lockdep.c:3053 [inline]
check_prevs_add kernel/locking/lockdep.c:3172 [inline]
validate_chain+0x1649/0x5930 kernel/locking/lockdep.c:3788
__lock_acquire+0x1295/0x1ff0 kernel/locking/lockdep.c:5012
lock_acquire+0x1db/0x4f0 kernel/locking/lockdep.c:5623
percpu_down_read include/linux/percpu-rwsem.h:51 [inline]
__sb_start_write include/linux/fs.h:1813 [inline]
sb_start_intwrite include/linux/fs.h:1930 [inline]
start_transaction+0x5a8/0x11a0 fs/btrfs/transaction.c:678
btrfs_dirty_inode+0xcc/0x1c0 fs/btrfs/inode.c:6436
btrfs_setattr+0x2d0/0xf70 fs/btrfs/inode.c:5495
notify_change+0xc6d/0xf50 fs/attr.c:505
chown_common+0x592/0x890 fs/open.c:680
do_fchownat+0x169/0x240 fs/open.c:711
__do_sys_lchown fs/open.c:736 [inline]
__se_sys_lchown fs/open.c:734 [inline]
__x64_sys_lchown+0x81/0x90 fs/open.c:734
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x3b/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x66/0xd0
RIP: 0033:0x7f8678e99ed9
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:00007f8676d10058 EFLAGS: 00000246 ORIG_RAX: 000000000000005e
RAX: ffffffffffffffda RBX: 00007f867905ffa0 RCX: 00007f8678e99ed9
RDX: 0000000000000000 RSI: 000000000000ee00 RDI: 0000000020000000
RBP: 00007f8678f0dcc8 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 0000000000000000 R14: 00007f867905ffa0 R15: 00007ffd5f224918
</TASK>


---
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 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

syzbot

unread,
Dec 9, 2024, 4:20:25 PM12/9/24
syzbot has found a reproducer for the following issue on:

HEAD commit: 0a51d2d4527b Linux 5.15.173
git tree: linux-5.15.y
console output: https://syzkaller.appspot.com/x/log.txt?x=160254df980000
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=178828f8580000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=156ca3e8580000
mounted in repro: https://storage.googleapis.com/syzbot-assets/265e73d6421a/mount_1.gz

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

BTRFS info (device loop0): clearing free space tree
BTRFS info (device loop0): clearing compat-ro feature flag for FREE_SPACE_TREE (0x1)
BTRFS info (device loop0): clearing compat-ro feature flag for FREE_SPACE_TREE_VALID (0x2)
======================================================
WARNING: possible circular locking dependency detected
5.15.173-syzkaller #0 Not tainted
------------------------------------------------------
syz-executor302/4161 is trying to acquire lock:
ffff88802a33c650 (sb_internal#2){.+.+}-{0:0}, at: btrfs_dirty_inode+0xcc/0x1c0 fs/btrfs/inode.c:6436

but task is already holding lock:
ffff888071218610 (&type->i_mutex_dir_key#6){++++}-{3:3}, at: inode_lock include/linux/fs.h:789 [inline]
ffff888071218610 (&type->i_mutex_dir_key#6){++++}-{3:3}, at: chown_common+0x499/0x890 fs/open.c:674

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #3 (&type->i_mutex_dir_key#6){++++}-{3:3}:
-> #0 (sb_internal#2){.+.+}-{0:0}:
check_prev_add kernel/locking/lockdep.c:3053 [inline]
check_prevs_add kernel/locking/lockdep.c:3172 [inline]
validate_chain+0x1649/0x5930 kernel/locking/lockdep.c:3788
__lock_acquire+0x1295/0x1ff0 kernel/locking/lockdep.c:5012
lock_acquire+0x1db/0x4f0 kernel/locking/lockdep.c:5623
percpu_down_read include/linux/percpu-rwsem.h:51 [inline]
__sb_start_write include/linux/fs.h:1813 [inline]
sb_start_intwrite include/linux/fs.h:1930 [inline]
start_transaction+0x5a8/0x11a0 fs/btrfs/transaction.c:678
btrfs_dirty_inode+0xcc/0x1c0 fs/btrfs/inode.c:6436
btrfs_setattr+0x2d0/0xf70 fs/btrfs/inode.c:5495
notify_change+0xc6d/0xf50 fs/attr.c:505
chown_common+0x592/0x890 fs/open.c:680
do_fchownat+0x169/0x240 fs/open.c:711
__do_sys_lchown fs/open.c:736 [inline]
__se_sys_lchown fs/open.c:734 [inline]
__x64_sys_lchown+0x81/0x90 fs/open.c:734
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x3b/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x66/0xd0

other info that might help us debug this:

Chain exists of:
sb_internal#2 --> &fs_devs->device_list_mutex --> &type->i_mutex_dir_key#6

Possible unsafe locking scenario:

CPU0 CPU1
---- ----
lock(&type->i_mutex_dir_key#6);
lock(&fs_devs->device_list_mutex);
lock(&type->i_mutex_dir_key#6);
lock(sb_internal#2);

*** DEADLOCK ***

2 locks held by syz-executor302/4161:
#0: ffff88802a33c460 (sb_writers#9){.+.+}-{0:0}, at: mnt_want_write+0x3b/0x80 fs/namespace.c:377
#1: ffff888071218610 (&type->i_mutex_dir_key#6){++++}-{3:3}, at: inode_lock include/linux/fs.h:789 [inline]
#1: ffff888071218610 (&type->i_mutex_dir_key#6){++++}-{3:3}, at: chown_common+0x499/0x890 fs/open.c:674

stack backtrace:
CPU: 1 PID: 4161 Comm: syz-executor302 Not tainted 5.15.173-syzkaller #0
RIP: 0033:0x7fc70478cb39
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 61 17 00 00 90 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 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffcf58a9ee8 EFLAGS: 00000246 ORIG_RA


---
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.
Reply all
Reply to author
Forward
0 new messages