]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: acpiview: Validate ACPI table 'Length' field
authorKrzysztof Koch <krzysztof.koch@arm.com>
Tue, 11 Feb 2020 10:01:17 +0000 (18:01 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 19 Feb 2020 06:01:39 +0000 (06:01 +0000)
Check if the ACPI table length, as reported in the ACPI table header, is
big enough to fit at least the header itself.

If not, report an error to the user and stop parsing the table in order
to prevent buffer overruns.

Signed-off-by: Krzysztof Koch <krzysztof.koch@arm.com>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
Reviewed-by: Zhichao Gao <zhichao.gao@intel.com>
ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.c

index d5500bcb2b4a55c7a69f45444aa49d36d2c1694f..501967c4dde680809c56e5d79ed744a1013a69e1 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   ACPI table parser\r
 \r
-  Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.\r
+  Copyright (c) 2016 - 2020, ARM Limited. All rights reserved.\r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 **/\r
 \r
@@ -176,6 +176,7 @@ ProcessAcpiTable (
   CONST UINT32* AcpiTableSignature;\r
   CONST UINT32* AcpiTableLength;\r
   CONST UINT8*  AcpiTableRevision;\r
+  CONST UINT8*  SignaturePtr;\r
   PARSE_ACPI_TABLE_PROC ParserProc;\r
 \r
   ParseAcpiHeader (\r
@@ -193,6 +194,23 @@ ProcessAcpiTable (
 \r
   if (Trace) {\r
     DumpRaw (Ptr, *AcpiTableLength);\r
+\r
+    // Do not process the ACPI table any further if the table length read\r
+    // is invalid. The ACPI table should at least contain the table header.\r
+    if (*AcpiTableLength < sizeof (EFI_ACPI_DESCRIPTION_HEADER)) {\r
+      SignaturePtr = (CONST UINT8*)AcpiTableSignature;\r
+      IncrementErrorCount ();\r
+      Print (\r
+        L"ERROR: Invalid %c%c%c%c table length. Length = %d\n",\r
+        SignaturePtr[0],\r
+        SignaturePtr[1],\r
+        SignaturePtr[2],\r
+        SignaturePtr[3],\r
+        *AcpiTableLength\r
+        );\r
+      return;\r
+    }\r
+\r
     if (GetConsistencyChecking ()) {\r
       VerifyChecksum (TRUE, Ptr, *AcpiTableLength);\r
     }\r