[v5.15] possible deadlock in ext4_writepages

0 views
Skip to first unread message

syzbot

unread,
May 2, 2023, 1:20:40 PM5/2/23
to syzkaller...@googlegroups.com
Hello,

syzbot found the following issue on:

HEAD commit: 8a7f2a5c5aa1 Linux 5.15.110
git tree: linux-5.15.y
console output: https://syzkaller.appspot.com/x/log.txt?x=15ec5330280000
kernel config: https://syzkaller.appspot.com/x/.config?x=ba8d5c9d6c5289f
dashboard link: https://syzkaller.appspot.com/bug?extid=fd1ac060cdca3c56e759
compiler: Debian clang version 15.0.7, GNU ld (GNU Binutils for Debian) 2.35.2

Unfortunately, I don't have any reproducer for this issue yet.

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/fc04f54c047f/disk-8a7f2a5c.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/6b4ba4cb1191/vmlinux-8a7f2a5c.xz
kernel image: https://storage.googleapis.com/syzbot-assets/d927dc3f9670/bzImage-8a7f2a5c.xz

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

======================================================
WARNING: possible circular locking dependency detected
5.15.110-syzkaller #0 Not tainted
------------------------------------------------------
syz-executor.5/25533 is trying to acquire lock:
ffff888024b8ebd8 (&sbi->s_writepages_rwsem){++++}-{0:0}, at: ext4_writepages+0x1f6/0x3d10 fs/ext4/inode.c:2687

but task is already holding lock:
ffff8880314fe940 (mapping.invalidate_lock){++++}-{3:3}, at: filemap_invalidate_lock include/linux/fs.h:832 [inline]
ffff8880314fe940 (mapping.invalidate_lock){++++}-{3:3}, at: ext4_collapse_range fs/ext4/extents.c:5335 [inline]
ffff8880314fe940 (mapping.invalidate_lock){++++}-{3:3}, at: ext4_fallocate+0xe77/0x2140 fs/ext4/extents.c:4718

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #6 (mapping.invalidate_lock){++++}-{3:3}:
lock_acquire+0x1db/0x4f0 kernel/locking/lockdep.c:5622
down_read+0x3b/0x50 kernel/locking/rwsem.c:1488
filemap_invalidate_lock_shared include/linux/fs.h:842 [inline]
ext4_page_mkwrite+0x1df/0x1290 fs/ext4/inode.c:6101
do_page_mkwrite+0x1a9/0x440 mm/memory.c:2883
wp_page_shared+0x179/0x690 mm/memory.c:3216
handle_pte_fault mm/memory.c:4626 [inline]
__handle_mm_fault mm/memory.c:4743 [inline]
handle_mm_fault+0x2a3d/0x5950 mm/memory.c:4841
do_user_addr_fault arch/x86/mm/fault.c:1397 [inline]
handle_page_fault arch/x86/mm/fault.c:1485 [inline]
exc_page_fault+0x271/0x740 arch/x86/mm/fault.c:1541
asm_exc_page_fault+0x22/0x30 arch/x86/include/asm/idtentry.h:568

-> #5 (sb_pagefaults#2){.+.+}-{0:0}:
lock_acquire+0x1db/0x4f0 kernel/locking/lockdep.c:5622
percpu_down_read+0x46/0x1b0 include/linux/percpu-rwsem.h:51
__sb_start_write include/linux/fs.h:1742 [inline]
sb_start_pagefault include/linux/fs.h:1841 [inline]
ext4_page_mkwrite+0x1b5/0x1290 fs/ext4/inode.c:6098
do_page_mkwrite+0x1a9/0x440 mm/memory.c:2883
wp_page_shared+0x179/0x690 mm/memory.c:3216
handle_pte_fault mm/memory.c:4626 [inline]
__handle_mm_fault mm/memory.c:4743 [inline]
handle_mm_fault+0x2a3d/0x5950 mm/memory.c:4841
do_user_addr_fault arch/x86/mm/fault.c:1397 [inline]
handle_page_fault arch/x86/mm/fault.c:1485 [inline]
exc_page_fault+0x271/0x740 arch/x86/mm/fault.c:1541
asm_exc_page_fault+0x22/0x30 arch/x86/include/asm/idtentry.h:568

-> #4 (&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

-> #3 (&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

-> #2 ((crypto_chain).rwsem){++++}-{3:3}:
lock_acquire+0x1db/0x4f0 kernel/locking/lockdep.c:5622
down_read+0x3b/0x50 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_prepare_new_inode+0x208/0x2f0 fs/crypto/keysetup.c:698
__ext4_new_inode+0x86b/0x4390 fs/ext4/ialloc.c:988
ext4_create+0x275/0x550 fs/ext4/namei.c:2808
lookup_open fs/namei.c:3392 [inline]
open_last_lookups fs/namei.c:3462 [inline]
path_openat+0x12f6/0x2f20 fs/namei.c:3669
do_filp_open+0x21c/0x460 fs/namei.c:3699
do_sys_openat2+0x13b/0x500 fs/open.c:1211
do_sys_open fs/open.c:1227 [inline]
__do_sys_openat fs/open.c:1243 [inline]
__se_sys_openat fs/open.c:1238 [inline]
__x64_sys_openat+0x243/0x290 fs/open.c:1238
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 (&mk->mk_sem){.+.+}-{3:3}:
lock_acquire+0x1db/0x4f0 kernel/locking/lockdep.c:5622
down_read+0x3b/0x50 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_prepare_new_inode+0x208/0x2f0 fs/crypto/keysetup.c:698
__ext4_new_inode+0x86b/0x4390 fs/ext4/ialloc.c:988
ext4_ext_migrate+0x679/0x12f0 fs/ext4/migrate.c:456
ext4_ioctl_setflags fs/ext4/ioctl.c:455 [inline]
ext4_fileattr_set+0xf80/0x17d0 fs/ext4/ioctl.c:763
vfs_fileattr_set+0x8f3/0xd30 fs/ioctl.c:700
ioctl_setflags fs/ioctl.c:732 [inline]
do_vfs_ioctl+0x1d85/0x2b70 fs/ioctl.c:843
__do_sys_ioctl fs/ioctl.c:872 [inline]
__se_sys_ioctl+0x81/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

