KASAN: use-after-free Read in is_bpf_text_address

Status: fixed on 2019/11/23 02:56
Subsystems: bpf
[Documentation on labels]
Reported-by: syzbot+0cd01c9e0f5cd37a357e@syzkaller.appspotmail.com
Fix commit: cd7455f1013e bpf: Fix use after free in subprog's jited symbol removal
First crash: 2592d, last: 2589d
Cause bisection: the cause commit could be any of (bisect log):
commit 7105e828c087de970fcb5a9509db51bfe6bd7894
Author: Daniel Borkmann <daniel@iogearbox.net>
Date: Wed Dec 20 12:42:57 2017 +0000

  bpf: allow for correlation of maps and helpers in dump

commit 7466177635be4d5f2452284085b5c2cc299367fe
Author: Alexei Starovoitov <ast@kernel.org>
Date: Thu Dec 21 02:09:41 2017 +0000

  Merge branch 'bpftool-improvements-kallsymfix'

commit 4f74d80971bce93d9e608c40324d662c70eb4664
Author: Daniel Borkmann <daniel@iogearbox.net>
Date: Wed Dec 20 12:42:56 2017 +0000

  bpf: fix kallsyms handling for subprogs

commit c475ffad58a8a2f1d3a2bd433eaa491471981b49
Author: Yonghong Song <yhs@fb.com>
Date: Wed Dec 20 18:37:08 2017 +0000

  tools/bpf: adjust rlimit RLIMIT_MEMLOCK for test_dev_cgroup

commit 5f5a641116391f6c8c5fb4dad717895d2da96678
Author: David Miller <davem@davemloft.net>
Date: Fri Dec 22 14:42:41 2017 +0000

  bpf: sparc64: Add JIT support for multi-function programs.

commit 7d9890ef505a8c2a778d304535e26e827d58c466
Author: David Miller <davem@davemloft.net>
Date: Tue Dec 19 20:53:11 2017 +0000

  libbpf: Fix build errors.

commit 06ef0ccb5a36e1feba9b413ff59a04ecc4407c1c
Author: Yonghong Song <yhs@fb.com>
Date: Mon Dec 18 18:13:44 2017 +0000

  bpf/cgroup: fix a verification error for a CGROUP_DEVICE type prog

commit fd05e57bb35ad5eb7e261b64e5cf46445250f842
Author: Gianluca Borello <g.borello@gmail.com>
Date: Sat Dec 23 10:09:55 2017 +0000

  bpf: fix stacksafe exploration when comparing states

commit 6b80ad299208b44ba33cb6df80bdaa3f63cf03e2
Author: Jann Horn <jannh@google.com>
Date: Fri Dec 22 18:12:35 2017 +0000

  bpf: selftest for late caller stack size increase

commit c060bc6115b6a204cb60e6b03fe64135731bc6c8
Author: Xiongwei Song <sxwjean@gmail.com>
Date: Mon Dec 18 23:17:15 2017 +0000

  bpf: make function xdp_do_generic_redirect_map() static

commit 4ca998fe46b1fce4988005851df2c85b7bf2addf
Author: Jakub Kicinski <jakub.kicinski@netronome.com>
Date: Mon Dec 18 23:11:30 2017 +0000

  selftests/bpf: add netdevsim to config

commit 70a87ffea8acc390ae315fa1930e849f656bdb88
Author: Alexei Starovoitov <ast@kernel.org>
Date: Mon Dec 25 21:15:40 2017 +0000

  bpf: fix maximum stack depth tracking logic

commit 5ee7f784cd32e63fbf54275b2b4f991ca085db61
Author: Alexei Starovoitov <ast@fb.com>
Date: Mon Dec 18 18:09:44 2017 +0000

  bpf: arm64: fix uninitialized variable

commit 6b86c4217c231cbd268bd8c6fda025b27047d3ed
Author: Alexei Starovoitov <ast@kernel.org>
Date: Mon Dec 25 21:15:41 2017 +0000

  selftests/bpf: additional stack depth tests

commit aada9ce644e53410954daa6beb1f7c4ca158abd7
Author: Alexei Starovoitov <ast@kernel.org>
Date: Mon Dec 25 21:15:42 2017 +0000

  bpf: fix max call depth check

