syzbot


KASAN: use-after-free Read in nr_release

Status: fixed on 2019/08/27 17:15
Subsystems: hams
[Documentation on labels]
Reported-by: syzbot+6eaef7158b19e3fec3a0@syzkaller.appspotmail.com
Fix commit: 4638faac0327 netrom: hold sock when setting skb->destructor
First crash: 2011d, last: 1930d
Cause bisection: introduced by (bisect log) :
commit c8c8218ec5af5d2598381883acbefbf604e56b5e
Author: Cong Wang <xiyou.wangcong@gmail.com>
Date: Thu Jun 27 21:30:58 2019 +0000

  netrom: fix a memory leak in nr_rx_frame()

Crash: WARNING: refcount bug in nr_insert_socket (log)
Repro: syz .config
  
Discussions (10)
Title Replies (including bot) Last reply
[PATCH 4.9 000/223] 4.9.187-stable review 231 (231) 2019/08/28 03:02
[PATCH 4.4 000/158] 4.4.187-stable review 166 (166) 2019/08/03 15:57
[PATCH 4.14 000/293] 4.14.135-stable review 302 (302) 2019/07/31 09:35
[PATCH 5.2 00/66] 5.2.4-stable review 78 (78) 2019/07/29 15:12
[PATCH 5.1 00/62] 5.1.21-stable review 68 (68) 2019/07/29 09:02
[PATCH 4.19 00/50] 4.19.62-stable review 56 (56) 2019/07/29 09:02
KASAN: use-after-free Read in nr_release 0 (4) 2019/07/27 09:55
[Patch net] netrom: hold sock when setting skb->destructor 2 (2) 2019/07/24 22:49
Reminder: 13 open syzbot bugs in "net/netrom" subsystem 2 (2) 2019/07/24 17:02
Reminder: 7 open syzbot bugs in "net/netrom" subsystem 1 (1) 2019/06/27 03:50
Similar bugs (3)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
linux-4.19 KASAN: use-after-free Read in nr_release C 327 644d 1947d 0/1 upstream: reported C repro on 2019/08/10 01:07
linux-4.14 KASAN: use-after-free Read in nr_release C 117 645d 1943d 0/1 upstream: reported C repro on 2019/08/13 12:20
upstream KASAN: use-after-free Read in nr_release (2) hams syz error error 59 1838d 1927d 0/28 auto-obsoleted due to no activity on 2023/04/12 23:03
Last patch testing requests (2)
Created Duration User Patch Repo Result
2019/07/22 20:55 16m xiyou.wangcong@gmail.com https://github.com/congwang/linux.git netrom OK
2019/07/18 18:08 17m xiyou.wangcong@gmail.com https://github.com/congwang/linux.git netrom OK

Sample crash report:
==================================================================
BUG: KASAN: use-after-free in atomic_read include/asm-generic/atomic-instrumented.h:26 [inline]
BUG: KASAN: use-after-free in refcount_inc_not_zero_checked+0x81/0x200 lib/refcount.c:123
Read of size 4 at addr ffff888091f30a80 by task syz-executor668/9662

CPU: 1 PID: 9662 Comm: syz-executor668 Not tainted 5.3.0-rc5+ #118
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+0x172/0x1f0 lib/dump_stack.c:113
 print_address_description.cold+0xd4/0x306 mm/kasan/report.c:351
 __kasan_report.cold+0x1b/0x36 mm/kasan/report.c:482
 kasan_report+0x12/0x17 mm/kasan/common.c:612
 check_memory_region_inline mm/kasan/generic.c:185 [inline]
 check_memory_region+0x134/0x1a0 mm/kasan/generic.c:192
 __kasan_check_read+0x11/0x20 mm/kasan/common.c:92
 atomic_read include/asm-generic/atomic-instrumented.h:26 [inline]
 refcount_inc_not_zero_checked+0x81/0x200 lib/refcount.c:123
 refcount_inc_checked+0x17/0x70 lib/refcount.c:156
 sock_hold include/net/sock.h:649 [inline]
 nr_release+0x62/0x3e0 net/netrom/af_netrom.c:520
 __sock_release+0xce/0x280 net/socket.c:590
 sock_close+0x1e/0x30 net/socket.c:1268
 __fput+0x2ff/0x890 fs/file_table.c:280
 ____fput+0x16/0x20 fs/file_table.c:313
 task_work_run+0x145/0x1c0 kernel/task_work.c:113
 exit_task_work include/linux/task_work.h:22 [inline]
 do_exit+0x92f/0x2e50 kernel/exit.c:879
 do_group_exit+0x135/0x360 kernel/exit.c:983
 get_signal+0x47c/0x2500 kernel/signal.c:2734
 do_signal+0x87/0x1700 arch/x86/kernel/signal.c:815
 exit_to_usermode_loop+0x286/0x380 arch/x86/entry/common.c:159
 prepare_exit_to_usermode arch/x86/entry/common.c:194 [inline]
 syscall_return_slowpath arch/x86/entry/common.c:274 [inline]
 do_syscall_64+0x5a9/0x6a0 arch/x86/entry/common.c:299
 entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x4464a9
