KASAN: slab-out-of-bounds Read in tun_net_xmit (2)

Status: fixed on 2019/01/15 20:25
Subsystems: net
[Documentation on labels]
Fix commit: aff6db454599 ptr_ring: wrap back ->producer in __ptr_ring_swap_queue()
First crash: 2051d, last: 1881d
Discussions (6)
Title Replies (including bot) Last reply
[PATCH 4.19 000/170] 4.19.14-stable review 194 (194) 2019/01/11 07:09
[PATCH 4.20 000/145] 4.20.1-stable review 164 (164) 2019/01/09 23:18
[PATCH 4.14 000/101] 4.14.92-stable review 130 (130) 2019/01/09 15:47
[PATCH 4.9 00/71] 4.9.149-stable review 85 (85) 2019/01/09 10:46
KASAN: slab-out-of-bounds Read in tun_net_xmit (2) 2 (4) 2019/01/02 03:32
[Patch net] ptr_ring: wrap back ->producer in __ptr_ring_swap_queue() 4 (4) 2019/01/01 19:59
Similar bugs (3)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
android-414 KASAN: slab-out-of-bounds Read in tun_net_xmit C 3 1871d 1780d 0/1 public: reported C repro on 2019/04/10 16:04
upstream KASAN: slab-out-of-bounds Read in tun_net_xmit net 2 2328d 2318d 0/26 closed as invalid on 2017/12/06 12:46
android-49 KASAN: slab-out-of-bounds Read in tun_net_xmit syz 3386 1542d 1776d 0/3 public: reported syz repro on 2019/04/14 09:28

Sample crash report:
IPVS: ftp: loaded support on port[0] = 21
nf_conntrack: default automatic helper assignment has been turned off for security reasons and CT-based  firewall rule not found. Use the iptables CT target to attach helpers instead.
BUG: KASAN: slab-out-of-bounds in __ptr_ring_produce include/linux/ptr_ring.h:110 [inline]
BUG: KASAN: slab-out-of-bounds in ptr_ring_produce include/linux/ptr_ring.h:133 [inline]
BUG: KASAN: slab-out-of-bounds in tun_net_xmit+0x197e/0x1be0 drivers/net/tun.c:1119
Read of size 8 at addr ffff88809fae36c8 by task syz-executor122/8080

CPU: 0 PID: 8080 Comm: syz-executor122 Not tainted 4.20.0+ #396
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+0x1d3/0x2c6 lib/dump_stack.c:113
 print_address_description.cold.5+0x9/0x1ff mm/kasan/report.c:187
 kasan_report.cold.6+0x1b/0x39 mm/kasan/report.c:317
 __asan_report_load8_noabort+0x14/0x20 mm/kasan/generic_report.c:135
 __ptr_ring_produce include/linux/ptr_ring.h:110 [inline]
 ptr_ring_produce include/linux/ptr_ring.h:133 [inline]
 tun_net_xmit+0x197e/0x1be0 drivers/net/tun.c:1119
 __netdev_start_xmit include/linux/netdevice.h:4382 [inline]
 netdev_start_xmit include/linux/netdevice.h:4391 [inline]
 xmit_one net/core/dev.c:3278 [inline]
 dev_hard_start_xmit+0x286/0xc80 net/core/dev.c:3294
 sch_direct_xmit+0x48b/0x1130 net/sched/sch_generic.c:327
 qdisc_restart net/sched/sch_generic.c:390 [inline]
 __qdisc_run+0x624/0x19f0 net/sched/sch_generic.c:398
 qdisc_run include/net/pkt_sched.h:121 [inline]
 __dev_xmit_skb net/core/dev.c:3473 [inline]
 __dev_queue_xmit+0x190c/0x3ac0 net/core/dev.c:3832
 dev_queue_xmit+0x17/0x20 net/core/dev.c:3897
 neigh_hh_output include/net/neighbour.h:498 [inline]
 neigh_output include/net/neighbour.h:506 [inline]
 ip6_finish_output2+0x144e/0x2930 net/ipv6/ip6_output.c:120
 ip6_finish_output+0x583/0xc50 net/ipv6/ip6_output.c:154
 NF_HOOK_COND include/linux/netfilter.h:278 [inline]
 ip6_output+0x232/0x9d0 net/ipv6/ip6_output.c:171
 dst_output include/net/dst.h:444 [inline]
 ip6_local_out+0xc5/0x1b0 net/ipv6/output_core.c:176
 ip6_send_skb+0xbc/0x340 net/ipv6/ip6_output.c:1727
 udp_v6_send_skb.isra.32+0x831/0x14a0 net/ipv6/udp.c:1169
 udpv6_sendmsg+0x2d86/0x36a0 net/ipv6/udp.c:1466
 inet_sendmsg+0x1a1/0x690 net/ipv4/af_inet.c:798
 sock_sendmsg_nosec net/socket.c:621 [inline]
 sock_sendmsg+0xd5/0x120 net/socket.c:631
 __sys_sendto+0x3d7/0x670 net/socket.c:1788
 __do_sys_sendto net/socket.c:1800 [inline]
 __se_sys_sendto net/socket.c:1796 [inline]
 __x64_sys_sendto+0xe1/0x1a0 net/socket.c:1796
 do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290
RIP: 0033:0x441ba9
Code: e8 4c 06 03 00 48 83 c4 18 c3 0f 1f 80 00 00 00 00 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 08 fc ff c3 66 2e 0f 1f 84 00 00 00 00
RSP: 002b:00007ffe6e3deec8 EFLAGS: 00000216 ORIG_RAX: 000000000000002c
RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 0000000000441ba9
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000003
RBP: 00000000000108fb R08: 00000000200001c0 R09: 000000000000001c
R10: 0000000000000000 R11: 0000000000000216 R12: 0000000000000000
R13: 0000000000402990 R14: 0000000000000000 R15: 0000000000000000

