syzbot


KASAN: use-after-free Write in sctp_auth_shkey_hold (2)

Status: fixed on 2023/02/24 13:50
Subsystems: sctp
[Documentation on labels]
Reported-by: syzbot+a236dd8e9622ed8954a3@syzkaller.appspotmail.com
Fix commit: 022152aaebe1 sctp: handle the error returned from sctp_auth_asoc_init_active_key
First crash: 649d, last: 578d
Cause bisection: the issue happens on the oldest tested release (bisect log)
Crash: KASAN: use-after-free Write in sctp_auth_shkey_hold (log)
Repro: C syz .config
  
Discussions (8)
Title Replies (including bot) Last reply
[PATCH 5.15 000/530] 5.15.75-rc1 review 542 (542) 2023/01/10 15:19
[PATCH 5.4 000/255] 5.4.220-rc1 review 276 (276) 2022/11/01 17:29
[PATCH 4.19 000/229] 4.19.262-rc1 review 242 (242) 2022/11/01 13:44
[PATCH 5.10 000/390] 5.10.150-rc1 review 407 (407) 2022/10/25 15:12
[PATCH 5.19 000/717] 5.19.17-rc1 review 732 (732) 2022/10/24 19:01
[PATCH 6.0 000/862] 6.0.3-rc1 review 899 (899) 2022/10/21 09:08
[PATCH net] sctp: handle the error returned from sctp_auth_asoc_init_active_key 2 (2) 2022/09/30 11:40
[syzbot] KASAN: use-after-free Write in sctp_auth_shkey_hold (2) 1 (2) 2022/09/27 22:58
Similar bugs (1)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KASAN: use-after-free Write in sctp_auth_shkey_hold sctp C done 4 1010d 1018d 20/26 fixed on 2021/11/10 00:50

Sample crash report:
==================================================================
BUG: KASAN: use-after-free in instrument_atomic_read_write include/linux/instrumented.h:101 [inline]
BUG: KASAN: use-after-free in atomic_fetch_add_relaxed include/linux/atomic/atomic-instrumented.h:116 [inline]
BUG: KASAN: use-after-free in __refcount_add include/linux/refcount.h:193 [inline]
BUG: KASAN: use-after-free in __refcount_inc include/linux/refcount.h:250 [inline]
BUG: KASAN: use-after-free in refcount_inc include/linux/refcount.h:267 [inline]
BUG: KASAN: use-after-free in sctp_auth_shkey_hold+0x22/0xa0 net/sctp/auth.c:112
Write of size 4 at addr ffff88806dbf39d8 by task syz-executor655/3831

CPU: 0 PID: 3831 Comm: syz-executor655 Not tainted 5.19.0-syzkaller-13930-g7ebfc85e2cd7 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/22/2022
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106
 print_address_description mm/kasan/report.c:317 [inline]
 print_report.cold+0x2ba/0x719 mm/kasan/report.c:433
 kasan_report+0xb1/0x1e0 mm/kasan/report.c:495
 check_region_inline mm/kasan/generic.c:183 [inline]
 kasan_check_range+0x13d/0x180 mm/kasan/generic.c:189
 instrument_atomic_read_write include/linux/instrumented.h:101 [inline]
 atomic_fetch_add_relaxed include/linux/atomic/atomic-instrumented.h:116 [inline]
 __refcount_add include/linux/refcount.h:193 [inline]
 __refcount_inc include/linux/refcount.h:250 [inline]
 refcount_inc include/linux/refcount.h:267 [inline]
 sctp_auth_shkey_hold+0x22/0xa0 net/sctp/auth.c:112
 sctp_set_owner_w net/sctp/socket.c:132 [inline]
 sctp_sendmsg_to_asoc+0xddc/0x1a30 net/sctp/socket.c:1863
 sctp_sendmsg+0x1053/0x1d50 net/sctp/socket.c:2025
 inet_sendmsg+0x99/0xe0 net/ipv4/af_inet.c:819
 sock_sendmsg_nosec net/socket.c:714 [inline]
 sock_sendmsg+0xcf/0x120 net/socket.c:734
 __sys_sendto+0x236/0x340 net/socket.c:2117
 __do_sys_sendto net/socket.c:2129 [inline]
 __se_sys_sendto net/socket.c:2125 [inline]
 __x64_sys_sendto+0xdd/0x1b0 net/socket.c:2125
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7f4491a381f9
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 a1 15 00 00 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f44919c52d8 EFLAGS: 00000246 ORIG_RAX: 000000000000002c
RAX: ffffffffffffffda RBX: 00007f4491ac04b0 RCX: 00007f4491a381f9
RDX: 0000000000000001 RSI: 0000000020000400 RDI: 0000000000000003
RBP: 00007f4491a8d5f4 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00007f44919c52f0
R13: 00007f4491ac04b8 R14: 0100000000000000 R15: 0000000000022000
 </TASK>

