Skip to contentSkip to conversation

intel_iommu: Check address mask before using it in pasid-based iotlb invalidation

PATCH Superseded Clément MATHIEU--DRIF 4 participants 5 messages Jul 15 – Jul 24

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 intel_iommu: Check address mask before using it in pasid-based iotlb invalidation

Prevent a buggy driver to execute malformed invalidation operations.

Add the same assert as in vtd_iotlb_page_invalidate.

Fixes 6ebe6cf2a066 ("intel_iommu: Process PASID-based iotlb invalidation")
---
 hw/i386/intel_iommu.c | 9 +++++++++
 1 file changed, 9 insertions(+)
hw/i386/intel_iommu.c +9 -0
index bf4f0f2f6b..c591d1db3f 100644
@@ -3021,6 +3021,8 @@ static void vtd_piotlb_page_invalidate(IntelIOMMUState *s, uint16_t domain_id,
 {
     VTDIOTLBPageInvInfo info;
 
+    assert(am <= VTD_MAMV);
+
     info.domain_id = domain_id;
     info.pasid = pasid;
     info.addr = addr;
@@ -3060,6 +3062,13 @@ static bool vtd_process_piotlb_desc(IntelIOMMUState *s,
 
     case VTD_INV_DESC_PIOTLB_PSI_IN_PASID:
         am = VTD_INV_DESC_PIOTLB_AM(inv_desc->val[1]);
+        if (am > VTD_MAMV) {
+            error_report_once("%s: invalid piotlb inv desc: hi=0x%"PRIx64
+                              ", lo=0x%"PRIx64" (am=%u > VTD_MAMV=%u)",
+                              __func__, inv_desc->val[1], inv_desc->val[0],
+                              am, (unsigned)VTD_MAMV);
+            return false;
+        }
         addr = (hwaddr) VTD_INV_DESC_PIOTLB_ADDR(inv_desc->val[1]);
         vtd_piotlb_page_invalidate(s, domain_id, pasid, addr, am,
                                    VTD_INV_DESC_PIOTLB_IH(inv_desc));
Signature · 1 line
2.54.0
Reviewed-by on v1 1/1
#1 lore raw

Hi Clement,

Quoted 5 lines

-----Original Message-----
From: Clément MATHIEU--DRIF <[email protected]>
Subject: [PATCH] intel_iommu: Check address mask before using it in pasid-based iotlb invalidation

Quoted 7 lines

Prevent a buggy driver to execute malformed invalidation operations.

Add the same assert as in vtd_iotlb_page_invalidate.

Fixes 6ebe6cf2a066 ("intel_iommu: Process PASID-based iotlb invalidation")

Thanks
Zhenzhong

Quoted 35 lines

---
hw/i386/intel_iommu.c | 9 +++++++++

1 file changed, 9 insertions(+)
hw/i386/intel_iommu.c +2 -0
index bf4f0f2f6b..c591d1db3f 100644
@@ -3021,6 +3021,8 @@ static void
 vtd_piotlb_page_invalidate(IntelIOMMUState *s, uint16_t domain_id,
 {
    VTDIOTLBPageInvInfo info;
 
+    assert(am <= VTD_MAMV);
+
    info.domain_id = domain_id;
    info.pasid = pasid;
    info.addr = addr;
hw/i386/intel_iommu.c +7 -0
@@ -3060,6 +3062,13 @@ static bool vtd_process_piotlb_desc(IntelIOMMUState
 *s,
 
    case VTD_INV_DESC_PIOTLB_PSI_IN_PASID:
        am = VTD_INV_DESC_PIOTLB_AM(inv_desc->val[1]);
+        if (am > VTD_MAMV) {
+            error_report_once("%s: invalid piotlb inv desc: hi=0x%"PRIx64
+                              ", lo=0x%"PRIx64" (am=%u > VTD_MAMV=%u)",
+                              __func__, inv_desc->val[1], inv_desc->val[0],
+                              am, (unsigned)VTD_MAMV);
+            return false;
+        }
        addr = (hwaddr) VTD_INV_DESC_PIOTLB_ADDR(inv_desc->val[1]);
        vtd_piotlb_page_invalidate(s, domain_id, pasid, addr, am,
                                   VTD_INV_DESC_PIOTLB_IH(inv_desc));

--
2.54.0

Reviewed-by on v1 1/1
#2 lore raw
In reply to Clément MATHIEU--DRIF
Quoted 25 lines · Clément MATHIEU--DRIF

Prevent a buggy driver to execute malformed invalidation operations.

Add the same assert as in vtd_iotlb_page_invalidate.

Fixes 6ebe6cf2a066 ("intel_iommu: Process PASID-based iotlb invalidation")
---
  hw/i386/intel_iommu.c | 9 +++++++++
  1 file changed, 9 insertions(+)
hw/i386/intel_iommu.c +2 -0
index bf4f0f2f6b..c591d1db3f 100644
@@ -3021,6 +3021,8 @@ static void vtd_piotlb_page_invalidate(IntelIOMMUState *s, uint16_t domain_id,
  {
      VTDIOTLBPageInvInfo info;
 
+    assert(am <= VTD_MAMV);
+
      info.domain_id = domain_id;
      info.pasid = pasid;
      info.addr = addr;

hw/i386/intel_iommu.c static bool vtd_process_piotlb_desc(IntelIOMMUState *s, · line 3069

Quoted 8 lines
hw/i386/intel_iommu.c +5 -0
@@ -3060,6 +3062,13 @@ static bool vtd_process_piotlb_desc(IntelIOMMUState *s,
 
      case VTD_INV_DESC_PIOTLB_PSI_IN_PASID:
          am = VTD_INV_DESC_PIOTLB_AM(inv_desc->val[1]);
+        if (am > VTD_MAMV) {
+            error_report_once("%s: invalid piotlb inv desc: hi=0x%"PRIx64
+                              ", lo=0x%"PRIx64" (am=%u > VTD_MAMV=%u)",
+                              __func__, inv_desc->val[1], inv_desc->val[0],
+                              am, (unsigned)VTD_MAMV);

Better use the PRIu64 format instead of this surprising cast, anyway:

Quoted 5 lines
hw/i386/intel_iommu.c +2 -0
+            return false;
+        }
          addr = (hwaddr) VTD_INV_DESC_PIOTLB_ADDR(inv_desc->val[1]);
          vtd_piotlb_page_invalidate(s, domain_id, pasid, addr, am,
                                     VTD_INV_DESC_PIOTLB_IH(inv_desc));
#3 lore raw
Quoted 26 lines · Philippe Mathieu-Daudé
Quoted 25 lines · Clément MATHIEU--DRIF

Prevent a buggy driver to execute malformed invalidation operations.

Add the same assert as in vtd_iotlb_page_invalidate.

Fixes 6ebe6cf2a066 ("intel_iommu: Process PASID-based iotlb invalidation")
---
  hw/i386/intel_iommu.c | 9 +++++++++
  1 file changed, 9 insertions(+)
hw/i386/intel_iommu.c +2 -0
index bf4f0f2f6b..c591d1db3f 100644
@@ -3021,6 +3021,8 @@ static void vtd_piotlb_page_invalidate(IntelIOMMUState *s, uint16_t domain_id,
  {
      VTDIOTLBPageInvInfo info;
+    assert(am <= VTD_MAMV);
+
      info.domain_id = domain_id;
      info.pasid = pasid;
      info.addr = addr;
@@ -3060,6 +3062,13 @@ static bool vtd_process_piotlb_desc(IntelIOMMUState *s,
      case VTD_INV_DESC_PIOTLB_PSI_IN_PASID:
Quoted 8 lines

hw/i386/intel_iommu.c static bool vtd_process_piotlb_desc(IntelIOMMUState *s, · line 3069

Quoted 6 lines
hw/i386/intel_iommu.c +5 -0
          am = VTD_INV_DESC_PIOTLB_AM(inv_desc->val[1]);
+        if (am > VTD_MAMV) {
+            error_report_once("%s: invalid piotlb inv desc: hi=0x%"PRIx64
+                              ", lo=0x%"PRIx64" (am=%u > VTD_MAMV=%u)",
+                              __func__, inv_desc->val[1], inv_desc->val[0],
+                              am, (unsigned)VTD_MAMV);

Better use the PRIu64 format instead of this surprising cast,

I think you mean %llu - PRIu64 is for uint64_t

Quoted 8 lines

anyway:

Quoted 5 lines
hw/i386/intel_iommu.c +2 -0
+            return false;
+        }
          addr = (hwaddr) VTD_INV_DESC_PIOTLB_ADDR(inv_desc->val[1]);
          vtd_piotlb_page_invalidate(s, domain_id, pasid, addr, am,
                                     VTD_INV_DESC_PIOTLB_IH(inv_desc));
#4 lore raw
Quoted 36 lines · Michael S. Tsirkin
Quoted 26 lines · Philippe Mathieu-Daudé
Quoted 25 lines · Clément MATHIEU--DRIF

Prevent a buggy driver to execute malformed invalidation operations.

Add the same assert as in vtd_iotlb_page_invalidate.

Fixes 6ebe6cf2a066 ("intel_iommu: Process PASID-based iotlb invalidation")
---
   hw/i386/intel_iommu.c | 9 +++++++++
   1 file changed, 9 insertions(+)
hw/i386/intel_iommu.c +2 -0
index bf4f0f2f6b..c591d1db3f 100644
@@ -3021,6 +3021,8 @@ static void vtd_piotlb_page_invalidate(IntelIOMMUState *s, uint16_t domain_id,
   {
       VTDIOTLBPageInvInfo info;
+    assert(am <= VTD_MAMV);
+
       info.domain_id = domain_id;
       info.pasid = pasid;
       info.addr = addr;
@@ -3060,6 +3062,13 @@ static bool vtd_process_piotlb_desc(IntelIOMMUState *s,
       case VTD_INV_DESC_PIOTLB_PSI_IN_PASID:
Quoted 8 lines

hw/i386/intel_iommu.c static bool vtd_process_piotlb_desc(IntelIOMMUState *s, · line 3069

Quoted 6 lines
hw/i386/intel_iommu.c +5 -0
           am = VTD_INV_DESC_PIOTLB_AM(inv_desc->val[1]);
+        if (am > VTD_MAMV) {
+            error_report_once("%s: invalid piotlb inv desc: hi=0x%"PRIx64
+                              ", lo=0x%"PRIx64" (am=%u > VTD_MAMV=%u)",
+                              __func__, inv_desc->val[1], inv_desc->val[0],
+                              am, (unsigned)VTD_MAMV);

Better use the PRIu64 format instead of this surprising cast,

Quoted 1 line

I think you mean %llu - PRIu64 is for uint64_t

Yes <:)

Quoted 11 lines
Quoted 9 lines

anyway:

Quoted 5 lines
hw/i386/intel_iommu.c +2 -0
+            return false;
+        }
           addr = (hwaddr) VTD_INV_DESC_PIOTLB_ADDR(inv_desc->val[1]);
           vtd_piotlb_page_invalidate(s, domain_id, pasid, addr, am,
                                      VTD_INV_DESC_PIOTLB_IH(inv_desc));