In the Linux kernel, the following vulnerability has been resolved:
VMCI: Fix use-after-free when removing resource in vmci_resource_remove()
When removing a resource from vmci_resource_table in
vmci_resource_remove(), the search is performed using the resource
handle by comparing context and resource fields.
It is possible though to create two resources with different types
but same handle (same context and resource fields).
When trying to remove one of the resources, vmci_resource_remove()
may not remove the intended one, but the object will still be freed
as in the case of the datagram type in vmci_datagram_destroy_handle().
vmci_resource_table will still hold a pointer to this freed resource
leading to a use-after-free vulnerability.
BUG: KASAN: use-after-free in vmci_handle_is_equal include/linux/vmw_vmci_defs.h:142[inline]BUG: KASAN: use-after-free in vmci_resource_remove+0x3a1/0x410drivers/misc/vmw_vmci/vmci_resource.c:147Read of size 4 at addr ffff88801c16d800 by task syz-executor197/1592
Call Trace:<TASK>__dump_stacklib/dump_stack.c:88[inline]dump_stack_lvl+0x82/0xa9lib/dump_stack.c:106print_address_description.constprop.0+0x21/0x366mm/kasan/report.c:239__kasan_report.cold+0x7f/0x132mm/kasan/report.c:425kasan_report+0x38/0x51mm/kasan/report.c:442vmci_handle_is_equalinclude/linux/vmw_vmci_defs.h:142[inline]vmci_resource_remove+0x3a1/0x410drivers/misc/vmw_vmci/vmci_resource.c:147vmci_qp_broker_detach+0x89a/0x11b9drivers/misc/vmw_vmci/vmci_queue_pair.c:2182ctx_free_ctx+0x473/0xbe1drivers/misc/vmw_vmci/vmci_context.c:444kref_putinclude/linux/kref.h:65[inline]vmci_ctx_putdrivers/misc/vmw_vmci/vmci_context.c:497[inline]vmci_ctx_destroy+0x170/0x1d6drivers/misc/vmw_vmci/vmci_context.c:195vmci_host_close+0x125/0x1acdrivers/misc/vmw_vmci/vmci_host.c:143__fput+0x261/0xa34fs/file_table.c:282task_work_run+0xf0/0x194kernel/task_work.c:164tracehook_notify_resumeinclude/linux/tracehook.h:189[inline]exit_to_user_mode_loop+0x184/0x189kernel/entry/common.c:187exit_to_user_mode_prepare+0x11b/0x123kernel/entry/common.c:220__syscall_exit_to_user_mode_workkernel/entry/common.c:302[inline]syscall_exit_to_user_mode+0x18/0x42kernel/entry/common.c:313do_syscall_64+0x41/0x85arch/x86/entry/common.c:86entry_SYSCALL_64_after_hwframe+0x6e/0x0
This change ensures the type is also checked when removing
the resource from vmci_resource_table in vmci_resource_remove().