KASAN: slab-out-of-bounds Read in perf_exclude_event

From: syzbot
Date: Sat Dec 29 2018 - 01:34:12 EST


Hello,

syzbot found the following crash on:

HEAD commit: 7566ec393f41 Linux 4.20-rc7
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=16c1b21b400000
kernel config: https://syzkaller.appspot.com/x/.config?x=861a3573f4e78ba1
dashboard link: https://syzkaller.appspot.com/bug?extid=90e033e65bf7256f2afb
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+90e033e65bf7256f2afb@xxxxxxxxxxxxxxxxxxxxxxxxx

==================================================================
BUG: KASAN: slab-out-of-bounds in perf_exclude_event+0x18b/0x1a0 kernel/events/core.c:7895
Read of size 8 at addr ffff8881b09cff90 by task syz-executor2/30277

CPU: 0 PID: 30277 Comm: syz-executor2 Not tainted 4.20.0-rc7+ #154
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
<IRQ>
__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
perf_exclude_event+0x18b/0x1a0 kernel/events/core.c:7895
perf_swevent_hrtimer+0x28f/0x510 kernel/events/core.c:9153
__run_hrtimer kernel/time/hrtimer.c:1398 [inline]
__hrtimer_run_queues+0x41c/0x10d0 kernel/time/hrtimer.c:1460
hrtimer_interrupt+0x313/0x780 kernel/time/hrtimer.c:1518
local_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1034 [inline]
smp_apic_timer_interrupt+0x1a1/0x760 arch/x86/kernel/apic/apic.c:1059
apic_timer_interrupt+0xf/0x20 arch/x86/entry/entry_64.S:807
</IRQ>

Allocated by task 30091:
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]
kzalloc include/linux/slab.h:741 [inline]
kernfs_iop_get_link+0x6d/0x690 fs/kernfs/symlink.c:136
get_link fs/namei.c:1084 [inline]
trailing_symlink+0x779/0x970 fs/namei.c:2263
path_openat+0xb58/0x5150 fs/namei.c:3536
do_filp_open+0x255/0x380 fs/namei.c:3564
do_sys_open+0x568/0x700 fs/open.c:1063
__do_sys_open fs/open.c:1081 [inline]
__se_sys_open fs/open.c:1076 [inline]
__x64_sys_open+0x7e/0xc0 fs/open.c:1076
do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290
entry_SYSCALL_64_after_hwframe+0x49/0xbe

Freed by task 30091:
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
kfree_link+0x15/0x20 fs/libfs.c:1105
do_delayed_call include/linux/delayed_call.h:28 [inline]
put_link fs/namei.c:883 [inline]
step_into fs/namei.c:1772 [inline]
do_last fs/namei.c:3383 [inline]
path_openat+0x1ed3/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_open fs/open.c:1081 [inline]
__se_sys_open fs/open.c:1076 [inline]
__x64_sys_open+0x7e/0xc0 fs/open.c:1076
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 ffff8881b09ce080
which belongs to the cache kmalloc-4k of size 4096
The buggy address is located 3856 bytes to the right of
4096-byte region [ffff8881b09ce080, ffff8881b09cf080)
The buggy address belongs to the page:
page:ffffea0006c27380 count:1 mapcount:0 mapping:ffff8881da800dc0 index:0x0 compound_mapcount: 0
flags: 0x2fffc0000010200(slab|head)
raw: 02fffc0000010200 ffffea00070ee188 ffffea0006ff4d08 ffff8881da800dc0
raw: 0000000000000000 ffff8881b09ce080 0000000100000001 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
ffff8881b09cfe80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ffff8881b09cff00: 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc fc
ffff8881b09cff80: fc fc fc fc fc fc fc fc fc fc fc f1 f1 f1 f1 00
^
ffff8881b09d0000: f2 f2 f2 00 00 00 00 00 00 00 00 00 00 00 00 00
ffff8881b09d0080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
==================================================================


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