syzbot


KASAN: use-after-free Read in refcount_sub_and_test_checked

Status: fixed on 2018/08/08 18:10
Subsystems: net
[Documentation on labels]
Fix commit: e6aed040eafb Revert "net/ipv6: fix metrics leak"
First crash: 2087d, last: 2086d
Similar bugs (1)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KASAN: use-after-free Read in refcount_sub_and_test_checked (2) perf syz done error 10 1527d 1933d 0/26 upstream: reported syz repro on 2019/01/02 11:26

Sample crash report:
IPVS: ftp: loaded support on port[0] = 21
==================================================================
BUG: KASAN: use-after-free in atomic_read include/asm-generic/atomic-instrumented.h:21 [inline]
BUG: KASAN: use-after-free in refcount_sub_and_test_checked+0x9a/0x350 lib/refcount.c:179
Read of size 4 at addr ffff8801c45627c4 by task syz-executor1/17999

CPU: 1 PID: 17999 Comm: syz-executor1 Not tainted 4.18.0-rc7-next-20180802+ #30
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+0x1c9/0x2b4 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/0x30d 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_read+0x11/0x20 mm/kasan/kasan.c:272
 atomic_read include/asm-generic/atomic-instrumented.h:21 [inline]
 refcount_sub_and_test_checked+0x9a/0x350 lib/refcount.c:179
 refcount_dec_and_test_checked+0x1a/0x20 lib/refcount.c:212
 fib6_metrics_release+0x4f/0x90 net/ipv6/ip6_fib.c:178
 fib6_drop_pcpu_from net/ipv6/ip6_fib.c:899 [inline]
 fib6_purge_rt+0x5ec/0x7f0 net/ipv6/ip6_fib.c:934
 fib6_del_route net/ipv6/ip6_fib.c:1784 [inline]
 fib6_del+0xc11/0x1310 net/ipv6/ip6_fib.c:1815
 fib6_clean_node+0x3ee/0x5e0 net/ipv6/ip6_fib.c:1976
 fib6_walk_continue+0x4b1/0x8e0 net/ipv6/ip6_fib.c:1899
 fib6_walk+0x95/0xf0 net/ipv6/ip6_fib.c:1947
 fib6_clean_tree+0x1ea/0x360 net/ipv6/ip6_fib.c:2024
 __fib6_clean_all+0x21c/0x420 net/ipv6/ip6_fib.c:2040
 fib6_clean_all net/ipv6/ip6_fib.c:2051 [inline]
 fib6_run_gc+0x182/0x3d0 net/ipv6/ip6_fib.c:2107
 ndisc_netdev_event+0x4ab/0x580 net/ipv6/ndisc.c:1790
 notifier_call_chain+0x180/0x390 kernel/notifier.c:93
 __raw_notifier_call_chain kernel/notifier.c:394 [inline]
 raw_notifier_call_chain+0x2d/0x40 kernel/notifier.c:401
 call_netdevice_notifiers_info+0x3f/0x90 net/core/dev.c:1734
 call_netdevice_notifiers net/core/dev.c:1752 [inline]
 dev_close_many+0x447/0x8d0 net/core/dev.c:1504
 rollback_registered_many+0x539/0x1250 net/core/dev.c:7919
 rollback_registered+0x1e9/0x420 net/core/dev.c:7984
 unregister_netdevice_queue+0x32f/0x660 net/core/dev.c:9028
 unregister_netdevice include/linux/netdevice.h:2589 [inline]
 __tun_detach+0x11d1/0x15e0 drivers/net/tun.c:728
 tun_detach drivers/net/tun.c:745 [inline]
 tun_chr_close+0xe3/0x180 drivers/net/tun.c:3271
 __fput+0x376/0x8a0 fs/file_table.c:279
 ____fput+0x15/0x20 fs/file_table.c:312
 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:0x4106e1
Code: 75 14 b8 03 00 00 00 0f 05 48 3d 01 f0 ff ff 0f 83 34 19 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:00007ffee29fec50 EFLAGS: 00000293 ORIG_RAX: 0000000000000003
RAX: 0000000000000000 RBX: 0000000000000016 RCX: 00000000004106e1
RDX: 0000000000000000 RSI: 0000000000730ab0 RDI: 0000000000000015
RBP: 0000000000000010 R08: 00000000000000a0 R09: ffffffffffffffff
R10: 0000000000930140 R11: 0000000000000293 R12: 0000000000000000
IPVS: ftp: loaded support on port[0] = 21
R13: 000000000003acb7 R14: 000000000000010c R15: badc0ffeebadface

