syzbot


KASAN: use-after-free Read in psock_map_pop

Status: fixed on 2019/10/04 12:05
Subsystems: bpf
[Documentation on labels]
Reported-by: syzbot+5bbe234204453085d43e@syzkaller.appspotmail.com
Fix commit: 5607fff30363 bpf: sockmap only allow ESTABLISHED sock state
First crash: 2080d, last: 2034d
Fix bisection: fixed by (bisect log) :
commit 5607fff303636d48b88414c6be353d9fed700af2
Author: John Fastabend <john.fastabend@gmail.com>
Date: Tue Sep 18 16:01:44 2018 +0000

  bpf: sockmap only allow ESTABLISHED sock state

  
Discussions (3)
Title Replies (including bot) Last reply
Reminder: 36 open syzbot bugs in "net/bpf" subsystem 1 (1) 2019/07/03 06:01
Reminder: 30 open syzbot bugs in "net/bpf" subsystem 1 (1) 2019/06/24 05:01
KASAN: use-after-free Read in psock_map_pop 0 (1) 2018/09/10 08:31
Similar bugs (1)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
linux-4.19 KASAN: use-after-free Read in psock_map_pop C unreliable 275 441d 1827d 0/1 upstream: reported C repro on 2019/05/18 22:40

Sample crash report:
==================================================================
BUG: KASAN: use-after-free in __lock_acquire+0x37c2/0x4ec0 kernel/locking/lockdep.c:3291
Read of size 8 at addr ffff8801be270b88 by task syz-executor843/16792

CPU: 0 PID: 16792 Comm: syz-executor843 Not tainted 4.19.0-rc2+ #51
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+0x1c4/0x2b4 lib/dump_stack.c:113
 print_address_description.cold.8+0x9/0x1ff mm/kasan/report.c:256
 kasan_report_error mm/kasan/report.c:354 [inline]
 kasan_report.cold.9+0x242/0x309 mm/kasan/report.c:412
 __asan_report_load8_noabort+0x14/0x20 mm/kasan/report.c:433
 __lock_acquire+0x37c2/0x4ec0 kernel/locking/lockdep.c:3291
 lock_acquire+0x1ed/0x520 kernel/locking/lockdep.c:3901
 __raw_spin_lock_bh include/linux/spinlock_api_smp.h:135 [inline]
 _raw_spin_lock_bh+0x31/0x40 kernel/locking/spinlock.c:168
 spin_lock_bh include/linux/spinlock.h:334 [inline]
 psock_map_pop.isra.22+0x93/0x3b0 kernel/bpf/sockmap.c:298
 bpf_tcp_close+0x6ca/0x10c0 kernel/bpf/sockmap.c:380
 inet_release+0x104/0x1f0 net/ipv4/af_inet.c:428
 inet6_release+0x50/0x70 net/ipv6/af_inet6.c:457
 __sock_release+0xd7/0x250 net/socket.c:579
 sock_close+0x19/0x20 net/socket.c:1139
 __fput+0x385/0xa30 fs/file_table.c:278
 ____fput+0x15/0x20 fs/file_table.c:309
 task_work_run+0x1e8/0x2a0 kernel/task_work.c:113
 tracehook_notify_resume include/linux/tracehook.h:193 [inline]
 exit_to_usermode_loop+0x318/0x380 arch/x86/entry/common.c:166
 prepare_exit_to_usermode arch/x86/entry/common.c:197 [inline]
 syscall_return_slowpath arch/x86/entry/common.c:268 [inline]
 do_syscall_64+0x6be/0x820 arch/x86/entry/common.c:293
 entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x4063c1
Code: 75 14 b8 03 00 00 00 0f 05 48 3d 01 f0 ff ff 0f 83 b4 17 00 00 c3 48 83 ec 08 e8 0a fc ff ff 48 89 04 24 b8 03 00 00 00 0f 05 <48> 8b 3c 24 48 89 c2 e8 53 fc ff ff 48 89 d0 48 83 c4 08 48 3d 01
RSP: 002b:00007ffdfa87cf10 EFLAGS: 00000293 ORIG_RAX: 0000000000000003
RAX: 0000000000000000 RBX: 0000000000000003 RCX: 00000000004063c1
RDX: 0000000000000000 RSI: 0000000000000080 RDI: 0000000000000003
RBP: 00000000006ddc30 R08: 00000000006ddc30 R09: 0000000000406c00
R10: 00007ffdfa87cf30 R11: 0000000000000293 R12: 00000000006ddc3c
R13: 00000000000003e8 R14: 0000000000000004 R15: 000000000000002d

