audit: type=1400 audit(1573656745.792:62): avc: denied { map } for pid=9726 comm="syz-executor.0" path="/dev/ashmem" dev="devtmpfs" ino=5099 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.153+ #0 Not tainted ------------------------------------------------------ syz-executor.0/9728 is trying to acquire lock: (&sb->s_type->i_mutex_key#10){+.+.}, at: [<000000001ce276fc>] inode_lock include/linux/fs.h:724 [inline] (&sb->s_type->i_mutex_key#10){+.+.}, at: [<000000001ce276fc>] shmem_fallocate+0x150/0xae0 mm/shmem.c:2904 but task is already holding lock: (ashmem_mutex){+.+.}, at: [<00000000f74fcc01>] ashmem_shrink_scan+0x53/0x4f0 drivers/staging/android/ashmem.c:446 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+0xf7/0x13e0 kernel/locking/mutex.c:893 ashmem_mmap+0x4c/0x450 drivers/staging/android/ashmem.c:369 call_mmap include/linux/fs.h:1803 [inline] mmap_region+0x7d9/0xfb0 mm/mmap.c:1736 do_mmap+0x548/0xb80 mm/mmap.c:1512 do_mmap_pgoff include/linux/mm.h:2220 [inline] vm_mmap_pgoff+0x177/0x1c0 mm/util.c:333 SYSC_mmap_pgoff mm/mmap.c:1564 [inline] SyS_mmap_pgoff+0xf4/0x1b0 mm/mmap.c:1520 do_syscall_64+0x19b/0x520 arch/x86/entry/common.c:292 entry_SYSCALL_64_after_hwframe+0x42/0xb7 -> #1 (&mm->mmap_sem){++++}: down_read+0x37/0xa0 kernel/locking/rwsem.c:24 __do_page_fault+0x8a4/0xbb0 arch/x86/mm/fault.c:1356 page_fault+0x22/0x50 arch/x86/entry/entry_64.S:1122 fault_in_pages_readable include/linux/pagemap.h:614 [inline] iov_iter_fault_in_readable+0x29c/0x350 lib/iov_iter.c:421 generic_perform_write+0x158/0x460 mm/filemap.c:3122 __generic_file_write_iter+0x32e/0x550 mm/filemap.c:3257 generic_file_write_iter+0x36f/0x650 mm/filemap.c:3285 call_write_iter include/linux/fs.h:1798 [inline] new_sync_write fs/read_write.c:471 [inline] __vfs_write+0x401/0x5a0 fs/read_write.c:484 vfs_write+0x17f/0x4d0 fs/read_write.c:546 SYSC_pwrite64 fs/read_write.c:636 [inline] SyS_pwrite64+0x136/0x160 fs/read_write.c:623 do_syscall_64+0x19b/0x520 arch/x86/entry/common.c:292 entry_SYSCALL_64_after_hwframe+0x42/0xb7 -> #0 (&sb->s_type->i_mutex_key#10){+.+.}: lock_acquire+0x12b/0x360 kernel/locking/lockdep.c:3994 down_write+0x34/0x90 kernel/locking/rwsem.c:54 inode_lock include/linux/fs.h:724 [inline] shmem_fallocate+0x150/0xae0 mm/shmem.c:2904 ashmem_shrink_scan drivers/staging/android/ashmem.c:453 [inline] ashmem_shrink_scan+0x1ca/0x4f0 drivers/staging/android/ashmem.c:437 ashmem_ioctl+0x2b4/0xd20 drivers/staging/android/ashmem.c:795 vfs_ioctl fs/ioctl.c:46 [inline] file_ioctl fs/ioctl.c:500 [inline] do_vfs_ioctl+0xabe/0x1040 fs/ioctl.c:684 SYSC_ioctl fs/ioctl.c:701 [inline] SyS_ioctl+0x7f/0xb0 fs/ioctl.c:692 do_syscall_64+0x19b/0x520 arch/x86/entry/common.c:292 entry_SYSCALL_64_after_hwframe+0x42/0xb7 other info that might help us debug this: Chain exists of: &sb->s_type->i_mutex_key#10 --> &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#10); *** DEADLOCK *** 1 lock held by syz-executor.0/9728: #0: (ashmem_mutex){+.+.}, at: [<00000000f74fcc01>] ashmem_shrink_scan+0x53/0x4f0 drivers/staging/android/ashmem.c:446 stack backtrace: CPU: 0 PID: 9728 Comm: syz-executor.0 Not tainted 4.14.153+ #0 Call Trace: __dump_stack lib/dump_stack.c:17 [inline] dump_stack+0xca/0x134 lib/dump_stack.c:53 print_circular_bug.isra.0.cold+0x2dc/0x425 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+0x2f5f/0x4320 kernel/locking/lockdep.c:3487 lock_acquire+0x12b/0x360 kernel/locking/lockdep.c:3994 down_write+0x34/0x90 kernel/locking/rwsem.c:54 inode_lock include/linux/fs.h:724 [inline] shmem_fallocate+0x150/0xae0 mm/shmem.c:2904 ashmem_shrink_scan drivers/staging/android/ashmem.c:453 [inline] ashmem_shrink_scan+0x1ca/0x4f0 drivers/staging/android/ashmem.c:437 ashmem_ioctl+0x2b4/0xd20 drivers/staging/android/ashmem.c:795 vfs_ioctl fs/ioctl.c:46 [inline] file_ioctl fs/ioctl.c:500 [inline] do_vfs_ioctl+0xabe/0x1040 fs/ioctl.c:684 SYSC_ioctl fs/ioctl.c:701 [inline] SyS_ioctl+0x7f/0xb0 fs/ioctl.c:692 do_syscall_64+0x19b/0x520 arch/x86/entry/common.c:292 entry_SYSCALL_64_after_hwframe+0x42/0xb7 RIP: 0033:0x45a219 RSP: 002b:00007f543d215c78 EFLAGS: 00000246 ORIG_RAX: 0000000000000010 RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 000000000045a219 RDX: 0000000000000000 RSI: 000000000000770a RDI: 0000000000000003 RBP: 000000000075bf20 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 00007f543d2166d4 R13: 00000000004c198d R14: 00000000004d5668 R15: 00000000ffffffff SELinux: unrecognized netlink message: protocol=0 nlmsg_type=0 sclass=netlink_route_socket pig=9743 comm=syz-executor.3 SELinux: unrecognized netlink message: protocol=0 nlmsg_type=0 sclass=netlink_route_socket pig=9812 comm=syz-executor.3 ================================================================== BUG: KASAN: use-after-free in disk_unblock_events+0x4b/0x50 block/genhd.c:1644 Read of size 8 at addr ffff8881cc037c68 by task syz-executor.0/9475 CPU: 1 PID: 9475 Comm: syz-executor.0 Not tainted 4.14.153+ #0 Call Trace: __dump_stack lib/dump_stack.c:17 [inline] dump_stack+0xca/0x134 lib/dump_stack.c:53 print_address_description+0x60/0x226 mm/kasan/report.c:187 __kasan_report.cold+0x1a/0x41 mm/kasan/report.c:316 disk_unblock_events+0x4b/0x50 block/genhd.c:1644 __blkdev_get+0x68f/0xf90 fs/block_dev.c:1556 blkdev_get+0x97/0x8b0 fs/block_dev.c:1612 blkdev_open+0x1cc/0x250 fs/block_dev.c:1770 do_dentry_open+0x44e/0xe20 fs/open.c:789 vfs_open+0x105/0x230 fs/open.c:903 do_last fs/namei.c:3539 [inline] path_openat+0xb6c/0x2be0 fs/namei.c:3681 do_filp_open+0x1a1/0x280 fs/namei.c:3715 do_sys_open+0x2ca/0x590 fs/open.c:1096 do_syscall_64+0x19b/0x520 arch/x86/entry/common.c:292 entry_SYSCALL_64_after_hwframe+0x42/0xb7 RIP: 0033:0x413f90 RSP: 002b:00007ffcc75644d8 EFLAGS: 00000246 ORIG_RAX: 0000000000000002 RAX: ffffffffffffffda RBX: 00000000000349ad RCX: 0000000000413f90 RDX: 00007ffcc756456a RSI: 0000000000000002 RDI: 00007ffcc7564560 RBP: 0000000000000047 R08: 0000000000000000 R09: 000000000000000a R10: 0000000000000075 R11: 0000000000000246 R12: 0000000000000000 R13: 00007ffcc7564510 R14: 000000000003467e R15: 00007ffcc7564520 Allocated by task 9983: save_stack mm/kasan/common.c:76 [inline] set_track mm/kasan/common.c:85 [inline] __kasan_kmalloc.part.0+0x53/0xc0 mm/kasan/common.c:501 kmem_cache_alloc_node_trace include/linux/slab.h:378 [inline] kmalloc_node include/linux/slab.h:526 [inline] kzalloc_node include/linux/slab.h:672 [inline] alloc_disk_node+0x5b/0x3d0 block/genhd.c:1387 loop_add+0x3ee/0x870 drivers/block/loop.c:1859 loop_control_ioctl+0x130/0x310 drivers/block/loop.c:1991 vfs_ioctl fs/ioctl.c:46 [inline] file_ioctl fs/ioctl.c:500 [inline] do_vfs_ioctl+0xabe/0x1040 fs/ioctl.c:684 SYSC_ioctl fs/ioctl.c:701 [inline] SyS_ioctl+0x7f/0xb0 fs/ioctl.c:692 do_syscall_64+0x19b/0x520 arch/x86/entry/common.c:292 entry_SYSCALL_64_after_hwframe+0x42/0xb7 0xffffffffffffffff Freed by task 9475: save_stack mm/kasan/common.c:76 [inline] set_track mm/kasan/common.c:85 [inline] __kasan_slab_free+0x164/0x210 mm/kasan/common.c:463 slab_free_hook mm/slub.c:1407 [inline] slab_free_freelist_hook mm/slub.c:1458 [inline] slab_free mm/slub.c:3039 [inline] kfree+0x108/0x3a0 mm/slub.c:3976 device_release+0xf4/0x1a0 drivers/base/core.c:823 kobject_cleanup lib/kobject.c:646 [inline] kobject_release lib/kobject.c:675 [inline] kref_put include/linux/kref.h:70 [inline] kobject_put+0x142/0x200 lib/kobject.c:692 put_disk+0x1f/0x30 block/genhd.c:1452 __blkdev_get+0x5fa/0xf90 fs/block_dev.c:1549 blkdev_get+0x97/0x8b0 fs/block_dev.c:1612 blkdev_open+0x1cc/0x250 fs/block_dev.c:1770 do_dentry_open+0x44e/0xe20 fs/open.c:789 vfs_open+0x105/0x230 fs/open.c:903 do_last fs/namei.c:3539 [inline] path_openat+0xb6c/0x2be0 fs/namei.c:3681 do_filp_open+0x1a1/0x280 fs/namei.c:3715 do_sys_open+0x2ca/0x590 fs/open.c:1096 do_syscall_64+0x19b/0x520 arch/x86/entry/common.c:292 entry_SYSCALL_64_after_hwframe+0x42/0xb7 0xffffffffffffffff The buggy address belongs to the object at ffff8881cc037700 which belongs to the cache kmalloc-2048 of size 2048 The buggy address is located 1384 bytes inside of 2048-byte region [ffff8881cc037700, ffff8881cc037f00) The buggy address belongs to the page: page:ffffea0007300c00 count:1 mapcount:0 mapping: (null) index:0x0 compound_mapcount: 0 flags: 0x4000000000010200(slab|head) raw: 4000000000010200 0000000000000000 0000000000000000 00000001000f000f raw: dead000000000100 dead000000000200 ffff8881da802800 0000000000000000 page dumped because: kasan: bad access detected Memory state around the buggy address: ffff8881cc037b00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff8881cc037b80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb >ffff8881cc037c00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ^ ffff8881cc037c80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff8881cc037d00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ==================================================================