public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-platforms][PATCH v2 1/1] MinPlatformPkg/TestPointCheckLib: Fix DMAR structure length calculation
@ 2021-12-11  0:22 Michael Kubacki
  2021-12-14  0:22 ` Nate DeSimone
  2021-12-14  0:26 ` Nate DeSimone
  0 siblings, 2 replies; 3+ messages in thread
From: Michael Kubacki @ 2021-12-11  0:22 UTC (permalink / raw)
  To: devel; +Cc: Chasel Chiu, Nate DeSimone, Liming Gao, Eric Dong

From: Michael Kubacki <michael.kubacki@microsoft.com>

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3768

When processing DMAR structures of type
EFI_ACPI_DMAR_STRUCTURE_HEADER within the ACPI DMAR table, the code
determines the structure length by subtracting the DMAR structure
headers present from the overall DMAR ACPI table size.

The terminating condition is that the remaining total DMAR length
is greater than zero. However, the current DMAR structure length
is subtracted after the DMAR structure pointer has already been
assigned to the next structure.

This change subtracts the current DMAR structure length before
transitioning to the next structure.

The terminating condition is also updated to ensure the remaining
size is at least as large as the expected structure header size.

Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Eric Dong <eric.dong@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
---

Notes:
    V2 Changes:
    
    - Updated the terminating condition to ensure the remaining size
      is at least as large as the expected structure size.

 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckAcpiDmar.c      | 8 ++++----
 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckDmaProtection.c | 4 ++--
 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiCheckDmaProtection.c | 4 ++--
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckAcpiDmar.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckAcpiDmar.c
index b2279966d8ed..e0b7aaa48527 100644
--- a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckAcpiDmar.c
+++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckAcpiDmar.c
@@ -133,7 +133,7 @@ DumpAcpiDmar (
   //
   DmarLen  = Dmar->Header.Length - sizeof(EFI_ACPI_DMAR_HEADER);
   DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)(Dmar + 1);
-  while (DmarLen > 0) {
+  while (DmarLen >= sizeof (*DmarStructHeader)) {
     switch (DmarStructHeader->Type) {
     case EFI_ACPI_DMAR_TYPE_DRHD:
       Drhd = (EFI_ACPI_DMAR_DRHD_HEADER *)DmarStructHeader;
@@ -204,8 +204,8 @@ DumpAcpiDmar (
       DEBUG ((DEBUG_INFO, "\n"));
       break;
     }
-    DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 *)DmarStructHeader + DmarStructHeader->Length);
     DmarLen         -= DmarStructHeader->Length;
+    DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 *)DmarStructHeader + DmarStructHeader->Length);
   }
 }
 
@@ -220,7 +220,7 @@ CheckAcpiDmar (
     
   DmarLen  = Dmar->Header.Length - sizeof(EFI_ACPI_DMAR_HEADER);
   DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)(Dmar + 1);
-  while (DmarLen > 0) {
+  while (DmarLen >= sizeof (*DmarStructHeader)) {
     switch (DmarStructHeader->Type) {
     case EFI_ACPI_DMAR_TYPE_DRHD:
       Drhd = (EFI_ACPI_DMAR_DRHD_HEADER *)DmarStructHeader;
@@ -232,8 +232,8 @@ CheckAcpiDmar (
     default:
       break;
     }
-    DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 *)DmarStructHeader + DmarStructHeader->Length);
     DmarLen         -= DmarStructHeader->Length;
+    DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 *)DmarStructHeader + DmarStructHeader->Length);
   }
   return EFI_SUCCESS;
 }
\ No newline at end of file
diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckDmaProtection.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckDmaProtection.c
index 10b44fe8b9b8..aba0985956f2 100644
--- a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckDmaProtection.c
+++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckDmaProtection.c
@@ -38,7 +38,7 @@ CheckDrhd (
   //
   DmarLen  = Dmar->Header.Length - sizeof(EFI_ACPI_DMAR_HEADER);
   DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)(Dmar + 1);
-  while (DmarLen > 0) {
+  while (DmarLen >= sizeof (*DmarStructHeader)) {
     switch (DmarStructHeader->Type) {
     case EFI_ACPI_DMAR_TYPE_DRHD:
       Drhd = (EFI_ACPI_DMAR_DRHD_HEADER *)DmarStructHeader;
@@ -56,8 +56,8 @@ CheckDrhd (
     default:
       break;
     }
-    DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 *)DmarStructHeader + DmarStructHeader->Length);
     DmarLen         -= DmarStructHeader->Length;
+    DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 *)DmarStructHeader + DmarStructHeader->Length);
   }
 
   return EFI_SUCCESS;
diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiCheckDmaProtection.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiCheckDmaProtection.c
index cb764b3633ef..5a18235eddf4 100644
--- a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiCheckDmaProtection.c
+++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiCheckDmaProtection.c
@@ -36,7 +36,7 @@ CheckDrhd (
   //
   DmarLen  = Dmar->Header.Length - sizeof(EFI_ACPI_DMAR_HEADER);
   DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)(Dmar + 1);
-  while (DmarLen > 0) {
+  while (DmarLen >= sizeof (*DmarStructHeader)) {
     switch (DmarStructHeader->Type) {
     case EFI_ACPI_DMAR_TYPE_DRHD:
       Drhd = (EFI_ACPI_DMAR_DRHD_HEADER *)DmarStructHeader;
@@ -61,8 +61,8 @@ CheckDrhd (
     default:
       break;
     }
-    DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 *)DmarStructHeader + DmarStructHeader->Length);
     DmarLen         -= DmarStructHeader->Length;
+    DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 *)DmarStructHeader + DmarStructHeader->Length);
   }
 
   return EFI_SUCCESS;
-- 
2.28.0.windows.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [edk2-platforms][PATCH v2 1/1] MinPlatformPkg/TestPointCheckLib: Fix DMAR structure length calculation
  2021-12-11  0:22 [edk2-platforms][PATCH v2 1/1] MinPlatformPkg/TestPointCheckLib: Fix DMAR structure length calculation Michael Kubacki
@ 2021-12-14  0:22 ` Nate DeSimone
  2021-12-14  0:26 ` Nate DeSimone
  1 sibling, 0 replies; 3+ messages in thread
From: Nate DeSimone @ 2021-12-14  0:22 UTC (permalink / raw)
  To: mikuback@linux.microsoft.com, devel@edk2.groups.io
  Cc: Chiu, Chasel, Gao, Liming, Dong, Eric

Reviewed-by: Nate DeSimone <nathaniel.l.desimone@intel.com>

-----Original Message-----
From: mikuback@linux.microsoft.com <mikuback@linux.microsoft.com> 
Sent: Friday, December 10, 2021 4:22 PM
To: devel@edk2.groups.io
Cc: Chiu, Chasel <chasel.chiu@intel.com>; Desimone, Nathaniel L <nathaniel.l.desimone@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>; Dong, Eric <eric.dong@intel.com>
Subject: [edk2-platforms][PATCH v2 1/1] MinPlatformPkg/TestPointCheckLib: Fix DMAR structure length calculation

From: Michael Kubacki <michael.kubacki@microsoft.com>

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3768

When processing DMAR structures of type
EFI_ACPI_DMAR_STRUCTURE_HEADER within the ACPI DMAR table, the code determines the structure length by subtracting the DMAR structure headers present from the overall DMAR ACPI table size.

The terminating condition is that the remaining total DMAR length is greater than zero. However, the current DMAR structure length is subtracted after the DMAR structure pointer has already been assigned to the next structure.

This change subtracts the current DMAR structure length before transitioning to the next structure.

The terminating condition is also updated to ensure the remaining size is at least as large as the expected structure header size.

Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Eric Dong <eric.dong@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
---

Notes:
    V2 Changes:
    
    - Updated the terminating condition to ensure the remaining size
      is at least as large as the expected structure size.

 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckAcpiDmar.c      | 8 ++++----
 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckDmaProtection.c | 4 ++--  Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiCheckDmaProtection.c | 4 ++--
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckAcpiDmar.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckAcpiDmar.c
index b2279966d8ed..e0b7aaa48527 100644
--- a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckAcpiDmar.c
+++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCh
+++ eckAcpiDmar.c
@@ -133,7 +133,7 @@ DumpAcpiDmar (
   //
   DmarLen  = Dmar->Header.Length - sizeof(EFI_ACPI_DMAR_HEADER);
   DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)(Dmar + 1);
-  while (DmarLen > 0) {
+  while (DmarLen >= sizeof (*DmarStructHeader)) {
     switch (DmarStructHeader->Type) {
     case EFI_ACPI_DMAR_TYPE_DRHD:
       Drhd = (EFI_ACPI_DMAR_DRHD_HEADER *)DmarStructHeader; @@ -204,8 +204,8 @@ DumpAcpiDmar (
       DEBUG ((DEBUG_INFO, "\n"));
       break;
     }
-    DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 *)DmarStructHeader + DmarStructHeader->Length);
     DmarLen         -= DmarStructHeader->Length;
+    DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 
+ *)DmarStructHeader + DmarStructHeader->Length);
   }
 }
 
@@ -220,7 +220,7 @@ CheckAcpiDmar (
     
   DmarLen  = Dmar->Header.Length - sizeof(EFI_ACPI_DMAR_HEADER);
   DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)(Dmar + 1);