Allocated by task 16796:
 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_node_trace+0x14c/0x740 mm/slab.c:3663
 kmalloc_node include/linux/slab.h:551 [inline]
 kzalloc_node include/linux/slab.h:718 [inline]
 smap_init_psock kernel/bpf/sockmap.c:1614 [inline]
 __sock_map_ctx_update_elem.isra.23+0x7a9/0x12f0 kernel/bpf/sockmap.c:1918
 sock_map_ctx_update_elem.isra.24+0x1a3/0xbe0 kernel/bpf/sockmap.c:1983
 sock_map_update_elem+0x22a/0x5a0 kernel/bpf/sockmap.c:2109
 map_update_elem+0x753/0xd50 kernel/bpf/syscall.c:799
 __do_sys_bpf kernel/bpf/syscall.c:2363 [inline]
 __se_sys_bpf kernel/bpf/syscall.c:2334 [inline]
 __x64_sys_bpf+0x32d/0x510 kernel/bpf/syscall.c:2334
 do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290
 entry_SYSCALL_64_after_hwframe+0x49/0xbe

Freed by task 14:
 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:3813
 smap_gc_work+0x910/0xc70 kernel/bpf/sockmap.c:1607
 process_one_work+0xc90/0x1b90 kernel/workqueue.c:2153
 worker_thread+0x17f/0x1390 kernel/workqueue.c:2296
 kthread+0x35a/0x420 kernel/kthread.c:246
 ret_from_fork+0x3a/0x50 arch/x86/entry/entry_64.S:413

The buggy address belongs to the object at ffff8801be270940
 which belongs to the cache kmalloc-1024 of size 1024
The buggy address is located 584 bytes inside of
 1024-byte region [ffff8801be270940, ffff8801be270d40)
The buggy address belongs to the page:
page:ffffea0006f89c00 count:1 mapcount:0 mapping:ffff8801da800ac0 index:0x0 compound_mapcount: 0
flags: 0x2fffc0000008100(slab|head)
raw: 02fffc0000008100 ffffea0006fa1408 ffffea0006f8ea08 ffff8801da800ac0
raw: 0000000000000000 ffff8801be270040 0000000100000007 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
 ffff8801be270a80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff8801be270b00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff8801be270b80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                      ^
 ffff8801be270c00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff8801be270c80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Crashes (204):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2018/09/08 06:12 bpf 28619527b8a7 6b5120a4 .config console log report syz C ci-upstream-bpf-kasan-gce
