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

From: syzbot <[email-masked]>
Date: Sat, 09 Dec 2017 02:42:01 -0800

Hello,

syzkaller hit the following crash on  
ae64f9bd1d3621b5e60d7363bc20afb46aede215
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/master
compiler: gcc (GCC) 7.1.1 20170620
.config is attached
Raw console output is attached.

Unfortunately, I don't have any reproducer for this bug yet.

Use struct sctp_sack_info instead
kasan: CONFIG_KASAN_INLINE enabled
==================================================================
BUG: KASAN: use-after-free in sk_drops_add include/net/sock.h:2211 [inline]
BUG: KASAN: use-after-free in tcp_drop+0xdd/0x100 net/ipv4/tcp_input.c:4285
Read of size 2 at addr ffff8801d3581986 by task syz-executor2/4533

CPU: 1 PID: 4533 Comm: syz-executor2 Not tainted 4.15.0-rc2+ #206
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:252
  kasan_report_error mm/kasan/report.c:351 [inline]
  kasan_report+0x25b/0x340 mm/kasan/report.c:409
  __asan_report_load2_noabort+0x14/0x20 mm/kasan/report.c:428
  sk_drops_add include/net/sock.h:2211 [inline]
  tcp_drop+0xdd/0x100 net/ipv4/tcp_input.c:4285
  tcp_rcv_state_process+0x401/0x4800 net/ipv4/tcp_input.c:6039
  tcp_v6_do_rcv+0x739/0x11b0 net/ipv6/tcp_ipv6.c:1331
  sk_backlog_rcv include/net/sock.h:911 [inline]
  __release_sock+0x124/0x360 net/core/sock.c:2264
  release_sock+0xa4/0x2a0 net/core/sock.c:2779
  tcp_close+0x57c/0xfc0 net/ipv4/tcp.c:2245
  inet_release+0xed/0x1c0 net/ipv4/af_inet.c:426
  inet6_release+0x50/0x70 net/ipv6/af_inet6.c:433
  sock_release+0x8d/0x1e0 net/socket.c:596
  sock_close+0x16/0x20 net/socket.c:1125
  __fput+0x333/0x7f0 fs/file_table.c:210
  ____fput+0x15/0x20 fs/file_table.c:244
  task_work_run+0x199/0x270 kernel/task_work.c:113
  exit_task_work include/linux/task_work.h:22 [inline]
  do_exit+0x9bb/0x1ae0 kernel/exit.c:865
  do_group_exit+0x149/0x400 kernel/exit.c:968
  get_signal+0x73f/0x16c0 kernel/signal.c:2335
  do_signal+0x94/0x1ee0 arch/x86/kernel/signal.c:809
  exit_to_usermode_loop+0x214/0x310 arch/x86/entry/common.c:158
  prepare_exit_to_usermode arch/x86/entry/common.c:195 [inline]
  syscall_return_slowpath+0x490/0x550 arch/x86/entry/common.c:264
  entry_SYSCALL_64_fastpath+0x94/0x96
RIP: 0033:0x4529d9
RSP: 002b:00007ff73e489ce8 EFLAGS: 00000246 ORIG_RAX: 00000000000000ca
RAX: fffffffffffffe00 RBX: 0000000000758100 RCX: 00000000004529d9
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000758100
RBP: 0000000000758100 R08: 00000000000001d0 R09: 00000000007580d8
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 0000000000a6f7ff R14: 00007ff73e48a9c0 R15: 0000000000000002

