================================================================== BUG: KASAN: slab-use-after-free in __xfrm_state_lookup_all net/xfrm/xfrm_state.c:1143 [inline] BUG: KASAN: slab-use-after-free in xfrm_state_find+0x8c90/0x91e8 net/xfrm/xfrm_state.c:1494 Read of size 1 at addr ffffaf801c604330 by task syz.3.1198/7852 CPU: 1 UID: 0 PID: 7852 Comm: syz.3.1198 Not tainted 6.17.0-rc1-syzkaller-g8f5ae30d69d7 #0 PREEMPT Hardware name: riscv-virtio,qemu (DT) Call Trace: [] dump_backtrace+0x2e/0x3c arch/riscv/kernel/stacktrace.c:132 [] show_stack+0x30/0x3c arch/riscv/kernel/stacktrace.c:138 [] __dump_stack lib/dump_stack.c:94 [inline] [] dump_stack_lvl+0x12e/0x1a6 lib/dump_stack.c:120 [] print_address_description mm/kasan/report.c:378 [inline] [] print_report+0x28e/0x5a2 mm/kasan/report.c:482 [] kasan_report+0xf0/0x214 mm/kasan/report.c:595 [] __asan_report_load1_noabort+0x12/0x1a mm/kasan/report_generic.c:378 [] __xfrm_state_lookup_all net/xfrm/xfrm_state.c:1143 [inline] [] xfrm_state_find+0x8c90/0x91e8 net/xfrm/xfrm_state.c:1494 [] xfrm_tmpl_resolve_one+0x25c/0xb4e net/xfrm/xfrm_policy.c:2522 [] xfrm_tmpl_resolve+0x1d2/0x3a8 net/xfrm/xfrm_policy.c:2573 [] xfrm_resolve_and_create_bundle+0x112/0x588 net/xfrm/xfrm_policy.c:2871 [] xfrm_bundle_lookup net/xfrm/xfrm_policy.c:3106 [inline] [] xfrm_lookup_with_ifid+0x478/0x20b2 net/xfrm/xfrm_policy.c:3237 [] xfrm_lookup+0x34/0x46 net/xfrm/xfrm_policy.c:3336 [] icmp_route_lookup.constprop.0+0x41e/0x12ea net/ipv4/icmp.c:513 [] __icmp_send+0xbf6/0x1c8e net/ipv4/icmp.c:746 [] icmp_send include/net/icmp.h:43 [inline] [] ip_options_compile+0xca/0x10e net/ipv4/ip_options.c:473 [] ip_rcv_options net/ipv4/ip_input.c:287 [inline] [] ip_rcv_finish_core+0x664/0x2698 net/ipv4/ip_input.c:394 [] ip_rcv_finish+0x116/0x2d2 net/ipv4/ip_input.c:452 [] NF_HOOK include/linux/netfilter.h:318 [inline] [] NF_HOOK include/linux/netfilter.h:312 [inline] [] ip_rcv+0xd6/0x44e net/ipv4/ip_input.c:574 [] __netif_receive_skb_one_core+0x106/0x16e net/core/dev.c:5979 [] __netif_receive_skb+0x2c/0x144 net/core/dev.c:6092 [] netif_receive_skb_internal net/core/dev.c:6178 [inline] [] netif_receive_skb+0x1aa/0xbf2 net/core/dev.c:6237 [] tun_rx_batched.isra.0+0x430/0x686 drivers/net/tun.c:1485 [] tun_get_user+0x294c/0x3e0e drivers/net/tun.c:1950 [] tun_chr_write_iter+0xc4/0x21a drivers/net/tun.c:1996 [] new_sync_write fs/read_write.c:593 [inline] [] vfs_write+0x766/0xd1c fs/read_write.c:686 [] ksys_write+0x126/0x234 fs/read_write.c:738 [] __do_sys_write fs/read_write.c:749 [inline] [] __se_sys_write fs/read_write.c:746 [inline] [] __riscv_sys_write+0x6e/0xa0 fs/read_write.c:746 [] syscall_handler+0x94/0x118 arch/riscv/include/asm/syscall.h:112 [] do_trap_ecall_u+0x396/0x530 arch/riscv/kernel/traps.c:343 [] handle_exception+0x146/0x152 arch/riscv/kernel/entry.S:197 Allocated by task 6457: stack_trace_save+0xa0/0xd2 kernel/stacktrace.c:122 kasan_save_stack+0x3e/0x6a mm/kasan/common.c:47 kasan_save_track+0x16/0x28 mm/kasan/common.c:68 kasan_save_alloc_info+0x30/0x3e mm/kasan/generic.c:562 unpoison_slab_object mm/kasan/common.c:330 [inline] __kasan_slab_alloc+0x7c/0x82 mm/kasan/common.c:356 kasan_slab_alloc include/linux/kasan.h:250 [inline] slab_post_alloc_hook mm/slub.c:4180 [inline] slab_alloc_node mm/slub.c:4229 [inline] kmem_cache_alloc_noprof+0x104/0x3bc mm/slub.c:4236 xfrm_state_alloc+0x2e/0x4ca net/xfrm/xfrm_state.c:733 __find_acq_core+0xdd0/0x29f0 net/xfrm/xfrm_state.c:1833 xfrm_find_acq+0x64/0x8c net/xfrm/xfrm_state.c:2353 xfrm_alloc_userspi+0x5b0/0xc10 net/xfrm/xfrm_user.c:1863 xfrm_user_rcv_msg+0x40c/0x9be net/xfrm/xfrm_user.c:3501 netlink_rcv_skb+0x206/0x3be net/netlink/af_netlink.c:2552 xfrm_netlink_rcv+0x7c/0xa6 net/xfrm/xfrm_user.c:3523 netlink_unicast_kernel net/netlink/af_netlink.c:1320 [inline] netlink_unicast+0x544/0x88a net/netlink/af_netlink.c:1346 netlink_sendmsg+0x860/0xdd8 net/netlink/af_netlink.c:1896 sock_sendmsg_nosec net/socket.c:714 [inline] __sock_sendmsg+0xcc/0x160 net/socket.c:729 ____sys_sendmsg+0x63e/0x79c net/socket.c:2614 ___sys_sendmsg+0x144/0x1e6 net/socket.c:2668 __sys_sendmsg+0x188/0x246 net/socket.c:2700 __do_sys_sendmsg net/socket.c:2705 [inline] __se_sys_sendmsg net/socket.c:2703 [inline] __riscv_sys_sendmsg+0x70/0xa2 net/socket.c:2703 syscall_handler+0x94/0x118 arch/riscv/include/asm/syscall.h:112 do_trap_ecall_u+0x396/0x530 arch/riscv/kernel/traps.c:343 handle_exception+0x146/0x152 arch/riscv/kernel/entry.S:197 Freed by task 5959: stack_trace_save+0xa0/0xd2 kernel/stacktrace.c:122 kasan_save_stack+0x3e/0x6a mm/kasan/common.c:47 kasan_save_track+0x16/0x28 mm/kasan/common.c:68 kasan_save_free_info+0x40/0x5a mm/kasan/generic.c:576 poison_slab_object mm/kasan/common.c:243 [inline] __kasan_slab_free+0x4a/0x62 mm/kasan/common.c:275 kasan_slab_free include/linux/kasan.h:233 [inline] slab_free_hook mm/slub.c:2417 [inline] slab_free mm/slub.c:4680 [inline] kmem_cache_free+0x2b4/0x562 mm/slub.c:4782 xfrm_state_free net/xfrm/xfrm_state.c:591 [inline] xfrm_state_gc_destroy net/xfrm/xfrm_state.c:618 [inline] xfrm_state_gc_task+0x4b0/0x6ea net/xfrm/xfrm_state.c:634 process_one_work+0x96a/0x1f32 kernel/workqueue.c:3236 process_scheduled_works kernel/workqueue.c:3319 [inline] worker_thread+0x5ce/0xde8 kernel/workqueue.c:3400 kthread+0x39c/0x7d4 kernel/kthread.c:463 ret_from_fork_kernel+0x2a/0xbb4 arch/riscv/kernel/process.c:214 ret_from_fork_kernel_asm+0x16/0x18 arch/riscv/kernel/entry.S:327 The buggy address belongs to the object at ffffaf801c604000 which belongs to the cache xfrm_state of size 928 The buggy address is located 816 bytes inside of freed 928-byte region [ffffaf801c604000, ffffaf801c6043a0) The buggy address belongs to the physical page: page: refcount:0 mapcount:0 mapping:0000000000000000 index:0xffffaf801c604440 pfn:0x9c604 head: order:2 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0 flags: 0xffe000000000040(head|node=0|zone=0|lastcpupid=0x7ff) page_type: f5(slab) raw: 0ffe000000000040 ffffaf80127e0280 dead000000000122 0000000000000000 raw: ffffaf801c604440 00000000800f000d 00000000f5000000 0000000000000000 head: 0ffe000000000040 ffffaf80127e0280 dead000000000122 0000000000000000 head: ffffaf801c604440 00000000800f000d 00000000f5000000 0000000000000000 head: 0ffe000000000002 ffff8d8000718101 00000000ffffffff 00000000ffffffff head: ffffffffffffffff 0000000000000000 00000000ffffffff 0000000000000004 page dumped because: kasan: bad access detected page_owner tracks the page as allocated page last allocated via order 2, migratetype Unmovable, gfp_mask 0x52820(GFP_ATOMIC|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP), pid 4588, tgid 4587 (syz.0.215), ts 1061164425900, free_ts 1060511471400 __set_page_owner+0x94/0x4a8 mm/page_owner.c:329 set_page_owner include/linux/page_owner.h:32 [inline] post_alloc_hook+0xdc/0x1ba mm/page_alloc.c:1851 prep_new_page mm/page_alloc.c:1859 [inline] get_page_from_freelist+0x7fa/0x359a mm/page_alloc.c:3858 __alloc_frozen_pages_noprof+0x22e/0x2120 mm/page_alloc.c:5148 alloc_pages_mpol+0x1fa/0x5bc mm/mempolicy.c:2416 alloc_frozen_pages_noprof+0x174/0x2f0 mm/mempolicy.c:2487 alloc_slab_page mm/slub.c:2487 [inline] allocate_slab mm/slub.c:2655 [inline] new_slab+0x27c/0x38c mm/slub.c:2709 ___slab_alloc+0xb5a/0x1192 mm/slub.c:3891 __slab_alloc.constprop.0+0x60/0xb0 mm/slub.c:3981 __slab_alloc_node mm/slub.c:4056 [inline] slab_alloc_node mm/slub.c:4217 [inline] kmem_cache_alloc_noprof+0xd0/0x3bc mm/slub.c:4236 xfrm_state_alloc+0x2e/0x4ca net/xfrm/xfrm_state.c:733 xfrm_add_acquire+0xfa/0xa30 net/xfrm/xfrm_user.c:2990 xfrm_user_rcv_msg+0x40c/0x9be net/xfrm/xfrm_user.c:3501 netlink_rcv_skb+0x206/0x3be net/netlink/af_netlink.c:2552 xfrm_netlink_rcv+0x7c/0xa6 net/xfrm/xfrm_user.c:3523 netlink_unicast_kernel net/netlink/af_netlink.c:1320 [inline] netlink_unicast+0x544/0x88a net/netlink/af_netlink.c:1346 page last free pid 4587 tgid 4587 stack trace: __reset_page_owner+0x78/0x1ba mm/page_owner.c:308 reset_page_owner include/linux/page_owner.h:25 [inline] free_pages_prepare mm/page_alloc.c:1395 [inline] __free_frozen_pages+0x836/0x145e mm/page_alloc.c:2895 free_frozen_pages+0xe/0x16 mm/page_alloc.c:2933 __free_slab+0xc0/0x18a mm/slub.c:2724 free_slab+0x3a/0x1b0 mm/slub.c:2747 discard_slab+0x42/0x5e mm/slub.c:2753 __slab_free+0x2de/0x32a mm/slub.c:4591 do_slab_free mm/slub.c:4632 [inline] ___cache_free+0x1a2/0x1dc mm/slub.c:4738 qlink_free mm/kasan/quarantine.c:163 [inline] qlist_free_all+0x76/0x168 mm/kasan/quarantine.c:179 kasan_quarantine_reduce+0x158/0x1ba mm/kasan/quarantine.c:286 __kasan_slab_alloc+0x5c/0x82 mm/kasan/common.c:340 kasan_slab_alloc include/linux/kasan.h:250 [inline] slab_post_alloc_hook mm/slub.c:4180 [inline] slab_alloc_node mm/slub.c:4229 [inline] kmem_cache_alloc_noprof+0x104/0x3bc mm/slub.c:4236 ptlock_alloc mm/memory.c:7161 [inline] ptlock_init include/linux/mm.h:2953 [inline] pmd_ptlock_init include/linux/mm.h:3081 [inline] pagetable_pmd_ctor include/linux/mm.h:3109 [inline] pmd_alloc_one_noprof include/asm-generic/pgalloc.h:145 [inline] __pmd_alloc+0xc2/0xa4e mm/memory.c:6450 pmd_alloc include/linux/mm.h:2844 [inline] __handle_mm_fault+0x8fc/0x58e8 mm/memory.c:6155 handle_mm_fault+0x49c/0x8aa mm/memory.c:6364 handle_page_fault+0x9f4/0x1cdc arch/riscv/mm/fault.c:362 Memory state around the buggy address: ffffaf801c604200: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffffaf801c604280: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb >ffffaf801c604300: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ^ ffffaf801c604380: fb fb fb fb fc fc fc fc fc fc fc fc fc fc fc fc ffffaf801c604400: fc fc fc fc fc fc fc fc fa fb fb fb fb fb fb fb ==================================================================