Allocated by task 3827:
 kasan_save_stack+0x1e/0x40 mm/kasan/common.c:38
 kasan_set_track mm/kasan/common.c:45 [inline]
 set_alloc_info mm/kasan/common.c:437 [inline]
 ____kasan_kmalloc mm/kasan/common.c:516 [inline]
 ____kasan_kmalloc mm/kasan/common.c:475 [inline]
 __kasan_kmalloc+0xa9/0xd0 mm/kasan/common.c:525
 kmalloc include/linux/slab.h:600 [inline]
 kzalloc include/linux/slab.h:733 [inline]
 sctp_auth_shkey_create+0x85/0x1f0 net/sctp/auth.c:84
 sctp_auth_asoc_copy_shkeys+0x1e8/0x350 net/sctp/auth.c:363
 sctp_association_init net/sctp/associola.c:256 [inline]
 sctp_association_new+0x18a1/0x2340 net/sctp/associola.c:297
 sctp_connect_new_asoc+0x1ac/0x770 net/sctp/socket.c:1089
 sctp_sendmsg_new_asoc net/sctp/socket.c:1691 [inline]
 sctp_sendmsg+0x13d7/0x1d50 net/sctp/socket.c:1998
 inet_sendmsg+0x99/0xe0 net/ipv4/af_inet.c:819
 sock_sendmsg_nosec net/socket.c:714 [inline]
 sock_sendmsg+0xcf/0x120 net/socket.c:734
 __sys_sendto+0x236/0x340 net/socket.c:2117
 __do_sys_sendto net/socket.c:2129 [inline]
 __se_sys_sendto net/socket.c:2125 [inline]
 __x64_sys_sendto+0xdd/0x1b0 net/socket.c:2125
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

Freed by task 3835:
 kasan_save_stack+0x1e/0x40 mm/kasan/common.c:38
 kasan_set_track+0x21/0x30 mm/kasan/common.c:45
 kasan_set_free_info+0x20/0x30 mm/kasan/generic.c:370
 ____kasan_slab_free mm/kasan/common.c:367 [inline]
 ____kasan_slab_free+0x166/0x1c0 mm/kasan/common.c:329
 kasan_slab_free include/linux/kasan.h:200 [inline]
 slab_free_hook mm/slub.c:1754 [inline]
 slab_free_freelist_hook+0x8b/0x1c0 mm/slub.c:1780
 slab_free mm/slub.c:3534 [inline]
 kfree+0xe2/0x580 mm/slub.c:4562
 sctp_auth_shkey_destroy net/sctp/auth.c:101 [inline]
 sctp_auth_shkey_release+0x100/0x160 net/sctp/auth.c:107
 sctp_auth_set_key+0x443/0x960 net/sctp/auth.c:866
 sctp_setsockopt_auth_key net/sctp/socket.c:3640 [inline]
 sctp_setsockopt+0x4c33/0xa9a0 net/sctp/socket.c:4683
 __sys_setsockopt+0x2d6/0x690 net/socket.c:2252
 __do_sys_setsockopt net/socket.c:2263 [inline]
 __se_sys_setsockopt net/socket.c:2260 [inline]
 __x64_sys_setsockopt+0xba/0x150 net/socket.c:2260
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

The buggy address belongs to the object at ffff88806dbf39c0
 which belongs to the cache kmalloc-32 of size 32
The buggy address is located 24 bytes inside of
 32-byte region [ffff88806dbf39c0, ffff88806dbf39e0)

