[v5.15] possible deadlock in __fat_readdir

0 views
Skip to first unread message

syzbot

unread,
Apr 29, 2024, 11:53:33 AMApr 29
to syzkaller...@googlegroups.com
Hello,

syzbot found the following issue on:

HEAD commit: b925f60c6ee7 Linux 5.15.157
git tree: linux-5.15.y
console output: https://syzkaller.appspot.com/x/log.txt?x=17ab5d5f180000
kernel config: https://syzkaller.appspot.com/x/.config?x=2a1cb0d51cbb9dfb
dashboard link: https://syzkaller.appspot.com/bug?extid=43113a55f9a2c504493e
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/07f51426f82f/disk-b925f60c.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/d41cc73399aa/vmlinux-b925f60c.xz
kernel image: https://storage.googleapis.com/syzbot-assets/0f542c09e64b/bzImage-b925f60c.xz

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+43113a...@syzkaller.appspotmail.com

FAT-fs (loop2): Invalid FSINFO signature: 0x41615252, 0x80417272 (sector = 1)
======================================================
WARNING: possible circular locking dependency detected
5.15.157-syzkaller #0 Not tainted
------------------------------------------------------
syz-executor.2/9868 is trying to acquire lock:
ffff88807d03f128 (&mm->mmap_lock){++++}-{3:3}, at: __might_fault+0x91/0x110 mm/memory.c:5327

but task is already holding lock:
ffff888043c381d0 (&sbi->s_lock#2){+.+.}-{3:3}, at: __fat_readdir+0x1d4/0x1b40 fs/fat/dir.c:571

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #4 (&sbi->s_lock#2){+.+.}-{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
msdos_lookup+0xf9/0x4f0 fs/fat/namei_msdos.c:209
__lookup_slow+0x275/0x3d0 fs/namei.c:1663
lookup_slow+0x53/0x70 fs/namei.c:1680
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
user_path_at_empty+0x40/0x180 fs/namei.c:2883
user_path_at include/linux/namei.h:57 [inline]
__do_sys_chdir fs/open.c:490 [inline]
__se_sys_chdir+0xbb/0x220 fs/open.c:484
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

-> #3 (&sb->s_type->i_mutex_key#26){++++}-{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:1388
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
insert_dev_extents fs/btrfs/block-group.c:2379 [inline]
btrfs_create_pending_block_groups+0x5c1/0x1130 fs/btrfs/block-group.c:2429
__btrfs_end_transaction+0x296/0x780 fs/btrfs/transaction.c:1014
flush_space+0x4cf/0xd50 fs/btrfs/space-info.c:674
btrfs_async_reclaim_data_space+0x118/0x3e0 fs/btrfs/space-info.c:1169
process_one_work+0x8a1/0x10c0 kernel/workqueue.c:2310
worker_thread+0xaca/0x1280 kernel/workqueue.c:2457
kthread+0x3f6/0x4f0 kernel/kthread.c:334
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:300

-> #1 (sb_internal#4){.+.+}-{0:0}:
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:1811 [inline]
sb_start_intwrite include/linux/fs.h:1928 [inline]
start_transaction+0x5a8/0x11a0 fs/btrfs/transaction.c:678
btrfs_dirty_inode+0xcc/0x1c0 fs/btrfs/inode.c:6428
inode_update_time fs/inode.c:1829 [inline]
touch_atime+0x34e/0x680 fs/inode.c:1902
file_accessed include/linux/fs.h:2516 [inline]
btrfs_file_mmap+0xbf/0x120 fs/btrfs/file.c:2424
call_mmap include/linux/fs.h:2177 [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+0x3b/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x66/0xd0

-> #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+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
__might_fault+0xb4/0x110 mm/memory.c:5328
fat_ioctl_filldir+0xd7/0x600 fs/fat/dir.c:759
dir_emit_dot include/linux/fs.h:3678 [inline]
dir_emit_dots include/linux/fs.h:3689 [inline]
__fat_readdir+0x349/0x1b40 fs/fat/dir.c:576
fat_ioctl_readdir fs/fat/dir.c:777 [inline]
fat_dir_ioctl+0x27e/0x3b0 fs/fat/dir.c:815
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

other info that might help us debug this:

Chain exists of:
&mm->mmap_lock --> &sb->s_type->i_mutex_key#26 --> &sbi->s_lock#2

Possible unsafe locking scenario:

CPU0 CPU1
---- ----
lock(&sbi->s_lock#2);
lock(&sb->s_type->i_mutex_key#26);
lock(&sbi->s_lock#2);
lock(&mm->mmap_lock);

*** DEADLOCK ***

2 locks held by syz-executor.2/9868:
#0: ffff88805dd8ae40 (&sb->s_type->i_mutex_key#29){++++}-{3:3}, at: inode_lock_shared include/linux/fs.h:799 [inline]
#0: ffff88805dd8ae40 (&sb->s_type->i_mutex_key#29){++++}-{3:3}, at: fat_ioctl_readdir fs/fat/dir.c:773 [inline]
#0: ffff88805dd8ae40 (&sb->s_type->i_mutex_key#29){++++}-{3:3}, at: fat_dir_ioctl+0x1bd/0x3b0 fs/fat/dir.c:815
#1: ffff888043c381d0 (&sbi->s_lock#2){+.+.}-{3:3}, at: __fat_readdir+0x1d4/0x1b40 fs/fat/dir.c:571

stack backtrace:
CPU: 0 PID: 9868 Comm: syz-executor.2 Not tainted 5.15.157-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 03/27/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
__might_fault+0xb4/0x110 mm/memory.c:5328
fat_ioctl_filldir+0xd7/0x600 fs/fat/dir.c:759
dir_emit_dot include/linux/fs.h:3678 [inline]
dir_emit_dots include/linux/fs.h:3689 [inline]
__fat_readdir+0x349/0x1b40 fs/fat/dir.c:576
fat_ioctl_readdir fs/fat/dir.c:777 [inline]
fat_dir_ioctl+0x27e/0x3b0 fs/fat/dir.c:815
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
RIP: 0033:0x7f6515081ea9
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 e1 20 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 b0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f65135f40c8 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 00007f65151aff80 RCX: 00007f6515081ea9
RDX: 0000000020000ac0 RSI: 0000000082307202 RDI: 0000000000000003
RBP: 00007f65150ce4a4 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 000000000000000b R14: 00007f65151aff80 R15: 00007ffe46693f98
</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 syzk...@googlegroups.com.

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