Subject: KASAN: use-after-free Read in l2tp_session_register

From: syzbot <[email-masked]>
Date: Fri, 16 Feb 2018 23:58:01 -0800

Hello,

syzbot hit the following crash on upstream commit
e525de3ab04621d227330aa82cd4073c0b0f3579 (Thu Feb 15 01:31:51 2018 +0000)
Merge branch 'x86-urgent-for-linus' of  
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

So far this crash happened 2 times on upstream.
Unfortunately, I don't have any reproducer for this crash yet.
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.

BUG: KASAN: use-after-free in perf_trace_lock_acquire+0x5b7/0x980  
include/trace/events/lock.h:13
Read of size 8 at addr ffff8801b7067ad0 by task syz-executor0/5537

CPU: 0 PID: 5537 Comm: syz-executor0 Not tainted 4.16.0-rc1+ #313
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
  print_address_description+0x73/0x250 mm/kasan/report.c:256
  kasan_report_error mm/kasan/report.c:354 [inline]
  kasan_report+0x23b/0x360 mm/kasan/report.c:412
  __asan_report_load8_noabort+0x14/0x20 mm/kasan/report.c:433
  perf_trace_lock_acquire+0x5b7/0x980 include/trace/events/lock.h:13
  trace_lock_acquire include/trace/events/lock.h:13 [inline]
  lock_acquire+0x394/0x580 kernel/locking/lockdep.c:3919
  __raw_write_lock_bh include/linux/rwlock_api_smp.h:203 [inline]
  _raw_write_lock_bh+0x31/0x40 kernel/locking/spinlock.c:312
  l2tp_session_register+0xe0/0xe20 net/l2tp/l2tp_core.c:322
  pppol2tp_connect+0x1345/0x1dd0 net/l2tp/l2tp_ppp.c:761
  SYSC_connect+0x213/0x4a0 net/socket.c:1639
  SyS_connect+0x24/0x30 net/socket.c:1620
  do_syscall_64+0x280/0x940 arch/x86/entry/common.c:287
  entry_SYSCALL_64_after_hwframe+0x42/0xb7
RIP: 0033:0x453a59
RSP: 002b:00007f73f05d1c68 EFLAGS: 00000246 ORIG_RAX: 000000000000002a
RAX: ffffffffffffffda RBX: 00007f73f05d26d4 RCX: 0000000000453a59
RDX: 000000000000002e RSI: 00000000205fafd2 RDI: 0000000000000014
RBP: 000000000071bea0 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00000000ffffffff
R13: 000000000000005c R14: 00000000006f0940 R15: 0000000000000000

Allocated by task 5537:
  save_stack+0x43/0xd0 mm/kasan/kasan.c:447
  set_track mm/kasan/kasan.c:459 [inline]
  kasan_kmalloc+0xad/0xe0 mm/kasan/kasan.c:552
  kmem_cache_alloc_trace+0x136/0x740 mm/slab.c:3607
  kmalloc include/linux/slab.h:512 [inline]
  kzalloc include/linux/slab.h:701 [inline]
  l2tp_tunnel_create+0x5e1/0x17f0 net/l2tp/l2tp_core.c:1545
  pppol2tp_connect+0x14b1/0x1dd0 net/l2tp/l2tp_ppp.c:707
  SYSC_connect+0x213/0x4a0 net/socket.c:1639
  SyS_connect+0x24/0x30 net/socket.c:1620
  do_syscall_64+0x280/0x940 arch/x86/entry/common.c:287
  entry_SYSCALL_64_after_hwframe+0x42/0xb7

Freed by task 4225:
  save_stack+0x43/0xd0 mm/kasan/kasan.c:447
  set_track mm/kasan/kasan.c:459 [inline]
  __kasan_slab_free+0x11a/0x170 mm/kasan/kasan.c:520
  kasan_slab_free+0xe/0x10 mm/kasan/kasan.c:527
  __cache_free mm/slab.c:3485 [inline]
  kfree+0xd9/0x260 mm/slab.c:3800
  __rcu_reclaim kernel/rcu/rcu.h:167 [inline]
  rcu_do_batch kernel/rcu/tree.c:2674 [inline]
  invoke_rcu_callbacks kernel/rcu/tree.c:2933 [inline]
  __rcu_process_callbacks kernel/rcu/tree.c:2900 [inline]
  rcu_process_callbacks+0xe94/0x17f0 kernel/rcu/tree.c:2917
  __do_softirq+0x2d7/0xb85 kernel/softirq.c:285

The buggy address belongs to the object at ffff8801b7067a80
  which belongs to the cache kmalloc-512 of size 512
The buggy address is located 80 bytes inside of
  512-byte region [ffff8801b7067a80, ffff8801b7067c80)
The buggy address belongs to the page:
page:ffffea0006dc19c0 count:1 mapcount:0 mapping:ffff8801b7067080 index:0x0
flags: 0x2fffc0000000100(slab)
raw: 02fffc0000000100 ffff8801b7067080 0000000000000000 0000000100000006
raw: ffffea0006ded1a0 ffffea00073277a0 ffff8801db000940 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
  ffff8801b7067980: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
  ffff8801b7067a00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
> ffff8801b7067a80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                                  ^
  ffff8801b7067b00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
  ffff8801b7067b80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

---
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
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.