-  while (DmarLen > 0) {
+  while (DmarLen >= sizeof (*DmarStructHeader)) {
     switch (DmarStructHeader->Type) {
     case EFI_ACPI_DMAR_TYPE_DRHD:
       Drhd = (EFI_ACPI_DMAR_DRHD_HEADER *)DmarStructHeader; @@ -232,8 +232,8 @@ CheckAcpiDmar (
     default:
       break;
     }
-    DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 *)DmarStructHeader + DmarStructHeader->Length);
     DmarLen         -= DmarStructHeader->Length;
+    DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 
+ *)DmarStructHeader + DmarStructHeader->Length);
   }
   return EFI_SUCCESS;
 }
\ No newline at end of file
diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckDmaProtection.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckDmaProtection.c
index 10b44fe8b9b8..aba0985956f2 100644
--- a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckDmaProtection.c
+++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCh
+++ eckDmaProtection.c
@@ -38,7 +38,7 @@ CheckDrhd (
   //
   DmarLen  = Dmar->Header.Length - sizeof(EFI_ACPI_DMAR_HEADER);
   DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)(Dmar + 1);
-  while (DmarLen > 0) {
+  while (DmarLen >= sizeof (*DmarStructHeader)) {
     switch (DmarStructHeader->Type) {
     case EFI_ACPI_DMAR_TYPE_DRHD:
       Drhd = (EFI_ACPI_DMAR_DRHD_HEADER *)DmarStructHeader; @@ -56,8 +56,8 @@ CheckDrhd (
     default:
       break;
     }
-    DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 *)DmarStructHeader + DmarStructHeader->Length);
     DmarLen         -= DmarStructHeader->Length;
+    DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 
+ *)DmarStructHeader + DmarStructHeader->Length);
   }
 
   return EFI_SUCCESS;
diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiCheckDmaProtection.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiCheckDmaProtection.c
index cb764b3633ef..5a18235eddf4 100644
--- a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiCheckDmaProtection.c
+++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiCh
+++ eckDmaProtection.c
@@ -36,7 +36,7 @@ CheckDrhd (
   //
   DmarLen  = Dmar->Header.Length - sizeof(EFI_ACPI_DMAR_HEADER);
   DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)(Dmar + 1);
-  while (DmarLen > 0) {
+  while (DmarLen >= sizeof (*DmarStructHeader)) {
     switch (DmarStructHeader->Type) {
     case EFI_ACPI_DMAR_TYPE_DRHD:
       Drhd = (EFI_ACPI_DMAR_DRHD_HEADER *)DmarStructHeader; @@ -61,8 +61,8 @@ CheckDrhd (
     default:
       break;
     }
-    DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 *)DmarStructHeader + DmarStructHeader->Length);
     DmarLen         -= DmarStructHeader->Length;
+    DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 
+ *)DmarStructHeader + DmarStructHeader->Length);
   }
 
   return EFI_SUCCESS;
--
2.28.0.windows.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [edk2-platforms][PATCH v2 1/1] MinPlatformPkg/TestPointCheckLib: Fix DMAR structure length calculation
  2021-12-11  0:22 [edk2-platforms][PATCH v2 1/1] MinPlatformPkg/TestPointCheckLib: Fix DMAR structure length calculation Michael Kubacki
  2021-12-14  0:22 ` Nate DeSimone
@ 2021-12-14  0:26 ` Nate DeSimone
  1 sibling, 0 replies; 3+ messages in thread
From: Nate DeSimone @ 2021-12-14  0:26 UTC (permalink / raw)
  To: mikuback@linux.microsoft.com, devel@edk2.groups.io
  Cc: Chiu, Chasel, Gao, Liming, Dong, Eric

Pushed: https://github.com/tianocore/edk2-platforms/commit/871ce77

-----Original Message-----
From: mikuback@linux.microsoft.com <mikuback@linux.microsoft.com> 
Sent: Friday, December 10, 2021 4:22 PM
To: devel@edk2.groups.io
Cc: Chiu, Chasel <chasel.chiu@intel.com>; Desimone, Nathaniel L <nathaniel.l.desimone@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>; Dong, Eric <eric.dong@intel.com>
Subject: [edk2-platforms][PATCH v2 1/1] MinPlatformPkg/TestPointCheckLib: Fix DMAR structure length calculation

From: Michael Kubacki <michael.kubacki@microsoft.com>

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3768

When processing DMAR structures of type
EFI_ACPI_DMAR_STRUCTURE_HEADER within the ACPI DMAR table, the code determines the structure length by subtracting the DMAR structure headers present from the overall DMAR ACPI table size.

The terminating condition is that the remaining total DMAR length is greater than zero. However, the current DMAR structure length is subtracted after the DMAR structure pointer has already been assigned to the next structure.

This change subtracts the current DMAR structure length before transitioning to the next structure.

The terminating condition is also updated to ensure the remaining size is at least as large as the expected structure header size.

Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Eric Dong <eric.dong@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
---