Allocated by task 8079:
 save_stack+0x43/0xd0 mm/kasan/common.c:73
 set_track mm/kasan/common.c:85 [inline]
 kasan_kmalloc+0xcb/0xd0 mm/kasan/common.c:482
 __do_kmalloc_node mm/slab.c:3671 [inline]
 __kmalloc_node+0x4d/0x70 mm/slab.c:3678
 kmalloc_node include/linux/slab.h:588 [inline]
 kvmalloc_node+0x65/0xf0 mm/util.c:416
 kvmalloc include/linux/mm.h:602 [inline]
 kvmalloc_array include/linux/mm.h:620 [inline]
 __ptr_ring_init_queue_alloc include/linux/ptr_ring.h:475 [inline]
 ptr_ring_resize_multiple include/linux/ptr_ring.h:635 [inline]
 tun_queue_resize drivers/net/tun.c:3606 [inline]
 tun_device_event+0x56a/0x106c drivers/net/tun.c:3625
 notifier_call_chain+0x17e/0x380 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:1739
 call_netdevice_notifiers_extack net/core/dev.c:1751 [inline]
 call_netdevice_notifiers net/core/dev.c:1765 [inline]
 dev_change_tx_queue_len+0x188/0x270 net/core/dev.c:7742
 dev_ifsioc+0x79b/0xa80 net/core/dev_ioctl.c:287
 dev_ioctl+0x1b5/0xcc0 net/core/dev_ioctl.c:488
 sock_do_ioctl+0x1f6/0x420 net/socket.c:973
 sock_ioctl+0x313/0x690 net/socket.c:1074
 vfs_ioctl fs/ioctl.c:46 [inline]
 file_ioctl fs/ioctl.c:509 [inline]
 do_vfs_ioctl+0x1de/0x1790 fs/ioctl.c:696
 ksys_ioctl+0xa9/0xd0 fs/ioctl.c:713
 __do_sys_ioctl fs/ioctl.c:720 [inline]
 __se_sys_ioctl fs/ioctl.c:718 [inline]
 __x64_sys_ioctl+0x73/0xb0 fs/ioctl.c:718
 do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290

Freed by task 4309:
 save_stack+0x43/0xd0 mm/kasan/common.c:73
 set_track mm/kasan/common.c:85 [inline]
 __kasan_slab_free+0x102/0x150 mm/kasan/common.c:444
 kasan_slab_free+0xe/0x10 mm/kasan/common.c:452
 __cache_free mm/slab.c:3485 [inline]
 kfree+0xcf/0x230 mm/slab.c:3804
 single_release+0x8f/0xb0 fs/seq_file.c:597
 __fput+0x385/0xa50 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:188 [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

The buggy address belongs to the object at ffff88809fae36c0
 which belongs to the cache kmalloc-32 of size 32
The buggy address is located 8 bytes inside of
 32-byte region [ffff88809fae36c0, ffff88809fae36e0)
The buggy address belongs to the page:
page:ffffea00027eb8c0 count:1 mapcount:0 mapping:ffff88812c3f01c0 index:0xffff88809fae3fc1
flags: 0x1fffc0000000200(slab)
raw: 01fffc0000000200 ffffea00027efec8 ffffea0002637708 ffff88812c3f01c0
raw: ffff88809fae3fc1 ffff88809fae3000 000000010000003f 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
 ffff88809fae3580: fb fb fb fb fc fc fc fc fb fb fb fb fc fc fc fc
 ffff88809fae3600: 00 fc fc fc fc fc fc fc 00 fc fc fc fc fc fc fc
>ffff88809fae3680: fb fb fb fb fc fc fc fc 00 fc fc fc fc fc fc fc
 ffff88809fae3700: fb fb fb fb fc fc fc fc fb fb fb fb fc fc fc fc
 ffff88809fae3780: fb fb fb fb fc fc fc fc fb fb fb fb fc fc fc fc

Crashes (10):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2018/12/30 18:21 upstream 195303136f19 9942de5f .config console log report syz C ci-upstream-kasan-gce-root
2018/12/30 18:21 upstream 195303136f19 9942de5f .config console log report syz C ci-upstream-kasan-gce-selinux-root
2018/12/30 18:21 upstream 195303136f19 9942de5f .config console log report syz C ci-upstream-kasan-gce-smack-root
2018/12/30 18:20 net-old f7d18ef6a95f 9942de5f .config console log report syz C ci-upstream-net-this-kasan-gce
2018/12/30 18:00 net-next-old b71acb0e3721 9942de5f .config console log report syz C ci-upstream-net-kasan-gce
2018/12/30 18:25 linux-next 6a1d293238c1 9942de5f .config console log report syz C ci-upstream-linux-next-kasan-gce-root
2018/12/07 06:01 upstream abb8d6ecbd8f dcf836b1 .config console log report ci-upstream-kasan-gce-root
2018/11/09 23:07 upstream 3541833fd1f2 f9815aaf .config console log report ci-upstream-kasan-gce-root
2018/07/13 14:55 net-old 8f19f12bdcc6 92a49505 .config console log report ci-upstream-net-this-kasan-gce
2018/12/30 17:33 net-next-old b71acb0e3721 9942de5f .config console log report ci-upstream-net-kasan-gce
* Struck through repros no longer work on HEAD.