possible deadlock in __do_page_fault

12 views
Skip to first unread message

syzbot

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

syzbot found the following crash on:

HEAD commit: 84ae3e35 Merge 4.14.73 into android-4.14
git tree: android-4.14
console output: https://syzkaller.appspot.com/x/log.txt?x=155b2181400000
kernel config: https://syzkaller.appspot.com/x/.config?x=9b3b342f97278cde
dashboard link: https://syzkaller.appspot.com/bug?extid=1fcc2f925ec16114fcaa
compiler: gcc (GCC) 8.0.1 20180413 (experimental)
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=11d7c4e6400000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=13b9f831400000

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

audit: type=1400 audit(1538373538.828:8): avc: denied { map } for
pid=1781 comm="syz-executor279" path="/dev/ashmem" dev="devtmpfs" ino=1083
scontext=unconfined_u:system_r:insmod_t:s0-s0:c0.c1023
tcontext=system_u:object_r:device_t:s0 tclass=chr_file permissive=1

======================================================
WARNING: possible circular locking dependency detected
4.14.73+ #12 Not tainted
------------------------------------------------------
syz-executor279/1804 is trying to acquire lock:
(&mm->mmap_sem){++++}, at: [<ffffffffa2eb4018>]
__do_page_fault+0x868/0xb60 arch/x86/mm/fault.c:1361