Notes:
    V2 Changes:
    
    - Updated the terminating condition to ensure the remaining size
      is at least as large as the expected structure size.

 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckAcpiDmar.c      | 8 ++++----
 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckDmaProtection.c | 4 ++--  Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiCheckDmaProtection.c | 4 ++--
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckAcpiDmar.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckAcpiDmar.c
index b2279966d8ed..e0b7aaa48527 100644
--- a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckAcpiDmar.c
+++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCh
+++ eckAcpiDmar.c
@@ -133,7 +133,7 @@ DumpAcpiDmar (
   //
   DmarLen  = Dmar->Header.Length - sizeof(EFI_ACPI_DMAR_HEADER);
   DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)(Dmar + 1);
-  while (DmarLen > 0) {
+  while (DmarLen >= sizeof (*DmarStructHeader)) {
     switch (DmarStructHeader->Type) {
     case EFI_ACPI_DMAR_TYPE_DRHD:
       Drhd = (EFI_ACPI_DMAR_DRHD_HEADER *)DmarStructHeader; @@ -204,8 +204,8 @@ DumpAcpiDmar (
       DEBUG ((DEBUG_INFO, "\n"));
       break;
     }
-    DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 *)DmarStructHeader + DmarStructHeader->Length);
     DmarLen         -= DmarStructHeader->Length;
+    DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 
+ *)DmarStructHeader + DmarStructHeader->Length);
   }
 }
 
@@ -220,7 +220,7 @@ CheckAcpiDmar (
     
   DmarLen  = Dmar->Header.Length - sizeof(EFI_ACPI_DMAR_HEADER);
   DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)(Dmar + 1);
-  while (DmarLen > 0) {
+  while (DmarLen >= sizeof (*DmarStructHeader)) {
     switch (DmarStructHeader->Type) {
     case EFI_ACPI_DMAR_TYPE_DRHD:
       Drhd = (EFI_ACPI_DMAR_DRHD_HEADER *)DmarStructHeader; @@ -232,8 +232,8 @@ CheckAcpiDmar (
     default:
       break;
     }
-    DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 *)DmarStructHeader + DmarStructHeader->Length);
     DmarLen         -= DmarStructHeader->Length;
+    DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 
+ *)DmarStructHeader + DmarStructHeader->Length);
   }
   return EFI_SUCCESS;
 }
\ No newline at end of file
diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckDmaProtection.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckDmaProtection.c
index 10b44fe8b9b8..aba0985956f2 100644
--- a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckDmaProtection.c
+++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCh
+++ eckDmaProtection.c
@@ -38,7 +38,7 @@ CheckDrhd (
   //
   DmarLen  = Dmar->Header.Length - sizeof(EFI_ACPI_DMAR_HEADER);
   DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)(Dmar + 1);
-  while (DmarLen > 0) {
+  while (DmarLen >= sizeof (*DmarStructHeader)) {
     switch (DmarStructHeader->Type) {
     case EFI_ACPI_DMAR_TYPE_DRHD:
       Drhd = (EFI_ACPI_DMAR_DRHD_HEADER *)DmarStructHeader; @@ -56,8 +56,8 @@ CheckDrhd (
     default:
       break;
     }
-    DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 *)DmarStructHeader + DmarStructHeader->Length);
     DmarLen         -= DmarStructHeader->Length;
+    DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 
+ *)DmarStructHeader + DmarStructHeader->Length);
   }
 
   return EFI_SUCCESS;
diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiCheckDmaProtection.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiCheckDmaProtection.c
index cb764b3633ef..5a18235eddf4 100644
--- a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiCheckDmaProtection.c
+++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiCh
+++ eckDmaProtection.c
@@ -36,7 +36,7 @@ CheckDrhd (
   //
   DmarLen  = Dmar->Header.Length - sizeof(EFI_ACPI_DMAR_HEADER);
   DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)(Dmar + 1);
-  while (DmarLen > 0) {
+  while (DmarLen >= sizeof (*DmarStructHeader)) {
     switch (DmarStructHeader->Type) {
     case EFI_ACPI_DMAR_TYPE_DRHD:
       Drhd = (EFI_ACPI_DMAR_DRHD_HEADER *)DmarStructHeader; @@ -61,8 +61,8 @@ CheckDrhd (
     default:
       break;
     }
-    DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 *)DmarStructHeader + DmarStructHeader->Length);
     DmarLen         -= DmarStructHeader->Length;
+    DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 
+ *)DmarStructHeader + DmarStructHeader->Length);
   }
 
   return EFI_SUCCESS;
--
2.28.0.windows.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-12-14  0:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-11  0:22 [edk2-platforms][PATCH v2 1/1] MinPlatformPkg/TestPointCheckLib: Fix DMAR structure length calculation Michael Kubacki
2021-12-14  0:22 ` Nate DeSimone
2021-12-14  0:26 ` Nate DeSimone

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox