KASAN: use-after-free Read in ucma_event_handler

From: syzbot
Date: Thu Nov 01 2018 - 10:33:07 EST


Hello,

syzbot found the following crash on:

HEAD commit: 11743c56785c Merge tag 'rpmsg-v4.20' of git://github.com/a..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=166b07cb400000
kernel config: https://syzkaller.appspot.com/x/.config?x=93932074d01b4a5
dashboard link: https://syzkaller.appspot.com/bug?extid=f3f3a1734458129344f5
compiler: gcc (GCC) 8.0.1 20180413 (experimental)

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

IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: syzbot+f3f3a1734458129344f5@xxxxxxxxxxxxxxxxxxxxxxxxx

==================================================================
BUG: KASAN: use-after-free in __mutex_lock_common kernel/locking/mutex.c:1009 [inline]
BUG: KASAN: use-after-free in __mutex_lock+0x1601/0x16f0 kernel/locking/mutex.c:1072
Read of size 8 at addr ffff8801c1918188 by task kworker/u4:1/21

CPU: 0 PID: 21 Comm: kworker/u4:1 Not tainted 4.19.0+ #88
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Workqueue: ib_addr process_one_req
Call Trace:
__dump_stack lib/dump_stack.c:77 [inline]
dump_stack+0x244/0x39d lib/dump_stack.c:113
print_address_description.cold.7+0x9/0x1ff mm/kasan/report.c:256
kasan_report_error mm/kasan/report.c:354 [inline]
kasan_report.cold.8+0x242/0x309 mm/kasan/report.c:412
__asan_report_load8_noabort+0x14/0x20 mm/kasan/report.c:433
__mutex_lock_common kernel/locking/mutex.c:1009 [inline]
__mutex_lock+0x1601/0x16f0 kernel/locking/mutex.c:1072
mutex_lock_nested+0x16/0x20 kernel/locking/mutex.c:1087
ucma_event_handler+0x116/0x1000 drivers/infiniband/core/ucma.c:354
addr_handler+0x305/0x420 drivers/infiniband/core/cma.c:2991
process_one_req+0x1a9/0x920 drivers/infiniband/core/addr.c:643
process_one_work+0xc90/0x1c40 kernel/workqueue.c:2153
worker_thread+0x17f/0x1390 kernel/workqueue.c:2296
kthread+0x35a/0x440 kernel/kthread.c:246
ret_from_fork+0x3a/0x50 arch/x86/entry/entry_64.S:350

Allocated by task 13266:
save_stack+0x43/0xd0 mm/kasan/kasan.c:448
set_track mm/kasan/kasan.c:460 [inline]
kasan_kmalloc+0xc7/0xe0 mm/kasan/kasan.c:553
kmem_cache_alloc_trace+0x152/0x750 mm/slab.c:3620
kmalloc include/linux/slab.h:546 [inline]
ucma_open+0xb5/0x3f0 drivers/infiniband/core/ucma.c:1721
misc_open+0x3ca/0x560 drivers/char/misc.c:141
chrdev_open+0x25a/0x710 fs/char_dev.c:417
do_dentry_open+0x499/0x1250 fs/open.c:771
vfs_open+0xa0/0xd0 fs/open.c:880
do_last fs/namei.c:3418 [inline]
path_openat+0x12bc/0x5150 fs/namei.c:3534
do_filp_open+0x255/0x380 fs/namei.c:3564
do_sys_open+0x568/0x700 fs/open.c:1063
__do_sys_openat fs/open.c:1090 [inline]
__se_sys_openat fs/open.c:1084 [inline]
__x64_sys_openat+0x9d/0x100 fs/open.c:1084
do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290
entry_SYSCALL_64_after_hwframe+0x49/0xbe

Freed by task 13265:
save_stack+0x43/0xd0 mm/kasan/kasan.c:448
set_track mm/kasan/kasan.c:460 [inline]
__kasan_slab_free+0x102/0x150 mm/kasan/kasan.c:521
kasan_slab_free+0xe/0x10 mm/kasan/kasan.c:528
__cache_free mm/slab.c:3498 [inline]
kfree+0xcf/0x230 mm/slab.c:3817
ucma_close+0x27e/0x310 drivers/infiniband/core/ucma.c:1780
__fput+0x385/0xa30 fs/file_table.c:278
____fput+0x15/0x20 fs/file_table.c:309
task_work_run+0x1e8/0x2a0 kernel/task_work.c:113
tracehook_notify_resume include/linux/tracehook.h:188 [inline]
exit_to_usermode_loop+0x318/0x380 arch/x86/entry/common.c:166
prepare_exit_to_usermode arch/x86/entry/common.c:197 [inline]
syscall_return_slowpath arch/x86/entry/common.c:268 [inline]
do_syscall_64+0x6be/0x820 arch/x86/entry/common.c:293
entry_SYSCALL_64_after_hwframe+0x49/0xbe

The buggy address belongs to the object at ffff8801c1918140
which belongs to the cache kmalloc-256 of size 256
The buggy address is located 72 bytes inside of
256-byte region [ffff8801c1918140, ffff8801c1918240)
The buggy address belongs to the page:
page:ffffea0007064600 count:1 mapcount:0 mapping:ffff8801da8007c0 index:0xffff8801c1918640
flags: 0x2fffc0000000200(slab)
raw: 02fffc0000000200 ffffea000707bd88 ffffea0007498608 ffff8801da8007c0
raw: ffff8801c1918640 ffff8801c1918000 0000000100000005 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
ffff8801c1918080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8801c1918100: fc fc fc fc fc fc fc fc fb fb fb fb fb fb fb fb
ffff8801c1918180: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff8801c1918200: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
ffff8801c1918280: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================


---
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 syzkaller@xxxxxxxxxxxxxxxxx

syzbot will keep track of this bug report. See:
https://goo.gl/tpsmEJ#bug-status-tracking for how to communicate with syzbot.