* [PATCH] xen/virtio: Fix use-after-free of grant DMA data after rebind
@ 2026-11-19 1:11 Changyul Lee
0 siblings, 0 replies; only message in thread
From: Changyul Lee @ 2026-11-19 1:11 UTC (permalink / raw)
To: Juergen Gross, Stefano Stabellini
Cc: Oleksandr Tyshchenko, xen-devel, linux-kernel, Changyul Lee
When the device is unbound, devres frees its grant DMA data but leaves
the entry in xen_grant_dma_devices. On rebind, the remaining entry
causes xen_grant_setup_dma_ops() to skip setup. Since x86 retains
dev->dma_ops across unbind, subsequent DMA operations access the freed
data.
Register a devres action to erase the entry before freeing the data.
Fixes: 61367688f1fb ("xen/virtio: enable grant based virtio on x86")
Signed-off-by: Changyul Lee <lcy8047@gmail.com>
---
Found with a static analysis tool we are developing.
Tested in QEMU with KVM Xen HVM emulation (xen-version=0x4000a) and
CONFIG_XEN_VIRTIO_FORCE_GRANT=y, using a virtio-keyboard-pci device with
iommu_platform=on. Unbinding and rebinding virtio-pci through sysfs
triggers a KASAN slab-use-after-free in xen_grant_dma_alloc() before
this patch and no report after it.
drivers/xen/grant-dma-ops.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/drivers/xen/grant-dma-ops.c b/drivers/xen/grant-dma-ops.c
index 5fcafa4c344f..784413e6d282 100644
--- a/drivers/xen/grant-dma-ops.c
+++ b/drivers/xen/grant-dma-ops.c
@@ -66,6 +66,15 @@ static int store_xen_grant_dma_data(struct device *dev,
return ret;
}
+static void remove_xen_grant_dma_data(void *dev)
+{
+ unsigned long flags;
+
+ xa_lock_irqsave(&xen_grant_dma_devices, flags);
+ __xa_erase(&xen_grant_dma_devices, (unsigned long)dev);
+ xa_unlock_irqrestore(&xen_grant_dma_devices, flags);
+}
+
/*
* DMA ops for Xen frontends (e.g. virtio).
*
@@ -396,6 +405,9 @@ static void xen_grant_setup_dma_ops(struct device *dev, domid_t backend_domid)
goto err;
}
+ if (devm_add_action_or_reset(dev, remove_xen_grant_dma_data, dev))
+ goto err;
+
dev->dma_ops = &xen_grant_dma_ops;
return;
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
--
2.43.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-19 1:11 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 1:11 [PATCH] xen/virtio: Fix use-after-free of grant DMA data after rebind Changyul Lee
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®