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

From: David Ahern
Date: Mon Jan 22 2018 - 17:42:51 EST


[ cc William Tu]

On 1/22/18 12:58 PM, syzbot wrote:
> Hello,
>
> syzbot hit the following crash on upstream commit
> 0d665e7b109d512b7cae3ccef6e8654714887844 (Fri Jan 19 12:49:24 2018 +0000)
> mm, page_vma_mapped: Drop faulty pointer arithmetics in check_pte()
>
> So far this crash happened 11 times on upstream.
> C reproducer is attached.
> syzkaller reproducer is attached.
> Raw console output is attached.
> compiler: gcc (GCC) 7.1.1 20170620
> .config is attached.
> user-space arch: i386
>
> IMPORTANT: if you fix the bug, please add the following tag to the commit:
> Reported-by: syzbot+eefa384efad8d7997f20@xxxxxxxxxxxxxxxxxxxxxxxxx
> It will help syzbot understand when the bug is fixed. See footer for
> details.
> If you forward the report, please keep this part and the footer.
>
> audit: type=1400 audit(1516645172.960:10): avc: denied { sys_chroot }
> for pid=3651 comm="syzkaller942389" capability=18Â
> scontext=unconfined_u:system_r:insmod_t:s0-s0:c0.c1023
> tcontext=unconfined_u:system_r:insmod_t:s0-s0:c0.c1023 tclass=cap_userns
> permissive=1
> ==================================================================
> BUG: KASAN: use-after-free in erspan_build_header+0x3bf/0x3d0
> net/ipv4/ip_gre.c:698
> Read of size 2 at addr ffff8801d82a834b by task syzkaller942389/3651
>
> CPU: 0 PID: 3651 Comm: syzkaller942389 Not tainted 4.15.0-rc9+ #184
> 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_load_n_noabort+0xf/0x20 mm/kasan/report.c:440
> Âerspan_build_header+0x3bf/0x3d0 net/ipv4/ip_gre.c:698
> Âerspan_xmit+0x3b8/0x13b0 net/ipv4/ip_gre.c:740
> Â__netdev_start_xmit include/linux/netdevice.h:4042 [inline]
> Ânetdev_start_xmit include/linux/netdevice.h:4051 [inline]
> Âpacket_direct_xmit+0x315/0x6b0 net/packet/af_packet.c:266
> Âpacket_snd net/packet/af_packet.c:2943 [inline]
> Âpacket_sendmsg+0x3aed/0x60b0 net/packet/af_packet.c:2968
> Âsock_sendmsg_nosec net/socket.c:638 [inline]
> Âsock_sendmsg+0xca/0x110 net/socket.c:648
> ÂSYSC_sendto+0x361/0x5c0 net/socket.c:1729
> ÂSyS_sendto+0x40/0x50 net/socket.c:1697
> Âdo_syscall_32_irqs_on arch/x86/entry/common.c:327 [inline]
> Âdo_fast_syscall_32+0x3ee/0xf9d arch/x86/entry/common.c:389
> Âentry_SYSENTER_compat+0x54/0x63 arch/x86/entry/entry_64_compat.S:129
> RIP: 0023:0xf7f0bc79
> RSP: 002b:000000000820fdfc EFLAGS: 00000216 ORIG_RAX: 0000000000000171
> RAX: ffffffffffffffda RBX: 0000000000000004 RCX: 0000000020003fd9
> RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000020008000
> RBP: 000000000000001c R08: 0000000000000000 R09: 0000000000000000
> R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
> R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
>
> Allocated by task 3767:
> Â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
> Âkasan_slab_alloc+0x12/0x20 mm/kasan/kasan.c:489
> Âkmem_cache_alloc+0x12e/0x760 mm/slab.c:3544
> Âprepare_creds+0x78/0x360 kernel/cred.c:252
> ÂSYSC_faccessat fs/open.c:365 [inline]
> ÂSyS_faccessat fs/open.c:353 [inline]
> ÂSYSC_access fs/open.c:431 [inline]
> ÂSyS_access+0x8f/0x6a0 fs/open.c:429
> Âentry_SYSCALL_64_fastpath+0x29/0xa0
>
> Freed by task 3768:
> Â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]
> Âkmem_cache_free+0x83/0x2a0 mm/slab.c:3746
> Âput_cred_rcu+0x263/0x400 kernel/cred.c:126
> Â__rcu_reclaim kernel/rcu/rcu.h:195 [inline]
> Ârcu_do_batch kernel/rcu/tree.c:2758 [inline]
> Âinvoke_rcu_callbacks kernel/rcu/tree.c:3012 [inline]
> Â__rcu_process_callbacks kernel/rcu/tree.c:2979 [inline]
> Ârcu_process_callbacks+0xd6c/0x17f0 kernel/rcu/tree.c:2996
> Â__do_softirq+0x2d7/0xb85 kernel/softirq.c:285
>
> The buggy address belongs to the object at ffff8801d82a8300
> Âwhich belongs to the cache cred_jar of size 168
> The buggy address is located 75 bytes inside of
> Â168-byte region [ffff8801d82a8300, ffff8801d82a83a8)
> The buggy address belongs to the page:
> page:ffffea000760aa00 count:1 mapcount:0 mapping:ffff8801d82a8000 index:0x0
> flags: 0x2fffc0000000100(slab)
> raw: 02fffc0000000100 ffff8801d82a8000 0000000000000000 0000000100000010
> raw: ffffea00076115a0 ffffea00076138a0 ffff8801dad30380 0000000000000000
> page dumped because: kasan: bad access detected
>
> Memory state around the buggy address:
> Âffff8801d82a8200: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> Âffff8801d82a8280: fb fb fb fb fb fc fc fc fc fc fc fc fc fc fc fc
>> ffff8801d82a8300: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ^
> Âffff8801d82a8380: fb fb fb fb fb fc fc fc fc fc fc fc fc fc fc fc
> Âffff8801d82a8400: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> ==================================================================
>
>
> ---
> This bug is generated by a dumb bot. It may contain errors.
> See https://goo.gl/tpsmEJ for details.
> Direct all questions to syzkaller@xxxxxxxxxxxxxxxxx
>
> syzbot will keep track of this bug report.
> If you forgot to add the Reported-by tag, once the fix for this bug is
> merged
> into any tree, please reply to this email with:
> #syz fix: exact-commit-title
> If you want to test a patch for this bug, please reply with:
> #syz test: git://repo/address.git branch
> and provide the patch inline or as an attachment.
> To mark this as a duplicate of another syzbot report, please reply with:
> #syz dup: exact-subject-of-another-report
> If it's a one-off invalid bug report, please reply with:
> #syz invalid
> Note: if the crash happens again, it will cause creation of a new bug
> report.
> Note: all commands must start from beginning of the line in the email body.