syzbot


possible deadlock in __generic_file_fsync (2)

Status: upstream: reported on 2024/11/03 19:56
Subsystems: exfat
[Documentation on labels]
Reported-by: syzbot+625941ecc67c107ef2bd@syzkaller.appspotmail.com
First crash: 39d, last: 8d00h
Discussions (2)
Title Replies (including bot) Last reply
[syzbot] Monthly exfat report (Dec 2024) 0 (1) 2024/12/07 16:12
[syzbot] [exfat?] possible deadlock in __generic_file_fsync (2) 0 (1) 2024/11/03 19:56
Similar bugs (4)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
linux-4.19 possible deadlock in __generic_file_fsync ext4 btrfs fat C 577 657d 2005d 0/1 upstream: reported C repro on 2019/06/13 18:12
linux-4.14 possible deadlock in __generic_file_fsync ext4 fat syz error 171 662d 1999d 0/1 upstream: reported syz repro on 2019/06/19 20:20
upstream possible deadlock in __generic_file_fsync ext4 C done unreliable 80 2105d 2245d 0/28 auto-obsoleted due to no activity on 2022/09/04 03:10
android-414 possible deadlock in __generic_file_fsync syz 262 1833d 2068d 0/1 public: reported syz repro on 2019/04/12 00:01

