[PATCH for 11.2] hw/virtio/virtio-iommu: Fix IOVA address lookup

Eric Auger posted 1 patch 6 days, 10 hours ago
hw/virtio/virtio-iommu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH for 11.2] hw/virtio/virtio-iommu: Fix IOVA address lookup
Posted by Eric Auger 6 days, 10 hours ago
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: qemu-stable@nongnu.org
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4754
Signed-off-by: Eric Auger <eric.auger@redhat.com>
---
 hw/virtio/virtio-iommu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c
index 208815096f..b9ecab01ee 100644
--- a/hw/virtio/virtio-iommu.c
+++ b/hw/virtio/virtio-iommu.c
@@ -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 = {
-- 
2.56.1
Re: [PATCH for 11.2] hw/virtio/virtio-iommu: Fix IOVA address lookup
Posted by Philippe Mathieu-Daudé 6 days, 6 hours ago
On 16/11/26 18:38, Eric Auger wrote:
> 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: qemu-stable@nongnu.org
> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4754
> Signed-off-by: Eric Auger <eric.auger@redhat.com>
> ---
>   hw/virtio/virtio-iommu.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>