syzbot


KASAN: use-after-free Read in bpf_prog_kallsyms_find (2)

Status: fixed on 2019/11/23 02:56
Subsystems: bpf
[Documentation on labels]
Reported-by: syzbot+0bd67ad376a3f4a8606e@syzkaller.appspotmail.com
Fix commit: cd7455f1013e bpf: Fix use after free in subprog's jited symbol removal
First crash: 1660d, last: 1642d
Cause bisection: introduced by (bisect log) :
commit 6c4fc209fcf9d27efbaa48368773e4d2bfbd59aa
Author: Daniel Borkmann <daniel@iogearbox.net>
Date: Sat Dec 15 23:49:47 2018 +0000

  bpf: remove useless version check for prog load

Crash: BUG: unable to handle kernel paging request in bpf_prog_kallsyms_find (log)
Repro: C syz .config
  
Discussions (1)
Title Replies (including bot) Last reply
KASAN: use-after-free Read in bpf_prog_kallsyms_find (2) 0 (1) 2019/10/14 02:50
Similar bugs (2)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KASAN: use-after-free Read in bpf_prog_kallsyms_find bpf 2 1907d 1937d 0/26 auto-closed as invalid on 2019/07/31 10:58
linux-4.19 KASAN: use-after-free Read in bpf_prog_kallsyms_find C error 11 1181d 1653d 0/1 upstream: reported C repro on 2019/10/14 06:50
Last patch testing requests (1)
Created Duration User Patch Repo Result
2019/10/23 08:27 18m daniel@iogearbox.net bpf OK

Sample crash report:
==================================================================
BUG: KASAN: use-after-free in __read_once_size include/linux/compiler.h:199 [inline]
BUG: KASAN: use-after-free in __lt_find include/linux/rbtree_latch.h:118 [inline]
BUG: KASAN: use-after-free in latch_tree_find include/linux/rbtree_latch.h:208 [inline]
BUG: KASAN: use-after-free in bpf_prog_kallsyms_find kernel/bpf/core.c:674 [inline]
BUG: KASAN: use-after-free in bpf_prog_kallsyms_find+0x2a9/0x2c0 kernel/bpf/core.c:667
Read of size 8 at addr ffff8880a90b7048 by task syz-executor688/11493

CPU: 1 PID: 11493 Comm: syz-executor688 Not tainted 5.4.0-rc4+ #0
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+0x172/0x1f0 lib/dump_stack.c:113
 print_address_description.constprop.0.cold+0xd4/0x30b mm/kasan/report.c:374
 __kasan_report.cold+0x1b/0x41 mm/kasan/report.c:506
 kasan_report+0x12/0x20 mm/kasan/common.c:634
 __asan_report_load8_noabort+0x14/0x20 mm/kasan/generic_report.c:132
 __read_once_size include/linux/compiler.h:199 [inline]
 __lt_find include/linux/rbtree_latch.h:118 [inline]
 latch_tree_find include/linux/rbtree_latch.h:208 [inline]
 bpf_prog_kallsyms_find kernel/bpf/core.c:674 [inline]
 bpf_prog_kallsyms_find+0x2a9/0x2c0 kernel/bpf/core.c:667
 is_bpf_text_address+0x78/0x170 kernel/bpf/core.c:709
 kernel_text_address+0x73/0xf0 kernel/extable.c:147
 __kernel_text_address+0xd/0x40 kernel/extable.c:102
 unwind_get_return_address arch/x86/kernel/unwind_frame.c:19 [inline]
 unwind_get_return_address+0x61/0xa0 arch/x86/kernel/unwind_frame.c:14
 arch_stack_walk+0x97/0xf0 arch/x86/kernel/stacktrace.c:26
 stack_trace_save+0xac/0xe0 kernel/stacktrace.c:123
 save_stack+0x23/0x90 mm/kasan/common.c:69
 set_track mm/kasan/common.c:77 [inline]
 __kasan_kmalloc mm/kasan/common.c:510 [inline]
 __kasan_kmalloc.constprop.0+0xcf/0xe0 mm/kasan/common.c:483
 kasan_slab_alloc+0xf/0x20 mm/kasan/common.c:518
 slab_post_alloc_hook mm/slab.h:584 [inline]
 slab_alloc mm/slab.c:3319 [inline]
 kmem_cache_alloc+0x121/0x710 mm/slab.c:3483
 __d_alloc+0x2e/0x8c0 fs/dcache.c:1688
 d_alloc+0x4d/0x280 fs/dcache.c:1767
 d_alloc_parallel+0xf4/0x1c30 fs/dcache.c:2519
 __lookup_slow+0x1ab/0x500 fs/namei.c:1646
 lookup_slow+0x58/0x80 fs/namei.c:1680
 walk_component+0x747/0x2000 fs/namei.c:1800
 link_path_walk.part.0+0x5ab/0x1340 fs/namei.c:2128
 link_path_walk fs/namei.c:2062 [inline]
 path_openat+0x202/0x46d0 fs/namei.c:3524
 do_filp_open+0x1a1/0x280 fs/namei.c:3555
 do_sys_open+0x3fe/0x5d0 fs/open.c:1097
 __do_sys_open fs/open.c:1115 [inline]
 __se_sys_open fs/open.c:1110 [inline]
 __x64_sys_open+0x7e/0xc0 fs/open.c:1110
 do_syscall_64+0xfa/0x760 arch/x86/entry/common.c:290
 entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x4011a0