Code: Bad RIP value.
RSP: 002b:00007ffeae42e068 EFLAGS: 00000246 ORIG_RAX: 0000000000000120
RAX: fffffffffffffe00 RBX: 0000000000000003 RCX: 00000000004464a9
RDX: 0000000020000240 RSI: 0000000000000000 RDI: 0000000000000006
RBP: 0000000000000005 R08: 0000000200000009 R09: 0000000200000009
R10: 0000000000000800 R11: 0000000000000246 R12: 00005555569b6850
R13: 0000000000000009 R14: 0000000000000000 R15: 0000000000000000

Allocated by task 9662:
 save_stack+0x23/0x90 mm/kasan/common.c:69
 set_track mm/kasan/common.c:77 [inline]
 __kasan_kmalloc mm/kasan/common.c:487 [inline]
 __kasan_kmalloc.constprop.0+0xcf/0xe0 mm/kasan/common.c:460
 kasan_kmalloc+0x9/0x10 mm/kasan/common.c:501
 __do_kmalloc mm/slab.c:3655 [inline]
 __kmalloc+0x163/0x770 mm/slab.c:3664
 kmalloc include/linux/slab.h:557 [inline]
 sk_prot_alloc+0x23a/0x310 net/core/sock.c:1603
 sk_alloc+0x39/0xf70 net/core/sock.c:1657
 nr_create+0xb9/0x5e0 net/netrom/af_netrom.c:433
 __sock_create+0x3d8/0x730 net/socket.c:1418
 sock_create net/socket.c:1469 [inline]
 __sys_socket+0x103/0x220 net/socket.c:1511
 __do_sys_socket net/socket.c:1520 [inline]
 __se_sys_socket net/socket.c:1518 [inline]
 __x64_sys_socket+0x73/0xb0 net/socket.c:1518
 do_syscall_64+0xfd/0x6a0 arch/x86/entry/common.c:296
 entry_SYSCALL_64_after_hwframe+0x49/0xbe

Freed by task 9662:
 save_stack+0x23/0x90 mm/kasan/common.c:69
 set_track mm/kasan/common.c:77 [inline]
 __kasan_slab_free+0x102/0x150 mm/kasan/common.c:449
 kasan_slab_free+0xe/0x10 mm/kasan/common.c:457
 __cache_free mm/slab.c:3425 [inline]
 kfree+0x10a/0x2c0 mm/slab.c:3756
 sk_prot_free net/core/sock.c:1640 [inline]
 __sk_destruct+0x4f7/0x6e0 net/core/sock.c:1726
 sk_destruct+0x86/0xa0 net/core/sock.c:1734
 __sk_free+0xfb/0x360 net/core/sock.c:1745
 sk_free+0x42/0x50 net/core/sock.c:1756
 sock_put include/net/sock.h:1725 [inline]
 nr_release+0x356/0x3e0 net/netrom/af_netrom.c:554
 __sock_release+0xce/0x280 net/socket.c:590
 sock_close+0x1e/0x30 net/socket.c:1268
 __fput+0x2ff/0x890 fs/file_table.c:280
 ____fput+0x16/0x20 fs/file_table.c:313
 task_work_run+0x145/0x1c0 kernel/task_work.c:113
 exit_task_work include/linux/task_work.h:22 [inline]
 do_exit+0x92f/0x2e50 kernel/exit.c:879
 do_group_exit+0x135/0x360 kernel/exit.c:983
 get_signal+0x47c/0x2500 kernel/signal.c:2734
 do_signal+0x87/0x1700 arch/x86/kernel/signal.c:815
 exit_to_usermode_loop+0x286/0x380 arch/x86/entry/common.c:159
 prepare_exit_to_usermode arch/x86/entry/common.c:194 [inline]
 syscall_return_slowpath arch/x86/entry/common.c:274 [inline]
 do_syscall_64+0x5a9/0x6a0 arch/x86/entry/common.c:299
 entry_SYSCALL_64_after_hwframe+0x49/0xbe