2018/09/08 06:13 net-next-old 98cdb4807123 6b5120a4 .config console log report syz C ci-upstream-net-kasan-gce
2018/09/08 05:44 bpf-next f6f3bac08ff9 6b5120a4 .config console log report syz C ci-upstream-bpf-next-kasan-gce
2018/09/09 17:30 upstream f8f65382c98a 6b5120a4 .config console log report syz ci-upstream-kasan-gce-smack-root
2018/09/09 14:24 upstream f8f65382c98a 6b5120a4 .config console log report syz ci-upstream-kasan-gce-root
2018/09/08 06:02 net-old f74dd480cf4e 6b5120a4 .config console log report syz ci-upstream-net-this-kasan-gce
2018/10/23 12:35 upstream 58a022870787 24fa2ad8 .config console log report ci-upstream-kasan-gce-smack-root
2018/10/23 03:20 upstream ca9eb48fe01f ecb386fe .config console log report ci-upstream-kasan-gce-selinux-root
2018/10/22 19:55 upstream 84df9525b0c2 ecb386fe .config console log report ci-upstream-kasan-gce-root
2018/10/22 05:22 upstream 467e050e9760 ecb386fe .config console log report ci-upstream-kasan-gce-smack-root
2018/10/20 17:52 upstream 270b77a0f30e ecb386fe .config console log report ci-upstream-kasan-gce-selinux-root
2018/10/20 09:29 upstream 270b77a0f30e ecb386fe .config console log report ci-upstream-kasan-gce-selinux-root
2018/10/18 20:12 upstream fa520c47eaa1 9aba67b5 .config console log report ci-upstream-kasan-gce-smack-root
2018/10/18 14:46 upstream 9bd871df56a7 d257b2d2 .config console log report ci-upstream-kasan-gce-smack-root
2018/10/18 09:01 upstream 9bd871df56a7 d257b2d2 .config console log report ci-upstream-kasan-gce-root
2018/10/16 11:41 upstream f0a7d1883d9f 8cd30605 .config console log report ci-upstream-kasan-gce-root
2018/10/14 07:17 upstream 7ec21823634d caf12900 .config console log report ci-upstream-kasan-gce-root
2018/10/04 05:39 upstream cec4de302c5f 8b311eaf .config console log report ci-upstream-kasan-gce-smack-root
2018/10/03 14:34 upstream 6bebe37927f3 8b311eaf .config console log report ci-upstream-kasan-gce-smack-root
2018/09/30 17:12 upstream 291d0e5d81e1 41e4b329 .config console log report ci-upstream-kasan-gce-selinux-root
2018/09/24 15:03 upstream 02214bfc89c7 2f485cdf .config console log report ci-upstream-kasan-gce-smack-root
2018/09/24 11:48 upstream 6bf4ca7fbc85 2f485cdf .config console log report ci-upstream-kasan-gce-smack-root
2018/09/24 07:23 upstream 6bf4ca7fbc85 28d9ac76 .config console log report ci-upstream-kasan-gce-smack-root
2018/09/23 07:22 upstream 328c6333ba3d 37079712 .config console log report ci-upstream-kasan-gce-root
2018/09/23 00:28 upstream 10dc890d4228 37079712 .config console log report ci-upstream-kasan-gce-selinux-root
2018/09/22 23:21 upstream 10dc890d4228 37079712 .config console log report ci-upstream-kasan-gce-smack-root
2018/09/22 21:59 upstream 10dc890d4228 37079712 .config console log report ci-upstream-kasan-gce-smack-root
2018/09/22 14:40 upstream 10dc890d4228 37079712 .config console log report ci-upstream-kasan-gce-selinux-root
2018/10/12 02:24 net-old 26450608348e ba6ddb43 .config console log report ci-upstream-net-this-kasan-gce
2018/10/03 12:35 net-old 45ec318578c0 0f3e0261 .config console log report ci-upstream-net-this-kasan-gce
2018/09/24 22:10 net-old d26ed6b0e5e2 2f485cdf .config console log report ci-upstream-net-this-kasan-gce
2018/09/22 10:41 net-old 8ac1ee6f4d62 37079712 .config console log report ci-upstream-net-this-kasan-gce
2018/09/19 18:27 bpf 4c3d795cb012 7f125108 .config console log report ci-upstream-bpf-kasan-gce
2018/10/04 14:40 net-next-old 7bdaae270cb5 8b311eaf .config console log report ci-upstream-net-kasan-gce
2018/10/01 17:58 net-next-old 804fe108fc92 48a50c6b .config console log report ci-upstream-net-kasan-gce
2018/10/01 09:56 net-next-old 804fe108fc92 48a50c6b .config console log report ci-upstream-net-kasan-gce
2018/09/28 07:19 net-next-old 1042caa79e93 0c2fa87b .config console log report ci-upstream-net-kasan-gce
2018/09/26 10:33 bpf-next d0e13a1488ad 455b6354 .config console log report ci-upstream-bpf-next-kasan-gce
2018/09/26 03:25 bpf-next d0e13a1488ad b7e11289 .config console log report ci-upstream-bpf-next-kasan-gce
2018/09/25 17:02 bpf-next d0e13a1488ad 0e7547d7 .config console log report ci-upstream-bpf-next-kasan-gce
2018/09/25 14:57 bpf-next 788758d1fe87 0e7547d7 .config console log report ci-upstream-bpf-next-kasan-gce
2018/09/25 09:25 bpf-next 788758d1fe87 0e7547d7 .config console log report ci-upstream-bpf-next-kasan-gce
2018/09/24 02:17 bpf-next 788758d1fe87 28d9ac76 .config console log report ci-upstream-bpf-next-kasan-gce
2018/09/23 23:52 bpf-next 788758d1fe87 28d9ac76 .config console log report ci-upstream-bpf-next-kasan-gce
2018/09/23 22:37 bpf-next 788758d1fe87 28d9ac76 .config console log report ci-upstream-bpf-next-kasan-gce
2018/09/23 12:45 bpf-next 788758d1fe87 37079712 .config console log report ci-upstream-bpf-next-kasan-gce
2018/09/23 11:07 net-next-old 739d0def85ca 37079712 .config console log report ci-upstream-net-kasan-gce
2018/09/22 17:20 bpf-next 788758d1fe87 37079712 .config console log report ci-upstream-bpf-next-kasan-gce
* Struck through repros no longer work on HEAD.