but task is already holding lock:
(&sb->s_type->i_mutex_key#10){+.+.}, at: [<ffffffffa322dbe9>] inode_lock
include/linux/fs.h:713 [inline]
(&sb->s_type->i_mutex_key#10){+.+.}, at: [<ffffffffa322dbe9>]
generic_file_write_iter+0x99/0x650 mm/filemap.c:3187

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #2 (&sb->s_type->i_mutex_key#10){+.+.}:
down_write+0x34/0x90 kernel/locking/rwsem.c:54
inode_lock include/linux/fs.h:713 [inline]
shmem_fallocate+0x149/0xb20 mm/shmem.c:2852
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

-> #1 (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

-> #0 (&mm->mmap_sem){++++}:
lock_acquire+0x10f/0x380 kernel/locking/lockdep.c:3991
down_read+0x37/0xa0 kernel/locking/rwsem.c:24
__do_page_fault+0x868/0xb60 arch/x86/mm/fault.c:1361
page_fault+0x22/0x50 arch/x86/entry/entry_64.S:1104
fault_in_pages_readable include/linux/pagemap.h:613 [inline]
iov_iter_fault_in_readable+0x2b9/0x370 lib/iov_iter.c:421
generic_perform_write+0x166/0x430 mm/filemap.c:3027
__generic_file_write_iter+0x345/0x540 mm/filemap.c:3162
generic_file_write_iter+0x36f/0x650 mm/filemap.c:3190
call_write_iter include/linux/fs.h:1782 [inline]
new_sync_write fs/read_write.c:471 [inline]
__vfs_write+0x417/0x5c0 fs/read_write.c:484
vfs_write+0x17f/0x4d0 fs/read_write.c:546
SYSC_write fs/read_write.c:593 [inline]
SyS_write+0xc2/0x1a0 fs/read_write.c:585
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:
&mm->mmap_sem --> ashmem_mutex --> &sb->s_type->i_mutex_key#10

Possible unsafe locking scenario:

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

*** DEADLOCK ***

2 locks held by syz-executor279/1804:
#0: (sb_writers#6){.+.+}, at: [<ffffffffa335bc17>] file_start_write
include/linux/fs.h:2722 [inline]
#0: (sb_writers#6){.+.+}, at: [<ffffffffa335bc17>] vfs_write+0x3d7/0x4d0
fs/read_write.c:545
#1: (&sb->s_type->i_mutex_key#10){+.+.}, at: [<ffffffffa322dbe9>]
inode_lock include/linux/fs.h:713 [inline]
#1: (&sb->s_type->i_mutex_key#10){+.+.}, at: [<ffffffffa322dbe9>]
generic_file_write_iter+0x99/0x650 mm/filemap.c:3187

stack backtrace:
CPU: 0 PID: 1804 Comm: syz-executor279 Not tainted 4.14.73+ #12
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_read+0x37/0xa0 kernel/locking/rwsem.c:24
__do_page_fault+0x868/0xb60 arch/x86/mm/fault.c:1361
page_fault+0x22/0x50 arch/x86/entry/entry_64.S:1104
RIP: 0010:fault_in_pages_readable include/linux/pagemap.h:613 [inline]
RIP: 0010:iov_iter_fault_in_readable+0x2b9/0x370 lib/iov_iter.c:421
RSP: 0018:ffff8801d1ae79f8 EFLAGS: 00010297
RAX: 0000000000000000 RBX: 000000000000007f RCX: 0000000000001000
RDX: 0000000000000000 RSI: 0000000000001000 RDI: ffff8801d1ae7cf8
RBP: 1ffff1003a35cf40 R08: 0000000000001000 R09: ffffea000738f5c0
R10: ffffffffa327e0d0 R11: ffff8801ce3d7fff R12: 0000000000000000
R13: 00000000204b353f R14: 0000000000001000 R15: ffff8801d1ae7cf0
generic_perform_write+0x166/0x430 mm/filemap.c:3027
__generic_file_write_iter+0x345/0x540 mm/filemap.c:3162
generic_file_write_iter+0x36f/0x650 mm/filemap.c:3190
call_write_iter include/linux/fs.h:1782 [inline]
new_sync_write fs/read_write.c:471 [inline]
__vfs_write+0x417/0x5c0 fs/read_write.c:484
vfs_write+0x17f/0x4d0 fs/read_write.c:546
SYSC_write fs/read_write.c:593 [inline]
SyS_write+0xc2/0x1a0 fs/read_write.c:585
do_syscall_64+0x19b/0x4b0 arch/x86/entry/common.c:289
entry_SYSCALL_64_after_hwframe+0x42/0xb7
RIP: 0033:0x446449
RSP: 002b:00007fe17400dda8 EFLAGS: 00000293 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 00000000006dbc28 RCX: 0000000000446449
RDX: 00000000fffffda2 RSI: 0000000020000540 RDI: 0000000000000003
RBP: 00000000006dbc20 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000293 R12: 00000000006dbc2c
R13: dfdd4f11168a8b2b R14: 6873612f7665642f R15: 0000000000000000


---
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:35 AM4/11/19
to syzkaller-a...@googlegroups.com
Hello,

syzbot found the following crash on:

HEAD commit: 1c7637ca Merge 4.9.130 into android-4.9
git tree: android-4.9
console output: https://syzkaller.appspot.com/x/log.txt?x=1599d14e400000
kernel config: https://syzkaller.appspot.com/x/.config?x=61c76ae5917af054
dashboard link: https://syzkaller.appspot.com/bug?extid=fb9dbeca926817d3d7e2
compiler: gcc (GCC) 8.0.1 20180413 (experimental)
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=14324b56400000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=1791f32a400000

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

random: crng init done

======================================================
[ INFO: possible circular locking dependency detected ]
4.9.130+ #46 Not tainted
-------------------------------------------------------
syz-executor792/2073 is trying to acquire lock:
(&mm->mmap_sem){++++++}, at: [<ffffffff810b2cbb>]
__do_page_fault+0x7db/0xa60 arch/x86/mm/fault.c:1342
but task is already holding lock:
(&sb->s_type->i_mutex_key#10){+.+.+.}, at: [<ffffffff8141254d>] inode_lock
include/linux/fs.h:766 [inline]
(&sb->s_type->i_mutex_key#10){+.+.+.}, at: [<ffffffff8141254d>]
generic_file_write_iter+0x9d/0x620 mm/filemap.c:2903
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
down_write+0x41/0xa0 kernel/locking/rwsem.c:52
inode_lock include/linux/fs.h:766 [inline]
shmem_fallocate+0x13c/0xb10 mm/shmem.c:2676
ashmem_shrink_scan+0x1b9/0x4c0 drivers/staging/android/ashmem.c:456
ashmem_ioctl+0x2c3/0xf00 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+0x19f/0x550 arch/x86/entry/common.c:285
entry_SYSCALL_64_after_swapgs+0x5d/0xdb

lock_acquire+0x130/0x3e0 kernel/locking/lockdep.c:3756
__mutex_lock_common kernel/locking/mutex.c:521 [inline]
mutex_lock_nested+0xc0/0x900 kernel/locking/mutex.c:621
ashmem_mmap+0x53/0x3f0 drivers/staging/android/ashmem.c:378
mmap_region+0x80c/0xf90 mm/mmap.c:1726
do_mmap+0x53d/0xbb0 mm/mmap.c:1505
do_mmap_pgoff include/linux/mm.h:2032 [inline]
vm_mmap_pgoff+0x168/0x1b0 mm/util.c:329
SYSC_mmap_pgoff mm/mmap.c:1555 [inline]
SyS_mmap_pgoff+0xfe/0x1b0 mm/mmap.c:1513
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+0x19f/0x550 arch/x86/entry/common.c:285
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+0x3189/0x4a10 kernel/locking/lockdep.c:3345
lock_acquire+0x130/0x3e0 kernel/locking/lockdep.c:3756
down_read+0x44/0xb0 kernel/locking/rwsem.c:22
__do_page_fault+0x7db/0xa60 arch/x86/mm/fault.c:1342
do_page_fault+0x27/0x30 arch/x86/mm/fault.c:1469
page_fault+0x25/0x30 arch/x86/entry/entry_64.S:951
generic_perform_write+0x1c7/0x500 mm/filemap.c:2743
__generic_file_write_iter+0x352/0x540 mm/filemap.c:2878
generic_file_write_iter+0x37a/0x620 mm/filemap.c:2906
new_sync_write fs/read_write.c:496 [inline]
__vfs_write+0x3d7/0x580 fs/read_write.c:509
vfs_write+0x187/0x520 fs/read_write.c:557
SYSC_write fs/read_write.c:604 [inline]
SyS_write+0xd9/0x1c0 fs/read_write.c:596
do_syscall_64+0x19f/0x550 arch/x86/entry/common.c:285
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(&sb->s_type->i_mutex_key#10);
lock(ashmem_mutex);
lock(&sb->s_type->i_mutex_key#10);
lock(&mm->mmap_sem);

*** DEADLOCK ***

2 locks held by syz-executor792/2073:
#0: (sb_writers#6){.+.+.+}, at: [<ffffffff8150ac4b>] file_start_write
include/linux/fs.h:2640 [inline]
#0: (sb_writers#6){.+.+.+}, at: [<ffffffff8150ac4b>]
vfs_write+0x3eb/0x520 fs/read_write.c:556
#1: (&sb->s_type->i_mutex_key#10){+.+.+.}, at: [<ffffffff8141254d>]
inode_lock include/linux/fs.h:766 [inline]
#1: (&sb->s_type->i_mutex_key#10){+.+.+.}, at: [<ffffffff8141254d>]
generic_file_write_iter+0x9d/0x620 mm/filemap.c:2903

stack backtrace:
CPU: 1 PID: 2073 Comm: syz-executor792 Not tainted 4.9.130+ #46
ffff8801ce127548 ffffffff81b36c89 ffffffff83cc2a10 ffffffff83cace70
ffffffff83ca3690 ffff8801ce80b878 ffff8801ce80af80 ffff8801ce127590
ffffffff813fe8a5 0000000000000002 00000000ce80b858 0000000000000002
Call Trace:
[<ffffffff81b36c89>] __dump_stack lib/dump_stack.c:15 [inline]
[<ffffffff81b36c89>] dump_stack+0xc1/0x128 lib/dump_stack.c:51
[<ffffffff813fe8a5>] print_circular_bug.cold.36+0x2f7/0x432
kernel/locking/lockdep.c:1202
[<ffffffff8120a039>] check_prev_add kernel/locking/lockdep.c:1828 [inline]
[<ffffffff8120a039>] check_prevs_add kernel/locking/lockdep.c:1938 [inline]
[<ffffffff8120a039>] validate_chain kernel/locking/lockdep.c:2265 [inline]
[<ffffffff8120a039>] __lock_acquire+0x3189/0x4a10
kernel/locking/lockdep.c:3345
[<ffffffff8120c3d0>] lock_acquire+0x130/0x3e0 kernel/locking/lockdep.c:3756
[<ffffffff827fcdd4>] down_read+0x44/0xb0 kernel/locking/rwsem.c:22
[<ffffffff810b2cbb>] __do_page_fault+0x7db/0xa60 arch/x86/mm/fault.c:1342
[<ffffffff810b2f97>] do_page_fault+0x27/0x30 arch/x86/mm/fault.c:1469
[<ffffffff82804035>] page_fault+0x25/0x30 arch/x86/entry/entry_64.S:951
[<ffffffff8140f2b7>] generic_perform_write+0x1c7/0x500 mm/filemap.c:2743
[<ffffffff814122c2>] __generic_file_write_iter+0x352/0x540
mm/filemap.c:2878
[<ffffffff8141282a>] generic_file_write_iter+0x37a/0x620 mm/filemap.c:2906
[<ffffffff81508197>] new_sync_write fs/read_write.c:496 [inline]
[<ffffffff81508197>] __vfs_write+0x3d7/0x580 fs/read_write.c:509
[<ffffffff8150a9e7>] vfs_write+0x187/0x520 fs/read_write.c:557
[<ffffffff8150e819>] SYSC_write fs/read_write.c:604 [inline]
[<ffffffff8150e819>] SyS_write+0xd9/0x1c0 fs/read_write.c:596
[<ffffffff810056ef>] do_syscall_64+0x19f/0x550 arch/x86/entry/common.c:285
[<ffffffff82803013>] entry_SYSCALL_64_after_swapgs+0x5d/0xdb
Reply all
Reply to author
Forward
0 new messages