The buggy address belongs to the object at ffff888091f30a00
 which belongs to the cache kmalloc-2k of size 2048
The buggy address is located 128 bytes inside of
 2048-byte region [ffff888091f30a00, ffff888091f31200)
The buggy address belongs to the page:
page:ffffea000247cc00 refcount:1 mapcount:0 mapping:ffff8880aa400e00 index:0x0 compound_mapcount: 0
flags: 0x1fffc0000010200(slab|head)
raw: 01fffc0000010200 ffffea0002611b88 ffffea00025a8788 ffff8880aa400e00
raw: 0000000000000000 ffff888091f30180 0000000100000003 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
 ffff888091f30980: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff888091f30a00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff888091f30a80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                   ^
 ffff888091f30b00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff888091f30b80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Crashes (25):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2019/08/20 23:45 upstream 5f97cbe22b76 cfc9868f .config console log report syz C ci-upstream-kasan-gce-root
2019/07/27 09:54 upstream 3ea54d9b0d65 c85e1c5b .config console log report syz C ci-upstream-kasan-gce-root
2019/07/27 15:56 net-next-old 31cc088a4f5d c85e1c5b .config console log report syz C ci-upstream-net-kasan-gce
2019/08/21 00:14 linux-next 54c851a8cc73 cfc9868f .config console log report syz C ci-upstream-linux-next-kasan-gce-root
2019/07/25 05:16 upstream bed38c3e2dca 32329ceb .config console log report syz ci-upstream-kasan-gce-selinux-root
2019/07/17 16:10 net-next-old 192f0f8e9db7 f613a7c4 .config console log report syz ci-upstream-net-kasan-gce
2019/08/12 16:13 upstream d45331b00ddb acb51638 .config console log report ci-upstream-kasan-gce-selinux-root
2019/08/12 01:00 upstream 296d05cb0d3c acb51638 .config console log report ci-upstream-kasan-gce-selinux-root
2019/08/10 01:46 upstream 7f20fd23377a acb51638 .config console log report ci-upstream-kasan-gce-root
2019/08/06 01:31 upstream 0eb0ce0a78e1 6affd8e8 .config console log report ci-upstream-kasan-gce-root
2019/08/05 13:21 upstream e21a712a9685 6affd8e8 .config console log report ci-upstream-kasan-gce-root
2019/08/03 17:49 upstream dcb8cfbd8fe9 6affd8e8 .config console log report ci-upstream-kasan-gce-smack-root
2019/07/25 02:16 upstream bed38c3e2dca 32329ceb .config console log report ci-upstream-kasan-gce-selinux-root
2019/07/24 04:56 upstream c6dd78fcb8ee de453f34 .config console log report ci-upstream-kasan-gce-root
2019/07/22 08:34 upstream c6dd78fcb8ee b3c615f5 .config console log report ci-upstream-kasan-gce-selinux-root
2019/07/20 15:48 upstream abdfd52a295f 1656845f .config console log report ci-upstream-kasan-gce-root
2019/07/21 14:30 net-old 1a03bb532934 1656845f .config console log report ci-upstream-net-this-kasan-gce
2019/06/26 16:31 net-old b8e8a86337c2 4d342240 .config console log report ci-upstream-net-this-kasan-gce
2019/06/13 23:08 net-old b8003cef2e63 a139f92f .config console log report ci-upstream-net-this-kasan-gce
2019/06/13 21:42 net-old b8003cef2e63 a139f92f .config console log report ci-upstream-net-this-kasan-gce
2019/06/07 07:52 net-old 85cb928787ea 698773cb .config console log report ci-upstream-net-this-kasan-gce
2019/06/06 22:14 net-old 85cb928787ea 698773cb .config console log report ci-upstream-net-this-kasan-gce
2019/08/26 08:57 linux-next 9733a7c62c66 d21c5d9d .config console log report ci-upstream-linux-next-kasan-gce-root
2019/07/18 10:28 linux-next 6d21a41b7b1f 7bb222f7 .config console log report ci-upstream-linux-next-kasan-gce-root
2019/07/17 14:30 linux-next e40115c06b1d f613a7c4 .config console log report ci-upstream-linux-next-kasan-gce-root
* Struck through repros no longer work on HEAD.