syzbot


KASAN: slab-out-of-bounds Read in decrypt_internal

Status: internal: reported C repro on 2022/01/07 23:05
Reported-by: syzbot+@syzkaller.appspotmail.com
Fix commit: 9381fe8c849c net/tls: fix slab-out-of-bounds bug in decrypt_internal
Patched on: [ci-qemu-upstream ci-qemu-upstream-386 ci-qemu2-arm32 ci-qemu2-arm64 ci-qemu2-arm64-compat ci-qemu2-arm64-mte ci-upstream-bpf-kasan-gce ci-upstream-bpf-next-kasan-gce ci-upstream-gce-leak ci-upstream-kasan-gce ci-upstream-kasan-gce-386 ci-upstream-kasan-gce-root ci-upstream-kasan-gce-selinux-root ci-upstream-kasan-gce-smack-root ci-upstream-kmsan-gce ci-upstream-kmsan-gce-386 ci-upstream-linux-next-kasan-gce-root ci-upstream-net-kasan-gce ci-upstream-net-this-kasan-gce ci2-upstream-kcsan-gce ci2-upstream-usb], missing on: [ci-qemu2-riscv64]
First crash: 172d, last: 82d

Cause bisection: the issue happens on the oldest tested release (bisect log)
Crash: KASAN: slab-out-of-bounds Read in decrypt_internal (log)
Repro: C syz .config

Fix bisection: fixed by (bisect log) :
commit 9381fe8c849cfbe50245ac01fc077554f6eaa0e2
Author: Ziyang Xuan <william.xuanziyang@huawei.com>
Date: Thu Mar 31 07:04:28 2022 +0000

  net/tls: fix slab-out-of-bounds bug in decrypt_internal


Sample crash report:
==================================================================
BUG: KASAN: slab-out-of-bounds in memcpy include/linux/fortify-string.h:225 [inline]
BUG: KASAN: slab-out-of-bounds in decrypt_internal+0x1471/0x1d90 net/tls/tls_sw.c:1497
Read of size 16 at addr ffff88801c43cd20 by task syz-executor849/3604

CPU: 0 PID: 3604 Comm: syz-executor849 Not tainted 5.16.0-rc8-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106
 print_address_description.constprop.0.cold+0x8d/0x320 mm/kasan/report.c:247
 __kasan_report mm/kasan/report.c:433 [inline]
 kasan_report.cold+0x83/0xdf mm/kasan/report.c:450
 check_region_inline mm/kasan/generic.c:183 [inline]
 kasan_check_range+0x13d/0x180 mm/kasan/generic.c:189
 memcpy+0x20/0x60 mm/kasan/shadow.c:65
 memcpy include/linux/fortify-string.h:225 [inline]
 decrypt_internal+0x1471/0x1d90 net/tls/tls_sw.c:1497
 decrypt_skb_update+0x141/0xbc0 net/tls/tls_sw.c:1577
 tls_sw_recvmsg+0x5f2/0x1570 net/tls/tls_sw.c:1848
 inet6_recvmsg+0x11b/0x5e0 net/ipv6/af_inet6.c:660
 sock_recvmsg_nosec net/socket.c:944 [inline]
 sock_recvmsg net/socket.c:962 [inline]
 sock_recvmsg net/socket.c:958 [inline]
 ____sys_recvmsg+0x2c4/0x600 net/socket.c:2628
 ___sys_recvmsg+0x127/0x200 net/socket.c:2670
 do_recvmmsg+0x24d/0x6d0 net/socket.c:2764
 __sys_recvmmsg net/socket.c:2843 [inline]
 __do_sys_recvmmsg net/socket.c:2866 [inline]
 __se_sys_recvmmsg net/socket.c:2859 [inline]
 __x64_sys_recvmmsg+0x20b/0x260 net/socket.c:2859
 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+0x44/0xae
RIP: 0033:0x7ff1a54a33f9
Code: 28 c3 e8 2a 14 00 00 66 2e 0f 1f 84 00 00 00 00 00 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 c0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fff2a46a138 EFLAGS: 00000246 ORIG_RAX: 000000000000012b
RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007ff1a54a33f9
RDX: 0000000000000001 RSI: 0000000020002900 RDI: 0000000000000003
RBP: 00007ff1a54673e0 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00007ff1a5467470
R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
 </TASK>

Allocated by task 3604:
 kasan_save_stack+0x1e/0x50 mm/kasan/common.c:38
 kasan_set_track mm/kasan/common.c:46 [inline]
 set_alloc_info mm/kasan/common.c:434 [inline]
 ____kasan_kmalloc mm/kasan/common.c:513 [inline]
 ____kasan_kmalloc mm/kasan/common.c:472 [inline]
 __kasan_kmalloc+0xa9/0xd0 mm/kasan/common.c:522
 kmalloc include/linux/slab.h:595 [inline]
 tls_set_sw_offload+0x800/0x1430 net/tls/tls_sw.c:2525
 do_tls_setsockopt_conf net/tls/tls_main.c:656 [inline]
 do_tls_setsockopt net/tls/tls_main.c:692 [inline]
 tls_setsockopt+0xb39/0xe70 net/tls/tls_main.c:712
 __sys_setsockopt+0x2db/0x610 net/socket.c:2176
 __do_sys_setsockopt net/socket.c:2187 [inline]
 __se_sys_setsockopt net/socket.c:2184 [inline]
 __x64_sys_setsockopt+0xba/0x150 net/socket.c:2184
 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+0x44/0xae

