syzbot


KASAN: use-after-free Read in bpf_tcp_close

Status: fixed on 2018/07/09 18:05
Subsystems: bpf
[Documentation on labels]
Reported-by: syzbot+fce8f2462c403d02af98@syzkaller.appspotmail.com
Fix commit: e9db4ef6bf4c bpf: sockhash fix omitted bucket lock in sock_close
First crash: 2189d, last: 2146d
Discussions (2)
Title Replies (including bot) Last reply
KASAN: use-after-free Read in bpf_tcp_close 2 (3) 2018/07/02 18:56
[bpf-next PATCH] bpf: sockhash fix race with bpf_tcp_close and map delete 7 (7) 2018/05/28 15:48
Similar bugs (1)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KASAN: use-after-free Read in bpf_tcp_close (2) bpf 4 2064d 2082d 0/26 auto-closed as invalid on 2019/03/23 04:55

Sample crash report:
==================================================================
BUG: KASAN: use-after-free in hlist_del_rcu include/linux/rculist.h:427 [inline]
BUG: KASAN: use-after-free in bpf_tcp_close+0xd7f/0xf80 kernel/bpf/sockmap.c:271
Read of size 8 at addr ffff8801acbaa010 by task syz-executor623/4777

CPU: 1 PID: 4777 Comm: syz-executor623 Not tainted 4.17.0-rc6+ #28
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+0x1b9/0x294 lib/dump_stack.c:113
 print_address_description+0x6c/0x20b mm/kasan/report.c:256
 kasan_report_error mm/kasan/report.c:354 [inline]
 kasan_report.cold.7+0x242/0x2fe mm/kasan/report.c:412
 __asan_report_load8_noabort+0x14/0x20 mm/kasan/report.c:433
 hlist_del_rcu include/linux/rculist.h:427 [inline]
 bpf_tcp_close+0xd7f/0xf80 kernel/bpf/sockmap.c:271
 inet_release+0x104/0x1f0 net/ipv4/af_inet.c:427
 inet6_release+0x50/0x70 net/ipv6/af_inet6.c:459
 sock_release+0x96/0x1b0 net/socket.c:594
 sock_close+0x16/0x20 net/socket.c:1149
 __fput+0x34d/0x890 fs/file_table.c:209
 ____fput+0x15/0x20 fs/file_table.c:243
 task_work_run+0x1e4/0x290 kernel/task_work.c:113
 exit_task_work include/linux/task_work.h:22 [inline]
 do_exit+0x1aee/0x2730 kernel/exit.c:865
 do_group_exit+0x16f/0x430 kernel/exit.c:968
 __do_sys_exit_group kernel/exit.c:979 [inline]
 __se_sys_exit_group kernel/exit.c:977 [inline]
 __x64_sys_exit_group+0x3e/0x50 kernel/exit.c:977
 do_syscall_64+0x1b1/0x800 arch/x86/entry/common.c:287
 entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x442459
RSP: 002b:00007ffe00ae0328 EFLAGS: 00000206 ORIG_RAX: 00000000000000e7
RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 0000000000442459
RDX: 0000000000442459 RSI: 0000000000000014 RDI: 0000000000000000
RBP: 0000000000000000 R08: 0000000000000011 R09: 0000000000000000
R10: 0000000000000011 R11: 0000000000000206 R12: 0000000000007d6f
R13: 00000000006ce448 R14: 0000000000000000 R15: 0000000000000000

Allocated by task 4777:
 save_stack+0x43/0xd0 mm/kasan/kasan.c:448
 set_track mm/kasan/kasan.c:460 [inline]
 kasan_kmalloc+0xc4/0xe0 mm/kasan/kasan.c:553
 __do_kmalloc_node mm/slab.c:3682 [inline]
 __kmalloc_node+0x47/0x70 mm/slab.c:3689
 kmalloc_node include/linux/slab.h:554 [inline]
 alloc_sock_hash_elem kernel/bpf/sockmap.c:2114 [inline]
 sock_hash_ctx_update_elem.isra.23+0xa57/0x1560 kernel/bpf/sockmap.c:2245
 sock_hash_update_elem+0x14f/0x2d0 kernel/bpf/sockmap.c:2303
 map_update_elem+0x5c4/0xc90 kernel/bpf/syscall.c:763
 __do_sys_bpf kernel/bpf/syscall.c:2353 [inline]
 __se_sys_bpf kernel/bpf/syscall.c:2324 [inline]
 __x64_sys_bpf+0x32d/0x510 kernel/bpf/syscall.c:2324
 do_syscall_64+0x1b1/0x800 arch/x86/entry/common.c:287
 entry_SYSCALL_64_after_hwframe+0x49/0xbe

Freed by task 18:
 save_stack+0x43/0xd0 mm/kasan/kasan.c:448
 set_track mm/kasan/kasan.c:460 [inline]
 __kasan_slab_free+0x11a/0x170 mm/kasan/kasan.c:521
 kasan_slab_free+0xe/0x10 mm/kasan/kasan.c:528
 __cache_free mm/slab.c:3498 [inline]
 kfree+0xd9/0x260 mm/slab.c:3813
 sock_hash_free+0x24e/0x6e0 kernel/bpf/sockmap.c:2093
 bpf_map_free_deferred+0xba/0xf0 kernel/bpf/syscall.c:262
 process_one_work+0xc1e/0x1b50 kernel/workqueue.c:2145
 worker_thread+0x1cc/0x1440 kernel/workqueue.c:2279
 kthread+0x345/0x410 kernel/kthread.c:240
 ret_from_fork+0x3a/0x50 arch/x86/entry/entry_64.S:412

