Re: KASAN: use-after-free Read in iotlb_access_ok

From: Jason Wang
Date: Tue Aug 07 2018 - 22:53:12 EST




On 2018å08æ07æ 19:16, syzbot wrote:
Hello,

syzbot found the following crash on:

HEAD commit:ÂÂÂ e30cb13c5a09 Merge git://git.kernel.org/pub/scm/linux/kern..
git tree:ÂÂÂÂÂÂ upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=10a153e0400000
kernel config: https://syzkaller.appspot.com/x/.config?x=2dc0cd7c2eefb46f
dashboard link: https://syzkaller.appspot.com/bug?extid=c51e6736a1bf614b3272
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+c51e6736a1bf614b3272@xxxxxxxxxxxxxxxxxxxxxxxxx

==================================================================
BUG: KASAN: use-after-free in vhost_vq_meta_fetch drivers/vhost/vhost.c:702 [inline]
BUG: KASAN: use-after-free in iotlb_access_ok+0x5c9/0x600 drivers/vhost/vhost.c:1177
Read of size 8 at addr ffff880197df2fc0 by task vhost-8938/8941

CPU: 0 PID: 8941 Comm: vhost-8938 Not tainted 4.18.0-rc7+ #174
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
Â__dump_stack lib/dump_stack.c:77 [inline]
Âdump_stack+0x1c9/0x2b4 lib/dump_stack.c:113
Âprint_address_description+0x6c/0x20b mm/kasan/report.c:256
Âkasan_report_error mm/kasan/report.c:354 [inline]
Âkasan_report.cold.7+0x242/0x2fe mm/kasan/report.c:412
Â__asan_report_load8_noabort+0x14/0x20 mm/kasan/report.c:433
Âvhost_vq_meta_fetch drivers/vhost/vhost.c:702 [inline]
Âiotlb_access_ok+0x5c9/0x600 drivers/vhost/vhost.c:1177
Âvq_iotlb_prefetch+0x10e/0x230 drivers/vhost/vhost.c:1214
Âhandle_rx+0x247/0x1f80 drivers/vhost/net.c:799
Âhandle_rx_net+0x19/0x20 drivers/vhost/net.c:934
Âvhost_worker+0x283/0x490 drivers/vhost/vhost.c:360
Âkthread+0x345/0x410 kernel/kthread.c:246
Âret_from_fork+0x3a/0x50 arch/x86/entry/entry_64.S:412

Allocated by task 8938:
Âsave_stack+0x43/0xd0 mm/kasan/kasan.c:448
Âset_track mm/kasan/kasan.c:460 [inline]
Âkasan_kmalloc+0xc4/0xe0 mm/kasan/kasan.c:553
Âkmem_cache_alloc_trace+0x152/0x780 mm/slab.c:3620
Âkmalloc include/linux/slab.h:513 [inline]
Âvhost_new_umem_range+0xcb/0x7c0 drivers/vhost/vhost.c:911
Âvhost_process_iotlb_msg drivers/vhost/vhost.c:1000 [inline]
Âvhost_chr_write_iter+0xe53/0x1a00 drivers/vhost/vhost.c:1043
Âvhost_net_chr_write_iter+0x59/0x70 drivers/vhost/net.c:1399
Âcall_write_iter include/linux/fs.h:1793 [inline]
Ânew_sync_write fs/read_write.c:474 [inline]
Â__vfs_write+0x6c6/0x9f0 fs/read_write.c:487
Âvfs_write+0x1f8/0x560 fs/read_write.c:549
Âksys_write+0x101/0x260 fs/read_write.c:598
Â__do_sys_write fs/read_write.c:610 [inline]
Â__se_sys_write fs/read_write.c:607 [inline]
Â__x64_sys_write+0x73/0xb0 fs/read_write.c:607
Âdo_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290
Âentry_SYSCALL_64_after_hwframe+0x49/0xbe

Freed by task 8950:
Âsave_stack+0x43/0xd0 mm/kasan/kasan.c:448
Âset_track mm/kasan/kasan.c:460 [inline]
Â__kasan_slab_free+0x11a/0x170 mm/kasan/kasan.c:521
Âkasan_slab_free+0xe/0x10 mm/kasan/kasan.c:528
Â__cache_free mm/slab.c:3498 [inline]
Âkfree+0xd9/0x260 mm/slab.c:3813
Âvhost_umem_free+0x944/0x14d0 drivers/vhost/vhost.c:576
Âvhost_umem_clean+0x83/0xf0 drivers/vhost/vhost.c:588
Âvhost_init_device_iotlb+0x1d7/0x290 drivers/vhost/vhost.c:1568
Âvhost_net_set_features drivers/vhost/net.c:1292 [inline]
Âvhost_net_ioctl+0xff3/0x1a80 drivers/vhost/net.c:1357
Âvfs_ioctl fs/ioctl.c:46 [inline]
Âfile_ioctl fs/ioctl.c:500 [inline]
Âdo_vfs_ioctl+0x1de/0x1720 fs/ioctl.c:684
Âksys_ioctl+0xa9/0xd0 fs/ioctl.c:701
Â__do_sys_ioctl fs/ioctl.c:708 [inline]
Â__se_sys_ioctl fs/ioctl.c:706 [inline]
Â__x64_sys_ioctl+0x73/0xb0 fs/ioctl.c:706
Âdo_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290
Âentry_SYSCALL_64_after_hwframe+0x49/0xbe

The buggy address belongs to the object at ffff880197df2f80
Âwhich belongs to the cache kmalloc-96 of size 96
The buggy address is located 64 bytes inside of
Â96-byte region [ffff880197df2f80, ffff880197df2fe0)
The buggy address belongs to the page:
page:ffffea00065f7c80 count:1 mapcount:0 mapping:ffff8801dac004c0 index:0x0
flags: 0x2fffc0000000100(slab)
raw: 02fffc0000000100 ffffea0007530148 ffffea000663b888 ffff8801dac004c0
raw: 0000000000000000 ffff880197df2000 0000000100000020 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
Âffff880197df2e80: fb fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc
Âffff880197df2f00: fb fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc
ffff880197df2f80: fb fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ^
Âffff880197df3000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
Âffff880197df3080: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
==================================================================


---
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.

Looks like the metadata IOTLB needs to be reset during set_features.

Will post a fix.

Thanks