syzbot


possible deadlock in btrfs_dirty_inode

Status: auto-obsoleted due to no activity on 2023/09/28 23:24
Reported-by: syzbot+a459e95d8791adeae6f3@syzkaller.appspotmail.com
First crash: 335d, last: 316d
Similar bugs (2)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
linux-5.15 possible deadlock in btrfs_dirty_inode (2) 1 18d 18d 0/3 upstream: reported on 2024/04/13 12:12
upstream possible deadlock in btrfs_dirty_inode btrfs C error done 48 522d 534d 0/26 auto-obsoleted due to no activity on 2023/05/16 05:18

Sample crash report:
======================================================
WARNING: possible circular locking dependency detected
5.15.117-syzkaller #0 Not tainted
------------------------------------------------------
syz-executor.5/17953 is trying to acquire lock:
ffff888043ea4650 (sb_internal#3){.+.+}-{0:0}, at: btrfs_dirty_inode+0xcc/0x1c0 fs/btrfs/inode.c:6322

but task is already holding lock:
ffff888011e69628 (&mm->mmap_lock#2){++++}-{3:3}, at: mmap_write_lock_killable include/linux/mmap_lock.h:87 [inline]
ffff888011e69628 (&mm->mmap_lock#2){++++}-{3:3}, at: vm_mmap_pgoff+0x175/0x2d0 mm/util.c:549

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #7 (&mm->mmap_lock#2){++++}-{3:3}:
       lock_acquire+0x1db/0x4f0 kernel/locking/lockdep.c:5622
       down_write+0x97/0x170 kernel/locking/rwsem.c:1541
       mmap_write_lock include/linux/mmap_lock.h:71 [inline]
       mpol_rebind_mm+0x34/0x2b0 mm/mempolicy.c:381
       cpuset_attach+0x393/0x540 kernel/cgroup/cpuset.c:2289
       cgroup_migrate_execute+0x7fb/0x10e0 kernel/cgroup/cgroup.c:2559
       cgroup_attach_task+0x58a/0x840 kernel/cgroup/cgroup.c:2854
       __cgroup1_procs_write+0x2ec/0x460 kernel/cgroup/cgroup-v1.c:528
       cgroup_file_write+0x2ac/0x670 kernel/cgroup/cgroup.c:3932
       kernfs_fop_write_iter+0x3a2/0x4f0 fs/kernfs/file.c:296
       call_write_iter include/linux/fs.h:2103 [inline]
       new_sync_write fs/read_write.c:507 [inline]
       vfs_write+0xacf/0xe50 fs/read_write.c:594
       ksys_write+0x1a2/0x2c0 fs/read_write.c:647
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x61/0xcb

-> #6 (&cpuset_rwsem){++++}-{0:0}:
       lock_acquire+0x1db/0x4f0 kernel/locking/lockdep.c:5622
       percpu_down_read include/linux/percpu-rwsem.h:51 [inline]
       cpuset_read_lock+0x40/0x150 kernel/cgroup/cpuset.c:356
       __sched_setscheduler+0x626/0x1df0 kernel/sched/core.c:7409
       _sched_setscheduler kernel/sched/core.c:7586 [inline]
       sched_setscheduler_nocheck+0x187/0x2d0 kernel/sched/core.c:7633
       __kthread_create_on_node+0x31b/0x3f0 kernel/kthread.c:413
       kthread_create_on_node+0xda/0x120 kernel/kthread.c:453
       cryptomgr_schedule_test crypto/algboss.c:219 [inline]
       cryptomgr_notify+0x125/0xc70 crypto/algboss.c:240
       notifier_call_chain kernel/notifier.c:83 [inline]
       blocking_notifier_call_chain+0x104/0x1b0 kernel/notifier.c:318
       crypto_probing_notify+0x21/0x70 crypto/api.c:251
       crypto_wait_for_test+0x3e/0xd0 crypto/algapi.c:396
       crypto_register_alg+0x25b/0x330 crypto/algapi.c:429
       do_one_initcall+0x22b/0x7a0 init/main.c:1306
       do_initcall_level+0x157/0x207 init/main.c:1379
       do_initcalls+0x49/0x86 init/main.c:1395
       kernel_init_freeable+0x43c/0x5c5 init/main.c:1619
       kernel_init+0x19/0x290 init/main.c:1510
       ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:298

-> #5 ((crypto_chain).rwsem){++++}-{3:3}:
       lock_acquire+0x1db/0x4f0 kernel/locking/lockdep.c:5622
       down_read+0x45/0x2e0 kernel/locking/rwsem.c:1488
       blocking_notifier_call_chain+0x5e/0x1b0 kernel/notifier.c:317
       crypto_probing_notify crypto/api.c:251 [inline]
       crypto_alg_mod_lookup+0x4e6/0x710 crypto/api.c:281
       crypto_find_alg crypto/api.c:490 [inline]
       crypto_alloc_tfm_node+0x12c/0x350 crypto/api.c:527
       cryptd_alloc_skcipher+0xde/0x1f0 crypto/cryptd.c:916
       simd_skcipher_init+0x63/0x130 crypto/simd.c:122
       crypto_create_tfm_node+0x105/0x360 crypto/api.c:457
       crypto_alloc_tfm_node+0x15d/0x350 crypto/api.c:533
       fscrypt_allocate_skcipher fs/crypto/keysetup.c:84 [inline]
       fscrypt_prepare_key+0x89/0x360 fs/crypto/keysetup.c:135
       fscrypt_set_per_file_enc_key fs/crypto/keysetup.c:160 [inline]
       fscrypt_setup_v2_file_key fs/crypto/keysetup.c:349 [inline]
       setup_file_encryption_key fs/crypto/keysetup.c:474 [inline]
       fscrypt_setup_encryption_info+0xcf4/0x13a0 fs/crypto/keysetup.c:553
       fscrypt_get_encryption_info+0x334/0x420 fs/crypto/keysetup.c:638
       fscrypt_prepare_readdir include/linux/fscrypt.h:908 [inline]
       ext4_readdir+0x178/0x38e0 fs/ext4/dir.c:137
       iterate_dir+0x224/0x570
       __do_sys_getdents64 fs/readdir.c:369 [inline]
       __se_sys_getdents64+0x209/0x4f0 fs/readdir.c:354
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x61/0xcb

-> #4 (&mk->mk_sem){++++}-{3:3}:
       lock_acquire+0x1db/0x4f0 kernel/locking/lockdep.c:5622
       down_read+0x45/0x2e0 kernel/locking/rwsem.c:1488
       setup_file_encryption_key fs/crypto/keysetup.c:456 [inline]
       fscrypt_setup_encryption_info+0x5b6/0x13a0 fs/crypto/keysetup.c:553
       fscrypt_get_encryption_info+0x334/0x420 fs/crypto/keysetup.c:638
       fscrypt_prepare_readdir include/linux/fscrypt.h:908 [inline]
       ext4_readdir+0x178/0x38e0 fs/ext4/dir.c:137
       iterate_dir+0x224/0x570
       __do_sys_getdents64 fs/readdir.c:369 [inline]
       __se_sys_getdents64+0x209/0x4f0 fs/readdir.c:354
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x61/0xcb

-> #3 (&type->i_mutex_dir_key#4){++++}-{3:3}:
       lock_acquire+0x1db/0x4f0 kernel/locking/lockdep.c:5622
       down_read+0x45/0x2e0 kernel/locking/rwsem.c:1488
       inode_lock_shared include/linux/fs.h:797 [inline]
       lookup_slow+0x45/0x70 fs/namei.c:1675
       walk_component+0x48c/0x610 fs/namei.c:1972
       lookup_last fs/namei.c:2427 [inline]
       path_lookupat+0x16f/0x450 fs/namei.c:2451
       filename_lookup+0x230/0x5c0 fs/namei.c:2480
       kern_path+0x37/0x180 fs/namei.c:2570
       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:1380
       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+0x3d/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x61/0xcb

-> #2 (&fs_devs->device_list_mutex){+.+.}-{3:3}:
       lock_acquire+0x1db/0x4f0 kernel/locking/lockdep.c:5622
       __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
       write_all_supers+0x13fd/0x4650 fs/btrfs/disk-io.c:4149
       btrfs_sync_log+0x1f78/0x2a00 fs/btrfs/tree-log.c:3327
       btrfs_sync_file+0xb4e/0xfa0 fs/btrfs/file.c:2349
       vfs_fsync_range fs/sync.c:188 [inline]
       vfs_fsync fs/sync.c:202 [inline]
       do_fsync fs/sync.c:212 [inline]
       __do_sys_fdatasync fs/sync.c:225 [inline]
       __se_sys_fdatasync fs/sync.c:223 [inline]
       __x64_sys_fdatasync+0xb1/0x100 fs/sync.c:223
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x61/0xcb

-> #1 (&fs_info->tree_log_mutex){+.+.}-{3:3}:
       lock_acquire+0x1db/0x4f0 kernel/locking/lockdep.c:5622
       __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_sync_log+0x1e77/0x2a00 fs/btrfs/tree-log.c:3308
       btrfs_sync_file+0xb4e/0xfa0 fs/btrfs/file.c:2349
       vfs_fsync_range fs/sync.c:188 [inline]
       vfs_fsync fs/sync.c:202 [inline]
       do_fsync fs/sync.c:212 [inline]
       __do_sys_fdatasync fs/sync.c:225 [inline]
       __se_sys_fdatasync fs/sync.c:223 [inline]
       __x64_sys_fdatasync+0xb1/0x100 fs/sync.c:223
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x61/0xcb

-> #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+0x1646/0x58b0 kernel/locking/lockdep.c:3787
       __lock_acquire+0x1295/0x1ff0 kernel/locking/lockdep.c:5011
       lock_acquire+0x1db/0x4f0 kernel/locking/lockdep.c:5622
       percpu_down_read include/linux/percpu-rwsem.h:51 [inline]
       __sb_start_write include/linux/fs.h:1742 [inline]
       sb_start_intwrite include/linux/fs.h:1859 [inline]
       start_transaction+0x5a8/0x11a0 fs/btrfs/transaction.c:677
       btrfs_dirty_inode+0xcc/0x1c0 fs/btrfs/inode.c:6322
       inode_update_time fs/inode.c:1787 [inline]
       touch_atime+0x34e/0x680 fs/inode.c:1860
       file_accessed include/linux/fs.h:2447 [inline]
       btrfs_file_mmap+0xbf/0x120 fs/btrfs/file.c:2424
       call_mmap include/linux/fs.h:2108 [inline]
       mmap_region+0x10e7/0x1670 mm/mmap.c:1791
       do_mmap+0x78d/0xe00 mm/mmap.c:1575
       vm_mmap_pgoff+0x1ca/0x2d0 mm/util.c:551
       ksys_mmap_pgoff+0x559/0x780 mm/mmap.c:1624
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x61/0xcb

other info that might help us debug this:

Chain exists of:
  sb_internal#3 --> &cpuset_rwsem --> &mm->mmap_lock#2

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&mm->mmap_lock#2);
                               lock(&cpuset_rwsem);
                               lock(&mm->mmap_lock#2);
  lock(sb_internal#3);

 *** DEADLOCK ***

2 locks held by syz-executor.5/17953:
 #0: ffff888011e69628 (&mm->mmap_lock#2){++++}-{3:3}, at: mmap_write_lock_killable include/linux/mmap_lock.h:87 [inline]
 #0: ffff888011e69628 (&mm->mmap_lock#2){++++}-{3:3}, at: vm_mmap_pgoff+0x175/0x2d0 mm/util.c:549
 #1: ffff888043ea4460 (sb_writers#20){.+.+}-{0:0}, at: file_accessed include/linux/fs.h:2447 [inline]
 #1: ffff888043ea4460 (sb_writers#20){.+.+}-{0:0}, at: btrfs_file_mmap+0xbf/0x120 fs/btrfs/file.c:2424

stack backtrace:
CPU: 0 PID: 17953 Comm: syz-executor.5 Not tainted 5.15.117-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 05/27/2023
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x1e3/0x2cb 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+0x1646/0x58b0 kernel/locking/lockdep.c:3787
 __lock_acquire+0x1295/0x1ff0 kernel/locking/lockdep.c:5011
 lock_acquire+0x1db/0x4f0 kernel/locking/lockdep.c:5622
 percpu_down_read include/linux/percpu-rwsem.h:51 [inline]
 __sb_start_write include/linux/fs.h:1742 [inline]
 sb_start_intwrite include/linux/fs.h:1859 [inline]
 start_transaction+0x5a8/0x11a0 fs/btrfs/transaction.c:677
 btrfs_dirty_inode+0xcc/0x1c0 fs/btrfs/inode.c:6322
 inode_update_time fs/inode.c:1787 [inline]
 touch_atime+0x34e/0x680 fs/inode.c:1860
 file_accessed include/linux/fs.h:2447 [inline]
 btrfs_file_mmap+0xbf/0x120 fs/btrfs/file.c:2424
 call_mmap include/linux/fs.h:2108 [inline]
 mmap_region+0x10e7/0x1670 mm/mmap.c:1791
 do_mmap+0x78d/0xe00 mm/mmap.c:1575
 vm_mmap_pgoff+0x1ca/0x2d0 mm/util.c:551
 ksys_mmap_pgoff+0x559/0x780 mm/mmap.c:1624
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x61/0xcb
RIP: 0033:0x7fbdb6a94389
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 f1 19 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:00007fbdadbc4168 EFLAGS: 00000246 ORIG_RAX: 0000000000000009
RAX: ffffffffffffffda RBX: 00007fbdb6bb4120 RCX: 00007fbdb6a94389
RDX: 000000000000000b RSI: 0000000000b36000 RDI: 0000000020000000
RBP: 00007fbdb6adf493 R08: 0000000000000004 R09: 0000000000000000
R10: 0000000000028011 R11: 0000000000000246 R12: 0000000000000000
R13: 00007fff0251136f R14: 00007fbdadbc4300 R15: 0000000000022000
 </TASK>

Crashes (3):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2023/06/20 23:24 linux-5.15.y 471e639e59d1 79782afc .config console log report info [disk image] [vmlinux] [kernel image] ci2-linux-5-15-kasan possible deadlock in btrfs_dirty_inode
2023/06/19 19:23 linux-5.15.y 471e639e59d1 d521bc56 .config console log report info [disk image] [vmlinux] [kernel image] ci2-linux-5-15-kasan possible deadlock in btrfs_dirty_inode
2023/06/01 22:37 linux-5.15.y 0ab06468cbd1 a4ae4f42 .config console log report info [disk image] [vmlinux] [kernel image] ci2-linux-5-15-kasan possible deadlock in btrfs_dirty_inode
* Struck through repros no longer work on HEAD.