syzbot


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

Status: fixed on 2023/02/24 13:50
Subsystems: net
[Documentation on labels]
Fix commit: c700525fcc06 net/packet: fix slab-out-of-bounds access in packet_recvmsg()
First crash: 1177d, last: 776d
Cause bisection: the issue happens on the oldest tested release (bisect log)
Crash: KASAN: stack-out-of-bounds Write in packet_recvmsg (log)
Repro: C syz .config
  
Similar bugs (2)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
android-5-10 KASAN: slab-out-of-bounds Read in packet_recvmsg C error 1 776d 776d 2/2 fixed on 2022/03/23 23:19
upstream KASAN: stack-out-of-bounds Write in packet_recvmsg net 1 1407d 1407d 0/26 auto-closed as invalid on 2020/09/18 03:11

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 packet_recvmsg+0x56c/0x1150 net/packet/af_packet.c:3487
Read of size 202 at addr ffff88801dfbb168 by task syz-executor390/3700

CPU: 0 PID: 3700 Comm: syz-executor390 Not tainted 5.17.0-rc7-syzkaller-00198-g46b348fd2d81 #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/0x336 mm/kasan/report.c:255
 __kasan_report mm/kasan/report.c:442 [inline]
 kasan_report.cold+0x83/0xdf mm/kasan/report.c:459
 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]
 packet_recvmsg+0x56c/0x1150 net/packet/af_packet.c:3487
 sock_recvmsg_nosec net/socket.c:948 [inline]
 sock_recvmsg net/socket.c:966 [inline]
 sock_recvmsg net/socket.c:962 [inline]
 ____sys_recvmsg+0x2c4/0x600 net/socket.c:2632
 ___sys_recvmsg+0x127/0x200 net/socket.c:2674
 __sys_recvmsg+0xe2/0x1a0 net/socket.c:2704
 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:0x7f629f10cc29
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 41 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 c0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffd00c16e18 EFLAGS: 00000246 ORIG_RAX: 000000000000002f
RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 00007f629f10cc29
RDX: 0000000000000000 RSI: 0000000020000500 RDI: 0000000000000005
RBP: 0000000000000000 R08: 000000000000000d R09: 000000000000000d
R10: 0000000000000000 R11: 0000000000000246 R12: 00007ffd00c16e30
R13: 00000000000f4240 R14: 000000000000e29c R15: 00007ffd00c16e24
 </TASK>

Allocated by task 3605:
 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:436 [inline]
 __kasan_slab_alloc+0x90/0xc0 mm/kasan/common.c:469
 kasan_slab_alloc include/linux/kasan.h:260 [inline]
 slab_post_alloc_hook mm/slab.h:732 [inline]
 slab_alloc_node mm/slub.c:3230 [inline]
 slab_alloc mm/slub.c:3238 [inline]
 kmem_cache_alloc+0x271/0x4b0 mm/slub.c:3243
 skb_clone+0x170/0x3c0 net/core/skbuff.c:1519
 dev_queue_xmit_nit+0x38c/0xa90 net/core/dev.c:2211
 xmit_one net/core/dev.c:3468 [inline]
 dev_hard_start_xmit+0xad/0x920 net/core/dev.c:3489
 sch_direct_xmit+0x19f/0xbe0 net/sched/sch_generic.c:342
 qdisc_restart net/sched/sch_generic.c:407 [inline]
 __qdisc_run+0x4c0/0x1720 net/sched/sch_generic.c:415
 qdisc_run include/net/pkt_sched.h:132 [inline]
 qdisc_run include/net/pkt_sched.h:129 [inline]
 net_tx_action+0x790/0xd30 net/core/dev.c:4952
 __do_softirq+0x29b/0x9c2 kernel/softirq.c:558

The buggy address belongs to the object at ffff88801dfbb140
 which belongs to the cache skbuff_head_cache of size 232
The buggy address is located 40 bytes inside of
 232-byte region [ffff88801dfbb140, ffff88801dfbb228)
