syzbot


possible deadlock in generic_file_write_iter

Status: upstream: reported on 2024/12/01 16:02
Reported-by: syzbot+f9180e8a3a9305085bc6@syzkaller.appspotmail.com
First crash: 20d, last: 20d
Similar bugs (7)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream possible deadlock in generic_file_write_iter (2) fs 182 2562d 2575d 0/28 closed as invalid on 2018/02/13 19:29
linux-4.19 possible deadlock in generic_file_write_iter 4 1657d 1664d 0/1 auto-closed as invalid on 2020/10/06 15:19
linux-6.1 possible deadlock in generic_file_write_iter C 76 41m 6d19h 0/3 upstream: reported C repro on 2024/12/14 20:42
linux-4.19 possible deadlock in generic_file_write_iter (2) C error 453 695d 1264d 0/1 upstream: reported C repro on 2021/07/06 07:41
linux-4.14 possible deadlock in generic_file_write_iter (2) C 20 662d 1094d 0/1 upstream: reported C repro on 2021/12/23 04:07
upstream possible deadlock in generic_file_write_iter C 61506 2580d 2603d 3/28 fixed on 2017/11/28 03:36
linux-4.14 possible deadlock in generic_file_write_iter 3 1661d 1735d 0/1 auto-closed as invalid on 2020/10/01 23:22

Sample crash report:
exFAT-fs (loop2): failed to load upcase table (idx : 0x0000fd4f, chksum : 0x46ae1815, utbl_chksum : 0xe619d30d)
exFAT-fs (loop2): bogus allocation bitmap size(need : 2, cur : 17179869186)
======================================================
WARNING: possible circular locking dependency detected
5.15.173-syzkaller #0 Not tainted
------------------------------------------------------
syz.2.465/6943 is trying to acquire lock:
ffff0000d252e2d8 (&mm->mmap_lock){++++}-{3:3}, at: __might_fault+0xa0/0x128 mm/memory.c:5354