The buggy address belongs to the object at ffff8801acbaa000
 which belongs to the cache kmalloc-64 of size 64
The buggy address is located 16 bytes inside of
 64-byte region [ffff8801acbaa000, ffff8801acbaa040)
The buggy address belongs to the page:
page:ffffea0006b2ea80 count:1 mapcount:0 mapping:ffff8801acbaa000 index:0x0
flags: 0x2fffc0000000100(slab)
raw: 02fffc0000000100 ffff8801acbaa000 0000000000000000 0000000100000020
raw: ffffea00075ecae0 ffffea0007616860 ffff8801da800340 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
 ffff8801acba9f00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff8801acba9f80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff8801acbaa000: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
                         ^
 ffff8801acbaa080: 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc fc
 ffff8801acbaa100: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
==================================================================

Crashes (1748):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2018/05/30 18:03 bpf-next 13a370b9d275 2f93b54f .config console log report syz C ci-upstream-bpf-next-kasan-gce
2018/05/29 16:19 bpf-next f198222f0567 e276de77 .config console log report syz C ci-upstream-bpf-next-kasan-gce
2018/05/25 10:44 bpf-next 10f678683e40 f48c20b8 .config console log report syz C ci-upstream-bpf-next-kasan-gce
2018/05/23 08:56 bpf-next 3fb48d881dbe f48c20b8 .config console log report syz C ci-upstream-bpf-next-kasan-gce
2018/06/28 09:53 upstream f57494321cbf dba0b50e .config console log report syz ci-upstream-kasan-gce-root
2018/06/28 09:29 bpf-next a7f7547f5e2b dba0b50e .config console log report syz ci-upstream-bpf-next-kasan-gce
2018/07/04 06:40 bpf-next 0b9e3d543f9f 317fc8ea .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/04 05:32 bpf-next 0b9e3d543f9f 317fc8ea .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/04 05:27 bpf-next 0b9e3d543f9f 317fc8ea .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/04 04:17 bpf-next 0b9e3d543f9f 317fc8ea .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/04 03:16 bpf-next 0b9e3d543f9f 317fc8ea .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/04 02:16 bpf-next 0b9e3d543f9f 317fc8ea .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/04 01:05 bpf-next 0b9e3d543f9f 317fc8ea .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/03 22:03 bpf-next 0b9e3d543f9f 317fc8ea .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/03 21:03 bpf-next 0b9e3d543f9f 317fc8ea .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/03 19:56 bpf-next 0b9e3d543f9f 317fc8ea .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/03 18:54 bpf-next 0b9e3d543f9f 317fc8ea .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/03 17:52 bpf-next 0b9e3d543f9f 317fc8ea .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/03 16:04 bpf-next 0b9e3d543f9f 317fc8ea .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/03 14:03 bpf-next 0b9e3d543f9f 317fc8ea .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/03 13:59 bpf-next 0b9e3d543f9f 317fc8ea .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/03 12:22 bpf-next 0b9e3d543f9f 317fc8ea .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/03 11:17 bpf-next 0b9e3d543f9f 317fc8ea .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/03 10:14 bpf-next 0b9e3d543f9f 317fc8ea .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/03 08:41 bpf-next 0b9e3d543f9f 317fc8ea .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/03 08:07 bpf-next 0b9e3d543f9f 317fc8ea .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/03 06:59 bpf-next 0b9e3d543f9f 317fc8ea .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/03 05:29 bpf-next 0b9e3d543f9f 317fc8ea .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/03 04:21 bpf-next 0b9e3d543f9f 317fc8ea .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/03 03:23 bpf-next 0b9e3d543f9f 317fc8ea .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/03 01:51 bpf-next 0b9e3d543f9f 574780b0 .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/03 00:46 bpf-next 0b9e3d543f9f 574780b0 .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/02 23:38 bpf-next 0b9e3d543f9f 574780b0 .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/02 23:23 bpf-next 0b9e3d543f9f 574780b0 .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/02 21:22 bpf-next 0b9e3d543f9f 574780b0 .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/02 18:52 bpf-next 0b9e3d543f9f 574780b0 .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/02 17:37 bpf-next 0b9e3d543f9f 574780b0 .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/02 15:48 bpf-next 0b9e3d543f9f 574780b0 .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/02 15:07 bpf-next 0b9e3d543f9f 574780b0 .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/02 13:47 bpf-next 0b9e3d543f9f dba0b50e .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/02 12:46 bpf-next 0b9e3d543f9f dba0b50e .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/02 11:30 bpf-next 0b9e3d543f9f dba0b50e .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/02 10:14 bpf-next 0b9e3d543f9f dba0b50e .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/02 09:07 bpf-next 0b9e3d543f9f dba0b50e .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/02 08:43 bpf-next 0b9e3d543f9f dba0b50e .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/02 07:14 bpf-next 0b9e3d543f9f dba0b50e .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/02 05:45 bpf-next 0b9e3d543f9f dba0b50e .config console log report ci-upstream-bpf-next-kasan-gce
2018/05/22 22:42 bpf-next 3fb48d881dbe f48c20b8 .config console log report ci-upstream-bpf-next-kasan-gce
* Struck through repros no longer work on HEAD.