possible deadlock in shmem_fallocate

12 views
Skip to first unread message

syzbot

unread,
Apr 10, 2019, 8:00:14 PM4/10/19
to syzkaller-a...@googlegroups.com
Hello,

syzbot found the following crash on:

HEAD commit: 47350a9f ANDROID: x86_64_cuttlefish_defconfig: Enable lz4 ..
git tree: android-4.14
console output: https://syzkaller.appspot.com/x/log.txt?x=11ccd801400000
kernel config: https://syzkaller.appspot.com/x/.config?x=10d236078f3378a3
dashboard link: https://syzkaller.appspot.com/bug?extid=ac021b56d1e4404041c2
compiler: gcc (GCC) 8.0.1 20180413 (experimental)
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=17185151400000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=142dfe0a400000

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

random: sshd: uninitialized urandom read (32 bytes read)
random: sshd: uninitialized urandom read (32 bytes read)
random: sshd: uninitialized urandom read (32 bytes read)

======================================================
WARNING: possible circular locking dependency detected
4.14.67+ #1 Not tainted
------------------------------------------------------
syz-executor947/1975 is trying to acquire lock:
(&sb->s_type->i_mutex_key#11){++++}, at: [<ffffffffb688a759>] inode_lock
include/linux/fs.h:713 [inline]
(&sb->s_type->i_mutex_key#11){++++}, at: [<ffffffffb688a759>]
shmem_fallocate+0x149/0xb20 mm/shmem.c:2850

but task is already holding lock:
(ashmem_mutex){+.+.}, at: [<ffffffffb75ec9b2>]
ashmem_shrink_scan+0x52/0x4e0 drivers/staging/android/ashmem.c:440

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #2 (ashmem_mutex){+.+.}:
__mutex_lock_common kernel/locking/mutex.c:756 [inline]
__mutex_lock+0xf5/0x1480 kernel/locking/mutex.c:893
ashmem_mmap+0x4c/0x3b0 drivers/staging/android/ashmem.c:369
call_mmap include/linux/fs.h:1787 [inline]
mmap_region+0x836/0xfb0 mm/mmap.c:1731
do_mmap+0x551/0xb80 mm/mmap.c:1509
do_mmap_pgoff include/linux/mm.h:2167 [inline]
vm_mmap_pgoff+0x180/0x1d0 mm/util.c:333
SYSC_mmap_pgoff mm/mmap.c:1559 [inline]
SyS_mmap_pgoff+0xf8/0x1a0 mm/mmap.c:1517
do_syscall_64+0x19b/0x4b0 arch/x86/entry/common.c:289
entry_SYSCALL_64_after_hwframe+0x42/0xb7

-> #1 (&mm->mmap_sem){++++}:
__might_fault+0x137/0x1b0 mm/memory.c:4519
_copy_to_user+0x27/0xc0 lib/usercopy.c:25
copy_to_user include/linux/uaccess.h:155 [inline]
filldir+0x192/0x340 fs/readdir.c:197
dir_emit_dot include/linux/fs.h:3380 [inline]
dir_emit_dots include/linux/fs.h:3391 [inline]
dcache_readdir+0x12f/0x5d0 fs/libfs.c:192
iterate_dir+0x19f/0x5e0 fs/readdir.c:52
SYSC_getdents fs/readdir.c:232 [inline]
SyS_getdents+0x146/0x270 fs/readdir.c:213
do_syscall_64+0x19b/0x4b0 arch/x86/entry/common.c:289
entry_SYSCALL_64_after_hwframe+0x42/0xb7

-> #0 (&sb->s_type->i_mutex_key#11){++++}:
lock_acquire+0x10f/0x380 kernel/locking/lockdep.c:3991
down_write+0x34/0x90 kernel/locking/rwsem.c:54
inode_lock include/linux/fs.h:713 [inline]
shmem_fallocate+0x149/0xb20 mm/shmem.c:2850
ashmem_shrink_scan+0x1b6/0x4e0 drivers/staging/android/ashmem.c:447
ashmem_ioctl+0x2cc/0xe20 drivers/staging/android/ashmem.c:789
vfs_ioctl fs/ioctl.c:46 [inline]
file_ioctl fs/ioctl.c:500 [inline]
do_vfs_ioctl+0x1a0/0x1030 fs/ioctl.c:684
SYSC_ioctl fs/ioctl.c:701 [inline]
SyS_ioctl+0x7e/0xb0 fs/ioctl.c:692
do_syscall_64+0x19b/0x4b0 arch/x86/entry/common.c:289
entry_SYSCALL_64_after_hwframe+0x42/0xb7

other info that might help us debug this:

Chain exists of:
&sb->s_type->i_mutex_key#11 --> &mm->mmap_sem --> ashmem_mutex

Possible unsafe locking scenario:

CPU0 CPU1
---- ----
lock(ashmem_mutex);
lock(&mm->mmap_sem);
lock(ashmem_mutex);
lock(&sb->s_type->i_mutex_key#11);

*** DEADLOCK ***

1 lock held by syz-executor947/1975:
#0: (ashmem_mutex){+.+.}, at: [<ffffffffb75ec9b2>]
ashmem_shrink_scan+0x52/0x4e0 drivers/staging/android/ashmem.c:440

stack backtrace:
CPU: 0 PID: 1975 Comm: syz-executor947 Not tainted 4.14.67+ #1
Call Trace:
__dump_stack lib/dump_stack.c:17 [inline]
dump_stack+0xb9/0x11b lib/dump_stack.c:53
print_circular_bug.isra.18.cold.43+0x2d3/0x40c
kernel/locking/lockdep.c:1258
check_prev_add kernel/locking/lockdep.c:1901 [inline]
check_prevs_add kernel/locking/lockdep.c:2018 [inline]
validate_chain kernel/locking/lockdep.c:2460 [inline]
__lock_acquire+0x2ff9/0x4320 kernel/locking/lockdep.c:3487
lock_acquire+0x10f/0x380 kernel/locking/lockdep.c:3991
down_write+0x34/0x90 kernel/locking/rwsem.c:54
inode_lock include/linux/fs.h:713 [inline]
shmem_fallocate+0x149/0xb20 mm/shmem.c:2850
ashmem_shrink_scan+0x1b6/0x4e0 drivers/staging/android/ashmem.c:447
ashmem_ioctl+0x2cc/0xe20 drivers/staging/android/ashmem.c:789
vfs_ioctl fs/ioctl.c:46 [inline]
file_ioctl fs/ioctl.c:500 [inline]
do_vfs_ioctl+0x1a0/0x1030 fs/ioctl.c:684
SYSC_ioctl fs/ioctl.c:701 [inline]
SyS_ioctl+0x7e/0xb0 fs/ioctl.c:692
do_syscall_64+0x19b/0x4b0 arch/x86/entry/common.c:289
entry_SYSCALL_64_after_hwframe+0


---
This bug 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 bug report. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
syzbot can test patches for this bug, for details see:
https://goo.gl/tpsmEJ#testing-patches

syzbot

unread,
Apr 11, 2019, 4:44:28 AM4/11/19
to syzkaller-a...@googlegroups.com
Hello,

syzbot found the following crash on:

HEAD commit: 71fce1ed UPSTREAM: tracing: always define trace_{irq,preem..
git tree: android-4.9
console output: https://syzkaller.appspot.com/x/log.txt?x=10ddf247800000
kernel config: https://syzkaller.appspot.com/x/.config?x=a54f56879744de40
dashboard link: https://syzkaller.appspot.com/bug?extid=9fce278e78218b0d5799
compiler: gcc (GCC) 8.0.1 20180413 (experimental)
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=14fa7a47800000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=15223a57800000

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

random: sshd: uninitialized urandom read (32 bytes read)
random: sshd: uninitialized urandom read (32 bytes read)
random: sshd: uninitialized urandom read (32 bytes read)

======================================================
[ INFO: possible circular locking dependency detected ]
4.9.96-g71fce1e #10 Not tainted
-------------------------------------------------------
syz-executor627/3802 is trying to acquire lock:
(&sb->s_type->i_mutex_key#10){++++++}, at: [<ffffffff8149174c>] inode_lock
include/linux/fs.h:766 [inline]
(&sb->s_type->i_mutex_key#10){++++++}, at: [<ffffffff8149174c>]
shmem_fallocate+0x13c/0xb40 mm/shmem.c:2674
but task is already holding lock:
(ashmem_mutex){+.+.+.}, at: [<ffffffff82e3ad75>]
ashmem_shrink_scan+0x55/0x3a0 drivers/staging/android/ashmem.c:449
which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

lock_acquire+0x130/0x3e0 kernel/locking/lockdep.c:3756
__mutex_lock_common kernel/locking/mutex.c:521 [inline]
mutex_lock_nested+0xc0/0x870 kernel/locking/mutex.c:621
ashmem_mmap+0x53/0x3f0 drivers/staging/android/ashmem.c:378
mmap_region+0x893/0x1040 mm/mmap.c:1694
do_mmap+0x4fa/0xc30 mm/mmap.c:1473
do_mmap_pgoff include/linux/mm.h:2032 [inline]
vm_mmap_pgoff+0x168/0x1b0 mm/util.c:329
SYSC_mmap_pgoff mm/mmap.c:1523 [inline]
SyS_mmap_pgoff+0x342/0x550 mm/mmap.c:1481
SYSC_mmap arch/x86/kernel/sys_x86_64.c:96 [inline]
SyS_mmap+0x16/0x20 arch/x86/kernel/sys_x86_64.c:87
do_syscall_64+0x1a6/0x490 arch/x86/entry/common.c:282
entry_SYSCALL_64_after_swapgs+0x5d/0xdb

lock_acquire+0x130/0x3e0 kernel/locking/lockdep.c:3756
__might_fault+0x14a/0x1d0 mm/memory.c:4014
copy_to_user arch/x86/include/asm/uaccess.h:727 [inline]
filldir+0x1a4/0x370 fs/readdir.c:195
dir_emit_dot include/linux/fs.h:3241 [inline]
dir_emit_dots include/linux/fs.h:3252 [inline]
dcache_readdir+0x130/0x5d0 fs/libfs.c:191
iterate_dir+0x1ac/0x600 fs/readdir.c:50
SYSC_getdents fs/readdir.c:230 [inline]
SyS_getdents+0x13c/0x2a0 fs/readdir.c:211
do_syscall_64+0x1a6/0x490 arch/x86/entry/common.c:282
entry_SYSCALL_64_after_swapgs+0x5d/0xdb

check_prev_add kernel/locking/lockdep.c:1828 [inline]
check_prevs_add kernel/locking/lockdep.c:1938 [inline]
validate_chain kernel/locking/lockdep.c:2265 [inline]
__lock_acquire+0x3019/0x4070 kernel/locking/lockdep.c:3345
lock_acquire+0x130/0x3e0 kernel/locking/lockdep.c:3756
down_write+0x41/0xa0 kernel/locking/rwsem.c:52
inode_lock include/linux/fs.h:766 [inline]
shmem_fallocate+0x13c/0xb40 mm/shmem.c:2674
ashmem_shrink_scan+0x1bd/0x3a0 drivers/staging/android/ashmem.c:456
ashmem_ioctl+0x2c1/0xf20 drivers/staging/android/ashmem.c:798
vfs_ioctl fs/ioctl.c:43 [inline]
file_ioctl fs/ioctl.c:493 [inline]
do_vfs_ioctl+0x1ac/0x11a0 fs/ioctl.c:677
SYSC_ioctl fs/ioctl.c:694 [inline]
SyS_ioctl+0x8f/0xc0 fs/ioctl.c:685
do_syscall_64+0x1a6/0x490 arch/x86/entry/common.c:282
entry_SYSCALL_64_after_swapgs+0x5d/0xdb

other info that might help us debug this:

Chain exists of:
Possible unsafe locking scenario:

CPU0 CPU1
---- ----
lock(ashmem_mutex);
lock(&mm->mmap_sem);
lock(ashmem_mutex);
lock(&sb->s_type->i_mutex_key#10);

*** DEADLOCK ***

1 lock held by syz-executor627/3802:
#0: (ashmem_mutex){+.+.+.}, at: [<ffffffff82e3ad75>]
ashmem_shrink_scan+0x55/0x3a0 drivers/staging/android/ashmem.c:449

stack backtrace:
CPU: 1 PID: 3802 Comm: syz-executor627 Not tainted 4.9.96-g71fce1e #10
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
Google 01/01/2011
ffff8801d94ff638 ffffffff81eb0b69 ffffffff853d0a10 ffffffff853eee60
ffffffff853d8030 ffff8801b7fe88e8 ffff8801b7fe8000 ffff8801d94ff680
ffffffff814242fd 0000000000000001 00000000b7fe8000 0000000000000001
Call Trace:
[<ffffffff81eb0b69>] __dump_stack lib/dump_stack.c:15 [inline]
[<ffffffff81eb0b69>] dump_stack+0xc1/0x128 lib/dump_stack.c:51
[<ffffffff814242fd>] print_circular_bug.cold.51+0x1bd/0x27d
kernel/locking/lockdep.c:1202
[<ffffffff81237399>] check_prev_add kernel/locking/lockdep.c:1828 [inline]
[<ffffffff81237399>] check_prevs_add kernel/locking/lockdep.c:1938 [inline]
[<ffffffff81237399>] validate_chain kernel/locking/lockdep.c:2265 [inline]
[<ffffffff81237399>] __lock_acquire+0x3019/0x4070
kernel/locking/lockdep.c:3345
[<ffffffff81238e60>] lock_acquire+0x130/0x3e0 kernel/locking/lockdep.c:3756
[<ffffffff839ece01>] down_write+0x41/0xa0 kernel/locking/rwsem.c:52
[<ffffffff8149174c>] inode_lock include/linux/fs.h:766 [inline]
[<ffffffff8149174c>] shmem_fallocate+0x13c/0xb40 mm/shmem.c:2674
[<ffffffff82e3aedd>] ashmem_shrink_scan+0x1bd/0x3a0
drivers/staging/android/ashmem.c:456
[<ffffffff82e3b5b1>] ashmem_ioctl+0x2c1/0xf20
drivers/staging/android/ashmem.c:798
[<ffffffff815b051c>] vfs_ioctl fs/ioctl.c:43 [inline]
[<ffffffff815b051c>] file_ioctl fs/ioctl.c:493 [inline]
[<ffffffff815b051c>] do_vfs_ioctl+0x1ac/0x11a0 fs/ioctl.c:677
[<ffffffff815b159f>] SYSC_ioctl fs/ioctl.c:694 [inline]
[<ffffffff815b159f>] SyS_ioctl+0x8f/0xc0 fs/ioctl.c:685
[<ffffffff81006316>] do_syscall_64+0x1a6/0x490 arch/x86/entry/common.c:282
[<ffffffff839f3313>] entry_SYSCALL_64_after_swapgs+0x5d/0xdb
random: crng init done
Reply all
Reply to author
Forward
0 new messages