gicv3_its_map_guest_device() adds the device to the domain's RB tree
before it allocates the host LPIs for the device. If an allocation
fails, the error path frees the device but leaves it in the tree.
A later lookup then walks into freed memory. The stale node corrupts
the device tree, and remove_mapped_guest_device() frees the ITT pages
a second time. The double free hits BUG() in free_heap_pages() and
panics Xen.
The hardware domain (Dom0) can trigger this. The host LPI pool is
limited, so Dom0 can fill it with large MAPD commands and make the next
MAPD fail.
Erase the node under its_devices_lock before the error path releases
the device.
Fixes: 69082e1c210d ("ARM: GICv3 ITS: introduce device mapping")
Signed-off-by: Mykola Kvach <mykola_kvach@epam.com>
---
xen/arch/arm/gic-v3-its.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/xen/arch/arm/gic-v3-its.c b/xen/arch/arm/gic-v3-its.c
index d561def0e4..f2fe596490 100644
--- a/xen/arch/arm/gic-v3-its.c
+++ b/xen/arch/arm/gic-v3-its.c
@@ -915,6 +915,10 @@ int gicv3_its_map_guest_device(struct domain *d,
if ( ret )
{
+ spin_lock(&d->arch.vgic.its_devices_lock);
+ rb_erase(&dev->rbnode, &d->arch.vgic.its_devices);
+ spin_unlock(&d->arch.vgic.its_devices_lock);
+
/* Clean up all allocated host LPI blocks. */
for ( ; i >= 0; i-- )
{
--
2.53.0