Skip to contentSkip to conversation

hw/virtio/virtio-iommu: Fix IOVA address lookup

PATCH In review Eric Auger 2 participants 2 messages Nov 16

lore
Share & tools
lore

Eric Auger

author
#0 lore raw

PATCH 1/1 hw/virtio/virtio-iommu: Fix IOVA address lookup

The translation code checks the address to be translated belongs to mapped segments by calling g_tree_lookup_extended(). This uses the interval_cmp() function. However the interval is badly formed with the .low=addr and .high= addr + 1 instead of both being set to addr.

As a result an attempt to translate an unmapped byte just before a mapped segment will not fault as expected.

Example: only [0x2000, 0x2fff] IOVA range is mapped. An attempt to translate 0x1fff will succeed

Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4754

---
 hw/virtio/virtio-iommu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/virtio-iommu.c +1 -1
index 208815096f..b9ecab01ee 100644
@@ -1185,7 +1185,7 @@ static IOMMUTLBEntry virtio_iommu_translate(IOMMUMemoryRegion *mr, hwaddr addr,
     GList *l;
 
     interval.low = addr;
-    interval.high = addr + 1;
+    interval.high = addr;
     granule = ctz64(s->config.page_size_mask);
 
     IOMMUTLBEntry entry = {
Signature · 1 line
2.56.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 12 lines · Eric Auger

The translation code checks the address to be translated belongs to mapped segments by calling g_tree_lookup_extended(). This uses the interval_cmp() function. However the interval is badly formed with the .low=addr and .high= addr + 1 instead of both being set to addr.

As a result an attempt to translate an unmapped byte just before a mapped segment will not fault as expected.

Example: only [0x2000, 0x2fff] IOVA range is mapped. An attempt to translate 0x1fff will succeed

Quoted 6 lines

Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4754

---
  hw/virtio/virtio-iommu.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)