KASAN: use-after-free Read in mon_bin_vma_fault

Status: fixed on 2018/02/04 11:35
Subsystems: usb
[Documentation on labels]
Fix commit: 46eb14a6e158 USB: fix usbmon BUG trigger
First crash: 2312d, last: 2296d
Discussions (1)
Title Replies (including bot) Last reply
Re: KASAN: use-after-free Read in mon_bin_vma_fault 1 (1) 2018/02/02 23:23

Sample crash report:
BUG: KASAN: use-after-free in mon_bin_vma_fault+0x378/0x400 drivers/usb/mon/mon_bin.c:1238
Read of size 8 at addr ffff8801cd040080 by task syz-executor1/5424

CPU: 1 PID: 5424 Comm: syz-executor1 Not tainted 4.15.0-rc5+ #238
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_address_description+0x73/0x250 mm/kasan/report.c:252
 kasan_report_error mm/kasan/report.c:351 [inline]
 kasan_report+0x25b/0x340 mm/kasan/report.c:409
 __asan_report_load8_noabort+0x14/0x20 mm/kasan/report.c:430
 mon_bin_vma_fault+0x378/0x400 drivers/usb/mon/mon_bin.c:1238
 __do_fault+0xeb/0x30f mm/memory.c:3196
 do_read_fault mm/memory.c:3606 [inline]
 do_fault mm/memory.c:3706 [inline]
 handle_pte_fault mm/memory.c:3937 [inline]
 __handle_mm_fault+0x1d8f/0x3ce0 mm/memory.c:4061
 handle_mm_fault+0x334/0x8d0 mm/memory.c:4098
 faultin_page mm/gup.c:502 [inline]
 __get_user_pages+0x50c/0x15f0 mm/gup.c:699
 populate_vma_page_range+0x20e/0x2f0 mm/gup.c:1216
 __mm_populate+0x23a/0x450 mm/gup.c:1266
 mm_populate include/linux/mm.h:2226 [inline]
 vm_mmap_pgoff+0x241/0x280 mm/util.c:338
 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
RIP: 0033:0x452ac9
RSP: 002b:00007f7721b03c58 EFLAGS: 00000212 ORIG_RAX: 0000000000000009
RAX: ffffffffffffffda RBX: 000000000071bea0 RCX: 0000000000452ac9
RDX: 0000000001000004 RSI: 0000000000004000 RDI: 0000000020ac6000
RBP: 000000000000039b R08: 0000000000000014 R09: 0000000000000000
R10: 0000000000008011 R11: 0000000000000212 R12: 00000000006f2728
R13: 00000000ffffffff R14: 00007f7721b046d4 R15: 0000000000000000

Allocated by task 5424:
 save_stack+0x43/0xd0 mm/kasan/kasan.c:447
 set_track mm/kasan/kasan.c:459 [inline]
 kasan_kmalloc+0xad/0xe0 mm/kasan/kasan.c:551
 kmem_cache_alloc_trace+0x136/0x750 mm/slab.c:3610
 kmalloc include/linux/slab.h:499 [inline]
 kzalloc include/linux/slab.h:688 [inline]
 mon_bin_open+0x1ae/0x4a0 drivers/usb/mon/mon_bin.c:703
 chrdev_open+0x257/0x730 fs/char_dev.c:417
 do_dentry_open+0x667/0xd40 fs/open.c:752
 vfs_open+0x107/0x220 fs/open.c:866
 do_last fs/namei.c:3379 [inline]
 path_openat+0x1151/0x3530 fs/namei.c:3519
 do_filp_open+0x25b/0x3b0 fs/namei.c:3554
 do_sys_open+0x502/0x6d0 fs/open.c:1059
 SYSC_open fs/open.c:1077 [inline]
 SyS_open+0x2d/0x40 fs/open.c:1072

Freed by task 5433:
 save_stack+0x43/0xd0 mm/kasan/kasan.c:447
 set_track mm/kasan/kasan.c:459 [inline]
 kasan_slab_free+0x71/0xc0 mm/kasan/kasan.c:524
 __cache_free mm/slab.c:3488 [inline]
 kfree+0xd6/0x260 mm/slab.c:3803
 mon_bin_ioctl+0x68d/0xd40 drivers/usb/mon/mon_bin.c:1040
 vfs_ioctl fs/ioctl.c:46 [inline]
 do_vfs_ioctl+0x1b1/0x1520 fs/ioctl.c:686
 SYSC_ioctl fs/ioctl.c:701 [inline]
 SyS_ioctl+0x8f/0xc0 fs/ioctl.c:692

The buggy address belongs to the object at ffff8801cd040080
 which belongs to the cache kmalloc-2048 of size 2048
The buggy address is located 0 bytes inside of
 2048-byte region [ffff8801cd040080, ffff8801cd040880)
The buggy address belongs to the page:
page:000000003d43a99d count:1 mapcount:0 mapping:0000000083654cb9 index:0x0 compound_mapcount: 0
flags: 0x2fffc0000008100(slab|head)
raw: 02fffc0000008100 ffff8801cd040080 0000000000000000 0000000100000003
raw: ffffea00072a2e20 ffffea00071e6920 ffff8801db000c40 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
 ffff8801cd03ff80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff8801cd040000: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff8801cd040080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff8801cd040100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff8801cd040180: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb

Crashes (7):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2017/12/27 12:00 upstream beacbc68ac3e 09c8f4c0 .config console log report ci-upstream-kasan-gce
2017/12/24 18:58 upstream 464e1d5f23cc 73aba437 .config console log report ci-upstream-kasan-gce
2018/01/09 01:52 mmots 69eed2290e1d 11dc42f6 .config console log report ci-upstream-mmots-kasan-gce
2018/01/08 00:39 linux-next 990b6a07d18c 19c05fff .config console log report ci-upstream-next-kasan-gce
2017/12/31 22:10 mmots 37759fa6d0fa 00193447 .config console log report ci-upstream-mmots-kasan-gce
2017/12/28 21:52 linux-next 0e08c463db38 7d240098 .config console log report ci-upstream-next-kasan-gce
2017/12/25 04:06 linux-next 0e08c463db38 73aba437 .config console log report ci-upstream-next-kasan-gce
* Struck through repros no longer work on HEAD.