syzbot


KASAN: use-after-free Write in bpf_tcp_close

Status: fixed on 2018/07/09 18:05
Subsystems: bpf
[Documentation on labels]
Reported-by: syzbot+31025a5f3f7650081204@syzkaller.appspotmail.com
Fix commit: e9db4ef6bf4c bpf: sockhash fix omitted bucket lock in sock_close
First crash: 2192d, last: 2152d
Discussions (1)
Title Replies (including bot) Last reply
KASAN: use-after-free Write in bpf_tcp_close 4 (5) 2018/07/02 18:55

Sample crash report:
==================================================================
BUG: KASAN: use-after-free in cmpxchg_size include/asm-generic/atomic-instrumented.h:355 [inline]
BUG: KASAN: use-after-free in bpf_tcp_close+0x6f5/0xf80 kernel/bpf/sockmap.c:265
Write of size 8 at addr ffff8801ca277680 by task syz-executor749/9723

CPU: 0 PID: 9723 Comm: syz-executor749 Not tainted 4.17.0-rc4+ #19
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
 check_memory_region_inline mm/kasan/kasan.c:260 [inline]
 check_memory_region+0x13e/0x1b0 mm/kasan/kasan.c:267
 kasan_check_write+0x14/0x20 mm/kasan/kasan.c:278
 cmpxchg_size include/asm-generic/atomic-instrumented.h:355 [inline]
 bpf_tcp_close+0x6f5/0xf80 kernel/bpf/sockmap.c:265
 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:0x440a59
RSP: 002b:00007ffdadf92488 EFLAGS: 00000206 ORIG_RAX: 00000000000000e7
RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 0000000000440a59
RDX: 0000000000440a59 RSI: 0000000000000020 RDI: 0000000000000000
RBP: 0000000000000000 R08: 00000000004002c8 R09: 0000000000401ea0
R10: 00000000004002c8 R11: 0000000000000206 R12: 000000000001b5ac
R13: 0000000000401ea0 R14: 0000000000000000 R15: 0000000000000000

Allocated by task 9723:
 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]
 bpf_map_area_alloc+0x3f/0x90 kernel/bpf/syscall.c:144
 sock_map_alloc+0x376/0x410 kernel/bpf/sockmap.c:1555
 find_and_alloc_map kernel/bpf/syscall.c:126 [inline]
 map_create+0x393/0x1010 kernel/bpf/syscall.c:448
 __do_sys_bpf kernel/bpf/syscall.c:2128 [inline]
 __se_sys_bpf kernel/bpf/syscall.c:2105 [inline]
 __x64_sys_bpf+0x300/0x4f0 kernel/bpf/syscall.c:2105
 do_syscall_64+0x1b1/0x800 arch/x86/entry/common.c:287
 entry_SYSCALL_64_after_hwframe+0x49/0xbe

Freed by task 4521:
 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
 kvfree+0x61/0x70 mm/util.c:440
 bpf_map_area_free+0x15/0x20 kernel/bpf/syscall.c:155
 sock_map_remove_complete kernel/bpf/sockmap.c:1443 [inline]
 sock_map_free+0x408/0x540 kernel/bpf/sockmap.c:1619
 bpf_map_free_deferred+0xba/0xf0 kernel/bpf/syscall.c:259
 process_one_work+0xc1e/0x1b50 kernel/workqueue.c:2145
 worker_thread+0x1cc/0x1440 kernel/workqueue.c:2279
 kthread+0x345/0x410 kernel/kthread.c:238
 ret_from_fork+0x3a/0x50 arch/x86/entry/entry_64.S:412

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

Memory state around the buggy address:
 ffff8801ca277580: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff8801ca277600: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff8801ca277680: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                   ^
 ffff8801ca277700: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff8801ca277780: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Crashes (67):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2018/05/23 19:43 bpf-next ff4fb475cea8 f48c20b8 .config console log report syz C ci-upstream-bpf-next-kasan-gce