commit fa2d41adb953235c4acaa98f6c980fd9eabe0062
Author: Colin Ian King <colin.king@canonical.com>
Date: Mon Dec 18 17:47:07 2017 +0000

  bpf: make function skip_callee static and return NULL rather than 0

commit 624588d9d6cc0a1a270a65fb4d5220f1ceddcf38
Author: Daniel Borkmann <daniel@iogearbox.net>
Date: Wed Dec 27 17:36:23 2017 +0000

  Merge branch 'bpf-stack-depth-tracking-fixes'

commit e90004d56bf805db7d4401fe51a80a93c311cfe6
Author: Colin Ian King <colin.king@canonical.com>
Date: Mon Dec 18 14:03:12 2017 +0000

  bpf: fix spelling mistake: "funcation"-> "function"

commit fcffe2edbd390cad499b27d20512ef000d7ecf54
Author: David S. Miller <davem@davemloft.net>
Date: Thu Dec 28 01:40:32 2017 +0000

  Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
▶ ▼ Discussions (1)
Title Replies (including bot) Last reply
KASAN: use-after-free Read in is_bpf_text_address 1 (2) 2019/10/22 14:25
▶ ▼ Last patch testing requests (2)
Created Duration User Patch Repo Result
2019/10/22 15:01 17m daniel@iogearbox.net git://git.kernel.org/pub/scm/linux/kernel/git/dborkman/bpf.git pr/kallsyms-fix no crash
2019/10/22 13:58 18m daniel@iogearbox.net git://git.kernel.org/pub/scm/linux/kernel/git/dborkman/bpf.git pr/kallsyms-fix no crash

