Subject: Re: KASAN: use-after-free Read in bpf_prog_kallsyms_add

From: syzbot <[email-masked]>
Date: Sun, 18 Nov 2018 09:28:03 -0800

syzbot has found a reproducer for the following crash on:

HEAD commit:    1ce80e0fe98e Merge tag 'fsnotify_for_v4.20-rc3' of git://g..
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=11752783400000
kernel config:  https://syzkaller.appspot.com/x/.config?x=d86f24333880b605
dashboard link: https://syzkaller.appspot.com/bug?extid=ac0311cfc9e80cd2e0e8
compiler:       gcc (GCC) 8.0.1 20180413 (experimental)
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=16abd093400000

IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: [email-masked]

IPv6: ADDRCONF(NETDEV_CHANGE): veth0: link becomes ready
8021q: adding VLAN 0 to HW filter on device team0
8021q: adding VLAN 0 to HW filter on device team0
==================================================================
BUG: KASAN: use-after-free in __list_add_valid+0x8f/0xac lib/list_debug.c:26
Read of size 8 at addr ffff8881b97b8560 by task syz-executor3/12896

CPU: 1 PID: 12896 Comm: syz-executor3 Not tainted 4.20.0-rc2+ #117
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+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
  __list_add_valid+0x8f/0xac lib/list_debug.c:26
  __list_add_rcu include/linux/rculist.h:52 [inline]
  list_add_tail_rcu include/linux/rculist.h:101 [inline]
  bpf_prog_ksym_node_add kernel/bpf/core.c:460 [inline]
  bpf_prog_kallsyms_add+0x200/0x9b0 kernel/bpf/core.c:491
  jit_subprogs kernel/bpf/verifier.c:5973 [inline]
  fixup_call_args kernel/bpf/verifier.c:6023 [inline]
  bpf_check+0x4fcb/0x6310 kernel/bpf/verifier.c:6404
  bpf_prog_load+0x113d/0x1cc0 kernel/bpf/syscall.c:1528
  __do_sys_bpf kernel/bpf/syscall.c:2504 [inline]
  __se_sys_bpf kernel/bpf/syscall.c:2466 [inline]
  __x64_sys_bpf+0x36c/0x520 kernel/bpf/syscall.c:2466
  do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290
  entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x457569
Code: fd b3 fb ff c3 66 2e 0f 1f 84 00 00 00 00 00 66 90 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 cb b3 fb ff c3 66 2e 0f 1f 84 00 00 00 00
RSP: 002b:00007f6de3718c78 EFLAGS: 00000246 ORIG_RAX: 0000000000000141
RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 0000000000457569
RDX: 0000000000000048 RSI: 0000000020000000 RDI: 0000000000000005
RBP: 000000000072bf00 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00007f6de37196d4
R13: 00000000004bd97c R14: 00000000004cc688 R15: 00000000ffffffff

Allocated by task 12883:
  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]
  bpf_prog_alloc+0x16b/0x3e0 kernel/bpf/core.c:89
  bpf_prog_load+0x435/0x1cc0 kernel/bpf/syscall.c:1482
  __do_sys_bpf kernel/bpf/syscall.c:2504 [inline]
  __se_sys_bpf kernel/bpf/syscall.c:2466 [inline]
  __x64_sys_bpf+0x36c/0x520 kernel/bpf/syscall.c:2466
  do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290
  entry_SYSCALL_64_after_hwframe+0x49/0xbe

Freed by task 17:
  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
  __bpf_prog_free kernel/bpf/core.c:146 [inline]
  bpf_prog_unlock_free include/linux/filter.h:743 [inline]
  bpf_prog_free_deferred+0x2a4/0x420 kernel/bpf/core.c:1781
  process_one_work+0xc90/0x1c40 kernel/workqueue.c:2153
  worker_thread+0x17f/0x1390 kernel/workqueue.c:2296
  kthread+0x35a/0x440 kernel/kthread.c:246
  ret_from_fork+0x3a/0x50 arch/x86/entry/entry_64.S:352

The buggy address belongs to the object at ffff8881b97b8500
  which belongs to the cache kmalloc-512 of size 512
The buggy address is located 96 bytes inside of
  512-byte region [ffff8881b97b8500, ffff8881b97b8700)
The buggy address belongs to the page:
page:ffffea0006e5ee00 count:1 mapcount:0 mapping:ffff8881da800940  
index:0xffff8881b97b8a00
flags: 0x2fffc0000000200(slab)
raw: 02fffc0000000200 ffffea0006ede848 ffffea0006e6b508 ffff8881da800940
raw: ffff8881b97b8a00 ffff8881b97b8000 0000000100000005 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
  ffff8881b97b8400: 00 00 fc fc fc fc fc fc fc fc fc fc fc fc fc fc
  ffff8881b97b8480: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
> ffff8881b97b8500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                                        ^
  ffff8881b97b8580: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
  ffff8881b97b8600: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================