[v6.1] possible deadlock in filemap_fault (2)

0 views
Skip to first unread message

syzbot

unread,
Dec 22, 2023, 4:26:21 PM12/22/23
to syzkaller...@googlegroups.com
Hello,

syzbot found the following issue on:

HEAD commit: 4aa6747d9352 Linux 6.1.69
git tree: linux-6.1.y
console output: https://syzkaller.appspot.com/x/log.txt?x=1764039ee80000
kernel config: https://syzkaller.appspot.com/x/.config?x=e1e9066810307299
dashboard link: https://syzkaller.appspot.com/bug?extid=b114e607666a3a11a128
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/209330361447/disk-4aa6747d.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/48aa2c86988d/vmlinux-4aa6747d.xz
kernel image: https://storage.googleapis.com/syzbot-assets/84320338eba6/bzImage-4aa6747d.xz

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

loop1: detected capacity change from 0 to 4096
======================================================
WARNING: possible circular locking dependency detected
6.1.69-syzkaller #0 Not tainted
------------------------------------------------------
syz-executor.1/6443 is trying to acquire lock:
ffff888070aefb40 (mapping.invalidate_lock#7){.+.+}-{3:3}, at: filemap_invalidate_lock_shared include/linux/fs.h:811 [inline]
ffff888070aefb40 (mapping.invalidate_lock#7){.+.+}-{3:3}, at: filemap_fault+0x640/0x17e0 mm/filemap.c:3182

but task is already holding lock:
ffff88801246ae58 (&mm->mmap_lock){++++}-{3:3}, at: mmap_read_lock_killable include/linux/mmap_lock.h:126 [inline]
ffff88801246ae58 (&mm->mmap_lock){++++}-{3:3}, at: __get_user_pages_locked mm/gup.c:1488 [inline]
ffff88801246ae58 (&mm->mmap_lock){++++}-{3:3}, at: get_user_pages_unlocked+0x3d7/0x8a0 mm/gup.c:2346

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #2 (&mm->mmap_lock){++++}-{3:3}:
lock_acquire+0x1f8/0x5a0 kernel/locking/lockdep.c:5662
__might_fault+0xbd/0x110 mm/memory.c:5811
_copy_to_user+0x26/0x130 lib/usercopy.c:36
copy_to_user include/linux/uaccess.h:169 [inline]
fiemap_fill_next_extent+0x231/0x410 fs/ioctl.c:144
ni_fiemap+0xa5a/0x1230 fs/ntfs3/frecord.c:2066
ntfs_fiemap+0x12e/0x170 fs/ntfs3/file.c:1245
ioctl_fiemap fs/ioctl.c:219 [inline]
do_vfs_ioctl+0x18e9/0x2a90 fs/ioctl.c:810
__do_sys_ioctl fs/ioctl.c:868 [inline]
__se_sys_ioctl+0x81/0x160 fs/ioctl.c:856
do_syscall_x64 arch/x86/entry/common.c:51 [inline]
do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:81
entry_SYSCALL_64_after_hwframe+0x63/0xcd

-> #1 (&ni->file.run_lock){.+.+}-{3:3}:
lock_acquire+0x1f8/0x5a0 kernel/locking/lockdep.c:5662
down_read+0xad/0xa30 kernel/locking/rwsem.c:1520
attr_data_get_block+0x276/0x2520 fs/ntfs3/attrib.c:903
ntfs_get_block_vbo+0x373/0xe60 fs/ntfs3/inode.c:590
do_mpage_readpage+0x8d2/0x2040 fs/mpage.c:208
mpage_readahead+0x450/0x920 fs/mpage.c:361
read_pages+0x17f/0x830 mm/readahead.c:161
page_cache_ra_unbounded+0x68b/0x7b0 mm/readahead.c:270
page_cache_sync_readahead include/linux/pagemap.h:1215 [inline]
filemap_get_pages mm/filemap.c:2636 [inline]
filemap_read+0x7fa/0x31d0 mm/filemap.c:2730
__kernel_read+0x41e/0x8a0 fs/read_write.c:428
integrity_kernel_read+0xac/0xf0 security/integrity/iint.c:228
ima_calc_file_hash_tfm security/integrity/ima/ima_crypto.c:485 [inline]
ima_calc_file_shash security/integrity/ima/ima_crypto.c:516 [inline]
ima_calc_file_hash+0xa57/0x1c00 security/integrity/ima/ima_crypto.c:573
ima_collect_measurement+0x59a/0xc30 security/integrity/ima/ima_api.c:293
process_measurement+0x135c/0x21b0 security/integrity/ima/ima_main.c:351
ima_file_check+0xed/0x170 security/integrity/ima/ima_main.c:534
do_open fs/namei.c:3560 [inline]
path_openat+0x2687/0x2e60 fs/namei.c:3715
do_filp_open+0x230/0x480 fs/namei.c:3742
do_sys_openat2+0x13b/0x500 fs/open.c:1318
do_sys_open fs/open.c:1334 [inline]
__do_sys_openat fs/open.c:1350 [inline]
__se_sys_openat fs/open.c:1345 [inline]
__x64_sys_openat+0x243/0x290 fs/open.c:1345
do_syscall_x64 arch/x86/entry/common.c:51 [inline]
do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:81
entry_SYSCALL_64_after_hwframe+0x63/0xcd

-> #0 (mapping.invalidate_lock#7){.+.+}-{3:3}:
check_prev_add kernel/locking/lockdep.c:3090 [inline]
check_prevs_add kernel/locking/lockdep.c:3209 [inline]
validate_chain+0x1661/0x5950 kernel/locking/lockdep.c:3825
__lock_acquire+0x125b/0x1f80 kernel/locking/lockdep.c:5049
lock_acquire+0x1f8/0x5a0 kernel/locking/lockdep.c:5662
down_read+0xad/0xa30 kernel/locking/rwsem.c:1520
filemap_invalidate_lock_shared include/linux/fs.h:811 [inline]
filemap_fault+0x640/0x17e0 mm/filemap.c:3182
__do_fault+0x136/0x4f0 mm/memory.c:4241
do_read_fault mm/memory.c:4592 [inline]
do_fault mm/memory.c:4721 [inline]
handle_pte_fault mm/memory.c:4993 [inline]
__handle_mm_fault mm/memory.c:5135 [inline]
handle_mm_fault+0x3412/0x5340 mm/memory.c:5256
faultin_page mm/gup.c:1009 [inline]
__get_user_pages+0x4f3/0x1190 mm/gup.c:1233
__get_user_pages_locked mm/gup.c:1437 [inline]
get_user_pages_unlocked+0x568/0x8a0 mm/gup.c:2346
__gup_longterm_unlocked mm/gup.c:2957 [inline]
internal_get_user_pages_fast+0x291d/0x2e70 mm/gup.c:3047
__iov_iter_get_pages_alloc+0x3b1/0xa70 lib/iov_iter.c:1460
iov_iter_get_pages2+0xcb/0x120 lib/iov_iter.c:1503
dio_refill_pages fs/direct-io.c:172 [inline]
dio_get_page fs/direct-io.c:215 [inline]
do_direct_IO fs/direct-io.c:932 [inline]
__blockdev_direct_IO+0x13d6/0x4810 fs/direct-io.c:1266
blockdev_direct_IO include/linux/fs.h:3273 [inline]
ntfs_direct_IO+0x193/0x360 fs/ntfs3/inode.c:795
generic_file_direct_write+0x204/0x460 mm/filemap.c:3732
__generic_file_write_iter+0x1c4/0x400 mm/filemap.c:3892
ntfs_file_write_iter+0x5fa/0x6d0 fs/ntfs3/file.c:1164
do_iter_write+0x6e6/0xc50 fs/read_write.c:861
vfs_writev fs/read_write.c:934 [inline]
do_pwritev+0x216/0x360 fs/read_write.c:1031
do_syscall_x64 arch/x86/entry/common.c:51 [inline]
do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:81
entry_SYSCALL_64_after_hwframe+0x63/0xcd

other info that might help us debug this:

Chain exists of:
mapping.invalidate_lock#7 --> &ni->file.run_lock --> &mm->mmap_lock

Possible unsafe locking scenario:

CPU0 CPU1
---- ----
lock(&mm->mmap_lock);
lock(&ni->file.run_lock);
lock(&mm->mmap_lock);
lock(mapping.invalidate_lock#7);

*** DEADLOCK ***

3 locks held by syz-executor.1/6443:
#0: ffff888080088460 (sb_writers#21){.+.+}-{0:0}, at: vfs_writev fs/read_write.c:933 [inline]
#0: ffff888080088460 (sb_writers#21){.+.+}-{0:0}, at: do_pwritev+0x1fa/0x360 fs/read_write.c:1031
#1: ffff888070aef9a0 (&sb->s_type->i_mutex_key#30){+.+.}-{3:3}, at: inode_trylock include/linux/fs.h:776 [inline]
#1: ffff888070aef9a0 (&sb->s_type->i_mutex_key#30){+.+.}-{3:3}, at: ntfs_file_write_iter+0x1c7/0x6d0 fs/ntfs3/file.c:1143
#2: ffff88801246ae58 (&mm->mmap_lock){++++}-{3:3}, at: mmap_read_lock_killable include/linux/mmap_lock.h:126 [inline]
#2: ffff88801246ae58 (&mm->mmap_lock){++++}-{3:3}, at: __get_user_pages_locked mm/gup.c:1488 [inline]
#2: ffff88801246ae58 (&mm->mmap_lock){++++}-{3:3}, at: get_user_pages_unlocked+0x3d7/0x8a0 mm/gup.c:2346

stack backtrace:
CPU: 1 PID: 6443 Comm: syz-executor.1 Not tainted 6.1.69-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/17/2023
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0x1e3/0x2cb lib/dump_stack.c:106
check_noncircular+0x2fa/0x3b0 kernel/locking/lockdep.c:2170
check_prev_add kernel/locking/lockdep.c:3090 [inline]
check_prevs_add kernel/locking/lockdep.c:3209 [inline]
validate_chain+0x1661/0x5950 kernel/locking/lockdep.c:3825
__lock_acquire+0x125b/0x1f80 kernel/locking/lockdep.c:5049
lock_acquire+0x1f8/0x5a0 kernel/locking/lockdep.c:5662
down_read+0xad/0xa30 kernel/locking/rwsem.c:1520
filemap_invalidate_lock_shared include/linux/fs.h:811 [inline]
filemap_fault+0x640/0x17e0 mm/filemap.c:3182
__do_fault+0x136/0x4f0 mm/memory.c:4241
do_read_fault mm/memory.c:4592 [inline]
do_fault mm/memory.c:4721 [inline]
handle_pte_fault mm/memory.c:4993 [inline]
__handle_mm_fault mm/memory.c:5135 [inline]
handle_mm_fault+0x3412/0x5340 mm/memory.c:5256
faultin_page mm/gup.c:1009 [inline]
__get_user_pages+0x4f3/0x1190 mm/gup.c:1233
__get_user_pages_locked mm/gup.c:1437 [inline]
get_user_pages_unlocked+0x568/0x8a0 mm/gup.c:2346
__gup_longterm_unlocked mm/gup.c:2957 [inline]
internal_get_user_pages_fast+0x291d/0x2e70 mm/gup.c:3047
__iov_iter_get_pages_alloc+0x3b1/0xa70 lib/iov_iter.c:1460
iov_iter_get_pages2+0xcb/0x120 lib/iov_iter.c:1503
dio_refill_pages fs/direct-io.c:172 [inline]
dio_get_page fs/direct-io.c:215 [inline]
do_direct_IO fs/direct-io.c:932 [inline]
__blockdev_direct_IO+0x13d6/0x4810 fs/direct-io.c:1266
blockdev_direct_IO include/linux/fs.h:3273 [inline]
ntfs_direct_IO+0x193/0x360 fs/ntfs3/inode.c:795
generic_file_direct_write+0x204/0x460 mm/filemap.c:3732
__generic_file_write_iter+0x1c4/0x400 mm/filemap.c:3892
ntfs_file_write_iter+0x5fa/0x6d0 fs/ntfs3/file.c:1164
do_iter_write+0x6e6/0xc50 fs/read_write.c:861
vfs_writev fs/read_write.c:934 [inline]
do_pwritev+0x216/0x360 fs/read_write.c:1031
do_syscall_x64 arch/x86/entry/common.c:51 [inline]
do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:81
entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7fb93aa7cce9
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:00007fb93b7e10c8 EFLAGS: 00000246 ORIG_RAX: 0000000000000148
RAX: ffffffffffffffda RBX: 00007fb93ab9bf80 RCX: 00007fb93aa7cce9
RDX: 0000000000000001 RSI: 0000000020000240 RDI: 0000000000000006
RBP: 00007fb93aac947a R08: 0000000000000000 R09: 0000000000000003
R10: 0000000000028000 R11: 0000000000000246 R12: 0000000000000000
R13: 000000000000000b R14: 00007fb93ab9bf80 R15: 00007ffc62c427b8
</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