2018/06/27 14:51 upstream 813835028e9a 43e60f7e .config console log report ci-upstream-kasan-gce-root
2018/06/21 20:43 upstream 1abd8a8f39cd 095ef806 .config console log report ci-upstream-kasan-gce-root
2018/07/02 13:10 bpf-next 0b9e3d543f9f dba0b50e .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/02 08:33 bpf-next 0b9e3d543f9f dba0b50e .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/01 20:11 bpf-next 0b9e3d543f9f dba0b50e .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/01 17:31 bpf-next 0b9e3d543f9f dba0b50e .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/01 11:41 bpf-next 0b9e3d543f9f dba0b50e .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/01 03:59 bpf-next 0b9e3d543f9f dba0b50e .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/01 01:41 bpf-next 0b9e3d543f9f dba0b50e .config console log report ci-upstream-bpf-next-kasan-gce
2018/07/01 00:04 bpf-next 0b9e3d543f9f dba0b50e .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/29 22:56 bpf-next 509fda105ba8 dba0b50e .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/28 13:58 bpf-next a7f7547f5e2b dba0b50e .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/28 10:17 bpf-next a7f7547f5e2b dba0b50e .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/27 17:51 bpf-next cc0dff6dc3b4 43e60f7e .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/27 06:48 bpf-next 651b4513bdd2 b0294c53 .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/27 04:44 bpf-next 651b4513bdd2 b0294c53 .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/26 20:55 bpf-next 651b4513bdd2 b0294c53 .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/26 14:35 bpf-next 651b4513bdd2 089f1181 .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/26 08:39 bpf-next f0dc7f9c6dd9 2064fc5c .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/26 07:38 bpf-next f0dc7f9c6dd9 2064fc5c .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/26 04:31 bpf-next f0dc7f9c6dd9 2064fc5c .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/25 13:50 bpf-next f0dc7f9c6dd9 2064fc5c .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/25 05:40 bpf-next f0dc7f9c6dd9 2064fc5c .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/25 01:39 bpf-next f0dc7f9c6dd9 2064fc5c .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/24 23:46 bpf-next f0dc7f9c6dd9 2064fc5c .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/24 21:36 bpf-next f0dc7f9c6dd9 2064fc5c .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/24 15:45 bpf-next f0dc7f9c6dd9 2064fc5c .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/24 14:33 bpf-next f0dc7f9c6dd9 2064fc5c .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/24 13:47 bpf-next f0dc7f9c6dd9 2064fc5c .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/24 11:13 bpf-next f0dc7f9c6dd9 2064fc5c .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/24 02:07 bpf-next f0dc7f9c6dd9 2064fc5c .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/23 17:12 bpf-next f0dc7f9c6dd9 2064fc5c .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/23 16:47 bpf-next f0dc7f9c6dd9 2064fc5c .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/23 16:25 bpf-next f0dc7f9c6dd9 2064fc5c .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/23 16:20 bpf-next f0dc7f9c6dd9 2064fc5c .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/23 05:50 bpf-next f0dc7f9c6dd9 89d2e600 .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/23 05:42 bpf-next f0dc7f9c6dd9 89d2e600 .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/23 02:40 bpf-next f0dc7f9c6dd9 c97f0d7a .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/23 01:01 bpf-next f0dc7f9c6dd9 c97f0d7a .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/22 22:55 bpf-next f0dc7f9c6dd9 c97f0d7a .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/22 22:07 bpf-next f0dc7f9c6dd9 c97f0d7a .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/22 19:05 bpf-next f0dc7f9c6dd9 c97f0d7a .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/22 17:18 bpf-next f0dc7f9c6dd9 c97f0d7a .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/20 07:58 bpf-next f0dc7f9c6dd9 095ef806 .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/19 10:49 bpf-next f0dc7f9c6dd9 732e4256 .config console log report ci-upstream-bpf-next-kasan-gce
2018/06/19 10:24 bpf-next f0dc7f9c6dd9 45c54f75 .config console log report ci-upstream-bpf-next-kasan-gce
* Struck through repros no longer work on HEAD.