Sample crash report:
======================================================
WARNING: possible circular locking dependency detected
6.12.0-syzkaller-11930-g0e287d31b62b #0 Not tainted
------------------------------------------------------
syz.3.565/7542 is trying to acquire lock:
ffff88805a15c7a0 (&sb->s_type->i_mutex_key#24){++++}-{4:4}, at: inode_lock include/linux/fs.h:818 [inline]
ffff88805a15c7a0 (&sb->s_type->i_mutex_key#24){++++}-{4:4}, at: __generic_file_fsync+0xb0/0x1f0 fs/libfs.c:1536

but task is already holding lock:
ffff8880259e9e00 (&q->q_usage_counter(io)#17){++++}-{0:0}, at: loop_set_status+0x1d9/0x700 drivers/block/loop.c:1267

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #2 (&q->q_usage_counter(io)#17){++++}-{0:0}:
       bio_queue_enter block/blk.h:75 [inline]
       blk_mq_submit_bio+0x1fb6/0x24c0 block/blk-mq.c:3092
       __submit_bio+0x384/0x540 block/blk-core.c:629
       __submit_bio_noacct_mq block/blk-core.c:710 [inline]
       submit_bio_noacct_nocheck+0x698/0xd70 block/blk-core.c:739
       submit_bio_noacct+0x93a/0x1e20 block/blk-core.c:868
       submit_bh fs/buffer.c:2819 [inline]
       __bread_slow fs/buffer.c:1264 [inline]
       __bread_gfp+0x189/0x340 fs/buffer.c:1488
       sb_bread include/linux/buffer_head.h:346 [inline]
       fat_ent_bread+0x16b/0x330 fs/fat/fatent.c:109
       fat_ent_read_block fs/fat/fatent.c:445 [inline]
       fat_alloc_clusters+0x58b/0xf80 fs/fat/fatent.c:493
       fat_add_new_entries+0x230/0xf50 fs/fat/dir.c:1230
       fat_add_entries+0xc34/0x1530 fs/fat/dir.c:1388
       vfat_add_entry+0x298d/0x2fe0 fs/fat/namei_vfat.c:677
       vfat_create+0x15f/0x2c0 fs/fat/namei_vfat.c:771
       lookup_open.isra.0+0x1177/0x14c0 fs/namei.c:3649
       open_last_lookups fs/namei.c:3748 [inline]
       path_openat+0x904/0x2d60 fs/namei.c:3984
       do_filp_open+0x20c/0x470 fs/namei.c:4014
       do_sys_openat2+0x17a/0x1e0 fs/open.c:1402
       do_sys_open fs/open.c:1417 [inline]
       __do_sys_openat fs/open.c:1433 [inline]
       __se_sys_openat fs/open.c:1428 [inline]
       __x64_sys_openat+0x175/0x210 fs/open.c:1428
       do_syscall_x64 arch/x86/entry/common.c:52 [inline]
       do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #1 (&sbi->fat_lock){+.+.}-{4:4}:
       __mutex_lock_common kernel/locking/mutex.c:585 [inline]
       __mutex_lock+0x19b/0xa60 kernel/locking/mutex.c:735
       lock_fat fs/fat/fatent.c:281 [inline]
       fat_alloc_clusters+0x1b9/0xf80 fs/fat/fatent.c:477
       fat_add_cluster+0x79/0x100 fs/fat/inode.c:107
       __fat_get_block fs/fat/inode.c:154 [inline]
       fat_get_block+0x38e/0xaf0 fs/fat/inode.c:189
       __block_write_begin_int+0x4fe/0x16e0 fs/buffer.c:2116
       block_write_begin+0x9a/0x1d0 fs/buffer.c:2226
       cont_write_begin+0x61d/0x950 fs/buffer.c:2577
       fat_write_begin+0x66/0x150 fs/fat/inode.c:228
       generic_perform_write+0x2bd/0x920 mm/filemap.c:4055
       __generic_file_write_iter+0x1f7/0x240 mm/filemap.c:4156
       generic_file_write_iter+0xe1/0x340 mm/filemap.c:4182
       new_sync_write fs/read_write.c:586 [inline]
       vfs_write+0x5b1/0x1150 fs/read_write.c:679
       ksys_write+0x12b/0x250 fs/read_write.c:731
       do_syscall_x64 arch/x86/entry/common.c:52 [inline]
       do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #0 (&sb->s_type->i_mutex_key#24){++++}-{4:4}:
       check_prev_add kernel/locking/lockdep.c:3161 [inline]
       check_prevs_add kernel/locking/lockdep.c:3280 [inline]
       validate_chain kernel/locking/lockdep.c:3904 [inline]
       __lock_acquire+0x249e/0x3c40 kernel/locking/lockdep.c:5226
       lock_acquire.part.0+0x11b/0x380 kernel/locking/lockdep.c:5849
       down_write+0x93/0x200 kernel/locking/rwsem.c:1577
       inode_lock include/linux/fs.h:818 [inline]
       __generic_file_fsync+0xb0/0x1f0 fs/libfs.c:1536
       fat_file_fsync+0x70/0x210 fs/fat/file.c:191
       vfs_fsync_range fs/sync.c:187 [inline]
       vfs_fsync+0x12d/0x1f0 fs/sync.c:201
       __loop_update_dio+0x182/0x570 drivers/block/loop.c:204
       loop_set_status+0x2a4/0x700 drivers/block/loop.c:1289
       loop_set_status64 drivers/block/loop.c:1398 [inline]
       lo_ioctl+0x6ec/0x18b0 drivers/block/loop.c:1548
       blkdev_ioctl+0x279/0x6d0 block/ioctl.c:693
       vfs_ioctl fs/ioctl.c:51 [inline]
       __do_sys_ioctl fs/ioctl.c:906 [inline]
       __se_sys_ioctl fs/ioctl.c:892 [inline]
       __x64_sys_ioctl+0x193/0x200 fs/ioctl.c:892
       do_syscall_x64 arch/x86/entry/common.c:52 [inline]
       do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

other info that might help us debug this:

Chain exists of:
  &sb->s_type->i_mutex_key#24 --> &sbi->fat_lock --> &q->q_usage_counter(io)#17

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&q->q_usage_counter(io)#17);
                               lock(&sbi->fat_lock);
                               lock(&q->q_usage_counter(io)#17);
  lock(&sb->s_type->i_mutex_key#24);

 *** DEADLOCK ***

3 locks held by syz.3.565/7542:
 #0: ffff8880256acb60 (&lo->lo_mutex){+.+.}-{4:4}, at: loop_set_status+0x2a/0x700 drivers/block/loop.c:1251
 #1: ffff8880259e9e00 (&q->q_usage_counter(io)#17){++++}-{0:0}, at: loop_set_status+0x1d9/0x700 drivers/block/loop.c:1267
 #2: ffff8880259e9e38 (&q->q_usage_counter(queue)){+.+.}-{0:0}, at: loop_set_status+0x1d9/0x700 drivers/block/loop.c:1267

stack backtrace:
CPU: 1 UID: 0 PID: 7542 Comm: syz.3.565 Not tainted 6.12.0-syzkaller-11930-g0e287d31b62b #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+0x116/0x1f0 lib/dump_stack.c:120
 print_circular_bug+0x419/0x5d0 kernel/locking/lockdep.c:2074
 check_noncircular+0x31a/0x400 kernel/locking/lockdep.c:2206
 check_prev_add kernel/locking/lockdep.c:3161 [inline]
 check_prevs_add kernel/locking/lockdep.c:3280 [inline]
 validate_chain kernel/locking/lockdep.c:3904 [inline]
 __lock_acquire+0x249e/0x3c40 kernel/locking/lockdep.c:5226
 lock_acquire.part.0+0x11b/0x380 kernel/locking/lockdep.c:5849
 down_write+0x93/0x200 kernel/locking/rwsem.c:1577
 inode_lock include/linux/fs.h:818 [inline]
 __generic_file_fsync+0xb0/0x1f0 fs/libfs.c:1536
 fat_file_fsync+0x70/0x210 fs/fat/file.c:191
 vfs_fsync_range fs/sync.c:187 [inline]
 vfs_fsync+0x12d/0x1f0 fs/sync.c:201
 __loop_update_dio+0x182/0x570 drivers/block/loop.c:204
 loop_set_status+0x2a4/0x700 drivers/block/loop.c:1289
 loop_set_status64 drivers/block/loop.c:1398 [inline]
 lo_ioctl+0x6ec/0x18b0 drivers/block/loop.c:1548
 blkdev_ioctl+0x279/0x6d0 block/ioctl.c:693
 vfs_ioctl fs/ioctl.c:51 [inline]
 __do_sys_ioctl fs/ioctl.c:906 [inline]
 __se_sys_ioctl fs/ioctl.c:892 [inline]
 __x64_sys_ioctl+0x193/0x200 fs/ioctl.c:892
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f0e45980849
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:00007f0e466d7058 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 00007f0e45b45fa0 RCX: 00007f0e45980849
RDX: 0000000020001300 RSI: 0000000000004c04 RDI: 0000000000000004
RBP: 00007f0e459f3986 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 0000000000000000 R14: 00007f0e45b45fa0 R15: 00007ffee3dbe258
 </TASK>

Crashes (2):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2024/12/01 00:06 upstream 0e287d31b62b 68914665 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-badwrites-root possible deadlock in __generic_file_fsync
2024/10/30 19:49 linux-next 86e3904dcdc7 66aeb999 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in __generic_file_fsync
* Struck through repros no longer work on HEAD.