but task is already holding lock:
ffff0000dd91bd30 (&sb->s_type->i_mutex_key#29){++++}-{3:3}, at: inode_lock include/linux/fs.h:789 [inline]
ffff0000dd91bd30 (&sb->s_type->i_mutex_key#29){++++}-{3:3}, at: generic_file_write_iter+0x84/0x1b8 mm/filemap.c:3941

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #3 (&sb->s_type->i_mutex_key#29){++++}-{3:3}:
       down_read+0xc0/0x398 kernel/locking/rwsem.c:1498
       inode_lock_shared include/linux/fs.h:799 [inline]
       lookup_slow+0x50/0x84 fs/namei.c:1679
       walk_component+0x394/0x4cc fs/namei.c:1976
       lookup_last fs/namei.c:2431 [inline]
       path_lookupat+0x13c/0x3d0 fs/namei.c:2455
       filename_lookup+0x1c4/0x4c8 fs/namei.c:2484
       kern_path+0x4c/0x194 fs/namei.c:2582
       lookup_bdev+0xc0/0x25c block/bdev.c:979
       device_matched fs/btrfs/volumes.c:568 [inline]
       btrfs_free_stale_devices+0x658/0x9ec fs/btrfs/volumes.c:608
       btrfs_forget_devices+0x5c/0x98 fs/btrfs/volumes.c:1395
       btrfs_control_ioctl+0x12c/0x248 fs/btrfs/super.c:2451
       vfs_ioctl fs/ioctl.c:51 [inline]
       __do_sys_ioctl fs/ioctl.c:874 [inline]
       __se_sys_ioctl fs/ioctl.c:860 [inline]
       __arm64_sys_ioctl+0x14c/0x1c8 fs/ioctl.c:860
       __invoke_syscall arch/arm64/kernel/syscall.c:38 [inline]
       invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:52
       el0_svc_common+0x138/0x258 arch/arm64/kernel/syscall.c:142
       do_el0_svc+0x58/0x14c arch/arm64/kernel/syscall.c:181
       el0_svc+0x7c/0x1f0 arch/arm64/kernel/entry-common.c:608
       el0t_64_sync_handler+0x84/0xe4 arch/arm64/kernel/entry-common.c:626
       el0t_64_sync+0x1a0/0x1a4 arch/arm64/kernel/entry.S:584

-> #2 (&fs_devs->device_list_mutex){+.+.}-{3:3}:
       __mutex_lock_common+0x194/0x2154 kernel/locking/mutex.c:596
       __mutex_lock kernel/locking/mutex.c:729 [inline]
       mutex_lock_nested+0xa4/0xf8 kernel/locking/mutex.c:743
       insert_dev_extents fs/btrfs/block-group.c:2395 [inline]
       btrfs_create_pending_block_groups+0x490/0xebc fs/btrfs/block-group.c:2445
       __btrfs_end_transaction+0x13c/0x610 fs/btrfs/transaction.c:1014
       btrfs_end_transaction+0x24/0x34 fs/btrfs/transaction.c:1050
       flush_space+0x458/0xc94 fs/btrfs/space-info.c:674
       btrfs_async_reclaim_data_space+0xec/0x37c fs/btrfs/space-info.c:1169
       process_one_work+0x790/0x11b8 kernel/workqueue.c:2310
       worker_thread+0x910/0x1034 kernel/workqueue.c:2457
       kthread+0x37c/0x45c kernel/kthread.c:334
       ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:870

-> #1 (sb_internal#2){.+.+}-{0:0}:
       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+0x644/0x1480 fs/btrfs/transaction.c:678
       btrfs_join_transaction+0x30/0x40 fs/btrfs/transaction.c:791
       btrfs_dirty_inode+0xb4/0x1c0 fs/btrfs/inode.c:6436
       btrfs_update_time+0x248/0x270 fs/btrfs/inode.c:6478
       inode_update_time fs/inode.c:1868 [inline]
       touch_atime+0x434/0xa4c fs/inode.c:1941
       file_accessed include/linux/fs.h:2523 [inline]
       btrfs_file_mmap+0xb0/0x11c fs/btrfs/file.c:2451
       call_mmap include/linux/fs.h:2179 [inline]
       mmap_region+0xcb4/0x12f0 mm/mmap.c:1791
       do_mmap+0x6c0/0xcec mm/mmap.c:1575
       vm_mmap_pgoff+0x1a4/0x2b4 mm/util.c:551
       ksys_mmap_pgoff+0x458/0x668 mm/mmap.c:1624
       __do_sys_mmap arch/arm64/kernel/sys.c:28 [inline]
       __se_sys_mmap arch/arm64/kernel/sys.c:21 [inline]
       __arm64_sys_mmap+0xf8/0x110 arch/arm64/kernel/sys.c:21
       __invoke_syscall arch/arm64/kernel/syscall.c:38 [inline]
       invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:52
       el0_svc_common+0x138/0x258 arch/arm64/kernel/syscall.c:142
       do_el0_svc+0x58/0x14c arch/arm64/kernel/syscall.c:181
       el0_svc+0x7c/0x1f0 arch/arm64/kernel/entry-common.c:608
       el0t_64_sync_handler+0x84/0xe4 arch/arm64/kernel/entry-common.c:626
       el0t_64_sync+0x1a0/0x1a4 arch/arm64/kernel/entry.S:584

-> #0 (&mm->mmap_lock){++++}-{3:3}:
       check_prev_add kernel/locking/lockdep.c:3053 [inline]
       check_prevs_add kernel/locking/lockdep.c:3172 [inline]
       validate_chain kernel/locking/lockdep.c:3788 [inline]
       __lock_acquire+0x32d4/0x7638 kernel/locking/lockdep.c:5012
       lock_acquire+0x240/0x77c kernel/locking/lockdep.c:5623
       __might_fault+0xc8/0x128 mm/memory.c:5355
       fault_in_readable+0xdc/0x56c mm/gup.c:1793
       fault_in_iov_iter_readable+0x130/0x1b0 lib/iov_iter.c:460
       generic_perform_write+0x198/0x520 mm/filemap.c:3775
       __generic_file_write_iter+0x230/0x454 mm/filemap.c:3912
       generic_file_write_iter+0xb4/0x1b8 mm/filemap.c:3944
       call_write_iter include/linux/fs.h:2174 [inline]
       new_sync_write fs/read_write.c:507 [inline]
       vfs_write+0x884/0xb44 fs/read_write.c:594
       ksys_write+0x15c/0x26c fs/read_write.c:647
       __do_sys_write fs/read_write.c:659 [inline]
       __se_sys_write fs/read_write.c:656 [inline]
       __arm64_sys_write+0x7c/0x90 fs/read_write.c:656
       __invoke_syscall arch/arm64/kernel/syscall.c:38 [inline]
       invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:52
       el0_svc_common+0x138/0x258 arch/arm64/kernel/syscall.c:142
       do_el0_svc+0x58/0x14c arch/arm64/kernel/syscall.c:181
       el0_svc+0x7c/0x1f0 arch/arm64/kernel/entry-common.c:608
       el0t_64_sync_handler+0x84/0xe4 arch/arm64/kernel/entry-common.c:626
       el0t_64_sync+0x1a0/0x1a4 arch/arm64/kernel/entry.S:584

other info that might help us debug this:

Chain exists of:
  &mm->mmap_lock --> &fs_devs->device_list_mutex --> &sb->s_type->i_mutex_key#29

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&sb->s_type->i_mutex_key#29);
                               lock(&fs_devs->device_list_mutex);
                               lock(&sb->s_type->i_mutex_key#29);
  lock(&mm->mmap_lock);

 *** DEADLOCK ***

2 locks held by syz.2.465/6943:
 #0: ffff0000d1868460 (sb_writers#26){.+.+}-{0:0}, at: vfs_write+0x228/0xb44 fs/read_write.c:590
 #1: ffff0000dd91bd30 (&sb->s_type->i_mutex_key#29){++++}-{3:3}, at: inode_lock include/linux/fs.h:789 [inline]
 #1: ffff0000dd91bd30 (&sb->s_type->i_mutex_key#29){++++}-{3:3}, at: generic_file_write_iter+0x84/0x1b8 mm/filemap.c:3941

stack backtrace:
CPU: 0 PID: 6943 Comm: syz.2.465 Not tainted 5.15.173-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024
Call trace:
 dump_backtrace+0x0/0x530 arch/arm64/kernel/stacktrace.c:152
 show_stack+0x2c/0x3c arch/arm64/kernel/stacktrace.c:216
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x108/0x170 lib/dump_stack.c:106
 dump_stack+0x1c/0x58 lib/dump_stack.c:113
 print_circular_bug+0x150/0x1b8 kernel/locking/lockdep.c:2011
 check_noncircular+0x2cc/0x378 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 kernel/locking/lockdep.c:3788 [inline]
 __lock_acquire+0x32d4/0x7638 kernel/locking/lockdep.c:5012
 lock_acquire+0x240/0x77c kernel/locking/lockdep.c:5623
 __might_fault+0xc8/0x128 mm/memory.c:5355
 fault_in_readable+0xdc/0x56c mm/gup.c:1793
 fault_in_iov_iter_readable+0x130/0x1b0 lib/iov_iter.c:460
 generic_perform_write+0x198/0x520 mm/filemap.c:3775
 __generic_file_write_iter+0x230/0x454 mm/filemap.c:3912
 generic_file_write_iter+0xb4/0x1b8 mm/filemap.c:3944
 call_write_iter include/linux/fs.h:2174 [inline]
 new_sync_write fs/read_write.c:507 [inline]
 vfs_write+0x884/0xb44 fs/read_write.c:594
 ksys_write+0x15c/0x26c fs/read_write.c:647
 __do_sys_write fs/read_write.c:659 [inline]
 __se_sys_write fs/read_write.c:656 [inline]
 __arm64_sys_write+0x7c/0x90 fs/read_write.c:656
 __invoke_syscall arch/arm64/kernel/syscall.c:38 [inline]
 invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:52
 el0_svc_common+0x138/0x258 arch/arm64/kernel/syscall.c:142
 do_el0_svc+0x58/0x14c arch/arm64/kernel/syscall.c:181
 el0_svc+0x7c/0x1f0 arch/arm64/kernel/entry-common.c:608
 el0t_64_sync_handler+0x84/0xe4 arch/arm64/kernel/entry-common.c:626
 el0t_64_sync+0x1a0/0x1a4 arch/arm64/kernel/entry.S:584

Crashes (1):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2024/12/01 16:01 linux-5.15.y 0a51d2d4527b 68914665 .config console log report info [disk image] [vmlinux] [kernel image] ci2-linux-5-15-kasan-arm64 possible deadlock in generic_file_write_iter
* Struck through repros no longer work on HEAD.