In the Linux kernel, the following vulnerability has been resolved:
tun: avoid double free in tun_free_netdev
Avoid double free in tun_free_netdev() by moving the
dev->tstats and tun->security allocs to a new ndo_init routine
(tun_net_init()) that will be called by register_netdevice().
ndo_init is paired with the desctructor (tun_free_netdev()),
so if there's an error in register_netdevice() the destructor
will handle the frees.
BUG: KASAN: double-free or invalid-free in selinux_tun_dev_free_security+0x1a/0x20security/selinux/hooks.c:5605CPU: 0 PID: 25750 Comm: syz-executor416 Not tainted 5.16.0-rc2-syzk #1
Hardware name: Red Hat KVM, BIOS
Call Trace:<TASK>__dump_stacklib/dump_stack.c:88[inline]dump_stack_lvl+0x89/0xb5lib/dump_stack.c:106print_address_description.constprop.9+0x28/0x160mm/kasan/report.c:247kasan_report_invalid_free+0x55/0x80mm/kasan/report.c:372____kasan_slab_freemm/kasan/common.c:346[inline]__kasan_slab_free+0x107/0x120mm/kasan/common.c:374kasan_slab_freeinclude/linux/kasan.h:235[inline]slab_free_hookmm/slub.c:1723[inline]slab_free_freelist_hookmm/slub.c:1749[inline]slab_freemm/slub.c:3513[inline]kfree+0xac/0x2d0mm/slub.c:4561selinux_tun_dev_free_security+0x1a/0x20security/selinux/hooks.c:5605security_tun_dev_free_security+0x4f/0x90security/security.c:2342tun_free_netdev+0xe6/0x150drivers/net/tun.c:2215netdev_run_todo+0x4df/0x840net/core/dev.c:10627rtnl_unlock+0x13/0x20net/core/rtnetlink.c:112__tun_chr_ioctl+0x80c/0x2870drivers/net/tun.c:3302tun_chr_ioctl+0x2f/0x40drivers/net/tun.c:3311vfs_ioctlfs/ioctl.c:51[inline]__do_sys_ioctlfs/ioctl.c:874[inline]__se_sys_ioctlfs/ioctl.c:860[inline]__x64_sys_ioctl+0x19d/0x220fs/ioctl.c:860do_syscall_x64arch/x86/entry/common.c:50[inline]do_syscall_64+0x3a/0x80arch/x86/entry/common.c:80entry_SYSCALL_64_after_hwframe+0x44/0xae