]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: acpiview: MADT: Split structure length validation
authorKrzysztof Koch <krzysztof.koch@arm.com>
Mon, 22 Jul 2019 22:50:25 +0000 (15:50 -0700)
committerJaben Carsey <jaben.carsey@intel.com>
Wed, 31 Jul 2019 16:52:57 +0000 (09:52 -0700)
Split the Interrupt Controller Structure length validation in the
acpiview UEFI shell tool into two logical parts:
1. Ensuring MADT table parser forward progress.
2. Preventing MADT table buffer overruns.

Also, make the condition for infinite loop detection applicable to
all types of Interrupt Controller Structures (for all interrupt models
which can be represented in MADT). Check if the controller length
specified is shorter than the byte size of the first two fields
('Type' and 'Length') present in every valid Interrupt Controller
Structure.

Signed-off-by: Krzysztof Koch <krzysztof.koch@arm.com>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Zhichao Gao <zhichao.gao@intel.com>
ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c

index 338295d30e35c366a60505225cf57145a8e73d93..d80ebd1a2bae7a4acffe687ca5ee7b4090f0e223 100644 (file)
@@ -260,16 +260,30 @@ ParseAcpiMadt (
       PARSER_PARAMS (MadtInterruptControllerHeaderParser)\r
       );\r
 \r
-    if (((Offset + (*MadtInterruptControllerLength)) > AcpiTableLength) ||\r
-        (*MadtInterruptControllerLength < 4)) {\r
+    // Make sure forward progress is made.\r
+    if (*MadtInterruptControllerLength < 2) {\r
       IncrementErrorCount ();\r
       Print (\r
-         L"ERROR: Invalid Interrupt Controller Length,"\r
-          L" Type = %d, Length = %d\n",\r
-         *MadtInterruptControllerType,\r
-         *MadtInterruptControllerLength\r
-         );\r
-      break;\r
+        L"ERROR: Structure length is too small: " \\r
+          L"MadtInterruptControllerLength = %d. " \\r
+          L"MadtInterruptControllerType = %d. MADT parsing aborted.\n",\r
+        *MadtInterruptControllerLength,\r
+        *MadtInterruptControllerType\r
+        );\r
+      return;\r
+    }\r
+\r
+    // Make sure the MADT structure lies inside the table\r
+    if ((Offset + *MadtInterruptControllerLength) > AcpiTableLength) {\r
+      IncrementErrorCount ();\r
+      Print (\r
+        L"ERROR: Invalid MADT structure length. " \\r
+          L"MadtInterruptControllerLength = %d. " \\r
+          L"RemainingTableBufferLength = %d. MADT parsing aborted.\n",\r
+        *MadtInterruptControllerLength,\r
+        AcpiTableLength - Offset\r
+        );\r
+      return;\r
     }\r
 \r
     switch (*MadtInterruptControllerType) {\r