The buggy address belongs to the object at ffff88801c43cd20
 which belongs to the cache kmalloc-16 of size 16
The buggy address is located 0 bytes inside of
 16-byte region [ffff88801c43cd20, ffff88801c43cd30)
The buggy address belongs to the page:
page:ffffea0000710f00 refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff88801c43c000 pfn:0x1c43c
flags: 0xfff00000000200(slab|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000000200 0000000000000000 dead000000000001 ffff888010c413c0
raw: ffff88801c43c000 0000000080800075 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 0x12cc0(GFP_KERNEL|__GFP_NOWARN|__GFP_NORETRY), pid 1, ts 9186592737, free_ts 9182344961
 prep_new_page mm/page_alloc.c:2418 [inline]
 get_page_from_freelist+0xa72/0x2f50 mm/page_alloc.c:4149
 __alloc_pages+0x1b2/0x500 mm/page_alloc.c:5369
 alloc_page_interleave+0x1e/0x200 mm/mempolicy.c:2036
 alloc_pages+0x29f/0x300 mm/mempolicy.c:2185
 alloc_slab_page mm/slub.c:1793 [inline]
 allocate_slab mm/slub.c:1930 [inline]
 new_slab+0x32d/0x4a0 mm/slub.c:1993
 ___slab_alloc+0x918/0xfe0 mm/slub.c:3022
 __slab_alloc.constprop.0+0x4d/0xa0 mm/slub.c:3109
 slab_alloc_node mm/slub.c:3200 [inline]
 slab_alloc mm/slub.c:3242 [inline]
 __kmalloc+0x2fb/0x340 mm/slub.c:4419
 kmalloc include/linux/slab.h:595 [inline]
 kzalloc include/linux/slab.h:724 [inline]
 rh_call_control drivers/usb/core/hcd.c:514 [inline]
 rh_urb_enqueue drivers/usb/core/hcd.c:841 [inline]
 usb_hcd_submit_urb+0x661/0x22c0 drivers/usb/core/hcd.c:1544
 usb_submit_urb+0x86d/0x18a0 drivers/usb/core/urb.c:594
 usb_start_wait_urb+0x101/0x4c0 drivers/usb/core/message.c:58
 usb_internal_control_msg drivers/usb/core/message.c:102 [inline]
 usb_control_msg+0x31c/0x4a0 drivers/usb/core/message.c:153
 usb_get_descriptor+0xdd/0x1d0 drivers/usb/core/message.c:793
 usb_get_configuration+0x296/0x3b30 drivers/usb/core/config.c:898
 usb_enumerate_device drivers/usb/core/hub.c:2395 [inline]
 usb_new_device+0x583/0x7d0 drivers/usb/core/hub.c:2533
 register_root_hub drivers/usb/core/hcd.c:1010 [inline]
 usb_add_hcd.cold+0x132b/0x16fd drivers/usb/core/hcd.c:2959
page last free stack trace:
 reset_page_owner include/linux/page_owner.h:24 [inline]
 free_pages_prepare mm/page_alloc.c:1338 [inline]
 free_pcp_prepare+0x374/0x870 mm/page_alloc.c:1389
 free_unref_page_prepare mm/page_alloc.c:3309 [inline]
 free_unref_page+0x19/0x690 mm/page_alloc.c:3388
 __vunmap+0x781/0xb70 mm/vmalloc.c:2632
 free_work+0x58/0x70 mm/vmalloc.c:95
 process_one_work+0x9b2/0x1660 kernel/workqueue.c:2298
 worker_thread+0x65d/0x1130 kernel/workqueue.c:2445
 kthread+0x405/0x4f0 kernel/kthread.c:327
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295

Memory state around the buggy address:
 ffff88801c43cc00: 00 00 fc fc 00 00 fc fc 00 00 fc fc 00 00 fc fc
 ffff88801c43cc80: 00 00 fc fc 00 00 fc fc 00 00 fc fc 00 00 fc fc
>ffff88801c43cd00: fa fb fc fc 00 04 fc fc fa fb fc fc fa fb fc fc
                                  ^
 ffff88801c43cd80: fa fb fc fc 00 00 fc fc fa fb fc fc fa fb fc fc
 ffff88801c43ce00: 00 00 fc fc 00 00 fc fc fa fb fc fc 00 00 fc fc
==================================================================

Crashes (4):
Manager Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Title
ci-upstream-kasan-gce 2022/01/07 23:39 upstream ddec8ed2d490 2ca0d385 .config log report syz C KASAN: slab-out-of-bounds Read in decrypt_internal
ci-upstream-net-this-kasan-gce 2022/01/08 00:12 net dc35616e6c29 2ca0d385 .config log report syz C KASAN: slab-out-of-bounds Read in decrypt_internal
ci-upstream-net-kasan-gce 2022/01/08 00:07 net-next ca1a6705b271 2ca0d385 .config log report syz C KASAN: slab-out-of-bounds Read in decrypt_internal
ci-upstream-kasan-gce 2022/01/07 23:04 upstream ddec8ed2d490 2ca0d385 .config log report info KASAN: slab-out-of-bounds Read in decrypt_internal