Code: 01 f0 ff ff 0f 83 c0 0b 00 00 c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 83 3d 2d 15 2d 00 00 75 14 b8 02 00 00 00 0f 05 <48> 3d 01 f0 ff ff 0f 83 94 0b 00 00 c3 48 83 ec 08 e8 fa 00 00 00
RSP: 002b:00007fff62581448 EFLAGS: 00000246 ORIG_RAX: 0000000000000002
RAX: ffffffffffffffda RBX: 00007fff62581474 RCX: 00000000004011a0
RDX: 00007fff6258147a RSI: 0000000000080001 RDI: 00000000004a2422
RBP: 00007fff62581470 R08: 0000000000000000 R09: 0000000000000004
R10: 0000000000000000 R11: 0000000000000246 R12: 00000000004021c0
R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000

Allocated by task 11491:
 save_stack+0x23/0x90 mm/kasan/common.c:69
 set_track mm/kasan/common.c:77 [inline]
 __kasan_kmalloc mm/kasan/common.c:510 [inline]
 __kasan_kmalloc.constprop.0+0xcf/0xe0 mm/kasan/common.c:483
 kasan_kmalloc+0x9/0x10 mm/kasan/common.c:524
 kmem_cache_alloc_trace+0x158/0x790 mm/slab.c:3550
 kmalloc include/linux/slab.h:556 [inline]
 kzalloc include/linux/slab.h:690 [inline]
 bpf_prog_alloc_no_stats+0xe6/0x2b0 kernel/bpf/core.c:88
 jit_subprogs kernel/bpf/verifier.c:8716 [inline]
 fixup_call_args kernel/bpf/verifier.c:8845 [inline]
 bpf_check+0x6b3d/0x99c0 kernel/bpf/verifier.c:9349
 bpf_prog_load+0xe68/0x1660 kernel/bpf/syscall.c:1709
 __do_sys_bpf+0xa44/0x3350 kernel/bpf/syscall.c:2866
 __se_sys_bpf kernel/bpf/syscall.c:2825 [inline]
 __x64_sys_bpf+0x73/0xb0 kernel/bpf/syscall.c:2825
 do_syscall_64+0xfa/0x760 arch/x86/entry/common.c:290
 entry_SYSCALL_64_after_hwframe+0x49/0xbe

Freed by task 3120:
 save_stack+0x23/0x90 mm/kasan/common.c:69
 set_track mm/kasan/common.c:77 [inline]
 kasan_set_free_info mm/kasan/common.c:332 [inline]
 __kasan_slab_free+0x102/0x150 mm/kasan/common.c:471
 kasan_slab_free+0xe/0x10 mm/kasan/common.c:480
 __cache_free mm/slab.c:3425 [inline]
 kfree+0x10a/0x2c0 mm/slab.c:3756
 __bpf_prog_free+0x87/0xc0 kernel/bpf/core.c:258
 bpf_jit_free+0x64/0x1b0
 bpf_prog_free_deferred+0x1a6/0x350 kernel/bpf/core.c:1980
 process_one_work+0x9af/0x1740 kernel/workqueue.c:2269
 worker_thread+0x98/0xe40 kernel/workqueue.c:2415
 kthread+0x361/0x430 kernel/kthread.c:255
 ret_from_fork+0x24/0x30 arch/x86/entry/entry_64.S:352

The buggy address belongs to the object at ffff8880a90b7000
 which belongs to the cache kmalloc-512 of size 512
The buggy address is located 72 bytes inside of
 512-byte region [ffff8880a90b7000, ffff8880a90b7200)
The buggy address belongs to the page:
page:ffffea0002a42dc0 refcount:1 mapcount:0 mapping:ffff8880aa400a80 index:0x0
flags: 0x1fffc0000000200(slab)
raw: 01fffc0000000200 ffffea0002a42d88 ffffea0002a1e088 ffff8880aa400a80
raw: 0000000000000000 ffff8880a90b7000 0000000100000004 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
 ffff8880a90b6f00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff8880a90b6f80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff8880a90b7000: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                              ^
 ffff8880a90b7080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff8880a90b7100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Crashes (9):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2019/10/24 18:55 upstream f116b96685a0 d01bb02a .config console log report syz C ci-upstream-kasan-gce-root
2019/10/21 04:53 upstream 4fe34d61a3a9 8c88c9c1 .config console log report syz C ci-upstream-kasan-gce-root
2019/10/07 03:05 upstream b212921b13bd f3f7d9c8 .config console log report syz C ci-upstream-kasan-gce-root
2019/10/20 04:20 net-old bd310aca442f 8c88c9c1 .config console log report syz C ci-upstream-net-this-kasan-gce
2019/10/20 04:18 net-next-old ebcd670d05d5 8c88c9c1 .config console log report syz C ci-upstream-net-kasan-gce
2019/10/14 06:49 net-next-old c208bdb93788 2f661ec4 .config console log report syz C ci-upstream-net-kasan-gce
2019/10/07 04:07 bpf-next a9eb048d5615 f3f7d9c8 .config console log report syz C ci-upstream-bpf-next-kasan-gce
2019/10/20 12:34 net-old 531e93d11470 8c88c9c1 .config console log report ci-upstream-net-this-kasan-gce
2019/10/13 21:54 net-next-old c208bdb93788 2f661ec4 .config console log report ci-upstream-net-kasan-gce
* Struck through repros no longer work on HEAD.