The buggy address belongs to the page:
page:ffffea000077eec0 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x1dfbb
flags: 0xfff00000000200(slab|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000000200 0000000000000000 dead000000000122 ffff888140758640
raw: 0000000000000000 00000000800c000c 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 0, ts 59048377184, free_ts 59039581932
 prep_new_page mm/page_alloc.c:2434 [inline]
 get_page_from_freelist+0xa72/0x2f50 mm/page_alloc.c:4165
 __alloc_pages+0x1b2/0x500 mm/page_alloc.c:5389
 alloc_pages+0x1aa/0x310 mm/mempolicy.c:2271
 alloc_slab_page mm/slub.c:1799 [inline]
 allocate_slab+0x27f/0x3c0 mm/slub.c:1944
 new_slab mm/slub.c:2004 [inline]
 ___slab_alloc+0xbe1/0x12b0 mm/slub.c:3018
 __slab_alloc.constprop.0+0x4d/0xa0 mm/slub.c:3105
 slab_alloc_node mm/slub.c:3196 [inline]
 kmem_cache_alloc_node+0x190/0x4f0 mm/slub.c:3266
 __alloc_skb+0x215/0x340 net/core/skbuff.c:414
 alloc_skb include/linux/skbuff.h:1158 [inline]
 wg_packet_send_keepalive+0x6e/0x300 drivers/net/wireguard/send.c:226
 wg_expired_send_persistent_keepalive+0x5a/0x70 drivers/net/wireguard/timers.c:141
 call_timer_fn+0x1a5/0x6b0 kernel/time/timer.c:1421
 expire_timers kernel/time/timer.c:1466 [inline]
 __run_timers.part.0+0x67c/0xa30 kernel/time/timer.c:1734
 __run_timers kernel/time/timer.c:1715 [inline]
 run_timer_softirq+0xb3/0x1d0 kernel/time/timer.c:1747
 __do_softirq+0x29b/0x9c2 kernel/softirq.c:558
page last free stack trace:
 reset_page_owner include/linux/page_owner.h:24 [inline]
 free_pages_prepare mm/page_alloc.c:1352 [inline]
 free_pcp_prepare+0x374/0x870 mm/page_alloc.c:1404
 free_unref_page_prepare mm/page_alloc.c:3325 [inline]
 free_unref_page+0x19/0x690 mm/page_alloc.c:3404
 __unfreeze_partials+0x320/0x340 mm/slub.c:2536
 qlink_free mm/kasan/quarantine.c:157 [inline]
 qlist_free_all+0x6d/0x160 mm/kasan/quarantine.c:176
 kasan_quarantine_reduce+0x180/0x200 mm/kasan/quarantine.c:283
 __kasan_slab_alloc+0xa2/0xc0 mm/kasan/common.c:446
 kasan_slab_alloc include/linux/kasan.h:260 [inline]
 slab_post_alloc_hook mm/slab.h:732 [inline]
 slab_alloc_node mm/slub.c:3230 [inline]
 kmem_cache_alloc_node+0x2c3/0x4f0 mm/slub.c:3266
 __alloc_skb+0x215/0x340 net/core/skbuff.c:414
 alloc_skb include/linux/skbuff.h:1158 [inline]
 alloc_skb_with_frags+0x93/0x620 net/core/skbuff.c:5956
 sock_alloc_send_pskb+0x793/0x920 net/core/sock.c:2586
 unix_dgram_sendmsg+0x414/0x1a10 net/unix/af_unix.c:1896
 sock_sendmsg_nosec net/socket.c:705 [inline]
 sock_sendmsg+0xcf/0x120 net/socket.c:725
 sock_write_iter+0x289/0x3c0 net/socket.c:1061
 call_write_iter include/linux/fs.h:2074 [inline]
 new_sync_write+0x431/0x660 fs/read_write.c:503
 vfs_write+0x7cd/0xae0 fs/read_write.c:590
 ksys_write+0x1ee/0x250 fs/read_write.c:643

Memory state around the buggy address:
 ffff88801dfbb100: fc fc fc fc fc fc fc fc 00 00 00 00 00 00 00 00
 ffff88801dfbb180: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>ffff88801dfbb200: 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc fc
                                  ^
 ffff88801dfbb280: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 ffff88801dfbb300: 00 00 00 00 00 00 00 00 00 00 00 00 00 fc fc fc
==================================================================

Crashes (12):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2022/03/12 15:26 net-old 46b348fd2d81 9e8eaa75 .config console log report syz C ci-upstream-net-this-kasan-gce KASAN: slab-out-of-bounds Read in packet_recvmsg
2022/03/12 14:56 upstream 68453767131a 9e8eaa75 .config console log report syz C ci-upstream-kasan-gce KASAN: stack-out-of-bounds Write in packet_recvmsg
2022/03/12 14:50 net-next-old 0b3660695e80 9e8eaa75 .config console log report syz C ci-upstream-net-kasan-gce KASAN: stack-out-of-bounds Write in packet_recvmsg
2022/03/11 09:13 net-next-old 3e18bcb778e6 9e8eaa75 .config console log report info ci-upstream-net-kasan-gce KASAN: slab-out-of-bounds Read in packet_recvmsg
2022/01/30 02:19 net-next-old ff58831fa02d 495e00c5 .config console log report info ci-upstream-net-kasan-gce KASAN: slab-out-of-bounds Read in packet_recvmsg
2021/08/01 15:36 net-next-old 3e12361b6d23 6c236867 .config console log report info ci-upstream-net-kasan-gce KASAN: slab-out-of-bounds Read in packet_recvmsg
2021/02/04 13:31 net-next-old 32d1bbb1d609 42b90a7c .config console log report info ci-upstream-net-kasan-gce KASAN: slab-out-of-bounds Read in packet_recvmsg
2021/10/23 07:33 net-old 64222515138e 282f03fb .config console log report info ci-upstream-net-this-kasan-gce KASAN: stack-out-of-bounds Write in packet_recvmsg
2021/10/02 19:26 net-old 7cd8b1542a7b db0f5787 .config console log report info ci-upstream-net-this-kasan-gce KASAN: stack-out-of-bounds Write in packet_recvmsg
2021/04/28 03:52 net-old bbd6f0a94813 805b5003 .config console log report info ci-upstream-net-this-kasan-gce KASAN: stack-out-of-bounds Write in packet_recvmsg
2021/12/11 15:39 net-next-old be3158290db8 49ca1f59 .config console log report info ci-upstream-net-kasan-gce KASAN: stack-out-of-bounds Write in packet_recvmsg
2021/05/13 12:08 net-next-old d8654f4f9300 ed7d41c5 .config console log report info ci-upstream-net-kasan-gce KASAN: stack-out-of-bounds Write in packet_recvmsg
* Struck through repros no longer work on HEAD.