summaryrefslogtreecommitdiffstats
path: root/ShellPkg
diff options
context:
space:
mode:
authorKrzysztof Koch <krzysztof.koch@arm.com>2019-08-01 16:44:07 -0700
committerJaben Carsey <jaben.carsey@intel.com>2019-08-12 10:14:07 -0700
commit48d5d6d5e09e5089d1c95c2d0812449e87f4ef7e (patch)
treeae67da57cb1c84d2c18f5087bc89d91df819cf10 /ShellPkg
parent5f0661220cdd3facf05276a9978ad58add9fe2f5 (diff)
downloadedk2-48d5d6d5e09e5089d1c95c2d0812449e87f4ef7e.tar.gz
edk2-48d5d6d5e09e5089d1c95c2d0812449e87f4ef7e.tar.bz2
edk2-48d5d6d5e09e5089d1c95c2d0812449e87f4ef7e.zip
ShellPkg: acpiview: SRAT: Prevent buffer overruns
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>
Diffstat (limited to 'ShellPkg')
-rw-r--r--ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
index 59c77401ea..a8aa420487 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
@@ -215,10 +215,22 @@ ParseAcpiSrat (
0,
NULL,
ResourcePtr,
- 2, // The length is 1 byte at offset 1
+ AcpiTableLength - Offset,
PARSER_PARAMS (SratResourceAllocationParser)
);
+ // Make sure the SRAT structure lies inside the table
+ if ((Offset + *SratRALength) > AcpiTableLength) {
+ IncrementErrorCount ();
+ Print (
+ L"ERROR: Invalid SRAT structure length. SratRALength = %d. " \
+ L"RemainingTableBufferLength = %d. SRAT parsing aborted.\n",
+ *SratRALength,
+ AcpiTableLength - Offset
+ );
+ return;
+ }
+
switch (*SratRAType) {
case EFI_ACPI_6_2_GICC_AFFINITY:
AsciiSPrint (