Allocated by task 15965:
 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
 kmem_cache_alloc_trace+0x152/0x780 mm/slab.c:3620
 kmalloc include/linux/slab.h:513 [inline]
 kzalloc include/linux/slab.h:707 [inline]
 fib6_metric_set+0x163/0x2c0 net/ipv6/ip6_fib.c:645
 fib6_add_rt2node+0xe36/0x27f0 net/ipv6/ip6_fib.c:1000
 fib6_add+0xaae/0x14d0 net/ipv6/ip6_fib.c:1308
 __ip6_ins_rt+0x54/0x80 net/ipv6/route.c:1163
 ip6_route_add+0x6d/0xc0 net/ipv6/route.c:3171
 addrconf_prefix_route.isra.48+0x51d/0x720 net/ipv6/addrconf.c:2345
 inet6_addr_modify net/ipv6/addrconf.c:4625 [inline]
 inet6_rtm_newaddr+0x112e/0x1b50 net/ipv6/addrconf.c:4741
 rtnetlink_rcv_msg+0x46e/0xc30 net/core/rtnetlink.c:4711
 netlink_rcv_skb+0x172/0x440 net/netlink/af_netlink.c:2454
 rtnetlink_rcv+0x1c/0x20 net/core/rtnetlink.c:4729
 netlink_unicast_kernel net/netlink/af_netlink.c:1317 [inline]
 netlink_unicast+0x5a0/0x760 net/netlink/af_netlink.c:1343
 netlink_sendmsg+0xa18/0xfc0 net/netlink/af_netlink.c:1908
 sock_sendmsg_nosec net/socket.c:622 [inline]
 sock_sendmsg+0xd5/0x120 net/socket.c:632
 ___sys_sendmsg+0x7fd/0x930 net/socket.c:2115
 __sys_sendmsg+0x11d/0x290 net/socket.c:2153
 __do_sys_sendmsg net/socket.c:2162 [inline]
 __se_sys_sendmsg net/socket.c:2160 [inline]
 __x64_sys_sendmsg+0x78/0xb0 net/socket.c:2160
 do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290
 entry_SYSCALL_64_after_hwframe+0x49/0xbe

Freed by task 17999:
 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
 fib6_metrics_release+0x77/0x90 net/ipv6/ip6_fib.c:179
 fib6_drop_pcpu_from net/ipv6/ip6_fib.c:899 [inline]
 fib6_purge_rt+0x5ec/0x7f0 net/ipv6/ip6_fib.c:934
 fib6_del_route net/ipv6/ip6_fib.c:1784 [inline]
 fib6_del+0xc11/0x1310 net/ipv6/ip6_fib.c:1815
 fib6_clean_node+0x3ee/0x5e0 net/ipv6/ip6_fib.c:1976
 fib6_walk_continue+0x4b1/0x8e0 net/ipv6/ip6_fib.c:1899
 fib6_walk+0x95/0xf0 net/ipv6/ip6_fib.c:1947
 fib6_clean_tree+0x1ea/0x360 net/ipv6/ip6_fib.c:2024
 __fib6_clean_all+0x21c/0x420 net/ipv6/ip6_fib.c:2040
 fib6_clean_all net/ipv6/ip6_fib.c:2051 [inline]
 fib6_run_gc+0x182/0x3d0 net/ipv6/ip6_fib.c:2107
 ndisc_netdev_event+0x4ab/0x580 net/ipv6/ndisc.c:1790
 notifier_call_chain+0x180/0x390 kernel/notifier.c:93
 __raw_notifier_call_chain kernel/notifier.c:394 [inline]
 raw_notifier_call_chain+0x2d/0x40 kernel/notifier.c:401
 call_netdevice_notifiers_info+0x3f/0x90 net/core/dev.c:1734
 call_netdevice_notifiers net/core/dev.c:1752 [inline]
 dev_close_many+0x447/0x8d0 net/core/dev.c:1504
 rollback_registered_many+0x539/0x1250 net/core/dev.c:7919
 rollback_registered+0x1e9/0x420 net/core/dev.c:7984
 unregister_netdevice_queue+0x32f/0x660 net/core/dev.c:9028
 unregister_netdevice include/linux/netdevice.h:2589 [inline]
 __tun_detach+0x11d1/0x15e0 drivers/net/tun.c:728
 tun_detach drivers/net/tun.c:745 [inline]
 tun_chr_close+0xe3/0x180 drivers/net/tun.c:3271
 __fput+0x376/0x8a0 fs/file_table.c:279
 ____fput+0x15/0x20 fs/file_table.c:312
 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

The buggy address belongs to the object at ffff8801c4562780
 which belongs to the cache kmalloc-96 of size 96
The buggy address is located 68 bytes inside of
 96-byte region [ffff8801c4562780, ffff8801c45627e0)
The buggy address belongs to the page:
page:ffffea0007115880 count:1 mapcount:0 mapping:ffff8801dac004c0 index:0xffff8801c4562b00
flags: 0x2fffc0000000100(slab)
raw: 02fffc0000000100 ffffea000760d248 ffffea0006eedd88 ffff8801dac004c0
raw: ffff8801c4562b00 ffff8801c4562000 000000010000001c 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
 ffff8801c4562680: 00 00 00 00 00 00 00 00 00 00 00 00 fc fc fc fc
 ffff8801c4562700: 00 00 00 00 00 00 00 00 00 00 00 00 fc fc fc fc
>ffff8801c4562780: fb fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc
                                           ^
 ffff8801c4562800: 00 00 00 00 00 00 00 00 00 00 00 00 fc fc fc fc
 ffff8801c4562880: 00 00 00 00 00 00 00 00 00 00 00 00 fc fc fc fc
==================================================================

Crashes (3):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2018/08/03 03:25 linux-next d237c54d5b28 5b7e23bb .config console log report ci-upstream-linux-next-kasan-gce-root
2018/08/02 15:23 linux-next d237c54d5b28 0a7cf4ec .config console log report ci-upstream-linux-next-kasan-gce-root
2018/08/01 18:11 linux-next d9bd94c0bcaa 0a7cf4ec .config console log report ci-upstream-linux-next-kasan-gce-root
* Struck through repros no longer work on HEAD.