syzbot


KASAN: stack-out-of-bounds Write in __nla_validate_parse

Status: fixed on 2023/10/12 12:48
Subsystems: net
[Documentation on labels]
Fix commit: 4d50e50045aa net: flower: fix stack-out-of-bounds in fl_set_key_cfm()
First crash: 449d, last: 434d
Cause bisection: introduced by (bisect log) :
commit 05c56e7b4319d7f6352f27da876a1acdc8fa5cc4
Author: Andrey Konovalov <andreyknvl@google.com>
Date: Tue Jul 4 00:52:05 2023 +0000

  kasan: fix type cast in memory_is_poisoned_n

Crash: KASAN: stack-out-of-bounds Write in __nla_validate_parse (log)
Repro: C syz .config
  
Similar bugs (2)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KASAN: global-out-of-bounds Read in __nla_validate_parse net C 5 188d 188d 25/28 fixed on 2024/06/05 13:52
upstream KMSAN: uninit-value in __nla_validate_parse (3) netfilter 24 214d 236d 25/28 fixed on 2024/03/26 19:49

Sample crash report:
netlink: 'syz-executor296': attribute type 8 has an invalid length.
==================================================================
BUG: KASAN: stack-out-of-bounds in __nla_validate_parse+0x136/0x2bd0 lib/nlattr.c:588
Write of size 32 at addr ffffc90003a0ee20 by task syz-executor296/5014

CPU: 0 PID: 5014 Comm: syz-executor296 Not tainted 6.5.0-rc2-syzkaller-00307-gd192f5382581 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/12/2023
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x1e7/0x2d0 lib/dump_stack.c:106
 print_address_description mm/kasan/report.c:364 [inline]
 print_report+0x163/0x540 mm/kasan/report.c:475
 kasan_report+0x175/0x1b0 mm/kasan/report.c:588
 kasan_check_range+0x27e/0x290 mm/kasan/generic.c:187
 __asan_memset+0x23/0x40 mm/kasan/shadow.c:84
 __nla_validate_parse+0x136/0x2bd0 lib/nlattr.c:588
 __nla_parse+0x40/0x50 lib/nlattr.c:700
 nla_parse_nested include/net/netlink.h:1262 [inline]
 fl_set_key_cfm+0x1e3/0x440 net/sched/cls_flower.c:1718
 fl_set_key+0x2168/0x6620 net/sched/cls_flower.c:1884
 fl_tmplt_create+0x1fe/0x510 net/sched/cls_flower.c:2666
 tc_chain_tmplt_add net/sched/cls_api.c:2959 [inline]
 tc_ctl_chain+0x131d/0x1ac0 net/sched/cls_api.c:3068
 rtnetlink_rcv_msg+0x82b/0xf50 net/core/rtnetlink.c:6424
 netlink_rcv_skb+0x1df/0x430 net/netlink/af_netlink.c:2549
 netlink_unicast_kernel net/netlink/af_netlink.c:1339 [inline]
 netlink_unicast+0x7c3/0x990 net/netlink/af_netlink.c:1365
 netlink_sendmsg+0xa2a/0xd60 net/netlink/af_netlink.c:1914
 sock_sendmsg_nosec net/socket.c:725 [inline]
 sock_sendmsg net/socket.c:748 [inline]
 ____sys_sendmsg+0x592/0x890 net/socket.c:2494
 ___sys_sendmsg net/socket.c:2548 [inline]
 __sys_sendmsg+0x2b0/0x3a0 net/socket.c:2577
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7f54c6150759
Code: 48 83 c4 28 c3 e8 d7 19 00 00 0f 1f 80 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 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffe06c30578 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
RAX: ffffffffffffffda RBX: 00007f54c619902d RCX: 00007f54c6150759
RDX: 0000000000000000 RSI: 0000000020000280 RDI: 0000000000000003
RBP: 00007ffe06c30590 R08: 0000000000000000 R09: 00007ffe06c305f0
R10: 0000000000000000 R11: 0000000000000246 R12: 00007f54c61c35f0
R13: 00007ffe06c30778 R14: 0000000000000001 R15: 0000000000000001
 </TASK>

The buggy address belongs to stack of task syz-executor296/5014
 and is located at offset 32 in frame:
 fl_set_key_cfm+0x0/0x440 net/sched/cls_flower.c:374

This frame has 1 object:
 [32, 56) 'nla_cfm_opt'

