Re: KASAN: stack-out-of-bounds Read in bpf_tcp_close

From: John Fastabend
Date: Tue Jul 31 2018 - 11:25:24 EST


On 07/18/2018 03:19 PM, syzbot wrote:
> Hello,
>
> syzbot found the following crash on:
>
> HEAD commit:ÂÂÂ 8ae71e76cf1f Merge branch 'bpf-offload-sharing'
> git tree:ÂÂÂÂÂÂ bpf-next
> console output: https://syzkaller.appspot.com/x/log.txt?x=1379a978400000
> kernel config:Â https://syzkaller.appspot.com/x/.config?x=89129667b46496c3
> dashboard link: https://syzkaller.appspot.com/bug?extid=65a97319fd875ea52b73
> compiler:ÂÂÂÂÂÂ gcc (GCC) 8.0.1 20180413 (experimental)
> syzkaller repro:https://syzkaller.appspot.com/x/repro.syz?x=114f4b2c400000
> C reproducer:ÂÂ https://syzkaller.appspot.com/x/repro.c?x=1774932c400000
>
> IMPORTANT: if you fix the bug, please add the following tag to the commit:
> Reported-by: syzbot+65a97319fd875ea52b73@xxxxxxxxxxxxxxxxxxxxxxxxx
>
> random: sshd: uninitialized urandom read (32 bytes read)
> random: sshd: uninitialized urandom read (32 bytes read)
> IPVS: ftp: loaded support on port[0] = 21
> ==================================================================
> swap_info_get: Bad swap file entry 8007fffc400d72b
> BUG: KASAN: stack-out-of-bounds in __read_once_size include/linux/compiler.h:188 [inline]
> BUG: KASAN: stack-out-of-bounds in smap_psock_sk kernel/bpf/sockmap.c:149 [inline]
> BUG: KASAN: stack-out-of-bounds in bpf_tcp_close+0xf10/0x1050 kernel/bpf/sockmap.c:316
> Read of size 8 at addr ffff8801adcc4428 by task syz-executor115/24313
> BUG: Bad page map in process syz-executor115Â pte:1ffff10035cac810 pmd:1ae564067
>
> CPU: 0 PID: 24313 Comm: syz-executor115 Not tainted 4.18.0-rc3+ #58
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
> Call Trace:
>
> addr:(____ptrval____) vm_flags:00000875 anon_vma:ÂÂÂÂÂÂÂÂÂ (null) mapping:(____ptrval____) index:0
> Allocated by task 2294230744:
> usercopy: Kernel memory overwrite attempt detected to SLAB object 'task_struct(17:syz0)' (offset 6088, size 2)!
> file:syz-executor115250413 fault:ext4_filemap_fault mmap:ext4_file_mmap readpage:ext4_readpage
> ------------[ cut here ]------------
> Bad or missing usercopy whitelist? Kernel memory overwrite attempt detected to SLAB object 'task_struct(17:syz0)' (offset 4936, size 2)!
> WARNING: CPU: 0 PID: 24313 at mm/usercopy.c:81 usercopy_warn+0xf5/0x120 mm/usercopy.c:76
> CPU: 1 PID: 4479 Comm: syz-executor115 Not tainted 4.18.0-rc3+ #58
> Kernel panic - not syncing: panic_on_warn set ...
>
> 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_bad_pte.cold.116+0x1cd/0x22b mm/memory.c:774
> Âzap_pte_range mm/memory.c:1380 [inline]
> Âzap_pmd_range mm/memory.c:1437 [inline]
> Âzap_pud_range mm/memory.c:1466 [inline]
> Âzap_p4d_range mm/memory.c:1487 [inline]
> Âunmap_page_range+0x1cb9/0x2220 mm/memory.c:1508
> Âunmap_single_vma+0x1a0/0x310 mm/memory.c:1553
> Âunmap_vmas+0x120/0x1f0 mm/memory.c:1583
> Âexit_mmap+0x2c2/0x5b0 mm/mmap.c:3105
> Â__mmput kernel/fork.c:970 [inline]
> Âmmput+0x265/0x620 kernel/fork.c:991
> Âexit_mm kernel/exit.c:544 [inline]
> Âdo_exit+0xea9/0x2750 kernel/exit.c:852
> Âdo_group_exit+0x177/0x440 kernel/exit.c:968
> Âget_signal+0x88e/0x1970 kernel/signal.c:2468
> Âdo_signal+0x9c/0x21c0 arch/x86/kernel/signal.c:816
> Âexit_to_usermode_loop+0x2e0/0x370 arch/x86/entry/common.c:162
> Âprepare_exit_to_usermode+0x342/0x3b0 arch/x86/entry/common.c:197
> Âretint_user+0x8/0x18
> RIP: 0033:0x4731e0
> Code: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 <00> 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
> RSP: 002b:00007ffd426a9928 EFLAGS: 00010246
> RAX: 0000000000000000 RBX: 0000000000002e7e RCX: 00000000004731e0
> RDX: 0000000000000000 RSI: 0000000000000000 RDI: 00007ffd426a9930
> RBP: 0000000000002e7e R08: 0000000000000001 R09: 0000000000e2a880
> R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000f7e
> R13: 000000000003ab5f R14: 0000000000000000 R15: 0000000000000000
> CPU: 0 PID: 24313 Comm: syz-executor115 Not tainted 4.18.0-rc3+ #58
> swap_info_get: Bad swap file entry 403fffe200725fc
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
> Call Trace:
> Dumping ftrace buffer:
> ÂÂ (ftrace buffer empty)
> Kernel Offset: disabled
> Rebooting in 86400 seconds..
>

Seems KCM and ULPs are colliding here, sockmap/tls need
some extra checks. I'll have a fix shortly.

Thanks,
John