-> #0 (&sbi->s_writepages_rwsem){++++}-{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+0x46/0x1b0 include/linux/percpu-rwsem.h:51
ext4_writepages+0x1f6/0x3d10 fs/ext4/inode.c:2687
do_writepages+0x481/0x730 mm/page-writeback.c:2364
filemap_fdatawrite_wbc+0x1d6/0x230 mm/filemap.c:400
__filemap_fdatawrite_range mm/filemap.c:433 [inline]
filemap_write_and_wait_range+0x19e/0x280 mm/filemap.c:704
ext4_collapse_range fs/ext4/extents.c:5350 [inline]
ext4_fallocate+0xee2/0x2140 fs/ext4/extents.c:4718
vfs_fallocate+0x54a/0x6b0 fs/open.c:308
ksys_fallocate fs/open.c:331 [inline]
__do_sys_fallocate fs/open.c:339 [inline]
__se_sys_fallocate fs/open.c:337 [inline]
__x64_sys_fallocate+0xb9/0x100 fs/open.c:337
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:
&sbi->s_writepages_rwsem --> sb_pagefaults#2 --> mapping.invalidate_lock

Possible unsafe locking scenario:

CPU0 CPU1
---- ----
lock(mapping.invalidate_lock);
lock(sb_pagefaults#2);
lock(mapping.invalidate_lock);
lock(&sbi->s_writepages_rwsem);

*** DEADLOCK ***

3 locks held by syz-executor.5/25533:
#0: ffff888024b8c460 (sb_writers#5){.+.+}-{0:0}, at: file_start_write include/linux/fs.h:2966 [inline]
#0: ffff888024b8c460 (sb_writers#5){.+.+}-{0:0}, at: vfs_fallocate+0x4bd/0x6b0 fs/open.c:307
#1: ffff8880314fe7a0 (&sb->s_type->i_mutex_key#9){++++}-{3:3}, at: inode_lock include/linux/fs.h:787 [inline]
#1: ffff8880314fe7a0 (&sb->s_type->i_mutex_key#9){++++}-{3:3}, at: ext4_collapse_range fs/ext4/extents.c:5308 [inline]
#1: ffff8880314fe7a0 (&sb->s_type->i_mutex_key#9){++++}-{3:3}, at: ext4_fallocate+0x991/0x2140 fs/ext4/extents.c:4718
#2: ffff8880314fe940 (mapping.invalidate_lock){++++}-{3:3}, at: filemap_invalidate_lock include/linux/fs.h:832 [inline]
#2: ffff8880314fe940 (mapping.invalidate_lock){++++}-{3:3}, at: ext4_collapse_range fs/ext4/extents.c:5335 [inline]
#2: ffff8880314fe940 (mapping.invalidate_lock){++++}-{3:3}, at: ext4_fallocate+0xe77/0x2140 fs/ext4/extents.c:4718

stack backtrace:
CPU: 1 PID: 25533 Comm: syz-executor.5 Not tainted 5.15.110-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 04/14/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+0x46/0x1b0 include/linux/percpu-rwsem.h:51
ext4_writepages+0x1f6/0x3d10 fs/ext4/inode.c:2687
do_writepages+0x481/0x730 mm/page-writeback.c:2364
filemap_fdatawrite_wbc+0x1d6/0x230 mm/filemap.c:400
__filemap_fdatawrite_range mm/filemap.c:433 [inline]
filemap_write_and_wait_range+0x19e/0x280 mm/filemap.c:704
ext4_collapse_range fs/ext4/extents.c:5350 [inline]
ext4_fallocate+0xee2/0x2140 fs/ext4/extents.c:4718
vfs_fallocate+0x54a/0x6b0 fs/open.c:308
ksys_fallocate fs/open.c:331 [inline]
__do_sys_fallocate fs/open.c:339 [inline]
__se_sys_fallocate fs/open.c:337 [inline]
__x64_sys_fallocate+0xb9/0x100 fs/open.c:337
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:0x7f6e14897169
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:00007f6e12da6168 EFLAGS: 00000246 ORIG_RAX: 000000000000011d
RAX: ffffffffffffffda RBX: 00007f6e149b71f0 RCX: 00007f6e14897169
RDX: 0000000000000000 RSI: 0000000000000008 RDI: 0000000000000007
RBP: 00007f6e148f2ca1 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000008000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007ffe4a4c545f R14: 00007f6e12da6300 R15: 0000000000022000
</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 bug is already fixed, let syzbot know by replying with:
#syz fix: exact-commit-title

If you want to change bug's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)

If the bug is a duplicate of another bug, reply with:
#syz dup: exact-subject-of-another-report

If you want to undo deduplication, reply with:
#syz undup

syzbot

unread,
Aug 23, 2023, 5:09:34 AM8/23/23
to syzkaller...@googlegroups.com
Auto-closing this bug as obsolete.
Crashes did not happen for a while, no reproducer and no activity.
Reply all
Reply to author
Forward
0 new messages