================================================================== BUG: KASAN: double-free or invalid-free in security_tun_dev_free_security+0x3e/0x70 security/security.c:2342 CPU: 0 PID: 9778 Comm: syz-executor.5 Not tainted 5.16.0-rc3-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Call Trace: __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/0x2ed mm/kasan/report.c:247 kasan_report_invalid_free+0x51/0x80 mm/kasan/report.c:372 ____kasan_slab_free mm/kasan/common.c:346 [inline] __kasan_slab_free+0xf6/0x110 mm/kasan/common.c:374 kasan_slab_free include/linux/kasan.h:235 [inline] __cache_free mm/slab.c:3445 [inline] kfree+0x10d/0x2c0 mm/slab.c:3802 security_tun_dev_free_security+0x3e/0x70 security/security.c:2342 tun_free_netdev+0xdc/0x140 drivers/net/tun.c:2215 netdev_run_todo+0x6b4/0xa80 net/core/dev.c:10630 __tun_chr_ioctl.isra.0+0x9a1/0x4230 drivers/net/tun.c:3302 vfs_ioctl fs/ioctl.c:51 [inline] __do_sys_ioctl fs/ioctl.c:874 [inline] __se_sys_ioctl fs/ioctl.c:860 [inline] __x64_sys_ioctl+0x193/0x200 fs/ioctl.c:860 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:0x7f0ca07feae9 Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 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 bc ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007f0c9f774188 EFLAGS: 00000246 ORIG_RAX: 0000000000000010 RAX: ffffffffffffffda RBX: 00007f0ca0911f60 RCX: 00007f0ca07feae9 RDX: 00000000200000c0 RSI: 00000000400454ca RDI: 0000000000000005 RBP: 00007f0ca0858ff7 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007ffee252892f R14: 00007f0c9f774300 R15: 0000000000022000 Allocated by task 9778: 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+0xa6/0xd0 mm/kasan/common.c:522 kasan_kmalloc include/linux/kasan.h:269 [inline] kmem_cache_alloc_trace+0x1ea/0x4a0 mm/slab.c:3575 kmalloc include/linux/slab.h:590 [inline] kzalloc include/linux/slab.h:724 [inline] selinux_tun_dev_alloc_security+0x43/0x180 security/selinux/hooks.c:5594 security_tun_dev_alloc_security+0x40/0x90 security/security.c:2336 __tun_chr_ioctl.isra.0+0x27e6/0x4230 drivers/net/tun.c:2727 vfs_ioctl fs/ioctl.c:51 [inline] __do_sys_ioctl fs/ioctl.c:874 [inline] __se_sys_ioctl fs/ioctl.c:860 [inline] __x64_sys_ioctl+0x193/0x200 fs/ioctl.c:860 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 Freed by task 9778: kasan_save_stack+0x1e/0x50 mm/kasan/common.c:38 kasan_set_track+0x21/0x30 mm/kasan/common.c:46 kasan_set_free_info+0x20/0x30 mm/kasan/generic.c:370 ____kasan_slab_free mm/kasan/common.c:366 [inline] ____kasan_slab_free mm/kasan/common.c:328 [inline] __kasan_slab_free+0xd1/0x110 mm/kasan/common.c:374 kasan_slab_free include/linux/kasan.h:235 [inline] __cache_free mm/slab.c:3445 [inline] kfree+0x10d/0x2c0 mm/slab.c:3802 security_tun_dev_free_security+0x3e/0x70 security/security.c:2342 __tun_chr_ioctl.isra.0+0x2cbf/0x4230 drivers/net/tun.c:2782 vfs_ioctl fs/ioctl.c:51 [inline] __do_sys_ioctl fs/ioctl.c:874 [inline] __se_sys_ioctl fs/ioctl.c:860 [inline] __x64_sys_ioctl+0x193/0x200 fs/ioctl.c:860 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 ffff888019386800 which belongs to the cache kmalloc-32 of size 32 The buggy address is located 0 bytes inside of 32-byte region [ffff888019386800, ffff888019386820) The buggy address belongs to the page: page:ffffea000064e180 refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff888019386fc1 pfn:0x19386 flags: 0xfff00000000200(slab|node=0|zone=1|lastcpupid=0x7ff) raw: 00fff00000000200 ffffea0001e018c8 ffffea0000793248 ffff888010c40100 raw: ffff888019386fc1 ffff888019386000 000000010000003a 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 0x242220(__GFP_HIGH|__GFP_ATOMIC|__GFP_NOWARN|__GFP_COMP|__GFP_THISNODE), pid 4545, ts 68185997429, free_ts 68069013076 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_pages_node include/linux/gfp.h:570 [inline] kmem_getpages mm/slab.c:1377 [inline] cache_grow_begin+0x75/0x470 mm/slab.c:2593 cache_alloc_refill+0x27f/0x380 mm/slab.c:2965 ____cache_alloc mm/slab.c:3048 [inline] ____cache_alloc mm/slab.c:3031 [inline] __do_cache_alloc mm/slab.c:3275 [inline] slab_alloc mm/slab.c:3316 [inline] __do_kmalloc mm/slab.c:3700 [inline] __kmalloc_track_caller+0x3b0/0x4d0 mm/slab.c:3717 kmemdup+0x23/0x50 mm/util.c:128 kmemdup include/linux/fortify-string.h:304 [inline] sidtab_sid2str_get+0x17c/0x650 security/selinux/ss/sidtab.c:615 sidtab_entry_to_string+0x33/0x110 security/selinux/ss/services.c:1287 security_sid_to_context_core+0x344/0x590 security/selinux/ss/services.c:1380 selinux_inode_init_security+0x4c8/0x6b0 security/selinux/hooks.c:3009 security_inode_init_security+0x14b/0x370 security/security.c:1089 shmem_symlink+0x10c/0x770 mm/shmem.c:3043 vfs_symlink fs/namei.c:4248 [inline] vfs_symlink+0x45d/0x6c0 fs/namei.c:4233 do_symlinkat+0x261/0x2e0 fs/namei.c:4277 __do_sys_symlink fs/namei.c:4299 [inline] __se_sys_symlink fs/namei.c:4297 [inline] __x64_sys_symlink+0x75/0x90 fs/namei.c:4297 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80 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_list+0x1a9/0xfa0 mm/page_alloc.c:3425 release_pages+0x3f4/0x1480 mm/swap.c:980 tlb_batch_pages_flush mm/mmu_gather.c:49 [inline] tlb_flush_mmu_free mm/mmu_gather.c:242 [inline] tlb_flush_mmu mm/mmu_gather.c:249 [inline] tlb_finish_mmu+0x165/0x8c0 mm/mmu_gather.c:340 exit_mmap+0x1ea/0x630 mm/mmap.c:3172 __mmput+0x122/0x4b0 kernel/fork.c:1113 mmput+0x56/0x60 kernel/fork.c:1134 exec_mmap fs/exec.c:1028 [inline] begin_new_exec+0xec4/0x2ca0 fs/exec.c:1286 load_elf_binary+0x1481/0x4b00 fs/binfmt_elf.c:1001 search_binary_handler fs/exec.c:1723 [inline] exec_binprm fs/exec.c:1764 [inline] bprm_execve fs/exec.c:1833 [inline] bprm_execve+0x7ef/0x19b0 fs/exec.c:1795 do_execveat_common+0x5e3/0x780 fs/exec.c:1922 do_execve fs/exec.c:1990 [inline] __do_sys_execve fs/exec.c:2066 [inline] __se_sys_execve fs/exec.c:2061 [inline] __x64_sys_execve+0x8f/0xc0 fs/exec.c:2061 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 Memory state around the buggy address: ffff888019386700: fb fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc ffff888019386780: fa fb fb fb fc fc fc fc 00 00 01 fc fc fc fc fc >ffff888019386800: fa fb fb fb fc fc fc fc 00 01 fc fc fc fc fc fc ^ ffff888019386880: 00 00 01 fc fc fc fc fc fb fb fb fb fc fc fc fc ffff888019386900: 00 05 fc fc fc fc fc fc 00 05 fc fc fc fc fc fc ==================================================================