Re: WARNING: kmalloc bug in tun_device_event

From: Jason Wang
Date: Wed Feb 07 2018 - 01:47:27 EST




On 2018å02æ07æ 06:58, syzbot wrote:
Hello,

syzbot hit the following crash on net-next commit
617aebe6a97efa539cc4b8a52adccd89596e6be0 (Sun Feb 4 00:25:42 2018 +0000)
Merge tag 'usercopy-v4.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux

So far this crash happened 5 times on net-next, upstream.
C reproducer is attached.
syzkaller reproducer is attached.
Raw console output is attached.
compiler: gcc (GCC) 7.1.1 20170620
.config is attached.

IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: syzbot+e4d4f9ddd4295539735d@xxxxxxxxxxxxxxxxxxxxxxxxx
It will help syzbot understand when the bug is fixed. See footer for details.
If you forward the report, please keep this part and the footer.

WARNING: CPU: 1 PID: 4134 at mm/slab_common.c:1012 kmalloc_slab+0x5d/0x70 mm/slab_common.c:1012
Kernel panic - not syncing: panic_on_warn set ...

CPU: 1 PID: 4134 Comm: syzkaller993072 Not tainted 4.15.0+ #221
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
Â__dump_stack lib/dump_stack.c:17 [inline]
Âdump_stack+0x194/0x257 lib/dump_stack.c:53
Âpanic+0x1e4/0x41c kernel/panic.c:183
Â__warn+0x1dc/0x200 kernel/panic.c:547
Âreport_bug+0x211/0x2d0 lib/bug.c:184
Âfixup_bug.part.11+0x37/0x80 arch/x86/kernel/traps.c:178
Âfixup_bug arch/x86/kernel/traps.c:247 [inline]
Âdo_error_trap+0x2d7/0x3e0 arch/x86/kernel/traps.c:296
Âdo_invalid_op+0x1b/0x20 arch/x86/kernel/traps.c:315
Âinvalid_op+0x22/0x40 arch/x86/entry/entry_64.S:1097
RIP: 0010:kmalloc_slab+0x5d/0x70 mm/slab_common.c:1012
RSP: 0018:ffff8801ba7ceb20 EFLAGS: 00010246
RAX: 0000000000000000 RBX: 0000000000000000 RCX: ffffffff83b88bed
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000400000008
RBP: ffff8801ba7ceb20 R08: 1ffff100374f9cd7 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000000 R12: 0000000400000008
R13: dffffc0000000000 R14: 00000000014080c0 R15: ffff8801b5d52080
Â__do_kmalloc mm/slab.c:3700 [inline]
Â__kmalloc+0x25/0x760 mm/slab.c:3714
Âkmalloc_array include/linux/slab.h:631 [inline]
Âkcalloc include/linux/slab.h:642 [inline]
Â__ptr_ring_init_queue_alloc include/linux/ptr_ring.h:469 [inline]
Âptr_ring_resize_multiple include/linux/ptr_ring.h:629 [inline]
Âtun_queue_resize drivers/net/tun.c:3319 [inline]
Âtun_device_event+0x471/0xec0 drivers/net/tun.c:3338
Ânotifier_call_chain+0x136/0x2c0 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+0x32/0x70 net/core/dev.c:1707
Âcall_netdevice_notifiers net/core/dev.c:1725 [inline]
Âdev_change_tx_queue_len+0x117/0x220 net/core/dev.c:7065
Âdo_setlink+0xba7/0x3bb0 net/core/rtnetlink.c:2341
Ârtnl_newlink+0xf1c/0x1a20 net/core/rtnetlink.c:2915
Ârtnetlink_rcv_msg+0x57f/0xb10 net/core/rtnetlink.c:4587
Ânetlink_rcv_skb+0x14b/0x380 net/netlink/af_netlink.c:2442
Ârtnetlink_rcv+0x1c/0x20 net/core/rtnetlink.c:4605
Ânetlink_unicast_kernel net/netlink/af_netlink.c:1308 [inline]
Ânetlink_unicast+0x4c4/0x6b0 net/netlink/af_netlink.c:1334
Ânetlink_sendmsg+0xa4a/0xe60 net/netlink/af_netlink.c:1897
Âsock_sendmsg_nosec net/socket.c:630 [inline]
Âsock_sendmsg+0xca/0x110 net/socket.c:640
Â___sys_sendmsg+0x767/0x8b0 net/socket.c:2046
Â__sys_sendmsg+0xe5/0x210 net/socket.c:2080
ÂSYSC_sendmsg net/socket.c:2091 [inline]
ÂSyS_sendmsg+0x2d/0x50 net/socket.c:2087
Âentry_SYSCALL_64_fastpath+0x29/0xa0
RIP: 0033:0x4463c9
RSP: 002b:00007ffe63916e68 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
RAX: ffffffffffffffda RBX: 00000000004a7af2 RCX: 00000000004463c9
RDX: 0000000000000000 RSI: 0000000020504000 RDI: 0000000000000004
RBP: 00007ffe63916f08 R08: 0000000000000000 R09: 00000000004a7af2
R10: 0000000000000000 R11: 0000000000000246 R12: 00007ffe63916f08
R13: 0000000000403890 R14: 0000000000000000 R15: 0000000000000000
Dumping ftrace buffer:
ÂÂ (ftrace buffer empty)
Kernel Offset: disabled
Rebooting in 86400 seconds..


---
This bug is generated by a dumb bot. It may contain errors.
See https://goo.gl/tpsmEJ for details.
Direct all questions to syzkaller@xxxxxxxxxxxxxxxxx

syzbot will keep track of this bug report.
If you forgot to add the Reported-by tag, once the fix for this bug is merged
into any tree, please reply to this email with:
#syz fix: exact-commit-title
If you want to test a patch for this bug, please reply with:
#syz test: git://repo/address.git branch
and provide the patch inline or as an attachment.
To mark this as a duplicate of another syzbot report, please reply with:
#syz dup: exact-subject-of-another-report
If it's a one-off invalid bug report, please reply with:
#syz invalid
Note: if the crash happens again, it will cause creation of a new bug report.
Note: all commands must start from beginning of the line in the email body.

Looks like we need cap the maximum size that ptr_ring could allocate.

Will post a patch soon.

Thanks