Sample crash report:
==================================================================
BUG: KASAN: use-after-free in __lt_find include/linux/rbtree_latch.h:120 [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 is_bpf_text_address+0x250/0x3b0 kernel/bpf/core.c:709
Read of size 8 at addr ffff8880a366b448 by task syz-executor594/8353

CPU: 1 PID: 8353 Comm: syz-executor594 Not tainted 5.4.0-rc3+ #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+0x1d8/0x2f8 lib/dump_stack.c:113
 print_address_description+0x75/0x5c0 mm/kasan/report.c:374
 __kasan_report+0x14b/0x1c0 mm/kasan/report.c:506
 kasan_report+0x26/0x50 mm/kasan/common.c:634
 __asan_report_load8_noabort+0x14/0x20 mm/kasan/generic_report.c:132
 __lt_find include/linux/rbtree_latch.h:120 [inline]
 latch_tree_find include/linux/rbtree_latch.h:208 [inline]
 bpf_prog_kallsyms_find kernel/bpf/core.c:674 [inline]
 is_bpf_text_address+0x250/0x3b0 kernel/bpf/core.c:709
 kernel_text_address kernel/extable.c:147 [inline]
 __kernel_text_address+0x9a/0x110 kernel/extable.c:102
 unwind_get_return_address+0x4c/0x90 arch/x86/kernel/unwind_frame.c:19
 arch_stack_walk+0x98/0xe0 arch/x86/kernel/stacktrace.c:26
 stack_trace_save+0xb6/0x150 kernel/stacktrace.c:123
 save_stack mm/kasan/common.c:69 [inline]
 set_track mm/kasan/common.c:77 [inline]
 __kasan_kmalloc+0x11c/0x1b0 mm/kasan/common.c:510
 kasan_slab_alloc+0xf/0x20 mm/kasan/common.c:518
 slab_post_alloc_hook mm/slab.h:584 [inline]
 slab_alloc_node mm/slab.c:3262 [inline]
 kmem_cache_alloc_node+0x235/0x280 mm/slab.c:3574
 alloc_vmap_area+0x1eb/0x1b60 mm/vmalloc.c:1094
 __get_vm_area_node+0x199/0x320 mm/vmalloc.c:2063
 __vmalloc_node_range+0xea/0x860 mm/vmalloc.c:2491
 kasan_module_alloc+0x73/0xc0 mm/kasan/common.c:607
 module_alloc+0x9a/0xb0 arch/x86/kernel/module.c:80
 bpf_jit_alloc_exec+0x15/0x20
 bpf_jit_binary_alloc+0xa0/0x1b0 kernel/bpf/core.c:812
 bpf_int_jit_compile+0x6f5d/0x7a80 arch/x86/net/bpf_jit_comp.c:1151
 jit_subprogs kernel/bpf/verifier.c:8741 [inline]
 fixup_call_args kernel/bpf/verifier.c:8845 [inline]
 bpf_check+0xc423/0xe790 kernel/bpf/verifier.c:9349
 bpf_prog_load kernel/bpf/syscall.c:1709 [inline]
 __do_sys_bpf+0x7a4f/0xbef0 kernel/bpf/syscall.c:2866
 __se_sys_bpf kernel/bpf/syscall.c:2825 [inline]
 __x64_sys_bpf+0x7a/0x90 kernel/bpf/syscall.c:2825
 do_syscall_64+0xf7/0x1c0 arch/x86/entry/common.c:290
 entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x441449
Code: e8 ac e8 ff ff 48 83 c4 18 c3 0f 1f 80 00 00 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 0f 83 eb 08 fc ff c3 66 2e 0f 1f 84 00 00 00 00
RSP: 002b:00007ffe2e84b718 EFLAGS: 00000246 ORIG_RAX: 0000000000000141
RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 0000000000441449
RDX: 0000000000000032 RSI: 0000000020000440 RDI: 0000000000000005
RBP: 0000000000073d8f R08: 0000000000000004 R09: 00000000004002c8
R10: 0000000000000000 R11: 0000000000000246 R12: 00000000004021c0
R13: 0000000000402250 R14: 0000000000000000 R15: 0000000000000000

Allocated by task 8355:
 save_stack mm/kasan/common.c:69 [inline]
 set_track mm/kasan/common.c:77 [inline]
 __kasan_kmalloc+0x11c/0x1b0 mm/kasan/common.c:510
 kasan_kmalloc+0x9/0x10 mm/kasan/common.c:524
 kmem_cache_alloc_trace+0x221/0x2f0 mm/slab.c:3550
 kmalloc include/linux/slab.h:556 [inline]
 kzalloc include/linux/slab.h:690 [inline]
 bpf_prog_alloc_no_stats+0xdc/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+0xbe9a/0xe790 kernel/bpf/verifier.c:9349
 bpf_prog_load kernel/bpf/syscall.c:1709 [inline]
 __do_sys_bpf+0x7a4f/0xbef0 kernel/bpf/syscall.c:2866
 __se_sys_bpf kernel/bpf/syscall.c:2825 [inline]
 __x64_sys_bpf+0x7a/0x90 kernel/bpf/syscall.c:2825
 do_syscall_64+0xf7/0x1c0 arch/x86/entry/common.c:290
 entry_SYSCALL_64_after_hwframe+0x49/0xbe

Freed by task 2923:
 save_stack mm/kasan/common.c:69 [inline]
 set_track mm/kasan/common.c:77 [inline]
 kasan_set_free_info mm/kasan/common.c:332 [inline]
 __kasan_slab_free+0x12a/0x1e0 mm/kasan/common.c:471
 kasan_slab_free+0xe/0x10 mm/kasan/common.c:480
 __cache_free mm/slab.c:3425 [inline]
 kfree+0x115/0x200 mm/slab.c:3756
 bpf_jit_free+0x189/0x1f0
 bpf_prog_free_deferred+0x1b9/0x380 kernel/bpf/core.c:1980
 process_one_work+0x7ef/0x10e0 kernel/workqueue.c:2269
 worker_thread+0xc01/0x1630 kernel/workqueue.c:2415
 kthread+0x332/0x350 kernel/kthread.c:255
 ret_from_fork+0x24/0x30 arch/x86/entry/entry_64.S:352

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

Memory state around the buggy address:
 ffff8880a366b300: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff8880a366b380: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff8880a366b400: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                              ^
 ffff8880a366b480: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff8880a366b500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Crashes (3):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2019/10/20 21:14 upstream 4fe34d61a3a9 8c88c9c1 .config console log report syz C ci-upstream-kasan-gce-smack-root
2019/10/23 21:56 upstream 13b86bc4cd64 b602d64b .config console log report syz ci-upstream-kasan-gce-smack-root
2019/10/22 00:23 upstream 7d194c2100ad b24d2b8a .config console log report ci-upstream-kasan-gce-smack-root
* Struck through repros no longer work on HEAD.