Subject: WARNING: kmalloc bug in xfrm_add_sa

From: syzbot <[email-masked]>
Date: Mon, 12 Feb 2018 04:59:02 -0800

Hello,

syzbot hit the following crash on upstream commit
581e400ff935d34d95811258586128bf11baef15 (Wed Feb 7 22:29:34 2018 +0000)
Merge tag 'modules-for-v4.16' of  
git://git.kernel.org/pub/scm/linux/kernel/git/jeyu/linux

So far this crash happened 2 times on 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: [email-masked]
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.

audit: type=1400 audit(1518094627.868:7): avc:  denied  { map } for   
pid=4171 comm="syzkaller731818" path="/root/syzkaller731818472" dev="sda1"  
ino=16481 scontext=unconfined_u:system_r:insmod_t:s0-s0:c0.c1023  
tcontext=unconfined_u:object_r:user_home_t:s0 tclass=file permissive=1
WARNING: CPU: 1 PID: 4172 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: 4172 Comm: syzkaller731818 Not tainted 4.15.0+ #302
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:988
RIP: 0010:kmalloc_slab+0x5d/0x70 mm/slab_common.c:1012
RSP: 0018:ffff8801bb7af2f0 EFLAGS: 00010246
RAX: 0000000000000000 RBX: 00000000fffff5bc RCX: ffffffff84c14688
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 00000000fffff5bc
RBP: ffff8801bb7af2f0 R08: 0000000000000000 R09: 1ffff100376f5e21
R10: ffff8801bb7af040 R11: 0000000000000001 R12: 00000000fffff5bc
R13: ffff8801bb7af598 R14: 00000000014080c0 R15: ffff8801c8224dc0
  __do_kmalloc mm/slab.c:3700 [inline]
  __kmalloc+0x25/0x760 mm/slab.c:3714
  kmalloc include/linux/slab.h:517 [inline]
  kzalloc include/linux/slab.h:701 [inline]
  xfrm_alloc_replay_state_esn net/xfrm/xfrm_user.c:442 [inline]
  xfrm_state_construct net/xfrm/xfrm_user.c:601 [inline]
  xfrm_add_sa+0x1b15/0x3440 net/xfrm/xfrm_user.c:647
  xfrm_user_rcv_msg+0x41c/0x860 net/xfrm/xfrm_user.c:2595
  netlink_rcv_skb+0x14b/0x380 net/netlink/af_netlink.c:2442
  xfrm_netlink_rcv+0x6f/0x90 net/xfrm/xfrm_user.c:2603
  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
  do_syscall_64+0x282/0x940 arch/x86/entry/common.c:287
  entry_SYSCALL_64_after_hwframe+0x26/0x9b
RIP: 0033:0x445a09
RSP: 002b:00007ff29bc19da8 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
RAX: ffffffffffffffda RBX: 00000000006dac24 RCX: 0000000000445a09
RDX: 0000000000000000 RSI: 000000002014f000 RDI: 0000000000000003
RBP: 00000000006dac20 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0073746174735f68
R13: 7361682f6376612f R14: 78756e696c65732f R15: 0000000000000004
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 [email-masked].

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.