Allocated by task 4533:
  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:551
  __do_kmalloc_node mm/slab.c:3675 [inline]
  __kmalloc_node_track_caller+0x47/0x70 mm/slab.c:3689
  __kmalloc_reserve.isra.41+0x41/0xd0 net/core/skbuff.c:137
  __alloc_skb+0x13b/0x780 net/core/skbuff.c:205
  alloc_skb include/linux/skbuff.h:983 [inline]
  tcp_send_ack.part.41+0xce/0x610 net/ipv4/tcp_output.c:3596
  tcp_send_ack+0x49/0x60 net/ipv4/tcp_output.c:3587
  tcp_fin+0x40b/0x960 net/ipv4/tcp_input.c:4033
  tcp_data_queue+0x206b/0x3dd0 net/ipv4/tcp_input.c:4604
  tcp_rcv_state_process+0xec1/0x4800 net/ipv4/tcp_input.c:6026
  tcp_v6_do_rcv+0x739/0x11b0 net/ipv6/tcp_ipv6.c:1331
  sk_backlog_rcv include/net/sock.h:911 [inline]
  __release_sock+0x124/0x360 net/core/sock.c:2264
  release_sock+0xa4/0x2a0 net/core/sock.c:2779
  tcp_close+0x57c/0xfc0 net/ipv4/tcp.c:2245
  inet_release+0xed/0x1c0 net/ipv4/af_inet.c:426
  inet6_release+0x50/0x70 net/ipv6/af_inet6.c:433
  sock_release+0x8d/0x1e0 net/socket.c:596
  sock_close+0x16/0x20 net/socket.c:1125
  __fput+0x333/0x7f0 fs/file_table.c:210
  ____fput+0x15/0x20 fs/file_table.c:244
  task_work_run+0x199/0x270 kernel/task_work.c:113
  exit_task_work include/linux/task_work.h:22 [inline]
  do_exit+0x9bb/0x1ae0 kernel/exit.c:865
  do_group_exit+0x149/0x400 kernel/exit.c:968
  get_signal+0x73f/0x16c0 kernel/signal.c:2335
  do_signal+0x94/0x1ee0 arch/x86/kernel/signal.c:809
  exit_to_usermode_loop+0x214/0x310 arch/x86/entry/common.c:158
  prepare_exit_to_usermode arch/x86/entry/common.c:195 [inline]
  syscall_return_slowpath+0x490/0x550 arch/x86/entry/common.c:264
  entry_SYSCALL_64_fastpath+0x94/0x96

Freed by task 1310:
  save_stack+0x43/0xd0 mm/kasan/kasan.c:447
  set_track mm/kasan/kasan.c:459 [inline]
  kasan_slab_free+0x71/0xc0 mm/kasan/kasan.c:524
  __cache_free mm/slab.c:3491 [inline]
  kfree+0xca/0x250 mm/slab.c:3806
  tty_port_destructor drivers/tty/tty_port.c:265 [inline]
  kref_put include/linux/kref.h:70 [inline]
  tty_port_put+0x142/0x170 drivers/tty/tty_port.c:271
  pty_cleanup+0x37/0x50 drivers/tty/pty.c:449
  release_one_tty+0x133/0x510 drivers/tty/tty_io.c:1414
  process_one_work+0xbfd/0x1be0 kernel/workqueue.c:2112
  worker_thread+0x223/0x1990 kernel/workqueue.c:2246
  kthread+0x37a/0x440 kernel/kthread.c:238
  ret_from_fork+0x24/0x30 arch/x86/entry/entry_64.S:441

The buggy address belongs to the object at ffff8801d35816c0
  which belongs to the cache kmalloc-1024 of size 1024
The buggy address is located 710 bytes inside of
  1024-byte region [ffff8801d35816c0, ffff8801d3581ac0)
The buggy address belongs to the page:
page:00000000634be806 count:1 mapcount:0 mapping:00000000425a9030 index:0x0  
compound_mapcount: 0
flags: 0x2fffc0000008100(slab|head)
raw: 02fffc0000008100 ffff8801d3580040 0000000000000000 0000000100000007
raw: ffffea00070dfc20 ffffea000709ba20 ffff8801db000ac0 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
  ffff8801d3581880: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
  ffff8801d3581900: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> ffff8801d3581980: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                    ^
  ffff8801d3581a00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
  ffff8801d3581a80: 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].
Please credit me with: Reported-by: syzbot <[email-masked]>

syzbot will keep track of this bug report.
Once a fix for this bug is merged into any tree, 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.