The buggy address belongs to the virtual mapping at
 [ffffc90003a08000, ffffc90003a11000) created by:
 copy_process+0x5c8/0x4290 kernel/fork.c:2330

The buggy address belongs to the physical page:
page:ffffea0000aa4600 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x2a918
flags: 0xfff00000000000(node=0|zone=1|lastcpupid=0x7ff)
page_type: 0xffffffff()
raw: 00fff00000000000 0000000000000000 dead000000000122 0000000000000000
raw: 0000000000000000 0000000000000000 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 0x2dc2(GFP_KERNEL|__GFP_HIGHMEM|__GFP_NOWARN|__GFP_ZERO), pid 4895, tgid 4895 (dhcpcd-run-hook), ts 43346656688, free_ts 43344678988
 set_page_owner include/linux/page_owner.h:31 [inline]
 post_alloc_hook+0x1e6/0x210 mm/page_alloc.c:1570
 prep_new_page mm/page_alloc.c:1577 [inline]
 get_page_from_freelist+0x31e8/0x3370 mm/page_alloc.c:3221
 __alloc_pages+0x255/0x670 mm/page_alloc.c:4477
 vm_area_alloc_pages mm/vmalloc.c:3059 [inline]
 __vmalloc_area_node mm/vmalloc.c:3135 [inline]
 __vmalloc_node_range+0x9a3/0x1490 mm/vmalloc.c:3316
 alloc_thread_stack_node kernel/fork.c:309 [inline]
 dup_task_struct+0x3e5/0x7d0 kernel/fork.c:1113
 copy_process+0x5c8/0x4290 kernel/fork.c:2330
 kernel_clone+0x222/0x800 kernel/fork.c:2912
 __do_sys_clone kernel/fork.c:3055 [inline]
 __se_sys_clone kernel/fork.c:3039 [inline]
 __x64_sys_clone+0x258/0x2a0 kernel/fork.c:3039
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
page last free stack trace:
 reset_page_owner include/linux/page_owner.h:24 [inline]
 free_pages_prepare mm/page_alloc.c:1161 [inline]
 free_unref_page_prepare+0x903/0xa30 mm/page_alloc.c:2348
 free_unref_page_list+0x596/0x830 mm/page_alloc.c:2489
 release_pages+0x2193/0x2470 mm/swap.c:1042
 tlb_batch_pages_flush mm/mmu_gather.c:97 [inline]
 tlb_flush_mmu_free mm/mmu_gather.c:292 [inline]
 tlb_flush_mmu+0x100/0x210 mm/mmu_gather.c:299
 tlb_finish_mmu+0xd4/0x1f0 mm/mmu_gather.c:391
 exit_mmap+0x3e2/0xad0 mm/mmap.c:3214
 __mmput+0x115/0x3c0 kernel/fork.c:1348
 exit_mm+0x21f/0x300 kernel/exit.c:567
 do_exit+0x612/0x2290 kernel/exit.c:861
 do_group_exit+0x206/0x2c0 kernel/exit.c:1024
 __do_sys_exit_group kernel/exit.c:1035 [inline]
 __se_sys_exit_group kernel/exit.c:1033 [inline]
 __x64_sys_exit_group+0x3f/0x40 kernel/exit.c:1033
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

Memory state around the buggy address:
 ffffc90003a0ed00: 00 f3 f3 f3 00 00 00 00 00 00 00 00 00 00 00 00
 ffffc90003a0ed80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>ffffc90003a0ee00: f1 f1 f1 f1 00 00 00 f3 f3 f3 f3 f3 00 00 00 00
                                        ^
 ffffc90003a0ee80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 ffffc90003a0ef00: 00 00 00 00 00 00 00 00 f1 f1 f1 f1 00 00 f3 f3
==================================================================

Crashes (4):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2023/07/22 04:04 upstream d192f5382581 27cbe77f .config strace log report syz C [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-smack-root KASAN: stack-out-of-bounds Write in __nla_validate_parse
2023/08/05 22:07 git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci 86d7896480b0 4ffcc9ef .config console log report syz C [disk image] [vmlinux] [kernel image] ci-upstream-gce-arm64 KASAN: stack-out-of-bounds Write in __nla_validate_parse
2023/07/22 03:07 upstream d192f5382581 27cbe77f .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-smack-root KASAN: stack-out-of-bounds Write in __nla_validate_parse
2023/07/22 03:05 upstream d192f5382581 27cbe77f .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-smack-root KASAN: stack-out-of-bounds Write in __nla_validate_parse
* Struck through repros no longer work on HEAD.