[PATCH] AMD/IOMMU: check fault-reported dev ID against table limit

Jan Beulich posted 1 patch 1 day, 2 hours ago
[PATCH] AMD/IOMMU: check fault-reported dev ID against table limit
Posted by Jan Beulich 1 day, 2 hours ago
Requests with IDs beyond the device table limit report the bad ID in the
resulting fault. Hence like hardware we should not try to access the (out-
of-bounds) table entry.

Fixes: 0e461c2d7f45 ("AMD/IOMMU: walk trees upon page fault")
Reported-by: Roger Pau Monné <roger.pau@amd.com>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Roger Pau Monné <roger@xenproject.org>

--- a/xen/drivers/passthrough/amd/iommu_map.c
+++ b/xen/drivers/passthrough/amd/iommu_map.c
@@ -556,6 +556,12 @@ void amd_iommu_print_entries(const struc
     unsigned int level;
     const struct amd_iommu_dte *dt = iommu->dev_table.buffer;
 
+    if ( dev_id >= ivrs_bdf_entries )
+    {
+        printk("%pp: beyond table limit\n", &PCI_SBDF(iommu->sbdf.seg, dev_id));
+        return;
+    }
+
     if ( !dt[dev_id].tv )
     {
         printk("%pp: no root\n", &PCI_SBDF(iommu->sbdf.seg, dev_id));