The buggy address belongs to the physical page:
page:ffffea0001b6fcc0 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x6dbf3
flags: 0xfff00000000200(slab|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000000200 0000000000000000 dead000000000122 ffff888011841500
raw: 0000000000000000 0000000000400040 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 0, migratetype Unmovable, gfp_mask 0x12a20(GFP_ATOMIC|__GFP_NOWARN|__GFP_NORETRY), pid 3821, tgid 3820 (syz-executor655), ts 49655858476, free_ts 9922793482
 prep_new_page mm/page_alloc.c:2532 [inline]
 get_page_from_freelist+0x109b/0x2ce0 mm/page_alloc.c:4283
 __alloc_pages+0x1c7/0x510 mm/page_alloc.c:5515
 alloc_pages+0x1a6/0x270 mm/mempolicy.c:2270
 alloc_slab_page mm/slub.c:1824 [inline]
 allocate_slab+0x27e/0x3d0 mm/slub.c:1969
 new_slab mm/slub.c:2029 [inline]
 ___slab_alloc+0x7f1/0xe10 mm/slub.c:3031
 __slab_alloc.constprop.0+0x4d/0xa0 mm/slub.c:3118
 slab_alloc_node mm/slub.c:3209 [inline]
 slab_alloc mm/slub.c:3251 [inline]
 kmem_cache_alloc_trace+0x323/0x3e0 mm/slub.c:3282
 kmalloc include/linux/slab.h:600 [inline]
 kzalloc include/linux/slab.h:733 [inline]
 ref_tracker_alloc+0x14c/0x550 lib/ref_tracker.c:85
 __netdev_tracker_alloc include/linux/netdevice.h:3960 [inline]
 netdev_hold include/linux/netdevice.h:3989 [inline]
 dst_init+0xe0/0x520 net/core/dst.c:52
 dst_alloc+0x16b/0x1f0 net/core/dst.c:96
 rt_dst_alloc+0x51/0x430 net/ipv4/route.c:1633
 __mkroute_output net/ipv4/route.c:2592 [inline]
 ip_route_output_key_hash_rcu+0x895/0x2bc0 net/ipv4/route.c:2814
 ip_route_output_key_hash+0x18b/0x300 net/ipv4/route.c:2643
 __ip_route_output_key include/net/route.h:140 [inline]
 ip_route_output_flow+0x23/0x150 net/ipv4/route.c:2873
 ip_route_output_key include/net/route.h:156 [inline]
 sctp_v4_get_dst+0x2a3/0x11c0 net/sctp/protocol.c:448
 sctp_transport_route+0x125/0x350 net/sctp/transport.c:454
page last free stack trace:
 reset_page_owner include/linux/page_owner.h:24 [inline]
 free_pages_prepare mm/page_alloc.c:1449 [inline]
 free_pcp_prepare+0x5e4/0xd20 mm/page_alloc.c:1499
 free_unref_page_prepare mm/page_alloc.c:3380 [inline]
 free_unref_page+0x19/0x4d0 mm/page_alloc.c:3476
 free_contig_range+0xb1/0x180 mm/page_alloc.c:9408
 destroy_args+0xa8/0x646 mm/debug_vm_pgtable.c:1031
 debug_vm_pgtable+0x2945/0x29d6 mm/debug_vm_pgtable.c:1354
 do_one_initcall+0xfe/0x650 init/main.c:1296
 do_initcall_level init/main.c:1369 [inline]
 do_initcalls init/main.c:1385 [inline]
 do_basic_setup init/main.c:1404 [inline]
 kernel_init_freeable+0x6b1/0x73a init/main.c:1611
 kernel_init+0x1a/0x1d0 init/main.c:1500
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:306

Memory state around the buggy address:
 ffff88806dbf3880: fa fb fb fb fc fc fc fc 00 00 00 00 fc fc fc fc
 ffff88806dbf3900: fa fb fb fb fc fc fc fc 00 00 00 00 fc fc fc fc
>ffff88806dbf3980: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc
                                                    ^
 ffff88806dbf3a00: 00 00 00 00 fc fc fc fc fa fb fb fb fc fc fc fc
 ffff88806dbf3a80: fa fb fb fb fc fc fc fc 00 00 00 00 fc fc fc fc
==================================================================

Crashes (7):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2022/08/12 22:22 upstream 7ebfc85e2cd7 402cd70d .config console log report syz C ci-upstream-kasan-gce-root KASAN: use-after-free Write in sctp_auth_shkey_hold
2022/07/16 08:44 upstream 9b59ec8d50a1 95cb00d1 .config console log report syz C ci-upstream-kasan-gce KASAN: use-after-free Write in sctp_auth_shkey_hold
2022/07/16 10:29 net-old 11052589cf5c 95cb00d1 .config console log report syz C ci-upstream-net-this-kasan-gce KASAN: use-after-free Write in sctp_auth_shkey_hold
2022/07/16 13:10 net-next-old 2acd1022549e 95cb00d1 .config strace log report syz C ci-upstream-net-kasan-gce KASAN: use-after-free Write in sctp_auth_shkey_hold
2022/09/26 01:11 linux-next aaa11ce2ffc8 0042f2b4 .config strace log report syz C ci-upstream-linux-next-kasan-gce-root KASAN: use-after-free Write in sctp_auth_shkey_hold
2022/07/16 08:09 linux-next cb71b93c2dc3 95cb00d1 .config strace log report syz C ci-upstream-linux-next-kasan-gce-root KASAN: use-after-free Write in sctp_auth_shkey_hold
2022/07/16 07:42 linux-next cb71b93c2dc3 95cb00d1 .config console log report info ci-upstream-linux-next-kasan-gce-root KASAN: use-after-free Write in sctp_auth_shkey_hold
* Struck through repros no longer work on HEAD.