* [PATCH v2] misc: vmw_vmci: Leak queue pair endpoint if detach fails on exit
@ 2026-11-23 14:51 Yuho Choi
0 siblings, 0 replies; only message in thread
From: Yuho Choi @ 2026-11-23 14:51 UTC (permalink / raw)
To: Bryan Tan, Vishnu Dasa, Greg Kroah-Hartman
Cc: Arnd Bergmann, bcm-kernel-feedback-list, linux-kernel, Yuho Choi
When the VMCI guest device is removed, vmci_qp_guest_endpoints_exit()
asks the hypervisor to detach each remaining queue pair and then frees
its queue pages with qp_guest_endpoint_destroy(), even if the detach
hypercall failed.
If the detach fails, the hypervisor may still have the queue pair, and
the peer may keep writing to the queue pages after they have gone back
to the page allocator. The device reset that follows in
vmci_guest_remove_device() comes only after the pages have been freed.
qp_detatch_guest_work() already handles the same failure by keeping the
entry, because the peer "might still be accessing the shared memory",
and leaves the cleanup to this exit path, which then frees it anyway.
Leak the endpoint instead if the detach fails, and warn with its handle
and the detach result so that the leak is not silent. This also keeps
its handle in the resource table, so the handle is not given to a new
queue pair while the hypervisor may still have the old one.
Fixes: 06164d2b72aa ("VMCI: queue pairs implementation.")
Signed-off-by: Yuho Choi <oss.patchbox@gmail.com>
---
v2:
- Reworded the comment above vmci_qp_guest_endpoints_exit() as
suggested by Vishnu.
- Added a pr_warn() with the handle and the detach result when an
endpoint is leaked (Vishnu).
- Rebased on current mainline (8dac6df92a2e).
v1: https://lore.kernel.org/all/20261106034419.134545-2-oss.patchbox@gmail.com/
Compile-tested only (x86_64 with VMWARE_VMCI, W=1); I do not have a
VMware setup to test it on.
drivers/misc/vmw_vmci/vmci_queue_pair.c | 27 +++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/drivers/misc/vmw_vmci/vmci_queue_pair.c b/drivers/misc/vmw_vmci/vmci_queue_pair.c
index ceafda4bf32f..f90d99b14128 100644
--- a/drivers/misc/vmw_vmci/vmci_queue_pair.c
+++ b/drivers/misc/vmw_vmci/vmci_queue_pair.c
@@ -2387,30 +2387,45 @@ int vmci_qp_broker_unmap(struct vmci_handle handle,
}
/*
- * Destroys all guest queue pair endpoints. If active guest queue
- * pairs still exist, hypercalls to attempt detach from these
- * queue pairs will be made. Any failure to detach is silently
- * ignored.
+ * Destroys all guest queue pair endpoints. If active guest queue pairs
+ * still exist, hypercalls to attempt detach from these queue pairs will
+ * be made.
+ *
+ * If a detach hypercall fails, the hypervisor may still have the queue
+ * pair's pages mapped. Freeing them can cause a use-after-free bug if
+ * the peer continues to access the pages. The endpoint is therefore
+ * intentionally leaked instead.
*/
void vmci_qp_guest_endpoints_exit(void)
{
struct qp_entry *entry;
struct qp_guest_endpoint *ep;
+ int result;
mutex_lock(&qp_guest_endpoints.mutex);
while ((entry = qp_list_get_head(&qp_guest_endpoints))) {
ep = (struct qp_guest_endpoint *)entry;
+ result = VMCI_SUCCESS;
/* Don't make a hypercall for local queue_pairs. */
if (!(entry->flags & VMCI_QPFLAG_LOCAL))
- qp_detatch_hypercall(entry->handle);
+ result = qp_detatch_hypercall(entry->handle);
/* We cannot fail the exit, so let's reset ref_count. */
entry->ref_count = 0;
qp_list_remove_entry(&qp_guest_endpoints, entry);
- qp_guest_endpoint_destroy(ep);
+ /*
+ * If the detach failed, the peer may still access the
+ * queues, so leak the endpoint.
+ */
+ if (result >= VMCI_SUCCESS)
+ qp_guest_endpoint_destroy(ep);
+ else
+ pr_warn("Failed to detach queue pair (handle=0x%x:0x%x), error: %d, leaking it\n",
+ entry->handle.context, entry->handle.resource,
+ result);
}
mutex_unlock(&qp_guest_endpoints.mutex);
base-commit: 8dac6df92a2e66e2098bbc69061964cfe7e8375b
--
2.56.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-23 14:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 14:51 [PATCH v2] misc: vmw_vmci: Leak queue pair endpoint if detach fails on exit Yuho Choi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox