]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: acpiview: SRAT: Prevent buffer overruns
authorKrzysztof Koch <krzysztof.koch@arm.com>
Thu, 1 Aug 2019 23:44:07 +0000 (16:44 -0700)
committerJaben Carsey <jaben.carsey@intel.com>
Mon, 12 Aug 2019 17:14:07 +0000 (10:14 -0700)
Modify the SRAT parsing logic to prevent reading past the table buffer
length provided.

Check if the Static Resource Allocation Structure's buffer fits in the
SRAT table buffer before its contents are dumped.

Prevent buffer overruns when reading the Static Resource Allocation
Structure's header.

References:
- ACPI 6.3, January 2019, Section 5.2.16

Signed-off-by: Krzysztof Koch <krzysztof.koch@arm.com>
Reviewed-by: Alexei Fedorov <Alexei.Fedorov@arm.com>
Reviewed-by: Zhichao Gao <zhichao.gao@inte.com>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c

index 59c77401eaab32b73a9f83fd4d63785221b3c222..a8aa420487bb6bf29fc38221d0b221573c64b8b3 100644 (file)
@@ -215,10 +215,22 @@ ParseAcpiSrat (
       0,\r
       NULL,\r
       ResourcePtr,\r
-      2,  // The length is 1 byte at offset 1\r
+      AcpiTableLength - Offset,\r
       PARSER_PARAMS (SratResourceAllocationParser)\r
       );\r
 \r
+    // Make sure the SRAT structure lies inside the table\r
+    if ((Offset + *SratRALength) > AcpiTableLength) {\r
+      IncrementErrorCount ();\r
+      Print (\r
+        L"ERROR: Invalid SRAT structure length. SratRALength = %d. " \\r
+          L"RemainingTableBufferLength = %d. SRAT parsing aborted.\n",\r
+        *SratRALength,\r
+        AcpiTableLength - Offset\r
+        );\r
+      return;\r
+    }\r
+\r
     switch (*SratRAType) {\r
       case EFI_ACPI_6_2_GICC_AFFINITY:\r
         AsciiSPrint (\r