======================================================
audit: type=1400 audit(1515561124.711:8): avc:  denied  { map } for  pid=3491 comm="syzkaller858611" path="/dev/ashmem" dev="devtmpfs" ino=1155 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.15.0-rc7+ #255 Not tainted
------------------------------------------------------
syzkaller858611/3491 is trying to acquire lock:
 (&sb->s_type->i_mutex_key#11){++++}, at: [<000000000eab9618>] inode_lock include/linux/fs.h:713 [inline]
 (&sb->s_type->i_mutex_key#11){++++}, at: [<000000000eab9618>] shmem_file_llseek+0xef/0x240 mm/shmem.c:2579

but task is already holding lock:
 (ashmem_mutex){+.+.}, at: [<000000007678cd50>] ashmem_llseek+0x56/0x1f0 drivers/staging/android/ashmem.c:334

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+0x16f/0x1a80 kernel/locking/mutex.c:893
       mutex_lock_nested+0x16/0x20 kernel/locking/mutex.c:908
       ashmem_mmap+0x53/0x410 drivers/staging/android/ashmem.c:370
       call_mmap include/linux/fs.h:1777 [inline]
       mmap_region+0xa99/0x15a0 mm/mmap.c:1705
       do_mmap+0x6c0/0xe00 mm/mmap.c:1483
       do_mmap_pgoff include/linux/mm.h:2217 [inline]
       vm_mmap_pgoff+0x1de/0x280 mm/util.c:333
       SYSC_mmap_pgoff mm/mmap.c:1533 [inline]
       SyS_mmap_pgoff+0x462/0x5f0 mm/mmap.c:1491
       SYSC_mmap arch/x86/kernel/sys_x86_64.c:100 [inline]
       SyS_mmap+0x16/0x20 arch/x86/kernel/sys_x86_64.c:91
       entry_SYSCALL_64_fastpath+0x23/0x9a

-> #1 (&mm->mmap_sem){++++}:
       __might_fault+0x13a/0x1d0 mm/memory.c:4529
       _copy_to_user+0x2c/0xc0 lib/usercopy.c:25
       copy_to_user include/linux/uaccess.h:155 [inline]
       filldir+0x1a7/0x320 fs/readdir.c:196
       dir_emit_dot include/linux/fs.h:3374 [inline]
       dir_emit_dots include/linux/fs.h:3385 [inline]
       dcache_readdir+0x12d/0x5e0 fs/libfs.c:192
       iterate_dir+0x1ca/0x530 fs/readdir.c:51
       SYSC_getdents fs/readdir.c:231 [inline]
       SyS_getdents+0x225/0x450 fs/readdir.c:212
       entry_SYSCALL_64_fastpath+0x23/0x9a

-> #0 (&sb->s_type->i_mutex_key#11){++++}:
       lock_acquire+0x1d5/0x580 kernel/locking/lockdep.c:3914
       down_write+0x87/0x120 kernel/locking/rwsem.c:70
       inode_lock include/linux/fs.h:713 [inline]
       shmem_file_llseek+0xef/0x240 mm/shmem.c:2579
       vfs_llseek+0xa2/0xd0 fs/read_write.c:300
       ashmem_llseek+0xe7/0x1f0 drivers/staging/android/ashmem.c:346
       vfs_llseek fs/read_write.c:300 [inline]
       SYSC_lseek fs/read_write.c:313 [inline]
       SyS_lseek+0xeb/0x170 fs/read_write.c:304
       entry_SYSCALL_64_fastpath+0x23/0x9a

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 syzkaller858611/3491:
 #0:  (ashmem_mutex){+.+.}, at: [<000000007678cd50>] ashmem_llseek+0x56/0x1f0 drivers/staging/android/ashmem.c:334

stack backtrace:
CPU: 1 PID: 3491 Comm: syzkaller858611 Not tainted 4.15.0-rc7+ #255
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
 __dump_stack lib/dump_stack.c:17 [inline]
 dump_stack+0x194/0x257 lib/dump_stack.c:53
 print_circular_bug.isra.37+0x2cd/0x2dc kernel/locking/lockdep.c:1218
 check_prev_add kernel/locking/lockdep.c:1858 [inline]
 check_prevs_add kernel/locking/lockdep.c:1971 [inline]
 validate_chain kernel/locking/lockdep.c:2412 [inline]
 __lock_acquire+0x30a8/0x3e00 kernel/locking/lockdep.c:3426
 lock_acquire+0x1d5/0x580 kernel/locking/lockdep.c:3914
 down_write+0x87/0x120 kernel/locking/rwsem.c:70
 inode_lock include/linux/fs.h:713 [inline]
 shmem_file_llseek+0xef/0x240 mm/shmem.c:2579
 vfs_llseek+0xa2/0xd0 fs/read_write.c:300
 ashmem_llseek+0xe7/0x1f0 drivers/staging/android/ashmem.c:346
 vfs_llseek fs/read_write.c:300 [inline]
 SYSC_lseek fs/read_write.c:313 [inline]
 SyS_lseek+0xeb/0x170 fs/read_write.c:304
 entry_SYSCALL_64_fastpath+0x23/0x9a
RIP: 0033:0x444ac9
RSP: 002b:00007ffc6ae26748 EFLAGS: 00000217 ORIG_RAX: 0000000000000008
RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 0000000000444ac9
RDX: 0000000000000003 RSI: 0000000000000000 RDI: 0000000000000004
RBP: 00000000