================================================================== BUG: KASAN: use-after-free in dev_map_enqueue+0x40/0x340 kernel/bpf/devmap.c:529 Read of size 8 at addr ffff888113a74980 by task syz.0.1375/3533 CPU: 1 PID: 3533 Comm: syz.0.1375 Not tainted 6.1.112-syzkaller-00011-g8ed9a61b544c #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024 Call Trace: __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0x151/0x1b7 lib/dump_stack.c:106 print_address_description mm/kasan/report.c:316 [inline] print_report+0x158/0x4e0 mm/kasan/report.c:427 kasan_report+0x13c/0x170 mm/kasan/report.c:531 __asan_report_load8_noabort+0x14/0x20 mm/kasan/report_generic.c:351 dev_map_enqueue+0x40/0x340 kernel/bpf/devmap.c:529 __xdp_do_redirect_frame net/core/filter.c:4294 [inline] xdp_do_redirect+0x5ed/0xc60 net/core/filter.c:4342 tun_xdp_act+0xdb/0xc00 drivers/net/tun.c:1625 tun_build_skb drivers/net/tun.c:1715 [inline] tun_get_user+0xb35/0x3a90 drivers/net/tun.c:1818 tun_chr_write_iter+0x129/0x210 drivers/net/tun.c:2044 call_write_iter include/linux/fs.h:2274 [inline] new_sync_write fs/read_write.c:491 [inline] vfs_write+0xaf6/0xed0 fs/read_write.c:584 ksys_write+0x199/0x2c0 fs/read_write.c:637 __do_sys_write fs/read_write.c:649 [inline] __se_sys_write fs/read_write.c:646 [inline] __x64_sys_write+0x7b/0x90 fs/read_write.c:646 x64_sys_call+0x2f/0x9a0 arch/x86/include/generated/asm/syscalls_64.h:2 do_syscall_x64 arch/x86/entry/common.c:51 [inline] do_syscall_64+0x3b/0xb0 arch/x86/entry/common.c:81 entry_SYSCALL_64_after_hwframe+0x68/0xd2 RIP: 0033:0x7febe2f7d1ff Code: 89 54 24 18 48 89 74 24 10 89 7c 24 08 e8 c9 8d 02 00 48 8b 54 24 18 48 8b 74 24 10 41 89 c0 8b 7c 24 08 b8 01 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 31 44 89 c7 48 89 44 24 08 e8 1c 8e 02 00 48 RSP: 002b:00007febe3cd0000 EFLAGS: 00000293 ORIG_RAX: 0000000000000001 RAX: ffffffffffffffda RBX: 00007febe3135f80 RCX: 00007febe2f7d1ff RDX: 0000000000000066 RSI: 0000000020001580 RDI: 00000000000000c8 RBP: 00007febe2ff175e R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000066 R11: 0000000000000293 R12: 0000000000000000 R13: 0000000000000000 R14: 00007febe3135f80 R15: 00007ffe3716e158 Allocated by task 3180: kasan_save_stack mm/kasan/common.c:45 [inline] kasan_set_track+0x4b/0x70 mm/kasan/common.c:52 kasan_save_alloc_info+0x1f/0x30 mm/kasan/generic.c:505 ____kasan_kmalloc mm/kasan/common.c:379 [inline] __kasan_kmalloc+0x9c/0xb0 mm/kasan/common.c:388 kasan_kmalloc include/linux/kasan.h:212 [inline] __do_kmalloc_node mm/slab_common.c:938 [inline] __kmalloc_node+0xb4/0x1e0 mm/slab_common.c:945 kmalloc_node include/linux/slab.h:583 [inline] bpf_map_kmalloc_node+0xd0/0x2c0 kernel/bpf/syscall.c:454 __dev_map_alloc_node+0x5c/0x4e0 kernel/bpf/devmap.c:848 __dev_map_update_elem kernel/bpf/devmap.c:913 [inline] dev_map_update_elem+0x20e/0x3f0 kernel/bpf/devmap.c:932 bpf_map_update_value+0x23a/0x410 kernel/bpf/syscall.c:228 map_update_elem+0x500/0x680 kernel/bpf/syscall.c:1443 __sys_bpf+0x460/0x7f0 kernel/bpf/syscall.c:4990 __do_sys_bpf kernel/bpf/syscall.c:5106 [inline] __se_sys_bpf kernel/bpf/syscall.c:5104 [inline] __x64_sys_bpf+0x7c/0x90 kernel/bpf/syscall.c:5104 x64_sys_call+0x87f/0x9a0 arch/x86/include/generated/asm/syscalls_64.h:322 do_syscall_x64 arch/x86/entry/common.c:51 [inline] do_syscall_64+0x3b/0xb0 arch/x86/entry/common.c:81 entry_SYSCALL_64_after_hwframe+0x68/0xd2 Freed by task 330: kasan_save_stack mm/kasan/common.c:45 [inline] kasan_set_track+0x4b/0x70 mm/kasan/common.c:52 kasan_save_free_info+0x2b/0x40 mm/kasan/generic.c:516 ____kasan_slab_free+0x131/0x180 mm/kasan/common.c:241 __kasan_slab_free+0x11/0x20 mm/kasan/common.c:249 kasan_slab_free include/linux/kasan.h:178 [inline] slab_free_hook mm/slub.c:1745 [inline] slab_free_freelist_hook mm/slub.c:1771 [inline] slab_free mm/slub.c:3684 [inline] __kmem_cache_free+0x218/0x3b0 mm/slub.c:3697 kfree+0x7a/0xf0 mm/slab_common.c:990 dev_map_free+0x596/0x6c0 kernel/bpf/devmap.c:238 bpf_map_free_deferred+0xf7/0x1b0 kernel/bpf/syscall.c:637 process_one_work+0x73d/0xcb0 kernel/workqueue.c:2299 worker_thread+0xa60/0x1260 kernel/workqueue.c:2446 kthread+0x26d/0x300 kernel/kthread.c:386 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295 Last potentially related work creation: kasan_save_stack+0x3b/0x60 mm/kasan/common.c:45 __kasan_record_aux_stack+0xb4/0xc0 mm/kasan/generic.c:486 kasan_record_aux_stack_noalloc+0xb/0x10 mm/kasan/generic.c:496 kvfree_call_rcu+0x9f/0x800 kernel/rcu/tree.c:3445 kernfs_unlink_open_file+0x327/0x3d0 fs/kernfs/file.c:635 kernfs_fop_release+0x253/0x310 fs/kernfs/file.c:807 __fput+0x1e5/0x870 fs/file_table.c:320 ____fput+0x15/0x20 fs/file_table.c:348 task_work_run+0x24d/0x2e0 kernel/task_work.c:203 resume_user_mode_work include/linux/resume_user_mode.h:49 [inline] exit_to_user_mode_loop+0x94/0xa0 kernel/entry/common.c:177 exit_to_user_mode_prepare+0x5a/0xa0 kernel/entry/common.c:210 __syscall_exit_to_user_mode_work kernel/entry/common.c:292 [inline] syscall_exit_to_user_mode+0x26/0x130 kernel/entry/common.c:303 do_syscall_64+0x47/0xb0 arch/x86/entry/common.c:87 entry_SYSCALL_64_after_hwframe+0x68/0xd2 Second to last potentially related work creation: kasan_save_stack+0x3b/0x60 mm/kasan/common.c:45 __kasan_record_aux_stack+0xb4/0xc0 mm/kasan/generic.c:486 kasan_record_aux_stack_noalloc+0xb/0x10 mm/kasan/generic.c:496 kvfree_call_rcu+0x9f/0x800 kernel/rcu/tree.c:3445 kernfs_unlink_open_file+0x327/0x3d0 fs/kernfs/file.c:635 kernfs_fop_release+0x253/0x310 fs/kernfs/file.c:807 __fput+0x1e5/0x870 fs/file_table.c:320 ____fput+0x15/0x20 fs/file_table.c:348 task_work_run+0x24d/0x2e0 kernel/task_work.c:203 resume_user_mode_work include/linux/resume_user_mode.h:49 [inline] exit_to_user_mode_loop+0x94/0xa0 kernel/entry/common.c:177 exit_to_user_mode_prepare+0x5a/0xa0 kernel/entry/common.c:210 __syscall_exit_to_user_mode_work kernel/entry/common.c:292 [inline] syscall_exit_to_user_mode+0x26/0x130 kernel/entry/common.c:303 do_syscall_64+0x47/0xb0 arch/x86/entry/common.c:87 entry_SYSCALL_64_after_hwframe+0x68/0xd2 The buggy address belongs to the object at ffff888113a74980 which belongs to the cache kmalloc-96 of size 96 The buggy address is located 0 bytes inside of 96-byte region [ffff888113a74980, ffff888113a749e0) The buggy address belongs to the physical page: page:ffffea00044e9d00 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x113a74 flags: 0x4000000000000200(slab|zone=1) raw: 4000000000000200 0000000000000000 dead000000000001 ffff888100042900 raw: 0000000000000000 0000000000200020 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 0x112c40(GFP_NOFS|__GFP_NOWARN|__GFP_NORETRY|__GFP_HARDWALL), pid 915, tgid 913 (syz.3.250), ts 35366890470, free_ts 35307045200 set_page_owner include/linux/page_owner.h:33 [inline] post_alloc_hook+0x213/0x220 mm/page_alloc.c:2590 prep_new_page+0x1b/0x110 mm/page_alloc.c:2597 get_page_from_freelist+0x2980/0x2a10 mm/page_alloc.c:4439 __alloc_pages+0x234/0x610 mm/page_alloc.c:5728 alloc_slab_page+0x6c/0xf0 allocate_slab mm/slub.c:1962 [inline] new_slab+0x90/0x3e0 mm/slub.c:2015 ___slab_alloc+0x6f9/0xb80 mm/slub.c:3203 __slab_alloc+0x5d/0xa0 mm/slub.c:3302 slab_alloc_node mm/slub.c:3387 [inline] __kmem_cache_alloc_node+0x1af/0x250 mm/slub.c:3460 __do_kmalloc_node mm/slab_common.c:937 [inline] __kmalloc+0xa3/0x1e0 mm/slab_common.c:951 kmalloc_array include/linux/slab.h:609 [inline] kcalloc include/linux/slab.h:640 [inline] ext4_find_extent+0x370/0xdb0 fs/ext4/extents.c:914 ext4_clu_mapped+0x1c8/0x770 fs/ext4/extents.c:5843 ext4_insert_delayed_block fs/ext4/inode.c:1719 [inline] ext4_da_map_blocks fs/ext4/inode.c:1841 [inline] ext4_da_get_block_prep+0xb00/0x1370 fs/ext4/inode.c:1881 ext4_block_write_begin+0x55e/0x1200 fs/ext4/inode.c:1123 ext4_da_write_begin+0x51f/0x920 fs/ext4/inode.c:3024 generic_perform_write+0x2f9/0x5c0 mm/filemap.c:3849 page last free stack trace: reset_page_owner include/linux/page_owner.h:26 [inline] free_pages_prepare mm/page_alloc.c:1498 [inline] free_pcp_prepare mm/page_alloc.c:1572 [inline] free_unref_page_prepare+0x83d/0x850 mm/page_alloc.c:3511 free_unref_page+0xb2/0x5c0 mm/page_alloc.c:3607 free_the_page mm/page_alloc.c:798 [inline] __free_pages+0x61/0xf0 mm/page_alloc.c:5817 __free_slab+0xce/0x1a0 mm/slub.c:2039 free_slab mm/slub.c:2054 [inline] discard_slab+0x29/0x40 mm/slub.c:2060 __slab_free+0x205/0x280 mm/slub.c:3597 do_slab_free mm/slub.c:3638 [inline] ___cache_free+0xc6/0xd0 mm/slub.c:3691 qlink_free mm/kasan/quarantine.c:168 [inline] qlist_free_all+0xc5/0x140 mm/kasan/quarantine.c:187 kasan_quarantine_reduce+0x15a/0x180 mm/kasan/quarantine.c:294 __kasan_slab_alloc+0x24/0x80 mm/kasan/common.c:310 kasan_slab_alloc include/linux/kasan.h:202 [inline] slab_post_alloc_hook+0x53/0x2c0 mm/slab.h:768 slab_alloc_node mm/slub.c:3421 [inline] slab_alloc mm/slub.c:3429 [inline] __kmem_cache_alloc_lru mm/slub.c:3436 [inline] kmem_cache_alloc+0x175/0x2c0 mm/slub.c:3445 getname_flags+0xba/0x520 fs/namei.c:139 vfs_fstatat fs/stat.c:266 [inline] __do_sys_newfstatat fs/stat.c:437 [inline] __se_sys_newfstatat+0xe2/0x7b0 fs/stat.c:431 __x64_sys_newfstatat+0x9b/0xb0 fs/stat.c:431 x64_sys_call+0x6e2/0x9a0 arch/x86/include/generated/asm/syscalls_64.h:263 Memory state around the buggy address: ffff888113a74880: fa fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc ffff888113a74900: fa fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc >ffff888113a74980: fa fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc ^ ffff888113a74a00: fa fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc ffff888113a74a80: fa fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc ================================================================== general protection fault, probably for non-canonical address 0xdffffc0000000044: 0000 [#1] PREEMPT SMP KASAN KASAN: null-ptr-deref in range [0x0000000000000220-0x0000000000000227] CPU: 1 PID: 3533 Comm: syz.0.1375 Tainted: G B 6.1.112-syzkaller-00011-g8ed9a61b544c #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024 RIP: 0010:__xdp_enqueue kernel/bpf/devmap.c:478 [inline] RIP: 0010:dev_map_enqueue+0x91/0x340 kernel/bpf/devmap.c:531 Code: d0 00 00 00 4c 89 e8 48 c1 e8 03 42 80 3c 20 00 74 08 4c 89 ef e8 4f 65 25 00 bb 20 02 00 00 49 03 5d 00 48 89 d8 48 c1 e8 03 <42> 80 3c 20 00 74 08 48 89 df e8 30 65 25 00 48 83 3b 00 0f 84 eb RSP: 0018:ffffc9000f73f7a0 EFLAGS: 00010206 RAX: 0000000000000044 RBX: 0000000000000220 RCX: ffffffff8197a881 RDX: 0000000000000000 RSI: 0000000000000008 RDI: ffff88811682e450 RBP: ffffc9000f73f7e0 R08: ffffffff8144a2c3 R09: fffffbfff0f6e0fd R10: 0000000000000000 R11: dffffc0000000001 R12: dffffc0000000000 R13: ffff88811682e450 R14: ffff88811682e380 R15: ffff888113b68000 FS: 00007febe3cd06c0(0000) GS:ffff8881f6f00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 000055558dc994a8 CR3: 00000001173b6000 CR4: 00000000003526a0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: __xdp_do_redirect_frame net/core/filter.c:4294 [inline] xdp_do_redirect+0x5ed/0xc60 net/core/filter.c:4342 tun_xdp_act+0xdb/0xc00 drivers/net/tun.c:1625 tun_build_skb drivers/net/tun.c:1715 [inline] tun_get_user+0xb35/0x3a90 drivers/net/tun.c:1818 tun_chr_write_iter+0x129/0x210 drivers/net/tun.c:2044 call_write_iter include/linux/fs.h:2274 [inline] new_sync_write fs/read_write.c:491 [inline] vfs_write+0xaf6/0xed0 fs/read_write.c:584 ksys_write+0x199/0x2c0 fs/read_write.c:637 __do_sys_write fs/read_write.c:649 [inline] __se_sys_write fs/read_write.c:646 [inline] __x64_sys_write+0x7b/0x90 fs/read_write.c:646 x64_sys_call+0x2f/0x9a0 arch/x86/include/generated/asm/syscalls_64.h:2 do_syscall_x64 arch/x86/entry/common.c:51 [inline] do_syscall_64+0x3b/0xb0 arch/x86/entry/common.c:81 entry_SYSCALL_64_after_hwframe+0x68/0xd2 RIP: 0033:0x7febe2f7d1ff Code: 89 54 24 18 48 89 74 24 10 89 7c 24 08 e8 c9 8d 02 00 48 8b 54 24 18 48 8b 74 24 10 41 89 c0 8b 7c 24 08 b8 01 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 31 44 89 c7 48 89 44 24 08 e8 1c 8e 02 00 48 RSP: 002b:00007febe3cd0000 EFLAGS: 00000293 ORIG_RAX: 0000000000000001 RAX: ffffffffffffffda RBX: 00007febe3135f80 RCX: 00007febe2f7d1ff RDX: 0000000000000066 RSI: 0000000020001580 RDI: 00000000000000c8 RBP: 00007febe2ff175e R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000066 R11: 0000000000000293 R12: 0000000000000000 R13: 0000000000000000 R14: 00007febe3135f80 R15: 00007ffe3716e158 Modules linked in: ---[ end trace 0000000000000000 ]--- RIP: 0010:__xdp_enqueue kernel/bpf/devmap.c:478 [inline] RIP: 0010:dev_map_enqueue+0x91/0x340 kernel/bpf/devmap.c:531 Code: d0 00 00 00 4c 89 e8 48 c1 e8 03 42 80 3c 20 00 74 08 4c 89 ef e8 4f 65 25 00 bb 20 02 00 00 49 03 5d 00 48 89 d8 48 c1 e8 03 <42> 80 3c 20 00 74 08 48 89 df e8 30 65 25 00 48 83 3b 00 0f 84 eb RSP: 0018:ffffc9000f73f7a0 EFLAGS: 00010206 RAX: 0000000000000044 RBX: 0000000000000220 RCX: ffffffff8197a881 RDX: 0000000000000000 RSI: 0000000000000008 RDI: ffff88811682e450 RBP: ffffc9000f73f7e0 R08: ffffffff8144a2c3 R09: fffffbfff0f6e0fd R10: 0000000000000000 R11: dffffc0000000001 R12: dffffc0000000000 R13: ffff88811682e450 R14: ffff88811682e380 R15: ffff888113b68000 FS: 00007febe3cd06c0(0000) GS:ffff8881f6f00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 000055558dc994a8 CR3: 00000001173b6000 CR4: 00000000003526a0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 ---------------- Code disassembly (best guess): 0: d0 00 rolb (%rax) 2: 00 00 add %al,(%rax) 4: 4c 89 e8 mov %r13,%rax 7: 48 c1 e8 03 shr $0x3,%rax b: 42 80 3c 20 00 cmpb $0x0,(%rax,%r12,1) 10: 74 08 je 0x1a 12: 4c 89 ef mov %r13,%rdi 15: e8 4f 65 25 00 call 0x256569 1a: bb 20 02 00 00 mov $0x220,%ebx 1f: 49 03 5d 00 add 0x0(%r13),%rbx 23: 48 89 d8 mov %rbx,%rax 26: 48 c1 e8 03 shr $0x3,%rax * 2a: 42 80 3c 20 00 cmpb $0x0,(%rax,%r12,1) <-- trapping instruction 2f: 74 08 je 0x39 31: 48 89 df mov %rbx,%rdi 34: e8 30 65 25 00 call 0x256569 39: 48 83 3b 00 cmpq $0x0,(%rbx) 3d: 0f .byte 0xf 3e: 84 eb test %ch,%bl