Re: [edk2-devel] [edk2-platforms][PATCH v1 1/1] Platform/ARM/ArmJunoDxe: Fix 'unused variable' error for DynamicTables

2020-01-20 Thread Krzysztof Koch
Sure! I don't mind changing the commit message. Shall I resubmit the patch?

Kind regards,
Krzysztof

-Original Message-
From: Philippe Mathieu-Daudé  
Sent: Monday, January 20, 2020 9:15
To: devel@edk2.groups.io; Krzysztof Koch 
Cc: Ard Biesheuvel ; Leif Lindholm 
; Michael D Kinney ; Sami 
Mujawar ; Matteo Carlini ; nd 

Subject: Re: [edk2-devel] [edk2-platforms][PATCH v1 1/1] 
Platform/ARM/ArmJunoDxe: Fix 'unused variable' error for DynamicTables

On 1/9/20 10:35 AM, Krzysztof Koch wrote:
> Fix 'mAcpiRegistration defined but not used' compiler error for 
> Dynamic Tables Framework builds.
> 
> Do not declare the mAcpiRegistration variable in the Dynamic Tables 
> Framework context.
> 
> An earlier patch made mAcpiRegistration variable STATIC. Reducing the

Can we change "An earlier patch" -> "Commit 484a683ab9f"?

> scope made scope resolution simpler, thus, the 'defined but not used'
> error got raised.
> 
> Signed-off-by: Krzysztof Koch 

Reviewed-by: Philippe Mathieu-Daude 

> ---
> 
> Changes can be seen at: 
> https://github.com/KrzysztofKoch1/edk2-platforms/tree/723_fix_unused_v
> ariable_juno_dxe_v1
> 
> Notes:
>  v1:
>  - Fix 'defined but not used' Dynamic Tables build error 
> [Krzysztof]
> 
>   Platform/ARM/JunoPkg/Drivers/ArmJunoDxe/ArmJunoDxe.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/Platform/ARM/JunoPkg/Drivers/ArmJunoDxe/ArmJunoDxe.c 
> b/Platform/ARM/JunoPkg/Drivers/ArmJunoDxe/ArmJunoDxe.c
> index 
> e3b64992e02c003f7e3a6636340a6afa573f477a..cd7a205f90f131560419cfd744dd
> 5c22df726c99 100644
> --- a/Platform/ARM/JunoPkg/Drivers/ArmJunoDxe/ArmJunoDxe.c
> +++ b/Platform/ARM/JunoPkg/Drivers/ArmJunoDxe/ArmJunoDxe.c
> @@ -1,6 +1,6 @@
>   /** @file
>   *
> -*  Copyright (c) 2013-2019, ARM Limited. All rights reserved.
> +*  Copyright (c) 2013-2020, ARM Limited. All rights reserved.
>   *
>   *  SPDX-License-Identifier: BSD-2-Clause-Patent
>   *
> @@ -30,9 +30,9 @@
>   #ifndef DYNAMIC_TABLES_FRAMEWORK
>   // This GUID must match the FILE_GUID in 
> ArmPlatformPkg/ArmJunoPkg/AcpiTables/AcpiTables.inf
>   STATIC CONST EFI_GUID mJunoAcpiTableFile = { 0xa1dd808e, 0x1e95, 
> 0x4399, { 0xab, 0xc0, 0x65, 0x3c, 0x82, 0xe8, 0x53, 0x0c } }; -#endif
> -
>   STATIC VOID *mAcpiRegistration = NULL;
> +#endif
> +
>   STATIC VOID *mPciIoNotificationRegistration = NULL;
>   
>   /**
> --
> 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'
> 
> 
> 
> 
> 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#53399): https://edk2.groups.io/g/devel/message/53399
Mute This Topic: https://groups.io/mt/69576071/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 06/11] ShellPkg: acpiview: SRAT: Validate global pointers before use

2020-01-20 Thread Krzysztof Koch
Check if SratRAType and SratRALength pointers have been successfully
updated before they are used for further table parsing.

Signed-off-by: Krzysztof Koch 
---

Notes:
v3:
- Rebase on latest master [Krzysztof]

v1:
- Test against NULL pointers [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c | 13 
+
 1 file changed, 13 insertions(+)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
index 
6fe7bf681132df08133e3e03e3ee3f020d905dd2..3613900ae322483fdd3d3383de4e22ba75b2128b
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
@@ -399,6 +399,19 @@ ParseAcpiSrat (
   PARSER_PARAMS (SratResourceAllocationParser)
   );
 
+// Check if the values used to control the parsing logic have been
+// successfully read.
+if ((SratRAType == NULL) ||
+(SratRALength == NULL)) {
+  IncrementErrorCount ();
+  Print (
+L"ERROR: Insufficient remaining table buffer length to read the " \
+  L"Static Resource Allocation structure header. Length = %d.\n",
+AcpiTableLength - Offset
+);
+  return;
+}
+
 // Make sure the SRAT structure lies inside the table
 if ((Offset + *SratRALength) > AcpiTableLength) {
   IncrementErrorCount ();
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#53411): https://edk2.groups.io/g/devel/message/53411
Mute This Topic: https://groups.io/mt/69929575/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 01/11] ShellPkg: acpiview: Set ItemPtr to NULL for unprocessed table fields

2020-01-20 Thread Krzysztof Koch
For fields outside the buffer length provided, reset any pointers,
which were supposed to be updated by a ParseAcpi() function call to
NULL. This way one can easily validate if a pointer was successfully
updated.

The ParseAcpi() function parses the given ACPI table buffer by a
number of bytes which is a minimum of the buffer length and the length
described by ACPI_PARSER array. If the buffer length is shorter than
the array describing how to process the ACPI structure, then it is
possible that the ItemPtr inside ACPI_PARSER may not get updated or
initialized. This can lead to an error if the value pointed to by
ItemPtr is later used to control the parsing logic.

A typical example would be a 'number of elements' field in an ACPI
structure header which defines how many substructures of a given type
are present in the structure body. If the 'number of elements' field
is not parsed, we will have a dangling pointer which could cause a
problem later.

Signed-off-by: Krzysztof Koch 
---

Notes:
v3:
- Rebase on latest master [Krzysztof]

v1:
- Set ItemPtr to NULL for unprocessed table fields [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
index 
2b2ecb93cef9ee28b752e7bf2d920b059dbf7d6b..84c5f0468da55477acc96dfd0f949a5908d0f7a5
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
@@ -543,8 +543,15 @@ ParseAcpi (
 
   for (Index = 0; Index < ParserItems; Index++) {
 if ((Offset + Parser[Index].Length) > Length) {
+
+  // For fields outside the buffer length provided, reset any pointers
+  // which were supposed to be updated by this function call
+  if (Parser[Index].ItemPtr != NULL) {
+*Parser[Index].ItemPtr = NULL;
+  }
+
   // We don't parse past the end of the max length specified
-  break;
+  continue;
 }
 
 if (GetConsistencyChecking () &&
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#53405): https://edk2.groups.io/g/devel/message/53405
Mute This Topic: https://groups.io/mt/69929569/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 08/11] ShellPkg: acpiview: PPTT: Validate global pointers before use

2020-01-20 Thread Krzysztof Koch
Check if the NumberOfPrivateResources, ProcessorTopologyStructureType
and ProcessorTopologyStructureLength pointers have been successfully
updated before they are used for further table parsing.

Signed-off-by: Krzysztof Koch 
---

Notes:
v3:
- Rebase on latest master [Krzysztof]

v1:
- Test against NULL pointers [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c | 25 

 1 file changed, 25 insertions(+)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c
index 
6254b9913fffb429fc54bb1301bf3e4b2e5bf161..675ba75f02b367cd5ad9f2ac23c30ed0ab58f286
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c
@@ -264,6 +264,17 @@ DumpProcessorHierarchyNodeStructure (
  PARSER_PARAMS (ProcessorHierarchyNodeStructureParser)
  );
 
+  // Check if the values used to control the parsing logic have been
+  // successfully read.
+  if (NumberOfPrivateResources == NULL) {
+IncrementErrorCount ();
+Print (
+  L"ERROR: Insufficient Processor Hierarchy Node length. Length = %d.\n",
+  Length
+  );
+return;
+  }
+
   // Make sure the Private Resource array lies inside this structure
   if (Offset + (*NumberOfPrivateResources * sizeof (UINT32)) > Length) {
 IncrementErrorCount ();
@@ -387,6 +398,7 @@ ParseAcpiPptt (
  AcpiTableLength,
  PARSER_PARAMS (PpttParser)
  );
+
   ProcessorTopologyStructurePtr = Ptr + Offset;
 
   while (Offset < AcpiTableLength) {
@@ -400,6 +412,19 @@ ParseAcpiPptt (
   PARSER_PARAMS (ProcessorTopologyStructureHeaderParser)
   );
 
+// Check if the values used to control the parsing logic have been
+// successfully read.
+if ((ProcessorTopologyStructureType == NULL) ||
+(ProcessorTopologyStructureLength == NULL)) {
+  IncrementErrorCount ();
+  Print (
+L"ERROR: Insufficient remaining table buffer length to read the " \
+  L"processor topology structure header. Length = %d.\n",
+AcpiTableLength - Offset
+);
+  return;
+}
+
 // Make sure the PPTT structure lies inside the table
 if ((Offset + *ProcessorTopologyStructureLength) > AcpiTableLength) {
   IncrementErrorCount ();
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#53409): https://edk2.groups.io/g/devel/message/53409
Mute This Topic: https://groups.io/mt/69929573/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 03/11] ShellPkg: acpiview: FADT: Validate global pointer before use

2020-01-20 Thread Krzysztof Koch
Check if global pointers have been successfully updated before they
are used for further table parsing.

Signed-off-by: Krzysztof Koch 
---

Notes:
v3:
- Rebase on latest master [Krzysztof]

v2:
- Do not require FadtMinorRevision and X_DsdtAddress pointers to be
  valid in order to process the remaining ACPI tables [Zhichao]

v1:
- Test against NULL pointers [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c | 21 
++--
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c
index 
5b8cc174f16afb3d4feb6a518952e60c6564ee34..37cbd8be287944656afcd609a3dd080440d5cfef
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c
@@ -1,7 +1,7 @@
 /** @file
   FADT table parser
 
-  Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
+  Copyright (c) 2016 - 2020, ARM Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
   @par Reference(s):
@@ -230,9 +230,11 @@ ParseAcpiFadt (
 );
 
   if (Trace) {
-Print (L"\nSummary:\n");
-PrintFieldName (2, L"FADT Version");
-Print (L"%d.%d\n",  *AcpiHdrInfo.Revision, *FadtMinorRevision);
+if (FadtMinorRevision != NULL) {
+  Print (L"\nSummary:\n");
+  PrintFieldName (2, L"FADT Version");
+  Print (L"%d.%d\n",  *AcpiHdrInfo.Revision, *FadtMinorRevision);
+}
 
 if (*GetAcpiXsdtHeaderInfo ()->OemTableId != *AcpiHdrInfo.OemTableId) {
   IncrementErrorCount ();
@@ -294,21 +296,20 @@ ParseAcpiFadt (
   );
   }
 
-  // If X_DSDT is not zero then use X_DSDT and ignore DSDT,
-  // else use DSDT.
-  if (*X_DsdtAddress != 0) {
+  // If X_DSDT is valid then use X_DSDT and ignore DSDT, else use DSDT.
+  if ((X_DsdtAddress != NULL) && (*X_DsdtAddress != 0)) {
 DsdtPtr = (UINT8*)(UINTN)(*X_DsdtAddress);
-  } else if (*DsdtAddress != 0) {
+  } else if ((DsdtAddress != NULL) && (*DsdtAddress != 0)) {
 DsdtPtr = (UINT8*)(UINTN)(*DsdtAddress);
   } else {
-// Both DSDT and X_DSDT cannot be zero.
+// Both DSDT and X_DSDT cannot be invalid.
 #if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
 if (Trace) {
   // The DSDT Table is mandatory for ARM systems
   // as the CPU information MUST be presented in
   // the DSDT.
   IncrementErrorCount ();
-  Print (L"ERROR: Both X_DSDT and DSDT are NULL.\n");
+  Print (L"ERROR: Both X_DSDT and DSDT are invalid.\n");
 }
 #endif
 return;
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#53404): https://edk2.groups.io/g/devel/message/53404
Mute This Topic: https://groups.io/mt/69929568/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 02/11] ShellPkg: acpiview: RSDP: Validate global pointer before use

2020-01-20 Thread Krzysztof Koch
Check if XsdtAddress pointer has been successfully updated before it
is used for further table parsing.

Signed-off-by: Krzysztof Koch 
---

Notes:
v3:
- Rebase on latest master [Krzysztof]

v1:
- Test against NULL pointers [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c | 12 

 1 file changed, 12 insertions(+)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c
index 
5a5c4b50c12e6eb0aa0efb1765df7e123f614da3..f4a8732a7db7c437031f2a3d2f266b80eff17b4b
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c
@@ -138,6 +138,18 @@ ParseAcpiRsdp (
 PARSER_PARAMS (RsdpParser)
 );
 
+  // Check if the values used to control the parsing logic have been
+  // successfully read.
+  if (XsdtAddress == NULL) {
+IncrementErrorCount ();
+Print (
+  L"ERROR: Insufficient table length. AcpiTableLength = %d." \
+L"RSDP parsing aborted.\n",
+  AcpiTableLength
+  );
+return;
+  }
+
   // This code currently supports parsing of XSDT table only
   // and does not parse the RSDT table. Platforms provide the
   // RSDT to enable compatibility with ACPI 1.0 operating systems.
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#53412): https://edk2.groups.io/g/devel/message/53412
Mute This Topic: https://groups.io/mt/69929577/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 09/11] ShellPkg: acpiview: IORT: Validate global pointers before use

2020-01-20 Thread Krzysztof Koch
Check if global (in the scope of the IORT parser) pointers have been
successfully updated before they are used for further table parsing.

Signed-off-by: Krzysztof Koch 
---

Notes:
v3:
- Rebase on latest master [Krzysztof]

v1:
- Test against NULL pointers [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c | 52 

 1 file changed, 52 insertions(+)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c
index 
72289c7680bc3cd5c81e8d6a719803202a9b..9d5d937c7b2c19945ca2ad3eba644bdfc09cc3f6
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c
@@ -322,6 +322,20 @@ DumpIortNodeSmmuV1V2 (
 PARSER_PARAMS (IortNodeSmmuV1V2Parser)
 );
 
+  // Check if the values used to control the parsing logic have been
+  // successfully read.
+  if ((InterruptContextCount == NULL)   ||
+  (InterruptContextOffset == NULL)  ||
+  (PmuInterruptCount == NULL)   ||
+  (PmuInterruptOffset == NULL)) {
+IncrementErrorCount ();
+Print (
+  L"ERROR: Insufficient SMMUv1/2 node length. Length = %d\n",
+  Length
+  );
+return;
+  }
+
   Offset = *InterruptContextOffset;
   Index = 0;
 
@@ -433,6 +447,17 @@ DumpIortNodeIts (
 PARSER_PARAMS (IortNodeItsParser)
 );
 
+  // Check if the values used to control the parsing logic have been
+  // successfully read.
+  if (ItsCount == NULL) {
+IncrementErrorCount ();
+Print (
+  L"ERROR: Insufficient ITS group length. Length = %d.\n",
+  Length
+  );
+return;
+  }
+
   Index = 0;
 
   while ((Index < *ItsCount) &&
@@ -617,6 +642,18 @@ ParseAcpiIort (
 PARSER_PARAMS (IortParser)
 );
 
+  // Check if the values used to control the parsing logic have been
+  // successfully read.
+  if ((IortNodeCount == NULL) ||
+  (IortNodeOffset == NULL)) {
+IncrementErrorCount ();
+Print (
+  L"ERROR: Insufficient table length. AcpiTableLength = %d.\n",
+  AcpiTableLength
+  );
+return;
+  }
+
   Offset = *IortNodeOffset;
   NodePtr = Ptr + Offset;
   Index = 0;
@@ -635,6 +672,21 @@ ParseAcpiIort (
   PARSER_PARAMS (IortNodeHeaderParser)
   );
 
+// Check if the values used to control the parsing logic have been
+// successfully read.
+if ((IortNodeType == NULL)||
+(IortNodeLength == NULL)  ||
+(IortIdMappingCount == NULL)  ||
+(IortIdMappingOffset == NULL)) {
+  IncrementErrorCount ();
+  Print (
+L"ERROR: Insufficient remaining table buffer length to read the " \
+  L"IORT node header. Length = %d.\n",
+AcpiTableLength - Offset
+);
+  return;
+}
+
 // Make sure the IORT Node is inside the table
 if ((Offset + (*IortNodeLength)) > AcpiTableLength) {
   IncrementErrorCount ();
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#53410): https://edk2.groups.io/g/devel/message/53410
Mute This Topic: https://groups.io/mt/69929574/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 11/11] ShellPkg: acpiview: DBG2: Validate global pointers before use

2020-01-20 Thread Krzysztof Koch
Check if global (in the scope of the DBG2 parser) pointers have been
successfully updated before they are used for further table parsing.

Signed-off-by: Krzysztof Koch 
---

Notes:
v3:
- Rebase on latest master [Krzysztof]

v1:
- Test against NULL pointers [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c | 43 

 1 file changed, 43 insertions(+)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
index 
869e700b9beda4886bf7bc5ae4ced3ab9a59efa3..0f730a306a94329a23fbaf54b59f1833b44616ba
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
@@ -123,6 +123,24 @@ DumpDbgDeviceInfo (
 PARSER_PARAMS (DbgDevInfoParser)
 );
 
+  // Check if the values used to control the parsing logic have been
+  // successfully read.
+  if ((GasCount == NULL)  ||
+  (NameSpaceStringLength == NULL) ||
+  (NameSpaceStringOffset == NULL) ||
+  (OEMDataLength == NULL) ||
+  (OEMDataOffset == NULL) ||
+  (BaseAddrRegOffset == NULL) ||
+  (AddrSizeOffset == NULL)) {
+IncrementErrorCount ();
+Print (
+  L"ERROR: Insufficient Debug Device Information Structure length. " \
+L"Length = %d.\n",
+  Length
+  );
+return;
+  }
+
   // GAS
   Index = 0;
   Offset = *BaseAddrRegOffset;
@@ -224,6 +242,18 @@ ParseAcpiDbg2 (
  PARSER_PARAMS (Dbg2Parser)
  );
 
+  // Check if the values used to control the parsing logic have been
+  // successfully read.
+  if ((OffsetDbgDeviceInfo == NULL) ||
+  (NumberDbgDeviceInfo == NULL)) {
+IncrementErrorCount ();
+Print (
+  L"ERROR: Insufficient table length. AcpiTableLength = %d\n",
+  AcpiTableLength
+  );
+return;
+  }
+
   Offset = *OffsetDbgDeviceInfo;
   Index = 0;
 
@@ -239,6 +269,19 @@ ParseAcpiDbg2 (
   PARSER_PARAMS (DbgDevInfoHeaderParser)
   );
 
+// Check if the values used to control the parsing logic have been
+// successfully read.
+if (DbgDevInfoLen == NULL) {
+  IncrementErrorCount ();
+  Print (
+L"ERROR: Insufficient remaining table buffer length to read the " \
+  L"Debug Device Information structure's 'Length' field. " \
+  L"RemainingTableBufferLength = %d.\n",
+AcpiTableLength - Offset
+);
+  return;
+}
+
 // Make sure the Debug Device Information structure lies inside the table.
 if ((Offset + *DbgDevInfoLen) > AcpiTableLength) {
   IncrementErrorCount ();
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#53414): https://edk2.groups.io/g/devel/message/53414
Mute This Topic: https://groups.io/mt/69929579/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 07/11] ShellPkg: acpiview: MADT: Validate global pointers before use

2020-01-20 Thread Krzysztof Koch
Check if the MadtInterruptControllerType and
MadtInterruptControllerLength pointers have been successfully updated
before they are used for further table parsing.

Signed-off-by: Krzysztof Koch 
---

Notes:
v3:
- Rebase on latest master [Krzysztof]

v1:
- Test against NULL pointers [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c | 13 
+
 1 file changed, 13 insertions(+)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c
index 
90bdafea1970db522e8ed96de7c6e986cdaca5ba..438905cb24f58b8b82e8fe61280e72f765d578d8
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c
@@ -260,6 +260,19 @@ ParseAcpiMadt (
   PARSER_PARAMS (MadtInterruptControllerHeaderParser)
   );
 
+// Check if the values used to control the parsing logic have been
+// successfully read.
+if ((MadtInterruptControllerType == NULL) ||
+(MadtInterruptControllerLength == NULL)) {
+  IncrementErrorCount ();
+  Print (
+L"ERROR: Insufficient remaining table buffer length to read the " \
+  L"Interrupt Controller Structure header. Length = %d.\n",
+AcpiTableLength - Offset
+);
+  return;
+}
+
 // Make sure forward progress is made.
 if (*MadtInterruptControllerLength < 2) {
   IncrementErrorCount ();
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#53408): https://edk2.groups.io/g/devel/message/53408
Mute This Topic: https://groups.io/mt/69929572/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 00/11] Test against invalid pointers in acpiview

2020-01-20 Thread Krzysztof Koch
Prevent the use of invalid pointers when parsing ACPI tables in the UEFI
shell acpiview tool.

The parsing of ACPI tables is often controlled with the values read
earlier from the same table. For example, the 'Offset' or 'Count' fields
found in a structure are later used to parse the substructures. If such
fields lie outside the structure's buffer length provided, then there
is a possibility for a wild or dangling pointer.

Currently, if the ParseAcpi() function terminates early because the end
of the input table data buffer has been reached, then the pointers
which were supposed to be updated by this function are left untouched.
This is a security issue as the values pointed to by these pointers are
later used for flow control.

This patch series aims to solve this security issue by explicitly
initializing any pointers lying outside the input ACPI data buffer to
NULL and testing for NULL whenever these pointers are dereferenced.

Changes can be seet at: 
https://github.com/KrzysztofKoch1/edk2/tree/612_add_pointer_validation_v3

Notes:
v3:
- Rebase on latest master [Krzysztof]

v2:
- Do not require FadtMinorRevision and X_DsdtAddress pointers to be
  valid in FADT table parser [Zhichao]

v1:
- Validate static pointers in acpiview parsers before use [Krzysztof]

Krzysztof Koch (11):
  ShellPkg: acpiview: Set ItemPtr to NULL for unprocessed table fields
  ShellPkg: acpiview: RSDP: Validate global pointer before use
  ShellPkg: acpiview: FADT: Validate global pointer before use
  ShellPkg: acpiview: SLIT: Validate global pointer before use
  ShellPkg: acpiview: SLIT: Validate System Locality count
  ShellPkg: acpiview: SRAT: Validate global pointers before use
  ShellPkg: acpiview: MADT: Validate global pointers before use
  ShellPkg: acpiview: PPTT: Validate global pointers before use
  ShellPkg: acpiview: IORT: Validate global pointers before use
  ShellPkg: acpiview: GTDT: Validate global pointers before use
  ShellPkg: acpiview: DBG2: Validate global pointers before use

 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c  |  9 ++-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c | 43 
++
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c | 21 
+++
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c | 37 

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c | 52 
+
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c | 13 
+
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c | 25 

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c | 12 

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c | 61 
++--
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c | 13 
+
 10 files changed, 269 insertions(+), 17 deletions(-)

--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#53403): https://edk2.groups.io/g/devel/message/53403
Mute This Topic: https://groups.io/mt/69929567/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 10/11] ShellPkg: acpiview: GTDT: Validate global pointers before use

2020-01-20 Thread Krzysztof Koch
Check if global (in the scope of the GTDT parser) pointers have been
successfully updated before they are used for further table parsing.

Signed-off-by: Krzysztof Koch 
---

Notes:
v3:
- Rebase on latest master [Krzysztof]

v1:
- Test against NULL pointers [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c | 37 

 1 file changed, 37 insertions(+)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c
index 
57174e14c80072f12b90e1996ebe8f0002d0c404..699a55b549ec3fa61bbd156898821055dc019199
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c
@@ -189,6 +189,18 @@ DumpGTBlock (
 PARSER_PARAMS (GtBlockParser)
 );
 
+  // Check if the values used to control the parsing logic have been
+  // successfully read.
+  if ((GtBlockTimerCount == NULL) ||
+  (GtBlockTimerOffset == NULL)) {
+IncrementErrorCount ();
+Print (
+  L"ERROR: Insufficient GT Block Structure length. Length = %d.\n",
+  Length
+  );
+return;
+  }
+
   Offset = *GtBlockTimerOffset;
   Index = 0;
 
@@ -272,6 +284,18 @@ ParseAcpiGtdt (
 PARSER_PARAMS (GtdtParser)
 );
 
+  // Check if the values used to control the parsing logic have been
+  // successfully read.
+  if ((GtdtPlatformTimerCount == NULL) ||
+  (GtdtPlatformTimerOffset == NULL)) {
+IncrementErrorCount ();
+Print (
+  L"ERROR: Insufficient table length. AcpiTableLength = %d.\n",
+  AcpiTableLength
+  );
+return;
+  }
+
   TimerPtr = Ptr + *GtdtPlatformTimerOffset;
   Offset = *GtdtPlatformTimerOffset;
   Index = 0;
@@ -290,6 +314,19 @@ ParseAcpiGtdt (
   PARSER_PARAMS (GtPlatformTimerHeaderParser)
   );
 
+// Check if the values used to control the parsing logic have been
+// successfully read.
+if ((PlatformTimerType == NULL) ||
+(PlatformTimerLength == NULL)) {
+  IncrementErrorCount ();
+  Print (
+L"ERROR: Insufficient remaining table buffer length to read the " \
+  L"Platform Timer Structure header. Length = %d.\n",
+AcpiTableLength - Offset
+);
+  return;
+}
+
 // Make sure the Platform Timer is inside the table.
 if ((Offset + *PlatformTimerLength) > AcpiTableLength) {
   IncrementErrorCount ();
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#53413): https://edk2.groups.io/g/devel/message/53413
Mute This Topic: https://groups.io/mt/69929578/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 04/11] ShellPkg: acpiview: SLIT: Validate global pointer before use

2020-01-20 Thread Krzysztof Koch
Check if SlitSystemLocalityCount pointer has been successfully updated
before it is used for further table parsing.

Signed-off-by: Krzysztof Koch 
---

Notes:
v3:
- Rebase on latest master [Krzysztof]

v1:
- Test against NULL pointers [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c | 16 
++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c
index 
ca2808db526b1bbb79aeb21ccfc0ae6c79b2dfd8..17e2166a09d8615b714e0c51d4d93d293fcdf601
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c
@@ -1,7 +1,7 @@
 /** @file
   SLIT table parser
 
-  Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
+  Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
   @par Reference(s):
@@ -75,9 +75,21 @@ ParseAcpiSlit (
  AcpiTableLength,
  PARSER_PARAMS (SlitParser)
  );
+
+  // Check if the values used to control the parsing logic have been
+  // successfully read.
+  if (SlitSystemLocalityCount == NULL) {
+IncrementErrorCount ();
+Print (
+  L"ERROR: Insufficient table length. AcpiTableLength = %d.\n",
+  AcpiTableLength
+  );
+return;
+  }
+
   LocalityPtr = Ptr + Offset;
-
   LocalityCount = *SlitSystemLocalityCount;
+
   // We only print the Localities if the count is less than 16
   // If the locality count is more than 16 then refer to the
   // raw data dump.
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#53406): https://edk2.groups.io/g/devel/message/53406
Mute This Topic: https://groups.io/mt/69929570/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 05/11] ShellPkg: acpiview: SLIT: Validate System Locality count

2020-01-20 Thread Krzysztof Koch
1. Check if the 'Number of System Localities' provided can be
represented in the SLIT table. The table 'Length' field is a 32-bit
value while the 'Number of System Localities' field is 64-bit long.

2. Check if the SLIT matrix fits in the table buffer. If N is the SLIT
locality count, then the matrix used to represent the localities is
N*N bytes long. The ACPI table length must be big enough to fit the
matrix.

3. Remove (now) redundant 64x64 bit multiplication.

Signed-off-by: Krzysztof Koch 
---

Notes:
v3:
- Rebase on latest master [Krzysztof]

v1:
- Validate the 'Number of System Localities' Field [Krzysztof]
- Remove redundant 64x64 bit multiplication [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c | 47 
+---
 1 file changed, 42 insertions(+), 5 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c
index 
17e2166a09d8615b714e0c51d4d93d293fcdf601..e4625ee8b13907893a9b6990ecb956baf91cc3b9
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c
@@ -30,7 +30,7 @@ STATIC CONST ACPI_PARSER SlitParser[] = {
 /**
   Macro to get the value of a System Locality
 **/
-#define SLIT_ELEMENT(Ptr, i, j) *(Ptr + (MultU64x64 (i, LocalityCount)) + j)
+#define SLIT_ELEMENT(Ptr, i, j) *(Ptr + (i * LocalityCount) + j)
 
 /**
   This function parses the ACPI SLIT table.
@@ -57,9 +57,9 @@ ParseAcpiSlit (
   )
 {
   UINT32 Offset;
-  UINT64 Count;
-  UINT64 Index;
-  UINT64 LocalityCount;
+  UINT32 Count;
+  UINT32 Index;
+  UINT32 LocalityCount;
   UINT8* LocalityPtr;
   CHAR16 Buffer[80];  // Used for AsciiName param of ParseAcpi
 
@@ -87,8 +87,45 @@ ParseAcpiSlit (
 return;
   }
 
+  /*
+Despite the 'Number of System Localities' being a 64-bit field in SLIT,
+the maximum number of localities that can be represented in SLIT is limited
+by the 'Length' field of the ACPI table.
+
+Since the ACPI table length field is 32-bit wide. The maximum number of
+localities that can be represented in SLIT can be calculated as:
+
+MaxLocality = sqrt (MAX_UINT32 - sizeof 
(EFI_ACPI_6_3_SYSTEM_LOCALITY_DISTANCE_INFORMATION_TABLE_HEADER))
+= 65535
+= MAX_UINT16
+  */
+  if (*SlitSystemLocalityCount > MAX_UINT16) {
+IncrementErrorCount ();
+Print (
+  L"ERROR: The Number of System Localities provided can't be represented " 
\
+L"in the SLIT table. SlitSystemLocalityCount = %ld. " \
+L"MaxLocalityCountAllowed = %d.\n",
+  *SlitSystemLocalityCount,
+  MAX_UINT16
+  );
+return;
+  }
+
+  LocalityCount = (UINT32)*SlitSystemLocalityCount;
+
+  // Make sure system localities fit in the table buffer provided
+  if (Offset + (LocalityCount * LocalityCount) > AcpiTableLength) {
+IncrementErrorCount ();
+Print (
+  L"ERROR: Invalid Number of System Localities. " \
+L"SlitSystemLocalityCount = %ld. AcpiTableLength = %d.\n",
+  *SlitSystemLocalityCount,
+  AcpiTableLength
+  );
+return;
+  }
+
   LocalityPtr = Ptr + Offset;
-  LocalityCount = *SlitSystemLocalityCount;
 
   // We only print the Localities if the count is less than 16
   // If the locality count is more than 16 then refer to the
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#53407): https://edk2.groups.io/g/devel/message/53407
Mute This Topic: https://groups.io/mt/69929571/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [edk2-platforms][PATCH v2 1/1] Platform/ARM/ArmJunoDxe: Fix 'unused variable' error for DynamicTables

2020-01-28 Thread Krzysztof Koch
Fix 'mAcpiRegistration defined but not used' compiler error for
Dynamic Tables Framework builds.

Do not declare the mAcpiRegistration variable in the Dynamic Tables
Framework context.

Commit 484a683ab9f made mAcpiRegistration variable STATIC. Reducing
scope made scope resolution simpler, thus, the 'defined but not used'
error got raised.

Signed-off-by: Krzysztof Koch 
---

Changes can be seen at: 
https://github.com/KrzysztofKoch1/edk2-platforms/tree/723_fix_unused_variable_juno_dxe_v2

Notes:
v2:
- Specify which previous commit inroduced the error [Philippe]

v1:
- Fix 'defined but not used' Dynamic Tables build error [Krzysztof]

 Platform/ARM/JunoPkg/Drivers/ArmJunoDxe/ArmJunoDxe.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Platform/ARM/JunoPkg/Drivers/ArmJunoDxe/ArmJunoDxe.c 
b/Platform/ARM/JunoPkg/Drivers/ArmJunoDxe/ArmJunoDxe.c
index 
e3b64992e02c003f7e3a6636340a6afa573f477a..cd7a205f90f131560419cfd744dd5c22df726c99
 100644
--- a/Platform/ARM/JunoPkg/Drivers/ArmJunoDxe/ArmJunoDxe.c
+++ b/Platform/ARM/JunoPkg/Drivers/ArmJunoDxe/ArmJunoDxe.c
@@ -1,6 +1,6 @@
 /** @file
 *
-*  Copyright (c) 2013-2019, ARM Limited. All rights reserved.
+*  Copyright (c) 2013-2020, ARM Limited. All rights reserved.
 *
 *  SPDX-License-Identifier: BSD-2-Clause-Patent
 *
@@ -30,9 +30,9 @@
 #ifndef DYNAMIC_TABLES_FRAMEWORK
 // This GUID must match the FILE_GUID in 
ArmPlatformPkg/ArmJunoPkg/AcpiTables/AcpiTables.inf
 STATIC CONST EFI_GUID mJunoAcpiTableFile = { 0xa1dd808e, 0x1e95, 0x4399, { 
0xab, 0xc0, 0x65, 0x3c, 0x82, 0xe8, 0x53, 0x0c } };
-#endif
-
 STATIC VOID *mAcpiRegistration = NULL;
+#endif
+
 STATIC VOID *mPciIoNotificationRegistration = NULL;
 
 /**
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#53503): https://edk2.groups.io/g/devel/message/53503
Mute This Topic: https://groups.io/mt/70219746/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 1/1] MdePkg: Add PCCT table signature definition

2020-01-30 Thread Krzysztof Koch
Acpi63.h contains definitions describing the Platform Communications
Channel Table's (PCCT) structure. However, a macro for the table's
signature is missing.

This patch adds the definition of Platform Communications Channel
Table's signature.

References:
- ACPI 6.3, January 2019, Section 14.1

Signed-off-by: Krzysztof Koch 
---

Changes can be seen at: 
https://github.com/KrzysztofKoch1/edk2/tree/617_add_pcct_signature_def_v1

Notes:
v1:
- Add definition of PCCT table signature [Krzysztof]

 MdePkg/Include/IndustryStandard/Acpi63.h | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/MdePkg/Include/IndustryStandard/Acpi63.h 
b/MdePkg/Include/IndustryStandard/Acpi63.h
index 
eca1f9357b70f10887e680ff13c97c0beab3600b..b281b30155e90eba5169dc39bde9a3379e3b7005
 100644
--- a/MdePkg/Include/IndustryStandard/Acpi63.h
+++ b/MdePkg/Include/IndustryStandard/Acpi63.h
@@ -2,7 +2,7 @@
   ACPI 6.3 definitions from the ACPI Specification Revision 6.3 Jan, 2019.
 
   Copyright (c) 2017, Intel Corporation. All rights reserved.
-  Copyright (c) 2019, ARM Ltd. All rights reserved.
+  Copyright (c) 2019 - 2020, ARM Ltd. All rights reserved.
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 **/
@@ -2880,6 +2880,11 @@ typedef struct {
 ///
 #define EFI_ACPI_6_3_DATA_MANAGEMENT_TABLE_SIGNATURE  SIGNATURE_32('M', 'S', 
'D', 'M')
 
+///
+/// "PCCT" Platform Communications Channel Table
+///
+#define EFI_ACPI_6_3_PLATFORM_COMMUNICATIONS_CHANNEL_TABLE_SIGNATURE  
SIGNATURE_32('P', 'C', 'C', 'T')
+
 ///
 /// "SDEI" Software Delegated Exceptions Interface Table
 ///
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#53574): https://edk2.groups.io/g/devel/message/53574
Mute This Topic: https://groups.io/mt/70268100/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 1/1] ShellPkg: acpiview: Remove duplicate ACPI structure size definitions

2020-01-30 Thread Krzysztof Koch
Remove duplicate Generic Address Structure (GAS) and ACPI table header
size definitions. Replace any dependencies with the definitions from
Acpi63.h.

AcpiParser.h redefines the size of Generic Address Structure (GAS) and
the ACPI table header. The motivation is to 'minimise any reference to
the EDK2 ACPI headers in an attempt to provide cross checking'. While
the redefined values are unlikely to change, redefinition causes
unnecessary maintenance overhead for acpiview.

In addition to this, EDK2 ACPI headers are referenced throughout the
entire project, so the assumption should be that the definitions in
these header files are correct.

Signed-off-by: Krzysztof Koch 
---

Changes can be seen at: 
https://github.com/tianocore/edk2/compare/master...KrzysztofKoch1:remove_dup_defs_acpiview_v1?expand=1

Notes:
v1:
- Remove duplicate definitions [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c |  8 +++
 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h | 22 
+---
 2 files changed, 5 insertions(+), 25 deletions(-)

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
index 
2b2ecb93cef9ee28b752e7bf2d920b059dbf7d6b..ed8767da64280d0b02fe42b7d2120690d5573bba
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
@@ -1,7 +1,7 @@
 /** @file
   ACPI parser
 
-  Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
+  Copyright (c) 2016 - 2020, ARM Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 **/
 
@@ -666,7 +666,7 @@ DumpGas (
   IN UINT8*Ptr
   )
 {
-  DumpGasStruct (Ptr, 2, GAS_LENGTH);
+  DumpGasStruct (Ptr, 2, sizeof (EFI_ACPI_6_3_GENERIC_ADDRESS_STRUCTURE));
 }
 
 /**
@@ -687,7 +687,7 @@ DumpAcpiHeader (
0,
"ACPI Table Header",
Ptr,
-   ACPI_DESCRIPTION_HEADER_LENGTH,
+   sizeof (EFI_ACPI_DESCRIPTION_HEADER),
PARSER_PARAMS (AcpiHeaderParser)
);
 }
@@ -721,7 +721,7 @@ ParseAcpiHeader (
   0,
   NULL,
   Ptr,
-  ACPI_DESCRIPTION_HEADER_LENGTH,
+  sizeof (EFI_ACPI_DESCRIPTION_HEADER),
   PARSER_PARAMS (AcpiHeaderParser)
   );
 
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
index 
6deee3542e09bc18b03fdd18dece5b6f9725839c..f81ccac7e118378aa185db4b625e5bcd75f78347
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
@@ -1,7 +1,7 @@
 /** @file
   Header file for ACPI parser
 
-  Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
+  Copyright (c) 2016 - 2020, ARM Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 **/
 
@@ -396,26 +396,6 @@ ParseAcpi (
   { L"Creator Revision", 4, 32, L"0x%X", NULL,\
 (VOID**)&(Info)->CreatorRevision, NULL, NULL }
 
-/**
-  Length of the ACPI GAS structure.
-
-  NOTE: This might normally be defined as
-sizeof (EFI_ACPI_6_2_GENERIC_ADDRESS_STRUCTURE).
-However, we deliberately minimise any reference to the EDK2 ACPI
-headers in an attempt to provide cross checking.
-**/
-#define GAS_LENGTH 12
-
-/**
-  Length of the ACPI Header structure.
-
-  NOTE: This might normally be defined as
-sizeof (EFI_ACPI_DESCRIPTION_HEADER).
-However, we deliberately minimise any reference to the EDK2 ACPI
-headers in an attempt to provide cross checking.
-**/
-#define ACPI_DESCRIPTION_HEADER_LENGTH  36
-
 /**
   This function indents and traces the GAS structure as described by the 
GasParser.
 
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#53577): https://edk2.groups.io/g/devel/message/53577
Mute This Topic: https://groups.io/mt/70268417/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 1/1] ShellPkg: acpiview: Validate ACPI table 'Length' field

2020-01-30 Thread Krzysztof Koch
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 
---

Changes can be seet at: 
https://github.com/KrzysztofKoch1/edk2/pull/new/650_add_checks_process_acpi_table_v1

Notes:
v1:
- Validate ACPI table length [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.c | 22 
+++-
 1 file changed, 21 insertions(+), 1 deletion(-)

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



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#53585): https://edk2.groups.io/g/devel/message/53585
Mute This Topic: https://groups.io/mt/70272674/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH v3 00/11] Test against invalid pointers in acpiview

2020-02-03 Thread Krzysztof Koch
Hi,

Is there any chance this patch series will get reviewed soon?
The v1 series has already been reviewed a few months ago and the patches which 
were not ok were re-submitted as v2.
The v3 series is basically a rebase of v1 on latest master with the v2 changes 
included.

Kind regards,
Krzysztof

-Original Message-
From: devel@edk2.groups.io  On Behalf Of Krzysztof Koch 
via Groups.Io
Sent: Monday, January 20, 2020 11:14
To: devel@edk2.groups.io
Cc: ray...@intel.com; zhichao@intel.com; Sami Mujawar 
; Matteo Carlini ; nd 

Subject: [edk2-devel] [PATCH v3 00/11] Test against invalid pointers in acpiview

Prevent the use of invalid pointers when parsing ACPI tables in the UEFI shell 
acpiview tool.

The parsing of ACPI tables is often controlled with the values read earlier 
from the same table. For example, the 'Offset' or 'Count' fields found in a 
structure are later used to parse the substructures. If such fields lie outside 
the structure's buffer length provided, then there is a possibility for a wild 
or dangling pointer.

Currently, if the ParseAcpi() function terminates early because the end of the 
input table data buffer has been reached, then the pointers which were supposed 
to be updated by this function are left untouched.
This is a security issue as the values pointed to by these pointers are later 
used for flow control.

This patch series aims to solve this security issue by explicitly initializing 
any pointers lying outside the input ACPI data buffer to NULL and testing for 
NULL whenever these pointers are dereferenced.

Changes can be seet at: 
https://github.com/KrzysztofKoch1/edk2/tree/612_add_pointer_validation_v3

Notes:
v3:
- Rebase on latest master [Krzysztof]

v2:
- Do not require FadtMinorRevision and X_DsdtAddress pointers to be
  valid in FADT table parser [Zhichao]

v1:
- Validate static pointers in acpiview parsers before use [Krzysztof]

Krzysztof Koch (11):
  ShellPkg: acpiview: Set ItemPtr to NULL for unprocessed table fields
  ShellPkg: acpiview: RSDP: Validate global pointer before use
  ShellPkg: acpiview: FADT: Validate global pointer before use
  ShellPkg: acpiview: SLIT: Validate global pointer before use
  ShellPkg: acpiview: SLIT: Validate System Locality count
  ShellPkg: acpiview: SRAT: Validate global pointers before use
  ShellPkg: acpiview: MADT: Validate global pointers before use
  ShellPkg: acpiview: PPTT: Validate global pointers before use
  ShellPkg: acpiview: IORT: Validate global pointers before use
  ShellPkg: acpiview: GTDT: Validate global pointers before use
  ShellPkg: acpiview: DBG2: Validate global pointers before use

 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c  |  9 ++-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c | 43 
++  
ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c | 21 
+++  ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c 
| 37   
ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c | 52 
+  
ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c | 13 
+  ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c | 
25   
ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c | 12 
  ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c | 
61 ++--  
ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c | 13 
+
 10 files changed, 269 insertions(+), 17 deletions(-)

--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'






-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#53650): https://edk2.groups.io/g/devel/message/53650
Mute This Topic: https://groups.io/mt/69929567/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v2 1/1] ShellPkg: acpiview: Validate ACPI table 'Length' field

2020-02-11 Thread Krzysztof Koch
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 
---

Changes can be seet at: 
https://github.com/KrzysztofKoch1/edk2/pull/new/650_add_checks_process_acpi_table_v2

Notes:
v2:
- Change code comment style [Zhichao]

v1:
- Validate ACPI table length [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.c | 20 
+++-
 1 file changed, 19 insertions(+), 1 deletion(-)

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


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#54192): https://edk2.groups.io/g/devel/message/54192
Mute This Topic: https://groups.io/mt/71163284/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH v1 1/1] MdePkg: Add PCCT table signature definition

2020-02-12 Thread Krzysztof Koch
Hi All,

Is there something I can do to help get this patch merged?

Kind regards,
Krzysztof

-Original Message-
From: Sami Mujawar  
Sent: Thursday, January 30, 2020 11:40
To: Krzysztof Koch ; devel@edk2.groups.io
Cc: michael.d.kin...@intel.com; liming@intel.com; Matteo Carlini 
; nd ; Laura Moretta 

Subject: RE: [PATCH v1 1/1] MdePkg: Add PCCT table signature definition

Reviewed-by: Sami Mujawar 

Regards,

Sami Mujawar

-Original Message-
From: Krzysztof Koch 
Sent: 30 January 2020 11:14
To: devel@edk2.groups.io
Cc: michael.d.kin...@intel.com; liming@intel.com; Matteo Carlini 
; Sami Mujawar ; nd 
Subject: [PATCH v1 1/1] MdePkg: Add PCCT table signature definition

Acpi63.h contains definitions describing the Platform Communications Channel 
Table's (PCCT) structure. However, a macro for the table's signature is missing.

This patch adds the definition of Platform Communications Channel Table's 
signature.

References:
- ACPI 6.3, January 2019, Section 14.1

Signed-off-by: Krzysztof Koch 
---

Changes can be seen at: 
https://github.com/KrzysztofKoch1/edk2/tree/617_add_pcct_signature_def_v1

Notes:
v1:
- Add definition of PCCT table signature [Krzysztof]

 MdePkg/Include/IndustryStandard/Acpi63.h | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/MdePkg/Include/IndustryStandard/Acpi63.h 
b/MdePkg/Include/IndustryStandard/Acpi63.h
index 
eca1f9357b70f10887e680ff13c97c0beab3600b..b281b30155e90eba5169dc39bde9a3379e3b7005
 100644
--- a/MdePkg/Include/IndustryStandard/Acpi63.h
+++ b/MdePkg/Include/IndustryStandard/Acpi63.h
@@ -2,7 +2,7 @@
   ACPI 6.3 definitions from the ACPI Specification Revision 6.3 Jan, 2019.
 
   Copyright (c) 2017, Intel Corporation. All rights reserved.
-  Copyright (c) 2019, ARM Ltd. All rights reserved.
+  Copyright (c) 2019 - 2020, ARM Ltd. All rights reserved.
 
   SPDX-License-Identifier: BSD-2-Clause-Patent  **/ @@ -2880,6 +2880,11 @@ 
typedef struct {  ///  #define EFI_ACPI_6_3_DATA_MANAGEMENT_TABLE_SIGNATURE  
SIGNATURE_32('M', 'S', 'D', 'M')
 
+///
+/// "PCCT" Platform Communications Channel Table /// #define 
+EFI_ACPI_6_3_PLATFORM_COMMUNICATIONS_CHANNEL_TABLE_SIGNATURE
+SIGNATURE_32('P', 'C', 'C', 'T')
+
 ///
 /// "SDEI" Software Delegated Exceptions Interface Table  ///
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#54285): https://edk2.groups.io/g/devel/message/54285
Mute This Topic: https://groups.io/mt/70268100/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH v1 1/1] MdePkg: Add PCCT table signature definition

2020-02-12 Thread Krzysztof Koch
Hi Liming,

No problem, I will resubmit the patch updating the relevant ACPI spec header 
files.

Thanks,
Krzysztof

-Original Message-
From: Gao, Liming  
Sent: Wednesday, February 12, 2020 13:59
To: Krzysztof Koch ; devel@edk2.groups.io
Cc: Kinney, Michael D ; Matteo Carlini 
; nd ; Laura Moretta 
; Sami Mujawar 
Subject: RE: [PATCH v1 1/1] MdePkg: Add PCCT table signature definition

Krzysztof:
  Sorry to miss this patch. I see PCCT table is added since ACPI 5.0. So, I 
think its table signature definition should also be added into Acpi50.h, 
Acpi51.h, Acpi60.h, Acpi61.h and Acpi62.h. 

Thanks
Liming
> -Original Message-
> From: Krzysztof Koch 
> Sent: Wednesday, February 12, 2020 6:55 PM
> To: devel@edk2.groups.io
> Cc: Kinney, Michael D ; Gao, Liming 
> ; Matteo Carlini ; nd 
> ; Laura Moretta ; Sami Mujawar 
> 
> Subject: RE: [PATCH v1 1/1] MdePkg: Add PCCT table signature 
> definition
> 
> Hi All,
> 
> Is there something I can do to help get this patch merged?
> 
> Kind regards,
> Krzysztof
> 
> -Original Message-
> From: Sami Mujawar 
> Sent: Thursday, January 30, 2020 11:40
> To: Krzysztof Koch ; devel@edk2.groups.io
> Cc: michael.d.kin...@intel.com; liming@intel.com; Matteo Carlini 
> ; nd ; Laura Moretta 
> 
> Subject: RE: [PATCH v1 1/1] MdePkg: Add PCCT table signature 
> definition
> 
> Reviewed-by: Sami Mujawar 
> 
> Regards,
> 
> Sami Mujawar
> 
> -Original Message-
> From: Krzysztof Koch 
> Sent: 30 January 2020 11:14
> To: devel@edk2.groups.io
> Cc: michael.d.kin...@intel.com; liming@intel.com; Matteo Carlini 
> ; Sami Mujawar ; nd 
> 
> Subject: [PATCH v1 1/1] MdePkg: Add PCCT table signature definition
> 
> Acpi63.h contains definitions describing the Platform Communications 
> Channel Table's (PCCT) structure. However, a macro for the table's signature 
> is missing.
> 
> This patch adds the definition of Platform Communications Channel Table's 
> signature.
> 
> References:
> - ACPI 6.3, January 2019, Section 14.1
> 
> Signed-off-by: Krzysztof Koch 
> ---
> 
> Changes can be seen at: 
> https://github.com/KrzysztofKoch1/edk2/tree/617_add_pcct_signature_def
> _v1
> 
> Notes:
> v1:
> - Add definition of PCCT table signature [Krzysztof]
> 
>  MdePkg/Include/IndustryStandard/Acpi63.h | 7 ++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/MdePkg/Include/IndustryStandard/Acpi63.h 
> b/MdePkg/Include/IndustryStandard/Acpi63.h
> index 
> eca1f9357b70f10887e680ff13c97c0beab3600b..b281b30155e90eba5169dc39bde9
> a3379e3b7005 100644
> --- a/MdePkg/Include/IndustryStandard/Acpi63.h
> +++ b/MdePkg/Include/IndustryStandard/Acpi63.h
> @@ -2,7 +2,7 @@
>ACPI 6.3 definitions from the ACPI Specification Revision 6.3 Jan, 2019.
> 
>Copyright (c) 2017, Intel Corporation. All rights reserved.
> -  Copyright (c) 2019, ARM Ltd. All rights reserved.
> +  Copyright (c) 2019 - 2020, ARM Ltd. All rights reserved.
> 
>SPDX-License-Identifier: BSD-2-Clause-Patent  **/ @@ -2880,6 
> +2880,11 @@ typedef struct {  ///  #define 
> EFI_ACPI_6_3_DATA_MANAGEMENT_TABLE_SIGNATURE  SIGNATURE_32('M', 'S', 
> 'D', 'M')
> 
> +///
> +/// "PCCT" Platform Communications Channel Table /// #define 
> +EFI_ACPI_6_3_PLATFORM_COMMUNICATIONS_CHANNEL_TABLE_SIGNATURE
> +SIGNATURE_32('P', 'C', 'C', 'T')
> +
>  ///
>  /// "SDEI" Software Delegated Exceptions Interface Table  ///
> --
> 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'
> 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#54297): https://edk2.groups.io/g/devel/message/54297
Mute This Topic: https://groups.io/mt/70268100/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v2 1/1] MdePkg: Add PCCT table signature definition

2020-02-12 Thread Krzysztof Koch
The Platform Communications Channel Table (PCCT) was defined in:
ACPI Specification Version 5.0, Errata A - Published Nov. 13, 2013.

Starting from the Acpi50.h header file, there are definitions
describing the table but a macro with the table's signature is missing.

This patch adds the definition of Platform Communications Channel
Table's signature to the relevant ACPI header files.

Signed-off-by: Krzysztof Koch 
---

Changes can be seen at: 
https://github.com/KrzysztofKoch1/edk2/tree/617_add_pcct_signature_def_v2

Notes:
v2:
- Replicate the definition from Acpi50.h onwards [Liming]

v1:
- Add definition of PCCT table signature [Krzysztof]

 MdePkg/Include/IndustryStandard/Acpi50.h | 6 ++
 MdePkg/Include/IndustryStandard/Acpi51.h | 6 ++
 MdePkg/Include/IndustryStandard/Acpi60.h | 6 ++
 MdePkg/Include/IndustryStandard/Acpi61.h | 6 ++
 MdePkg/Include/IndustryStandard/Acpi62.h | 6 ++
 MdePkg/Include/IndustryStandard/Acpi63.h | 7 ++-
 6 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/MdePkg/Include/IndustryStandard/Acpi50.h 
b/MdePkg/Include/IndustryStandard/Acpi50.h
index 
46dcdb950741020420a5695a8577dde5ac409ed7..31a47e6a2c4276d5b1ad7b834af84844090b64c5
 100644
--- a/MdePkg/Include/IndustryStandard/Acpi50.h
+++ b/MdePkg/Include/IndustryStandard/Acpi50.h
@@ -3,6 +3,7 @@
 
   Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
   Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.
+  Copyright (c) 2020, ARM Ltd. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 **/
 
@@ -2057,6 +2058,11 @@ typedef struct {
 ///
 #define EFI_ACPI_5_0_DATA_MANAGEMENT_TABLE_SIGNATURE  SIGNATURE_32('M', 'S', 
'D', 'M')
 
+///
+/// "PCCT" Platform Communications Channel Table
+///
+#define EFI_ACPI_5_0_PLATFORM_COMMUNICATIONS_CHANNEL_TABLE_SIGNATURE  
SIGNATURE_32('P', 'C', 'C', 'T')
+
 ///
 /// "SLIC" MS Software Licensing Table Specification
 ///
diff --git a/MdePkg/Include/IndustryStandard/Acpi51.h 
b/MdePkg/Include/IndustryStandard/Acpi51.h
index 
0132f25de8ce945135714e59b4b9e5bd286b2c22..fc28ffa18fc6a22e52fda88fade6ad80b2817cc3
 100644
--- a/MdePkg/Include/IndustryStandard/Acpi51.h
+++ b/MdePkg/Include/IndustryStandard/Acpi51.h
@@ -4,6 +4,7 @@
   Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
   Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.
   (C) Copyright 2015 Hewlett Packard Enterprise Development LP
+  Copyright (c) 2020, ARM Ltd. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 **/
 
@@ -2078,6 +2079,11 @@ typedef struct {
 ///
 #define EFI_ACPI_5_1_DATA_MANAGEMENT_TABLE_SIGNATURE  SIGNATURE_32('M', 'S', 
'D', 'M')
 
+///
+/// "PCCT" Platform Communications Channel Table
+///
+#define EFI_ACPI_5_1_PLATFORM_COMMUNICATIONS_CHANNEL_TABLE_SIGNATURE  
SIGNATURE_32('P', 'C', 'C', 'T')
+
 ///
 /// "SLIC" MS Software Licensing Table Specification
 ///
diff --git a/MdePkg/Include/IndustryStandard/Acpi60.h 
b/MdePkg/Include/IndustryStandard/Acpi60.h
index 
94a30a81b369d96dc83dce7aa1e274ef54b315aa..5dcd73b6f1ec4bccc7fdae7d56c2963ab58764f9
 100644
--- a/MdePkg/Include/IndustryStandard/Acpi60.h
+++ b/MdePkg/Include/IndustryStandard/Acpi60.h
@@ -3,6 +3,7 @@
 
   Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.
   (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP
+  Copyright (c) 2020, ARM Ltd. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 **/
 
@@ -2321,6 +2322,11 @@ typedef struct {
 ///
 #define EFI_ACPI_6_0_DATA_MANAGEMENT_TABLE_SIGNATURE  SIGNATURE_32('M', 'S', 
'D', 'M')
 
+///
+/// "PCCT" Platform Communications Channel Table
+///
+#define EFI_ACPI_6_0_PLATFORM_COMMUNICATIONS_CHANNEL_TABLE_SIGNATURE  
SIGNATURE_32('P', 'C', 'C', 'T')
+
 ///
 /// "SLIC" MS Software Licensing Table Specification
 ///
diff --git a/MdePkg/Include/IndustryStandard/Acpi61.h 
b/MdePkg/Include/IndustryStandard/Acpi61.h
index 
985c8273ce61c86d445e61d0d5c1d8ae7c00cb8d..8626833a794dfb4a6f19d459d5214c6caefdbbee
 100644
--- a/MdePkg/Include/IndustryStandard/Acpi61.h
+++ b/MdePkg/Include/IndustryStandard/Acpi61.h
@@ -3,6 +3,7 @@
 
   Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.
  (C) Copyright 2016 Hewlett Packard Enterprise Development LP
+  Copyright (c) 2020, ARM Ltd. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 **/
 
@@ -2353,6 +2354,11 @@ typedef struct {
 ///
 #define EFI_ACPI_6_1_DATA_MANAGEMENT_TABLE_SIGNATURE  SIGNATURE_32('M', 'S', 
'D', 'M')
 
+///
+/// "PCCT" Platform Communications Channel Table
+///
+#define EFI_ACPI_6_1_PLATF

[edk2-devel] [PATCH v1 1/1] ShellPkg: acpiview: Prevent infinite loop if structure length is 0

2020-02-14 Thread Krzysztof Koch
Extend validation of ACPI structure lengths which are read from the
ACPI table being parsed. Additionally check if the structure 'Length'
field value is positive. If not, stop parsing the faulting table.

Some ACPI tables define internal structures of variable size. The
'Length' field inside the substructure is used to update a pointer used
for table traversal. If the byte-length of the structure is equal to 0,
acpiview can enter an infinite loop. This condition can occur if, for
example, the zero-allocated ACPI table buffer is not fully populated.
This is typically a bug on the ACPI table writer side.

In short, this method helps acpiview recover gracefully from a
zero-valued ACPI structure length.

Signed-off-by: Krzysztof Koch 
---

Changes can be seen at: 
https://github.com/KrzysztofKoch1/edk2/tree/612_acpiview_prevent_inf_loops_v1

Notes:
v1:
- prevent infinite loops in acpiview parsers [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c | 15 
++-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c | 13 
-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c | 14 
+-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c | 28 
++--
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c | 15 
++-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c | 14 
+-
 6 files changed, 47 insertions(+), 52 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
index 
0f730a306a94329a23fbaf54b59f1833b44616ba..9df111ecaa7d7a703a13a39c243ed78b9f12ee97
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
@@ -1,7 +1,7 @@
 /** @file
   DBG2 table parser
 
-  Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
+  Copyright (c) 2016 - 2020, ARM Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
   @par Reference(s):
@@ -282,15 +282,16 @@ ParseAcpiDbg2 (
   return;
 }
 
-// Make sure the Debug Device Information structure lies inside the table.
-if ((Offset + *DbgDevInfoLen) > AcpiTableLength) {
+// Validate Debug Device Information Structure length
+if ((*DbgDevInfoLen == 0) ||
+((Offset + (*DbgDevInfoLen)) > AcpiTableLength)) {
   IncrementErrorCount ();
   Print (
-L"ERROR: Invalid Debug Device Information structure length. " \
-  L"DbgDevInfoLen = %d. RemainingTableBufferLength = %d. " \
-  L"DBG2 parsing aborted.\n",
+L"ERROR: Invalid Debug Device Information Structure length. " \
+  L"Length = %d. Offset = %d. AcpiTableLength = %d.\n",
 *DbgDevInfoLen,
-AcpiTableLength - Offset
+Offset,
+AcpiTableLength
 );
   return;
 }
diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c
index 
699a55b549ec3fa61bbd156898821055dc019199..bdd30ff45c61142c071ead63a27babab8998721b
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c
@@ -1,7 +1,7 @@
 /** @file
   GTDT table parser
 
-  Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
+  Copyright (c) 2016 - 2020, ARM Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
   @par Reference(s):
@@ -327,15 +327,16 @@ ParseAcpiGtdt (
   return;
 }
 
-// Make sure the Platform Timer is inside the table.
-if ((Offset + *PlatformTimerLength) > AcpiTableLength) {
+// Validate Platform Timer Structure length
+if ((*PlatformTimerLength == 0) ||
+((Offset + (*PlatformTimerLength)) > AcpiTableLength)) {
   IncrementErrorCount ();
   Print (
 L"ERROR: Invalid Platform Timer Structure length. " \
-  L"PlatformTimerLength = %d. RemainingTableBufferLength = %d. " \
-  L"GTDT parsing aborted.\n",
+  L"Length = %d. Offset = %d. AcpiTableLength = %d.\n",
 *PlatformTimerLength,
-AcpiTableLength - Offset
+Offset,
+AcpiTableLength
 );
   return;
 }
diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c
index 
9d5d937c7b2c19945ca2ad3eba644bdfc09cc3f6..9a006a01448b897865cd7cd85651c816933acf05
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/Ior

Re: [edk2-devel] [PATCH v1 1/1] ShellPkg: acpiview: Prevent infinite loop if structure length is 0

2020-02-17 Thread Krzysztof Koch
Hi Liming,

I haven't created a BZ yet, shall I create one? It would be great if the patch 
makes it to the stable tag.

Over the last few months I added some security features to acpiview. They make 
this debug tool less sensitive to exploits from ACPI tables. This patch 
completes my efforts in making the tool more reliable.

Kind regards,
Krzysztof

-Original Message-
From: devel@edk2.groups.io  On Behalf Of Liming Gao via 
Groups.Io
Sent: Monday, February 17, 2020 15:11
To: devel@edk2.groups.io; Krzysztof Koch 
Cc: Ni, Ray ; Gao, Zhichao ; Sami 
Mujawar ; Matteo Carlini ; nd 

Subject: Re: [edk2-devel] [PATCH v1 1/1] ShellPkg: acpiview: Prevent infinite 
loop if structure length is 0

Krzysztof:
  Is there one BZ for this issue? Does this patch catch to this edk2 stable tag 
202002?

Thanks
Liming
> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of 
> Krzysztof Koch
> Sent: Friday, February 14, 2020 9:59 PM
> To: devel@edk2.groups.io
> Cc: Ni, Ray ; Gao, Zhichao ; 
> sami.muja...@arm.com; matteo.carl...@arm.com; n...@arm.com
> Subject: [edk2-devel] [PATCH v1 1/1] ShellPkg: acpiview: Prevent 
> infinite loop if structure length is 0
> 
> Extend validation of ACPI structure lengths which are read from the 
> ACPI table being parsed. Additionally check if the structure 'Length'
> field value is positive. If not, stop parsing the faulting table.
> 
> Some ACPI tables define internal structures of variable size. The 
> 'Length' field inside the substructure is used to update a pointer 
> used for table traversal. If the byte-length of the structure is equal 
> to 0, acpiview can enter an infinite loop. This condition can occur 
> if, for example, the zero-allocated ACPI table buffer is not fully populated.
> This is typically a bug on the ACPI table writer side.
> 
> In short, this method helps acpiview recover gracefully from a 
> zero-valued ACPI structure length.
> 
> Signed-off-by: Krzysztof Koch 
> ---
> 
> Changes can be seen at: 
> https://github.com/KrzysztofKoch1/edk2/tree/612_acpiview_prevent_inf_l
> oops_v1
> 
> Notes:
> v1:
> - prevent infinite loops in acpiview parsers [Krzysztof]
> 
>
> ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c 
> | 15 ++-
> ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c 
> | 13 -
> ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c 
> | 14 +-
> ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c 
> | 28 ++--
> ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c 
> | 15 ++-
> ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c 
> | 14 +-
>  6 files changed, 47 insertions(+), 52 deletions(-)
> 
> diff --git 
> a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser
> .c 
> b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser
> .c index 
> 0f730a306a94329a23fbaf54b59f1833b44616ba..9df111ecaa7d7a703a13a39c243e
> d78b9f12ee97 100644
> --- 
> a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser
> .c
> +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Pa
> +++ rser.c
> @@ -1,7 +1,7 @@
>  /** @file
>DBG2 table parser
> 
> -  Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
> +  Copyright (c) 2016 - 2020, ARM Limited. All rights reserved.
>SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>@par Reference(s):
> @@ -282,15 +282,16 @@ ParseAcpiDbg2 (
>return;
>  }
> 
> -// Make sure the Debug Device Information structure lies inside the 
> table.
> -if ((Offset + *DbgDevInfoLen) > AcpiTableLength) {
> +// Validate Debug Device Information Structure length
> +if ((*DbgDevInfoLen == 0) ||
> +((Offset + (*DbgDevInfoLen)) > AcpiTableLength)) {
>IncrementErrorCount ();
>Print (
> -L"ERROR: Invalid Debug Device Information structure length. " \
> -  L"DbgDevInfoLen = %d. RemainingTableBufferLength = %d. " \
> -  L"DBG2 parsing aborted.\n",
> +L"ERROR: Invalid Debug Device Information Structure length. " \
> +  L"Length = %d. Offset = %d. AcpiTableLength = %d.\n",
>  *DbgDevInfoLen,
> -AcpiTableLength - Offset
> +Offset,
> +AcpiTableLength
>  );
>return;
>  }
> diff --git 
> a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser
> .c 
> b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser
> .c index 
> 699a55b549ec3fa61bbd156898821055d

Re: [edk2-devel] [PATCH v1 1/1] ShellPkg: acpiview: Prevent infinite loop if structure length is 0

2020-02-17 Thread Krzysztof Koch
Hi Liming,

The BZ is: https://bugzilla.tianocore.org/show_bug.cgi?id=2534
Please let me know if I should change something.

Kind regards,
Krzysztof

-Original Message-
From: devel@edk2.groups.io  On Behalf Of Krzysztof Koch 
via Groups.Io
Sent: Monday, February 17, 2020 15:23
To: devel@edk2.groups.io; liming@intel.com
Cc: Ni, Ray ; Gao, Zhichao ; Sami 
Mujawar ; Matteo Carlini ; nd 

Subject: Re: [edk2-devel] [PATCH v1 1/1] ShellPkg: acpiview: Prevent infinite 
loop if structure length is 0

Hi Liming,

I haven't created a BZ yet, shall I create one? It would be great if the patch 
makes it to the stable tag.

Over the last few months I added some security features to acpiview. They make 
this debug tool less sensitive to exploits from ACPI tables. This patch 
completes my efforts in making the tool more reliable.

Kind regards,
Krzysztof

-Original Message-
From: devel@edk2.groups.io  On Behalf Of Liming Gao via 
Groups.Io
Sent: Monday, February 17, 2020 15:11
To: devel@edk2.groups.io; Krzysztof Koch 
Cc: Ni, Ray ; Gao, Zhichao ; Sami 
Mujawar ; Matteo Carlini ; nd 

Subject: Re: [edk2-devel] [PATCH v1 1/1] ShellPkg: acpiview: Prevent infinite 
loop if structure length is 0

Krzysztof:
  Is there one BZ for this issue? Does this patch catch to this edk2 stable tag 
202002?

Thanks
Liming
> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of 
> Krzysztof Koch
> Sent: Friday, February 14, 2020 9:59 PM
> To: devel@edk2.groups.io
> Cc: Ni, Ray ; Gao, Zhichao ; 
> sami.muja...@arm.com; matteo.carl...@arm.com; n...@arm.com
> Subject: [edk2-devel] [PATCH v1 1/1] ShellPkg: acpiview: Prevent 
> infinite loop if structure length is 0
> 
> Extend validation of ACPI structure lengths which are read from the 
> ACPI table being parsed. Additionally check if the structure 'Length'
> field value is positive. If not, stop parsing the faulting table.
> 
> Some ACPI tables define internal structures of variable size. The 
> 'Length' field inside the substructure is used to update a pointer 
> used for table traversal. If the byte-length of the structure is equal 
> to 0, acpiview can enter an infinite loop. This condition can occur 
> if, for example, the zero-allocated ACPI table buffer is not fully populated.
> This is typically a bug on the ACPI table writer side.
> 
> In short, this method helps acpiview recover gracefully from a 
> zero-valued ACPI structure length.
> 
> Signed-off-by: Krzysztof Koch 
> ---
> 
> Changes can be seen at: 
> https://github.com/KrzysztofKoch1/edk2/tree/612_acpiview_prevent_inf_l
> oops_v1
> 
> Notes:
> v1:
> - prevent infinite loops in acpiview parsers [Krzysztof]
> 
>
> ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
> | 15 ++-
> ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c
> | 13 -
> ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c
> | 14 +-
> ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c
> | 28 ++--
> ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c
> | 15 ++-
> ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
> | 14 +-
>  6 files changed, 47 insertions(+), 52 deletions(-)
> 
> diff --git
> a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser
> .c
> b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser
> .c index
> 0f730a306a94329a23fbaf54b59f1833b44616ba..9df111ecaa7d7a703a13a39c243e
> d78b9f12ee97 100644
> ---
> a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser
> .c
> +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Pa
> +++ rser.c
> @@ -1,7 +1,7 @@
>  /** @file
>DBG2 table parser
> 
> -  Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
> +  Copyright (c) 2016 - 2020, ARM Limited. All rights reserved.
>SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>@par Reference(s):
> @@ -282,15 +282,16 @@ ParseAcpiDbg2 (
>return;
>  }
> 
> -// Make sure the Debug Device Information structure lies inside the 
> table.
> -if ((Offset + *DbgDevInfoLen) > AcpiTableLength) {
> +// Validate Debug Device Information Structure length
> +if ((*DbgDevInfoLen == 0) ||
> +((Offset + (*DbgDevInfoLen)) > AcpiTableLength)) {
>IncrementErrorCount ();
>Print (
> -L"ERROR: Invalid Debug Device Information structure length. " \
> -  L"DbgDevInfoLen = %d. RemainingTableBufferLength = %d. " \
> -  L"DBG2 parsing aborted.\n",
> +L"ERROR: Invalid Debug Device Information Struc

[edk2-devel] [PATCH v2 1/1] ShellPkg: acpiview: Prevent infinite loop if structure length is 0

2020-02-19 Thread Krzysztof Koch
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2534

Extend validation of ACPI structure lengths which are read from the
ACPI table being parsed. Additionally check if the structure 'Length'
field value is positive. If not, stop parsing the faulting table.

Some ACPI tables define internal structures of variable size. The
'Length' field inside the substructure is used to update a pointer used
for table traversal. If the byte-length of the structure is equal to 0,
acpiview can enter an infinite loop. This condition can occur if, for
example, the zero-allocated ACPI table buffer is not fully populated.
This is typically a bug on the ACPI table writer side.

In short, this method helps acpiview recover gracefully from a
zero-valued ACPI structure length.

Signed-off-by: Krzysztof Koch 
---

Changes can be seen at: 
https://github.com/KrzysztofKoch1/edk2/tree/612_acpiview_prevent_inf_loops_v2

Notes:
v2:
- Add BZ link to the commit message [Zhichao]

v1:
- prevent infinite loops in acpiview parsers [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c | 15 
++-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c | 13 
-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c | 14 
+-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c | 28 
++--
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c | 15 
++-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c | 14 
+-
 6 files changed, 47 insertions(+), 52 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
index 
0f730a306a94329a23fbaf54b59f1833b44616ba..9df111ecaa7d7a703a13a39c243ed78b9f12ee97
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
@@ -1,7 +1,7 @@
 /** @file
   DBG2 table parser
 
-  Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
+  Copyright (c) 2016 - 2020, ARM Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
   @par Reference(s):
@@ -282,15 +282,16 @@ ParseAcpiDbg2 (
   return;
 }
 
-// Make sure the Debug Device Information structure lies inside the table.
-if ((Offset + *DbgDevInfoLen) > AcpiTableLength) {
+// Validate Debug Device Information Structure length
+if ((*DbgDevInfoLen == 0) ||
+((Offset + (*DbgDevInfoLen)) > AcpiTableLength)) {
   IncrementErrorCount ();
   Print (
-L"ERROR: Invalid Debug Device Information structure length. " \
-  L"DbgDevInfoLen = %d. RemainingTableBufferLength = %d. " \
-  L"DBG2 parsing aborted.\n",
+L"ERROR: Invalid Debug Device Information Structure length. " \
+  L"Length = %d. Offset = %d. AcpiTableLength = %d.\n",
 *DbgDevInfoLen,
-AcpiTableLength - Offset
+Offset,
+AcpiTableLength
 );
   return;
 }
diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c
index 
699a55b549ec3fa61bbd156898821055dc019199..bdd30ff45c61142c071ead63a27babab8998721b
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c
@@ -1,7 +1,7 @@
 /** @file
   GTDT table parser
 
-  Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
+  Copyright (c) 2016 - 2020, ARM Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
   @par Reference(s):
@@ -327,15 +327,16 @@ ParseAcpiGtdt (
   return;
 }
 
-// Make sure the Platform Timer is inside the table.
-if ((Offset + *PlatformTimerLength) > AcpiTableLength) {
+// Validate Platform Timer Structure length
+if ((*PlatformTimerLength == 0) ||
+((Offset + (*PlatformTimerLength)) > AcpiTableLength)) {
   IncrementErrorCount ();
   Print (
 L"ERROR: Invalid Platform Timer Structure length. " \
-  L"PlatformTimerLength = %d. RemainingTableBufferLength = %d. " \
-  L"GTDT parsing aborted.\n",
+  L"Length = %d. Offset = %d. AcpiTableLength = %d.\n",
 *PlatformTimerLength,
-AcpiTableLength - Offset
+Offset,
+AcpiTableLength
 );
   return;
 }
diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c
index 
9d5d937c7b2c19945ca2ad3eba644bdfc09cc3f6..9a006a01448b897865cd7cd85651c816933acf05
 100644
--- a/ShellPkg/Library/UefiShel

[edk2-devel] [PATCH v3 1/1] ShellPkg: acpiview: Update SRAT parser to ACPI 6.3

2020-01-08 Thread Krzysztof Koch
Add support for revision 3 of System Resource Affinity Table (SRAT).

Decode and dump the new Generic Initiator Affinity Structure.

Validate the Device Handle Type field inside the Generic Initiator
Affinity Structure.

Signed-off-by: Krzysztof Koch 
---

The changes can be seen at: 
https://github.com/KrzysztofKoch1/edk2/tree/582_acpiview_6_3_srat_v3

Notes:
v1:
- update SRAT parser to ACPI 6.3 [Krzysztof]

v2:
- rebase on latest master [Krzysztof]

v3:
- remove redundant forward declarations [Zhichao]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c  |  33 

 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h  |  16 ++
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c | 209 
+++-
 3 files changed, 252 insertions(+), 6 deletions(-)

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
index 
a569c3c55406ab58536834e56ce9701f7edeffee..2b2ecb93cef9ee28b752e7bf2d920b059dbf7d6b
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
@@ -405,6 +405,39 @@ Dump8Chars (
 );
 }
 
+/**
+  This function traces 12 characters which can be optionally
+  formated using the format string if specified.
+
+  If no format string is specified the Format must be NULL.
+
+  @param [in] Format  Optional format string for tracing the data.
+  @param [in] Ptr Pointer to the start of the buffer.
+**/
+VOID
+EFIAPI
+Dump12Chars (
+  IN CONST CHAR16* Format OPTIONAL,
+  IN   UINT8*  Ptr
+  )
+{
+  Print (
+(Format != NULL) ? Format : L"%c%c%c%c%c%c%c%c%c%c%c%c",
+Ptr[0],
+Ptr[1],
+Ptr[2],
+Ptr[3],
+Ptr[4],
+Ptr[5],
+Ptr[6],
+Ptr[7],
+Ptr[8],
+Ptr[9],
+Ptr[10],
+Ptr[11]
+);
+}
+
 /**
   This function indents and prints the ACPI table Field Name.
 
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
index 
f374f8ebfe313954c05b2a432816cf7ad3af9e32..6deee3542e09bc18b03fdd18dece5b6f9725839c
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
@@ -184,6 +184,22 @@ Dump8Chars (
   IN UINT8*Ptr
   );
 
+/**
+  This function traces 12 characters which can be optionally
+  formated using the format string if specified.
+
+  If no format string is specified the Format must be NULL.
+
+  @param [in] Format  Optional format string for tracing the data.
+  @param [in] Ptr Pointer to the start of the buffer.
+**/
+VOID
+EFIAPI
+Dump12Chars (
+  IN CONST CHAR16* Format OPTIONAL,
+  IN   UINT8*  Ptr
+  );
+
 /**
   This function indents and prints the ACPI table Field Name.
 
diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
index 
a8aa420487bb6bf29fc38221d0b221573c64b8b3..6fe7bf681132df08133e3e03e3ee3f020d905dd2
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
@@ -5,7 +5,7 @@
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
   @par Reference(s):
-- ACPI 6.2 Specification - Errata A, September 2017
+- ACPI 6.3 Specification - January 2019
 **/
 
 #include 
@@ -17,6 +17,7 @@
 // Local Variables
 STATIC CONST UINT8* SratRAType;
 STATIC CONST UINT8* SratRALength;
+STATIC CONST UINT8* SratDeviceHandleType;
 STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
 
 /**
@@ -40,6 +41,167 @@ ValidateSratReserved (
   }
 }
 
+/**
+  This function validates the Device Handle Type field in the Generic Initiator
+  Affinity Structure.
+
+  @param [in] Ptr Pointer to the start of the field data.
+  @param [in] Context Pointer to context specific information e.g. this
+  could be a pointer to the ACPI table header.
+**/
+STATIC
+VOID
+EFIAPI
+ValidateSratDeviceHandleType (
+  IN UINT8* Ptr,
+  IN VOID*  Context
+  )
+{
+  UINT8   DeviceHandleType;
+
+  DeviceHandleType = *Ptr;
+
+  if (DeviceHandleType > EFI_ACPI_6_3_PCI_DEVICE_HANDLE) {
+IncrementErrorCount ();
+Print (
+  L"\nERROR: Invalid Device Handle Type: %d. Must be between 0 and %d.",
+  DeviceHandleType,
+  EFI_ACPI_6_3_PCI_DEVICE_HANDLE
+  );
+  }
+}
+
+/**
+  This function traces the PCI BDF Number field inside Device Handle - PCI
+
+  @param [in] Format  Format string for tracing the data.
+  @param [in] Ptr Pointer to the start of the buffer.
+**/
+STATIC
+VOID
+EFIAPI
+DumpSratPciBdfNumber (
+  IN CONST CHAR16* Format,
+  IN UINT8*Ptr
+  )
+{
+  CHAR16 Buffer[OUTPUT_FIELD_COLUMN_WIDTH];
+
+  Print (L"\n");
+
+  /*
+The PCI BDF Number subfields are printed in the order specifi

[edk2-devel] [edk2-platforms][PATCH v1 1/1] Platform/ARM/ArmJunoDxe: Fix 'unused variable' error for DynamicTables

2020-01-09 Thread Krzysztof Koch
Fix 'mAcpiRegistration defined but not used' compiler error for
Dynamic Tables Framework builds.

Do not declare the mAcpiRegistration variable in the Dynamic Tables
Framework context.

An earlier patch made mAcpiRegistration variable STATIC. Reducing the
scope made scope resolution simpler, thus, the 'defined but not used'
error got raised.

Signed-off-by: Krzysztof Koch 
---

Changes can be seen at: 
https://github.com/KrzysztofKoch1/edk2-platforms/tree/723_fix_unused_variable_juno_dxe_v1

Notes:
v1:
- Fix 'defined but not used' Dynamic Tables build error [Krzysztof]

 Platform/ARM/JunoPkg/Drivers/ArmJunoDxe/ArmJunoDxe.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Platform/ARM/JunoPkg/Drivers/ArmJunoDxe/ArmJunoDxe.c 
b/Platform/ARM/JunoPkg/Drivers/ArmJunoDxe/ArmJunoDxe.c
index 
e3b64992e02c003f7e3a6636340a6afa573f477a..cd7a205f90f131560419cfd744dd5c22df726c99
 100644
--- a/Platform/ARM/JunoPkg/Drivers/ArmJunoDxe/ArmJunoDxe.c
+++ b/Platform/ARM/JunoPkg/Drivers/ArmJunoDxe/ArmJunoDxe.c
@@ -1,6 +1,6 @@
 /** @file
 *
-*  Copyright (c) 2013-2019, ARM Limited. All rights reserved.
+*  Copyright (c) 2013-2020, ARM Limited. All rights reserved.
 *
 *  SPDX-License-Identifier: BSD-2-Clause-Patent
 *
@@ -30,9 +30,9 @@
 #ifndef DYNAMIC_TABLES_FRAMEWORK
 // This GUID must match the FILE_GUID in 
ArmPlatformPkg/ArmJunoPkg/AcpiTables/AcpiTables.inf
 STATIC CONST EFI_GUID mJunoAcpiTableFile = { 0xa1dd808e, 0x1e95, 0x4399, { 
0xab, 0xc0, 0x65, 0x3c, 0x82, 0xe8, 0x53, 0x0c } };
-#endif
-
 STATIC VOID *mAcpiRegistration = NULL;
+#endif
+
 STATIC VOID *mPciIoNotificationRegistration = NULL;
 
 /**
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#53055): https://edk2.groups.io/g/devel/message/53055
Mute This Topic: https://groups.io/mt/69576071/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v2 1/1] ShellPkg: acpiview: Update SRAT parser to ACPI 6.3

2019-11-12 Thread Krzysztof Koch
Add support for parsing revision 3 of System Resource Affinity Table
(SRAT).

Decode and dump the new Generic Initiator Affinity Structure.

Validate the Device Handle Type field inside the Generic Initiator
Affinity Structure.

Signed-off-by: Krzysztof Koch 
---

The changes can be seen at 
https://github.com/KrzysztofKoch1/edk2/tree/582_acpiview_6_3_srat_v2

Notes:
v2:
- rebase on latest master [Krzysztof]

 Readme.md  |   4 +-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c  |  33 
+++
 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h  |  16 +
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c | 313 
++--
 4 files changed, 343 insertions(+), 23 deletions(-)

diff --git a/Readme.md b/Readme.md
index 
acbcca88d3c62d392e6f94b1ad7de2d8627e3a38..594f16b20756ab78987fef4feac2e439743d5b4a
 100644
--- a/Readme.md
+++ b/Readme.md
@@ -17,7 +17,7 @@ for the UEFI and PI specifications from www.uefi.org.
   
 Windows
 VS2019
-edk2-ci
+master
 
   https://dev.azure.com/tianocore/edk2-ci/_build/latest?definitionId=32&branchName=master";>
   https://dev.azure.com/tianocore/edk2-ci/_apis/build/status/Windows%20VS2019%20CI?branchName=master"/>
@@ -34,7 +34,7 @@ for the UEFI and PI specifications from www.uefi.org.
   
 Ubuntu
 GCC
-edk2-ci
+master
 
   https://dev.azure.com/tianocore/edk2-ci/_build/latest?definitionId=31&branchName=master";>
   https://dev.azure.com/tianocore/edk2-ci/_apis/build/status/Ubuntu%20GCC5%20CI?branchName=master"/>
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
index 
a569c3c55406ab58536834e56ce9701f7edeffee..2b2ecb93cef9ee28b752e7bf2d920b059dbf7d6b
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
@@ -405,6 +405,39 @@ Dump8Chars (
 );
 }
 
+/**
+  This function traces 12 characters which can be optionally
+  formated using the format string if specified.
+
+  If no format string is specified the Format must be NULL.
+
+  @param [in] Format  Optional format string for tracing the data.
+  @param [in] Ptr Pointer to the start of the buffer.
+**/
+VOID
+EFIAPI
+Dump12Chars (
+  IN CONST CHAR16* Format OPTIONAL,
+  IN   UINT8*  Ptr
+  )
+{
+  Print (
+(Format != NULL) ? Format : L"%c%c%c%c%c%c%c%c%c%c%c%c",
+Ptr[0],
+Ptr[1],
+Ptr[2],
+Ptr[3],
+Ptr[4],
+Ptr[5],
+Ptr[6],
+Ptr[7],
+Ptr[8],
+Ptr[9],
+Ptr[10],
+Ptr[11]
+);
+}
+
 /**
   This function indents and prints the ACPI table Field Name.
 
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
index 
20ca358bddfa5953bfb1d1bebaebbf3079eaba01..0dc721bd2cc59538432d4a9cab6c21728cc77d33
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
@@ -184,6 +184,22 @@ Dump8Chars (
   IN UINT8*Ptr
   );
 
+/**
+  This function traces 12 characters which can be optionally
+  formated using the format string if specified.
+
+  If no format string is specified the Format must be NULL.
+
+  @param [in] Format  Optional format string for tracing the data.
+  @param [in] Ptr Pointer to the start of the buffer.
+**/
+VOID
+EFIAPI
+Dump12Chars (
+  IN CONST CHAR16* Format OPTIONAL,
+  IN   UINT8*  Ptr
+  );
+
 /**
   This function indents and prints the ACPI table Field Name.
 
diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
index 
a8aa420487bb6bf29fc38221d0b221573c64b8b3..d60476eb748e022f45d231e24c32b2b53e29bbd7
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
@@ -5,7 +5,7 @@
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
   @par Reference(s):
-- ACPI 6.2 Specification - Errata A, September 2017
+- ACPI 6.3 Specification - January 2019
 **/
 
 #include 
@@ -17,6 +17,7 @@
 // Local Variables
 STATIC CONST UINT8* SratRAType;
 STATIC CONST UINT8* SratRALength;
+STATIC CONST UINT8* SratDeviceHandleType;
 STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
 
 /**
@@ -32,13 +33,52 @@ EFIAPI
 ValidateSratReserved (
   IN UINT8* Ptr,
   IN VOID*  Context
-  )
-{
-  if (*(UINT32*)Ptr != 1) {
-IncrementErrorCount ();
-Print (L"\nERROR: Reserved should be 1 for backward compatibility.\n");
-  }
-}
+  );
+
+/**
+  This function validates the Device Handle Type field in the Generic Initiator
+  Affinity Structure.
+
+  @param [in] Ptr Pointer to the start of the fi

Re: [edk2-devel] [PATCH v2 1/1] ShellPkg: acpiview: Update SRAT parser to ACPI 6.3

2019-11-19 Thread Krzysztof Koch
Hi Liming,

This is a feature support. This patch is a rebased version of a reviewed patch 
that was pending to be merged due to a lack of 'tested-by',  see:
https://edk2.groups.io/g/devel/message/42297?p=,,,20,0,0,0::Created,,Krzysztof+Koch+SRAT,20,2,0,32042587
https://edk2.groups.io/g/devel/message/42665?p=,,,20,0,0,0::Created,,We+can+review+for+your+code+change.+And+for+our+personal+point%2C+the+change+is+OK.,20,2,0,32042696

Kind regards,
Krzysztof


-Original Message-
From: Gao, Liming  
Sent: Tuesday, November 19, 2019 14:24
To: devel@edk2.groups.io; Sami Mujawar ; Krzysztof Koch 

Cc: Ni, Ray ; Gao, Zhichao ; Matteo 
Carlini ; nd 
Subject: RE: [edk2-devel] [PATCH v2 1/1] ShellPkg: acpiview: Update SRAT parser 
to ACPI 6.3

Krzysztof:
  Does this patch plan to catch to edk2 201911 stable tag? This change is like 
a feature support. But, it doesn't pass review before soft feature freeze. 

Thanks
Liming
> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Sami 
> Mujawar
> Sent: Monday, November 18, 2019 5:33 PM
> To: Krzysztof Koch ; devel@edk2.groups.io
> Cc: Ni, Ray ; Gao, Zhichao ; 
> Matteo Carlini ; nd 
> Subject: Re: [edk2-devel] [PATCH v2 1/1] ShellPkg: acpiview: Update 
> SRAT parser to ACPI 6.3
> 
> Reviewed-by: Sami Mujawar 
> 
> Regards,
> 
> Sami Mujawar
> -Original Message-
> From: Krzysztof Koch 
> Sent: 12 November 2019 02:40 PM
> To: devel@edk2.groups.io
> Cc: ray...@intel.com; zhichao@intel.com; Matteo Carlini 
> ; Sami Mujawar ; nd 
> 
> Subject: [PATCH v2 1/1] ShellPkg: acpiview: Update SRAT parser to ACPI 
> 6.3
> 
> Add support for parsing revision 3 of System Resource Affinity Table (SRAT).
> 
> Decode and dump the new Generic Initiator Affinity Structure.
> 
> Validate the Device Handle Type field inside the Generic Initiator Affinity 
> Structure.
> 
> Signed-off-by: Krzysztof Koch 
> ---
> 
> The changes can be seen at 
> https://github.com/KrzysztofKoch1/edk2/tree/582_acpiview_6_3_srat_v2
> 
> Notes:
> v2:
> - rebase on latest master [Krzysztof]
> 
>  Readme.md  |   4 
> +-
>  ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c  |  33 
> +++
>  ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h  |  16 
> +
>
> ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c 
> | 313 ++--
>  4 files changed, 343 insertions(+), 23 deletions(-)
> 
> diff --git a/Readme.md b/Readme.md
> index 
> acbcca88d3c62d392e6f94b1ad7de2d8627e3a38..594f16b20756ab78987fef4feac2
> e439743d5b4a 100644
> --- a/Readme.md
> +++ b/Readme.md
> @@ -17,7 +17,7 @@ for the UEFI and PI specifications from www.uefi.org.
>
>  Windows
>  VS2019
> -edk2-ci
> +master
>  
> href="https://dev.azure.com/tianocore/edk2-ci/_build/latest?definitionId=32&branchName=master";>
> src="https://dev.azure.com/tianocore/edk2-ci/_apis/build/status/Window
> s%20VS2019%20CI?branchName=master"/>
> @@ -34,7 +34,7 @@ for the UEFI and PI specifications from www.uefi.org.
>
>  Ubuntu
>  GCC
> -edk2-ci
> +master
>  
> href="https://dev.azure.com/tianocore/edk2-ci/_build/latest?definitionId=31&branchName=master";>
> src="https://dev.azure.com/tianocore/edk2-ci/_apis/build/status/Ubuntu
> %20GCC5%20CI?branchName=master"/>
> diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c 
> b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
> index 
> a569c3c55406ab58536834e56ce9701f7edeffee..2b2ecb93cef9ee28b752e7bf2d92
> 0b059dbf7d6b 100644
> --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
> +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
> @@ -405,6 +405,39 @@ Dump8Chars (
>  );
>  }
> 
> +/**
> +  This function traces 12 characters which can be optionally
> +  formated using the format string if specified.
> +
> +  If no format string is specified the Format must be NULL.
> +
> +  @param [in] Format  Optional format string for tracing the data.
> +  @param [in] Ptr Pointer to the start of the buffer.
> +**/
> +VOID
> +EFIAPI
> +Dump12Chars (
> +  IN CONST CHAR16* Format OPTIONAL,
> +  IN   UINT8*  Ptr
> +  )
> +{
> +  Print (
> +(Format != NULL) ? Format : L"%c%c%c%c%c%c%c%c%c%c%c%c",
> +Ptr[0],
> +Ptr[1],
> +Ptr[2],
> +Ptr[3],
> +Ptr[4],
> +Ptr[5],
> +Ptr[6],
> +Ptr[7],
> +Ptr[8],
> +Ptr[9],
> +Ptr[10],
> +Ptr[11]
> +);
> +

[edk2-devel] [PATCH v1 2/3] ShellPkg: acpiview: Add library for SBBR ACPI requirements validation

2020-03-25 Thread Krzysztof Koch
For Arm-based platforms, define and implement an interface for Server
Base Boot Requirements (SBBR) compliance checks. The library is
responsible for validating that all mandatory ACPI tables are installed
on the platform.

Internally, the library maintains a data structure which tracks
instance counts for ACPI tables which are labeled as 'mandatory' in any
SBBR specification version. The provided interface allows:
- resetting all instance counts to 0
- incremementing the instance count for a table with a given signature
- validating the instance counts against the requirements in SBBR

The ACPI table requirements for each SBBR spec version are represented
internally as a list of table signatures.

Every missing mandatory table (for the input SBBR version) is reported
to the user as a separate error. If all requirements are met, an info
message is displayed.

Reference(s):
- Arm Server Base Boot Requirements 1.2, September 2019
- Arm Server Base Boot Requirements 1.1, May 2018
- Arm Server Base Boot Requirements 1.0, March 2016

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- add library for SBBR ACPI requirements validation [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Arm/SbbrValidator.c | 
222 
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Arm/SbbrValidator.h | 
 91 
 ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf | 
  6 +-
 3 files changed, 318 insertions(+), 1 deletion(-)

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Arm/SbbrValidator.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Arm/SbbrValidator.c
new file mode 100644
index 
..d3284417fa5f4da1c29ba56b8587f1119c776278
--- /dev/null
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Arm/SbbrValidator.c
@@ -0,0 +1,222 @@
+/** @file
+  Arm Server Base Boot Requirements ACPI table requirement validator.
+
+  Copyright (c) 2020, ARM Limited. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+  @par Glossary:
+- Sbbr or SBBR   - Server Base Boot Requirements
+- Sbsa or SBSA   - Server Base System Architecture
+
+  @par Reference(s):
+- Arm Server Base Boot Requirements 1.2, September 2019
+- Arm Server Base Boot Requirements 1.1, May 2018
+- Arm Server Base Boot Requirements 1.0, March 2016
+- Arm Server Base System Architecture 6.0
+**/
+
+#include 
+#include 
+#include "AcpiParser.h"
+#include "Arm/SbbrValidator.h"
+
+/**
+  SBBR specification version strings
+**/
+STATIC CONST CHAR8* ArmSbbrVersions[ArmSbbrVersionMax] = {
+  "1.0", // ArmSbbrVersion_1_0
+  "1.1", // ArmSbbrVersion_1_1
+  "1.2"  // ArmSbbrVersion_1_2
+};
+
+/**
+  SBBR 1.0 mandatory ACPI tables
+**/
+STATIC CONST UINT32 ArmSbbr10Mandatory[] = {
+  EFI_ACPI_6_3_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE,
+  EFI_ACPI_6_3_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE,
+  EFI_ACPI_6_3_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE,
+  EFI_ACPI_6_3_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE,
+  EFI_ACPI_6_3_GENERIC_TIMER_DESCRIPTION_TABLE_SIGNATURE,
+  EFI_ACPI_6_3_DEBUG_PORT_2_TABLE_SIGNATURE,
+  EFI_ACPI_6_3_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_SIGNATURE
+};
+
+/**
+  SBBR 1.1 mandatory ACPI tables
+**/
+STATIC CONST UINT32 ArmSbbr11Mandatory[] = {
+  EFI_ACPI_6_3_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE,
+  EFI_ACPI_6_3_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE,
+  EFI_ACPI_6_3_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE,
+  EFI_ACPI_6_3_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE,
+  EFI_ACPI_6_3_GENERIC_TIMER_DESCRIPTION_TABLE_SIGNATURE,
+  EFI_ACPI_6_3_DEBUG_PORT_2_TABLE_SIGNATURE,
+  EFI_ACPI_6_3_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_SIGNATURE,
+  
EFI_ACPI_6_3_PCI_EXPRESS_MEMORY_MAPPED_CONFIGURATION_SPACE_BASE_ADDRESS_DESCRIPTION_TABLE_SIGNATURE
+};
+
+/**
+  SBBR 1.2 mandatory ACPI tables
+**/
+STATIC CONST UINT32 ArmSbbr12Mandatory[] = {
+  EFI_ACPI_6_3_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE,
+  EFI_ACPI_6_3_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE,
+  EFI_ACPI_6_3_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE,
+  EFI_ACPI_6_3_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE,
+  EFI_ACPI_6_3_GENERIC_TIMER_DESCRIPTION_TABLE_SIGNATURE,
+  EFI_ACPI_6_3_DEBUG_PORT_2_TABLE_SIGNATURE,
+  EFI_ACPI_6_3_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_SIGNATURE,
+  
EFI_ACPI_6_3_PCI_EXPRESS_MEMORY_MAPPED_CONFIGURATION_SPACE_BASE_ADDRESS_DESCRIPTION_TABLE_SIGNATURE,
+  EFI_ACPI_6_3_PROCESSOR_PROPERTIES_TOPOLOGY_TABLE_STRUCTURE_SIGNATURE
+};
+
+/**
+  Mandatory ACPI tables for every SBBR specification version.
+**/
+STATIC CONST ACPI_SBBR_REQ ArmSbbrReqs[ArmSbbrVersionMax] = {
+  { ArmSbbr10Mandatory, ARRAY_SIZE (ArmSbbr10Mandatory) },// SBBR v1.0
+  { ArmSbbr11Mandatory, ARRAY_SIZE (ArmSbbr11Mandatory) },// SBBR v1.1
+  { ArmSbbr12Mandatory, ARRAY_SIZE (ArmSbbr12Mandatory) } // SBBR v1.2
+};
+
+/**
+ 

[edk2-devel] [PATCH v1 1/3] ShellPkg: acpiview: Add -r parameter for table requirements validation

2020-03-25 Thread Krzysztof Koch
Define a new command line parameter '-r' to enable checking if all
mandatory ACPI tables listed in a specification are present.

The -r parameter takes an integer value to specify which specification
the validation should be performed against.

The parameter is used to set two Acpiview variables. An interface to
access these variables is implemented in this patch.

The new functionality is aimed at Arm-based platforms, however,
there are no restriction on extending it to other architectures.
For the 32-bit and 64-bit Arm architectures, the possible values for
the -r parameter are:
  0: Arm Server Base Boot Requirements 1.0, March 2016
  1: Arm Server Base Boot Requirements 1.1, May 2018
  2: Arm Server Base Boot Requirements 1.2, September 2019

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- add '-r' parameter for table requirements validaiton [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c  | 
82 +++-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.h  | 
44 ++-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.uni | 
14 +++-
 3 files changed, 136 insertions(+), 4 deletions(-)

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c
index 
de0851dd5fbae51308def95bd4964f792fb9e680..49c2e87c430d7fb57793f6405ebee91cb8f6cbaa
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c
@@ -1,6 +1,6 @@
 /** @file
 
-  Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
+  Copyright (c) 2016 - 2020, ARM Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 **/
 
@@ -27,6 +27,8 @@ STATIC UINT32 mTableCount;
 STATIC UINT32 mBinTableCount;
 STATIC BOOLEANmConsistencyCheck;
 STATIC BOOLEANmColourHighlighting;
+STATIC BOOLEANmMandatoryTableValidate;
+STATIC UINTN  mMandatoryTableSpec;
 
 /**
   An array of acpiview command line parameters.
@@ -37,6 +39,7 @@ STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
   {L"-h", TypeFlag},
   {L"-l", TypeFlag},
   {L"-s", TypeValue},
+  {L"-r", TypeValue},
   {NULL, TypeMax}
 };
 
@@ -94,6 +97,60 @@ SetConsistencyChecking (
   mConsistencyCheck = ConsistencyChecking;
 }
 
+/**
+  This function returns the ACPI table requirements validation flag.
+
+  @retval TRUE if check for mandatory table presence should be performed.
+**/
+BOOLEAN
+GetMandatoryTableValidate (
+  VOID
+  )
+{
+  return mMandatoryTableValidate;
+}
+
+/**
+  This function sets the ACPI table requirements validation flag.
+
+  @param  ValidateEnable/Disable ACPI table requirements validation.
+**/
+VOID
+SetMandatoryTableValidate (
+  BOOLEAN Validate
+  )
+{
+  mMandatoryTableValidate = Validate;
+}
+
+/**
+  This function returns the identifier of specification to validate ACPI table
+  requirements against.
+
+  @return   ID of specification listing mandatory tables.
+**/
+UINTN
+GetMandatoryTableSpec (
+  VOID
+  )
+{
+  return mMandatoryTableSpec;
+}
+
+/**
+  This function sets the identifier of specification to validate ACPI table
+  requirements against.
+
+  @param  Spec  ID of specification listing mandatory tables.
+**/
+VOID
+SetMandatoryTableSpec (
+  UINTN Spec
+  )
+{
+  mMandatoryTableSpec = Spec;
+}
+
 /**
   This function returns the report options.
 
@@ -470,6 +527,7 @@ ShellCommandRunAcpiView (
   LIST_ENTRY*Package;
   CHAR16*ProblemParam;
   SHELL_FILE_HANDLE  TmpDumpFileHandle;
+  CONST CHAR16*  MandatoryTableSpecStr;
 
   // Set Defaults
   mReportType = ReportAll;
@@ -479,6 +537,8 @@ ShellCommandRunAcpiView (
   mSelectedAcpiTableName = NULL;
   mSelectedAcpiTableFound = FALSE;
   mConsistencyCheck = TRUE;
+  mMandatoryTableValidate = FALSE;
+  mMandatoryTableSpec = 0;
 
   ShellStatus = SHELL_SUCCESS;
   Package = NULL;
@@ -537,6 +597,18 @@ ShellCommandRunAcpiView (
 L"-s"
 );
   ShellStatus = SHELL_INVALID_PARAMETER;
+} else if (ShellCommandLineGetFlag (Package, L"-r") &&
+   ShellCommandLineGetValue (Package, L"-r") == NULL) {
+  ShellPrintHiiEx (
+-1,
+-1,
+NULL,
+STRING_TOKEN (STR_GEN_NO_VALUE),
+gShellAcpiViewHiiHandle,
+L"acpiview",
+L"-r"
+);
+  ShellStatus = SHELL_INVALID_PARAMETER;
 } else if ((ShellCommandLineGetFlag (Package, L"-s") &&
 ShellCommandLineGetFlag (Package, L"-l"))) {
   ShellPrintHiiEx (
@@ -568,6 +640,14 @@ ShellCommandRunAcpiView (
   // Surpress consistency checking if requested
   SetConsistencyChecking (!ShellCommandLineGetFlag (Package, L"-q&qu

[edk2-devel] [PATCH v1 0/3] Check if required ACPI tables are installed

2020-03-25 Thread Krzysztof Koch
This patch series adds a new capability to the Acpiview UEFI shell tool.
Using the -r command line parameter, it is now possible to choose a
specification which lists mandatory ACPI tables. The parameter value is
then consumed by a library which validates ACPI tables identified on the
platform against these requirements.

The -r parameter is architecture agnostic. However, as of now, the
possible values for the parameter are only defined in the context of
the Arm architecture.

For Arm-based platforms, it is now possible to validate that Server Base
Boot Requirements (SBBR) mandatory ACPI tables are present on the
platform.

Changes can be seen at: 
https://github.com/KrzysztofKoch1/edk2/tree/617_sbbr_validate_acpi_table_counts_v1

Krzysztof Koch (3):
  ShellPkg: acpiview: Add -r parameter for table requirements validation
  ShellPkg: acpiview: Add library for SBBR ACPI requirements validation
  ShellPkg: acpiview: Check if SBBR mandatory ACPI tables are installed

 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.c   | 
 16 ++
 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c  | 
104 -
 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.h  | 
 44 +++-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Arm/SbbrValidator.c | 
222 
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Arm/SbbrValidator.h | 
 91 
 ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf | 
  6 +-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.uni | 
 14 +-
 7 files changed, 492 insertions(+), 5 deletions(-)
 create mode 100644 
ShellPkg/Library/UefiShellAcpiViewCommandLib/Arm/SbbrValidator.c
 create mode 100644 
ShellPkg/Library/UefiShellAcpiViewCommandLib/Arm/SbbrValidator.h

--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#56265): https://edk2.groups.io/g/devel/message/56265
Mute This Topic: https://groups.io/mt/72537308/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 3/3] ShellPkg: acpiview: Check if SBBR mandatory ACPI tables are installed

2020-03-25 Thread Krzysztof Koch
For Arm-based platforms, count the instances of installed tables for
each ACPI table listed as 'mandatory' in any Server Base Boot
Requirements (SBBR) specification.

Validate that the all the mandatory SBBR tables present. Report an error
for each missing table.

This new feature is optional and can be enabled with the -r command line
parameter.

Reference(s):
- Arm Server Base Boot Requirements 1.2, September 2019
- Arm Server Base Boot Requirements 1.1, May 2018
- Arm Server Base Boot Requirements 1.0, March 2016

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- check if SBBR mandatory ACPI tables are installed [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.c | 16 
++
 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c| 22 

 2 files changed, 38 insertions(+)

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.c
index 
501967c4dde680809c56e5d79ed744a1013a69e1..d5b9eee5232399c4df50d0f9598810413759fed6
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.c
@@ -3,6 +3,12 @@
 
   Copyright (c) 2016 - 2020, ARM Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
+
+  @par Glossary:
+- Sbbr or SBBR   - Server Base Boot Requirements
+
+  @par Reference(s):
+- Arm Server Base Boot Requirements 1.2, September 2019
 **/
 
 #include 
@@ -12,6 +18,10 @@
 #include "AcpiTableParser.h"
 #include "AcpiView.h"
 
+#if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
+#include "Arm/SbbrValidator.h"
+#endif
+
 /**
   A list of registered ACPI table parsers.
 **/
@@ -216,6 +226,12 @@ ProcessAcpiTable (
 }
   }
 
+#if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
+  if (GetMandatoryTableValidate ()) {
+ArmSbbrIncrementTableCount (*AcpiTableSignature);
+  }
+#endif
+
   Status = GetParser (*AcpiTableSignature, &ParserProc);
   if (EFI_ERROR (Status)) {
 // No registered parser found, do default handling.
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c
index 
49c2e87c430d7fb57793f6405ebee91cb8f6cbaa..84ffb3595750a3e7d65fdb82c0f90bc2d76c659e
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c
@@ -2,6 +2,12 @@
 
   Copyright (c) 2016 - 2020, ARM Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
+
+  @par Glossary:
+- Sbbr or SBBR   - Server Base Boot Requirements
+
+  @par Reference(s):
+- Arm Server Base Boot Requirements 1.2, September 2019
 **/
 
 #include 
@@ -16,6 +22,10 @@
 #include "AcpiView.h"
 #include "UefiShellAcpiViewCommandLib.h"
 
+#if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
+#include "Arm/SbbrValidator.h"
+#endif
+
 EFI_HII_HANDLE gShellAcpiViewHiiHandle = NULL;
 
 // Report variables
@@ -438,6 +448,12 @@ AcpiView (
   return EFI_UNSUPPORTED;
 }
 
+#if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
+if (GetMandatoryTableValidate ()) {
+  ArmSbbrResetTableCounts ();
+}
+#endif
+
 // The RSDP length is 4 bytes starting at offset 20
 RsdpLength = *(UINT32*)(RsdpPtr + RSDP_LENGTH_OFFSET);
 
@@ -466,6 +482,12 @@ AcpiView (
 return EFI_NOT_FOUND;
   }
 
+#if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
+  if (GetMandatoryTableValidate ()) {
+ArmSbbrReqsValidate ((ARM_SBBR_VERSION)GetMandatoryTableSpec ());
+  }
+#endif
+
   ReportOption = GetReportOption ();
   if (ReportTableList != ReportOption) {
 if (((ReportSelected == ReportOption)  ||
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#56268): https://edk2.groups.io/g/devel/message/56268
Mute This Topic: https://groups.io/mt/72537314/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH v1 0/3] Check if required ACPI tables are installed

2020-04-14 Thread Krzysztof Koch
Hi,

Can I get a review for this patch series?

Thanks,

Krzysztof

-Original Message-
From: devel@edk2.groups.io  On Behalf Of Krzysztof Koch 
via Groups.Io
Sent: Wednesday, March 25, 2020 9:39
To: devel@edk2.groups.io
Cc: ray...@intel.com; zhichao@intel.com; Sami Mujawar 
; Matteo Carlini ; Laura Moretta 
; nd 
Subject: [edk2-devel] [PATCH v1 0/3] Check if required ACPI tables are installed

This patch series adds a new capability to the Acpiview UEFI shell tool.
Using the -r command line parameter, it is now possible to choose a 
specification which lists mandatory ACPI tables. The parameter value is then 
consumed by a library which validates ACPI tables identified on the platform 
against these requirements.

The -r parameter is architecture agnostic. However, as of now, the possible 
values for the parameter are only defined in the context of the Arm 
architecture.

For Arm-based platforms, it is now possible to validate that Server Base Boot 
Requirements (SBBR) mandatory ACPI tables are present on the platform.

Changes can be seen at: 
https://github.com/KrzysztofKoch1/edk2/tree/617_sbbr_validate_acpi_table_counts_v1

Krzysztof Koch (3):
  ShellPkg: acpiview: Add -r parameter for table requirements validation
  ShellPkg: acpiview: Add library for SBBR ACPI requirements validation
  ShellPkg: acpiview: Check if SBBR mandatory ACPI tables are installed

 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.c   | 
 16 ++
 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c  | 
104 -
 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.h  | 
 44 +++-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Arm/SbbrValidator.c | 
222 
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Arm/SbbrValidator.h | 
 91 
 ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf | 
  6 +-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.uni | 
 14 +-
 7 files changed, 492 insertions(+), 5 deletions(-)  create mode 100644 
ShellPkg/Library/UefiShellAcpiViewCommandLib/Arm/SbbrValidator.c
 create mode 100644 
ShellPkg/Library/UefiShellAcpiViewCommandLib/Arm/SbbrValidator.h

--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'





-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#57302): https://edk2.groups.io/g/devel/message/57302
Mute This Topic: https://groups.io/mt/72537308/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 00/11] Test against invalid pointers in acpiview

2019-08-15 Thread Krzysztof Koch
Prevent the use of invalid pointers when parsing ACPI tables in the UEFI
shell acpiview tool.

The parsing of ACPI tables is often controlled with the values read
earlier from the same table. For example, the 'Offset' or 'Count' fields
found in a structure are later used to parse the substructures. If such
fields lie outside the structure's buffer length provided, then there
is a possibility for a wild or dangling pointer.

Currently, if the ParseAcpi() function terminates early because the end
of the input table data buffer has been reached, then the pointers
which were supposed to be updated by this function are left untouched.
This is a security issue as the values pointed to by these pointers are
later used for flow control.

This patch series aims to solve this security issue by explicitly
initializing any pointers lying outside the input ACPI data buffer to
NULL and testing for NULL whenever these pointers are dereferenced.

Changes can be seet at: 
https://github.com/KrzysztofKoch1/edk2/tree/612_add_pointer_validation_v1

Krzysztof Koch (11):
  ShellPkg: acpiview: Set ItemPtr to NULL for unprocessed table fields
  ShellPkg: acpiview: RSDP: Validate global pointer before use
  ShellPkg: acpiview: FADT: Validate global pointer before use
  ShellPkg: acpiview: SLIT: Validate global pointer before use
  ShellPkg: acpiview: SLIT: Validate System Locality count
  ShellPkg: acpiview: SRAT: Validate global pointers before use
  ShellPkg: acpiview: MADT: Validate global pointers before use
  ShellPkg: acpiview: PPTT: Validate global pointers before use
  ShellPkg: acpiview: IORT: Validate global pointers before use
  ShellPkg: acpiview: GTDT: Validate global pointers before use
  ShellPkg: acpiview: DBG2: Validate global pointers before use

 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c  |  9 ++-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c | 43 
++
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c | 14 
+
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c | 37 

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c | 52 
+
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c | 13 
+
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c | 25 

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c | 12 

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c | 61 
++--
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c | 13 
+
 10 files changed, 272 insertions(+), 7 deletions(-)

--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45723): https://edk2.groups.io/g/devel/message/45723
Mute This Topic: https://groups.io/mt/32886564/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 04/11] ShellPkg: acpiview: SLIT: Validate global pointer before use

2019-08-15 Thread Krzysztof Koch
Check if SlitSystemLocalityCount pointer has been successfully updated
before it is used for further table parsing.

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- Test against NULL pointers [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c | 16 
++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c
index 
ca2808db526b1bbb79aeb21ccfc0ae6c79b2dfd8..17e2166a09d8615b714e0c51d4d93d293fcdf601
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c
@@ -1,7 +1,7 @@
 /** @file
   SLIT table parser
 
-  Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
+  Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
   @par Reference(s):
@@ -75,9 +75,21 @@ ParseAcpiSlit (
  AcpiTableLength,
  PARSER_PARAMS (SlitParser)
  );
+
+  // Check if the values used to control the parsing logic have been
+  // successfully read.
+  if (SlitSystemLocalityCount == NULL) {
+IncrementErrorCount ();
+Print (
+  L"ERROR: Insufficient table length. AcpiTableLength = %d.\n",
+  AcpiTableLength
+  );
+return;
+  }
+
   LocalityPtr = Ptr + Offset;
-
   LocalityCount = *SlitSystemLocalityCount;
+
   // We only print the Localities if the count is less than 16
   // If the locality count is more than 16 then refer to the
   // raw data dump.
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45721): https://edk2.groups.io/g/devel/message/45721
Mute This Topic: https://groups.io/mt/32886562/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 06/11] ShellPkg: acpiview: SRAT: Validate global pointers before use

2019-08-15 Thread Krzysztof Koch
Check if SratRAType and SratRALength pointers have been successfully
updated before they are used for further table parsing.

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- Test against NULL pointers [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c | 13 
+
 1 file changed, 13 insertions(+)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
index 
a8aa420487bb6bf29fc38221d0b221573c64b8b3..e09a7db8f5c92b44c96b6c37a44a39693352b442
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
@@ -219,6 +219,19 @@ ParseAcpiSrat (
   PARSER_PARAMS (SratResourceAllocationParser)
   );
 
+// Check if the values used to control the parsing logic have been
+// successfully read.
+if ((SratRAType == NULL) ||
+(SratRALength == NULL)) {
+  IncrementErrorCount ();
+  Print (
+L"ERROR: Insufficient remaining table buffer length to read the " \
+  L"Static Resource Allocation structure header. Length = %d.\n",
+AcpiTableLength - Offset
+);
+  return;
+}
+
 // Make sure the SRAT structure lies inside the table
 if ((Offset + *SratRALength) > AcpiTableLength) {
   IncrementErrorCount ();
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45725): https://edk2.groups.io/g/devel/message/45725
Mute This Topic: https://groups.io/mt/32886567/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 02/11] ShellPkg: acpiview: RSDP: Validate global pointer before use

2019-08-15 Thread Krzysztof Koch
Check if XsdtAddress pointer has been successfully updated before it
is used for further table parsing.

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- Test against NULL pointers [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c | 12 

 1 file changed, 12 insertions(+)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c
index 
5a5c4b50c12e6eb0aa0efb1765df7e123f614da3..f4a8732a7db7c437031f2a3d2f266b80eff17b4b
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c
@@ -138,6 +138,18 @@ ParseAcpiRsdp (
 PARSER_PARAMS (RsdpParser)
 );
 
+  // Check if the values used to control the parsing logic have been
+  // successfully read.
+  if (XsdtAddress == NULL) {
+IncrementErrorCount ();
+Print (
+  L"ERROR: Insufficient table length. AcpiTableLength = %d." \
+L"RSDP parsing aborted.\n",
+  AcpiTableLength
+  );
+return;
+  }
+
   // This code currently supports parsing of XSDT table only
   // and does not parse the RSDT table. Platforms provide the
   // RSDT to enable compatibility with ACPI 1.0 operating systems.
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45726): https://edk2.groups.io/g/devel/message/45726
Mute This Topic: https://groups.io/mt/32886568/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 03/11] ShellPkg: acpiview: FADT: Validate global pointer before use

2019-08-15 Thread Krzysztof Koch
Check if global pointers have been successfully updated before they
are used for further table parsing.

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- Test against NULL pointers [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c | 14 
++
 1 file changed, 14 insertions(+)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c
index 
e40c9ef8ee4b3285faf8c6edf3cb6236ee367397..e218e45926abced1096e75441e22108db7a3a811
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c
@@ -203,6 +203,20 @@ ParseAcpiFadt (
 PARSER_PARAMS (FadtParser)
 );
 
+  // Check if the values used to control the parsing logic have been
+  // successfully read.
+  if ((DsdtAddress == NULL)   ||
+  (FadtMinorRevision == NULL) ||
+  (X_DsdtAddress == NULL)) {
+IncrementErrorCount ();
+Print (
+  L"ERROR: Insufficient table length. AcpiTableLength = %d. " \
+L"FADT parsing aborted.\n",
+  AcpiTableLength
+  );
+return;
+  }
+
   if (Trace) {
 Print (L"\nSummary:\n");
 PrintFieldName (2, L"FADT Version");
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45724): https://edk2.groups.io/g/devel/message/45724
Mute This Topic: https://groups.io/mt/32886566/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 01/11] ShellPkg: acpiview: Set ItemPtr to NULL for unprocessed table fields

2019-08-15 Thread Krzysztof Koch
For fields outside the buffer length provided, reset any pointers,
which were supposed to be updated by a ParseAcpi() function call to
NULL. This way one can easily validate if a pointer was successfully
updated.

The ParseAcpi() function parses the given ACPI table buffer by a
number of bytes which is a minimum of the buffer length and the length
described by ACPI_PARSER array. If the buffer length is shorter than
the array describing how to process the ACPI structure, then it is
possible that the ItemPtr inside ACPI_PARSER may not get updated or
initialized. This can lead to an error if the value pointed to by
ItemPtr is later used to control the parsing logic.

A typical example would be a 'number of elements' field in an ACPI
structure header which defines how many substructures of a given type
are present in the structure body. If the 'number of elements' field
is not parsed, this could result in a dangling pointer which could
cause a problem later.

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- Set ItemPtr to NULL for unprocessed table fields [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
index 
2d6ff80e299eebe7853061d3db89332197c0dc0e..1ede12859721db75d17fd0bfc14dc9e9c0d573aa
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
@@ -502,8 +502,15 @@ ParseAcpi (
 
   for (Index = 0; Index < ParserItems; Index++) {
 if ((Offset + Parser[Index].Length) > Length) {
+
+  // For fields outside the buffer length provided, reset any pointers
+  // which were supposed to be updated by this function call
+  if (Parser[Index].ItemPtr != NULL) {
+*Parser[Index].ItemPtr = NULL;
+  }
+
   // We don't parse past the end of the max length specified
-  break;
+  continue;
 }
 
 if (GetConsistencyChecking () &&
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45722): https://edk2.groups.io/g/devel/message/45722
Mute This Topic: https://groups.io/mt/32886563/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 05/11] ShellPkg: acpiview: SLIT: Validate System Locality count

2019-08-15 Thread Krzysztof Koch
1. Check if the 'Number of System Localities' provided can be
represented in the SLIT table. The table 'Length' field is a 32-bit
value while the 'Number of System Localities' field is 64-bit long.

2. Check if the SLIT matrix fits in the table buffer. If N is the SLIT
locality count, then the matrix used to represent the localities is
N*N bytes long. The ACPI table length must be big enough to fit the
matrix.

3. Remove (now) redundant 64x64 bit multiplication.

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- Validate the 'Number of System Localities' Field [Krzysztof]
- Remove redundant 64x64 bit multiplication [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c | 47 
+---
 1 file changed, 42 insertions(+), 5 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c
index 
17e2166a09d8615b714e0c51d4d93d293fcdf601..e4625ee8b13907893a9b6990ecb956baf91cc3b9
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c
@@ -30,7 +30,7 @@ STATIC CONST ACPI_PARSER SlitParser[] = {
 /**
   Macro to get the value of a System Locality
 **/
-#define SLIT_ELEMENT(Ptr, i, j) *(Ptr + (MultU64x64 (i, LocalityCount)) + j)
+#define SLIT_ELEMENT(Ptr, i, j) *(Ptr + (i * LocalityCount) + j)
 
 /**
   This function parses the ACPI SLIT table.
@@ -57,9 +57,9 @@ ParseAcpiSlit (
   )
 {
   UINT32 Offset;
-  UINT64 Count;
-  UINT64 Index;
-  UINT64 LocalityCount;
+  UINT32 Count;
+  UINT32 Index;
+  UINT32 LocalityCount;
   UINT8* LocalityPtr;
   CHAR16 Buffer[80];  // Used for AsciiName param of ParseAcpi
 
@@ -87,8 +87,45 @@ ParseAcpiSlit (
 return;
   }
 
+  /*
+Despite the 'Number of System Localities' being a 64-bit field in SLIT,
+the maximum number of localities that can be represented in SLIT is limited
+by the 'Length' field of the ACPI table.
+
+Since the ACPI table length field is 32-bit wide. The maximum number of
+localities that can be represented in SLIT can be calculated as:
+
+MaxLocality = sqrt (MAX_UINT32 - sizeof 
(EFI_ACPI_6_3_SYSTEM_LOCALITY_DISTANCE_INFORMATION_TABLE_HEADER))
+= 65535
+= MAX_UINT16
+  */
+  if (*SlitSystemLocalityCount > MAX_UINT16) {
+IncrementErrorCount ();
+Print (
+  L"ERROR: The Number of System Localities provided can't be represented " 
\
+L"in the SLIT table. SlitSystemLocalityCount = %ld. " \
+L"MaxLocalityCountAllowed = %d.\n",
+  *SlitSystemLocalityCount,
+  MAX_UINT16
+  );
+return;
+  }
+
+  LocalityCount = (UINT32)*SlitSystemLocalityCount;
+
+  // Make sure system localities fit in the table buffer provided
+  if (Offset + (LocalityCount * LocalityCount) > AcpiTableLength) {
+IncrementErrorCount ();
+Print (
+  L"ERROR: Invalid Number of System Localities. " \
+L"SlitSystemLocalityCount = %ld. AcpiTableLength = %d.\n",
+  *SlitSystemLocalityCount,
+  AcpiTableLength
+  );
+return;
+  }
+
   LocalityPtr = Ptr + Offset;
-  LocalityCount = *SlitSystemLocalityCount;
 
   // We only print the Localities if the count is less than 16
   // If the locality count is more than 16 then refer to the
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45728): https://edk2.groups.io/g/devel/message/45728
Mute This Topic: https://groups.io/mt/32886579/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 09/11] ShellPkg: acpiview: IORT: Validate global pointers before use

2019-08-15 Thread Krzysztof Koch
Check if global (in the scope of the IORT parser) pointers have been
successfully updated before they are used for further table parsing.

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- Test against NULL pointers [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c | 52 

 1 file changed, 52 insertions(+)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c
index 
f1cdb9ac01d848f22ab588d8f824886387c5983d..c43ed4ee5fdd8de409052d57c13a27811c75c7d0
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c
@@ -317,6 +317,20 @@ DumpIortNodeSmmuV1V2 (
 PARSER_PARAMS (IortNodeSmmuV1V2Parser)
 );
 
+  // Check if the values used to control the parsing logic have been
+  // successfully read.
+  if ((InterruptContextCount == NULL)   ||
+  (InterruptContextOffset == NULL)  ||
+  (PmuInterruptCount == NULL)   ||
+  (PmuInterruptOffset == NULL)) {
+IncrementErrorCount ();
+Print (
+  L"ERROR: Insufficient SMMUv1/2 node length. Length = %d\n",
+  Length
+  );
+return;
+  }
+
   Offset = *InterruptContextOffset;
   Index = 0;
 
@@ -428,6 +442,17 @@ DumpIortNodeIts (
 PARSER_PARAMS (IortNodeItsParser)
 );
 
+  // Check if the values used to control the parsing logic have been
+  // successfully read.
+  if (ItsCount == NULL) {
+IncrementErrorCount ();
+Print (
+  L"ERROR: Insufficient ITS group length. Length = %d.\n",
+  Length
+  );
+return;
+  }
+
   Index = 0;
 
   while ((Index < *ItsCount) &&
@@ -612,6 +637,18 @@ ParseAcpiIort (
 PARSER_PARAMS (IortParser)
 );
 
+  // Check if the values used to control the parsing logic have been
+  // successfully read.
+  if ((IortNodeCount == NULL) ||
+  (IortNodeOffset == NULL)) {
+IncrementErrorCount ();
+Print (
+  L"ERROR: Insufficient table length. AcpiTableLength = %d.\n",
+  AcpiTableLength
+  );
+return;
+  }
+
   Offset = *IortNodeOffset;
   NodePtr = Ptr + Offset;
   Index = 0;
@@ -630,6 +667,21 @@ ParseAcpiIort (
   PARSER_PARAMS (IortNodeHeaderParser)
   );
 
+// Check if the values used to control the parsing logic have been
+// successfully read.
+if ((IortNodeType == NULL)||
+(IortNodeLength == NULL)  ||
+(IortIdMappingCount == NULL)  ||
+(IortIdMappingOffset == NULL)) {
+  IncrementErrorCount ();
+  Print (
+L"ERROR: Insufficient remaining table buffer length to read the " \
+  L"IORT node header. Length = %d.\n",
+AcpiTableLength - Offset
+);
+  return;
+}
+
 // Make sure the IORT Node is inside the table
 if ((Offset + (*IortNodeLength)) > AcpiTableLength) {
   IncrementErrorCount ();
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45730): https://edk2.groups.io/g/devel/message/45730
Mute This Topic: https://groups.io/mt/32886581/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 08/11] ShellPkg: acpiview: PPTT: Validate global pointers before use

2019-08-15 Thread Krzysztof Koch
Check if the NumberOfPrivateResources, ProcessorTopologyStructureType
and ProcessorTopologyStructureLength pointers have been successfully
updated before they are used for further table parsing.

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- Test against NULL pointers [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c | 25 

 1 file changed, 25 insertions(+)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c
index 
6254b9913fffb429fc54bb1301bf3e4b2e5bf161..675ba75f02b367cd5ad9f2ac23c30ed0ab58f286
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c
@@ -264,6 +264,17 @@ DumpProcessorHierarchyNodeStructure (
  PARSER_PARAMS (ProcessorHierarchyNodeStructureParser)
  );
 
+  // Check if the values used to control the parsing logic have been
+  // successfully read.
+  if (NumberOfPrivateResources == NULL) {
+IncrementErrorCount ();
+Print (
+  L"ERROR: Insufficient Processor Hierarchy Node length. Length = %d.\n",
+  Length
+  );
+return;
+  }
+
   // Make sure the Private Resource array lies inside this structure
   if (Offset + (*NumberOfPrivateResources * sizeof (UINT32)) > Length) {
 IncrementErrorCount ();
@@ -387,6 +398,7 @@ ParseAcpiPptt (
  AcpiTableLength,
  PARSER_PARAMS (PpttParser)
  );
+
   ProcessorTopologyStructurePtr = Ptr + Offset;
 
   while (Offset < AcpiTableLength) {
@@ -400,6 +412,19 @@ ParseAcpiPptt (
   PARSER_PARAMS (ProcessorTopologyStructureHeaderParser)
   );
 
+// Check if the values used to control the parsing logic have been
+// successfully read.
+if ((ProcessorTopologyStructureType == NULL) ||
+(ProcessorTopologyStructureLength == NULL)) {
+  IncrementErrorCount ();
+  Print (
+L"ERROR: Insufficient remaining table buffer length to read the " \
+  L"processor topology structure header. Length = %d.\n",
+AcpiTableLength - Offset
+);
+  return;
+}
+
 // Make sure the PPTT structure lies inside the table
 if ((Offset + *ProcessorTopologyStructureLength) > AcpiTableLength) {
   IncrementErrorCount ();
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45729): https://edk2.groups.io/g/devel/message/45729
Mute This Topic: https://groups.io/mt/32886580/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 07/11] ShellPkg: acpiview: MADT: Validate global pointers before use

2019-08-15 Thread Krzysztof Koch
Check if the MadtInterruptControllerType and
MadtInterruptControllerLength pointers have been successfully updated
before they are used for further table parsing.

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- Test against NULL pointers [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c | 13 
+
 1 file changed, 13 insertions(+)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c
index 
90bdafea1970db522e8ed96de7c6e986cdaca5ba..438905cb24f58b8b82e8fe61280e72f765d578d8
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c
@@ -260,6 +260,19 @@ ParseAcpiMadt (
   PARSER_PARAMS (MadtInterruptControllerHeaderParser)
   );
 
+// Check if the values used to control the parsing logic have been
+// successfully read.
+if ((MadtInterruptControllerType == NULL) ||
+(MadtInterruptControllerLength == NULL)) {
+  IncrementErrorCount ();
+  Print (
+L"ERROR: Insufficient remaining table buffer length to read the " \
+  L"Interrupt Controller Structure header. Length = %d.\n",
+AcpiTableLength - Offset
+);
+  return;
+}
+
 // Make sure forward progress is made.
 if (*MadtInterruptControllerLength < 2) {
   IncrementErrorCount ();
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45732): https://edk2.groups.io/g/devel/message/45732
Mute This Topic: https://groups.io/mt/32886584/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 10/11] ShellPkg: acpiview: GTDT: Validate global pointers before use

2019-08-15 Thread Krzysztof Koch
Check if global (in the scope of the GTDT parser) pointers have been
successfully updated before they are used for further table parsing.

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- Test against NULL pointers [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c | 37 

 1 file changed, 37 insertions(+)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c
index 
57174e14c80072f12b90e1996ebe8f0002d0c404..699a55b549ec3fa61bbd156898821055dc019199
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c
@@ -189,6 +189,18 @@ DumpGTBlock (
 PARSER_PARAMS (GtBlockParser)
 );
 
+  // Check if the values used to control the parsing logic have been
+  // successfully read.
+  if ((GtBlockTimerCount == NULL) ||
+  (GtBlockTimerOffset == NULL)) {
+IncrementErrorCount ();
+Print (
+  L"ERROR: Insufficient GT Block Structure length. Length = %d.\n",
+  Length
+  );
+return;
+  }
+
   Offset = *GtBlockTimerOffset;
   Index = 0;
 
@@ -272,6 +284,18 @@ ParseAcpiGtdt (
 PARSER_PARAMS (GtdtParser)
 );
 
+  // Check if the values used to control the parsing logic have been
+  // successfully read.
+  if ((GtdtPlatformTimerCount == NULL) ||
+  (GtdtPlatformTimerOffset == NULL)) {
+IncrementErrorCount ();
+Print (
+  L"ERROR: Insufficient table length. AcpiTableLength = %d.\n",
+  AcpiTableLength
+  );
+return;
+  }
+
   TimerPtr = Ptr + *GtdtPlatformTimerOffset;
   Offset = *GtdtPlatformTimerOffset;
   Index = 0;
@@ -290,6 +314,19 @@ ParseAcpiGtdt (
   PARSER_PARAMS (GtPlatformTimerHeaderParser)
   );
 
+// Check if the values used to control the parsing logic have been
+// successfully read.
+if ((PlatformTimerType == NULL) ||
+(PlatformTimerLength == NULL)) {
+  IncrementErrorCount ();
+  Print (
+L"ERROR: Insufficient remaining table buffer length to read the " \
+  L"Platform Timer Structure header. Length = %d.\n",
+AcpiTableLength - Offset
+);
+  return;
+}
+
 // Make sure the Platform Timer is inside the table.
 if ((Offset + *PlatformTimerLength) > AcpiTableLength) {
   IncrementErrorCount ();
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45731): https://edk2.groups.io/g/devel/message/45731
Mute This Topic: https://groups.io/mt/32886582/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 11/11] ShellPkg: acpiview: DBG2: Validate global pointers before use

2019-08-15 Thread Krzysztof Koch
Check if global (in the scope of the DBG2 parser) pointers have been
successfully updated before they are used for further table parsing.

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- Test against NULL pointers [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c | 43 

 1 file changed, 43 insertions(+)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
index 
869e700b9beda4886bf7bc5ae4ced3ab9a59efa3..0f730a306a94329a23fbaf54b59f1833b44616ba
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
@@ -123,6 +123,24 @@ DumpDbgDeviceInfo (
 PARSER_PARAMS (DbgDevInfoParser)
 );
 
+  // Check if the values used to control the parsing logic have been
+  // successfully read.
+  if ((GasCount == NULL)  ||
+  (NameSpaceStringLength == NULL) ||
+  (NameSpaceStringOffset == NULL) ||
+  (OEMDataLength == NULL) ||
+  (OEMDataOffset == NULL) ||
+  (BaseAddrRegOffset == NULL) ||
+  (AddrSizeOffset == NULL)) {
+IncrementErrorCount ();
+Print (
+  L"ERROR: Insufficient Debug Device Information Structure length. " \
+L"Length = %d.\n",
+  Length
+  );
+return;
+  }
+
   // GAS
   Index = 0;
   Offset = *BaseAddrRegOffset;
@@ -224,6 +242,18 @@ ParseAcpiDbg2 (
  PARSER_PARAMS (Dbg2Parser)
  );
 
+  // Check if the values used to control the parsing logic have been
+  // successfully read.
+  if ((OffsetDbgDeviceInfo == NULL) ||
+  (NumberDbgDeviceInfo == NULL)) {
+IncrementErrorCount ();
+Print (
+  L"ERROR: Insufficient table length. AcpiTableLength = %d\n",
+  AcpiTableLength
+  );
+return;
+  }
+
   Offset = *OffsetDbgDeviceInfo;
   Index = 0;
 
@@ -239,6 +269,19 @@ ParseAcpiDbg2 (
   PARSER_PARAMS (DbgDevInfoHeaderParser)
   );
 
+// Check if the values used to control the parsing logic have been
+// successfully read.
+if (DbgDevInfoLen == NULL) {
+  IncrementErrorCount ();
+  Print (
+L"ERROR: Insufficient remaining table buffer length to read the " \
+  L"Debug Device Information structure's 'Length' field. " \
+  L"RemainingTableBufferLength = %d.\n",
+AcpiTableLength - Offset
+);
+  return;
+}
+
 // Make sure the Debug Device Information structure lies inside the table.
 if ((Offset + *DbgDevInfoLen) > AcpiTableLength) {
   IncrementErrorCount ();
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45733): https://edk2.groups.io/g/devel/message/45733
Mute This Topic: https://groups.io/mt/32886586/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH v1 00/11] Test against invalid pointers in acpiview

2019-08-16 Thread Krzysztof Koch
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2089

Hi Liming,

Sure, no problem.

Kind regards,

Krzysztof

-Original Message-
From: Gao, Liming  
Sent: Friday, August 16, 2019 5:03
To: devel@edk2.groups.io; Krzysztof Koch 
Cc: Carsey, Jaben ; Ni, Ray ; Gao, 
Zhichao ; Sami Mujawar ; Matteo 
Carlini ; nd 
Subject: RE: [edk2-devel] [PATCH v1 00/11] Test against invalid pointers in 
acpiview

Krzysztof:
   Can you submit BZ in https://bugzilla.tianocore.org/ for this change? 

Thanks
Liming
>-Original Message-
>From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of 
>Krzysztof Koch
>Sent: Thursday, August 15, 2019 9:11 PM
>To: devel@edk2.groups.io
>Cc: Carsey, Jaben ; Ni, Ray ; 
>Gao, Zhichao ; sami.muja...@arm.com; 
>matteo.carl...@arm.com; n...@arm.com
>Subject: [edk2-devel] [PATCH v1 00/11] Test against invalid pointers in 
>acpiview
>
>Prevent the use of invalid pointers when parsing ACPI tables in the 
>UEFI shell acpiview tool.
>
>The parsing of ACPI tables is often controlled with the values read 
>earlier from the same table. For example, the 'Offset' or 'Count' 
>fields found in a structure are later used to parse the substructures. 
>If such fields lie outside the structure's buffer length provided, then 
>there is a possibility for a wild or dangling pointer.
>
>Currently, if the ParseAcpi() function terminates early because the end 
>of the input table data buffer has been reached, then the pointers 
>which were supposed to be updated by this function are left untouched.
>This is a security issue as the values pointed to by these pointers are 
>later used for flow control.
>
>This patch series aims to solve this security issue by explicitly 
>initializing any pointers lying outside the input ACPI data buffer to 
>NULL and testing for NULL whenever these pointers are dereferenced.
>
>Changes can be seet at:
>https://github.com/KrzysztofKoch1/edk2/tree/612_add_pointer_validation_
>v1
>
>Krzysztof Koch (11):
>  ShellPkg: acpiview: Set ItemPtr to NULL for unprocessed table fields
>  ShellPkg: acpiview: RSDP: Validate global pointer before use
>  ShellPkg: acpiview: FADT: Validate global pointer before use
>  ShellPkg: acpiview: SLIT: Validate global pointer before use
>  ShellPkg: acpiview: SLIT: Validate System Locality count
>  ShellPkg: acpiview: SRAT: Validate global pointers before use
>  ShellPkg: acpiview: MADT: Validate global pointers before use
>  ShellPkg: acpiview: PPTT: Validate global pointers before use
>  ShellPkg: acpiview: IORT: Validate global pointers before use
>  ShellPkg: acpiview: GTDT: Validate global pointers before use
>  ShellPkg: acpiview: DBG2: Validate global pointers before use
>
> ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c  |  9 
> ++-
> ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
>| 43 ++
> ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c 
>|
>14 +
> ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c
>| 37 
> ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c 
>|
>52 +
>
>ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c
>| 13 +
> ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c 
>|
>25 
> ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c
>| 12 
> ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c 
> | 61
>++--
> ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c 
>|
>13 +
> 10 files changed, 272 insertions(+), 7 deletions(-)
>
>--
>'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'
>
>
>
>


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45797): https://edk2.groups.io/g/devel/message/45797
Mute This Topic: https://groups.io/mt/32886564/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH v1 03/11] ShellPkg: acpiview: FADT: Validate global pointer before use

2019-08-16 Thread Krzysztof Koch
Hi Zhichao,

I think you're right. I will submit a v2 patch that minimizes the amount of 
pointer validation required for parsing the remaining tables.

Kind regards,

Krzysztof

-Original Message-
From: Gao, Zhichao  
Sent: Friday, August 16, 2019 8:35
To: Krzysztof Koch ; devel@edk2.groups.io
Cc: Carsey, Jaben ; Ni, Ray ; Sami 
Mujawar ; Matteo Carlini ; nd 

Subject: RE: [PATCH v1 03/11] ShellPkg: acpiview: FADT: Validate global pointer 
before use

For FadtMinorRevision and X_DsdtAddress, I don't think they are required 
section. Maybe we should consider check the length before check them. As I 
know, the OVMF's FACP table doesn't have the section after flag.

Thanks,
Zhichao

> -Original Message-
> From: Krzysztof Koch [mailto:krzysztof.k...@arm.com]
> Sent: Thursday, August 15, 2019 9:11 PM
> To: devel@edk2.groups.io
> Cc: Carsey, Jaben ; Ni, Ray 
> ; Gao, Zhichao ; 
> sami.muja...@arm.com; matteo.carl...@arm.com; n...@arm.com
> Subject: [PATCH v1 03/11] ShellPkg: acpiview: FADT: Validate global 
> pointer before use
> 
> Check if global pointers have been successfully updated before they 
> are used for further table parsing.
> 
> Signed-off-by: Krzysztof Koch 
> ---
> 
> Notes:
> v1:
> - Test against NULL pointers [Krzysztof]
> 
>
> ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c
> | 14 ++
>  1 file changed, 14 insertions(+)
> 
> diff --git
> a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.
> c
> b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.
> c
> index
> e40c9ef8ee4b3285faf8c6edf3cb6236ee367397..e218e45926abced1096e75441
> e22108db7a3a811 100644
> ---
> a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.
> c
> +++
> b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtPars
> +++ er.c
> @@ -203,6 +203,20 @@ ParseAcpiFadt (
>  PARSER_PARAMS (FadtParser)
>  );
> 
> +  // Check if the values used to control the parsing logic have been 
> + // successfully read.
> +  if ((DsdtAddress == NULL)   ||
> +  (FadtMinorRevision == NULL) ||
> +  (X_DsdtAddress == NULL)) {
> +IncrementErrorCount ();
> +Print (
> +  L"ERROR: Insufficient table length. AcpiTableLength = %d. " \
> +L"FADT parsing aborted.\n",
> +  AcpiTableLength
> +  );
> +return;
> +  }
> +
>if (Trace) {
>  Print (L"\nSummary:\n");
>  PrintFieldName (2, L"FADT Version");
> --
> 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'
> 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45816): https://edk2.groups.io/g/devel/message/45816
Mute This Topic: https://groups.io/mt/32886566/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH v1 05/11] ShellPkg: acpiview: SLIT: Validate System Locality count

2019-08-18 Thread Krzysztof Koch


Hi Zhichao,

Please find my comments inline marked as [Krzysztof].

Kind regards,

Krzysztof


-Original Message-
From: Gao, Zhichao  
Sent: Monday, August 19, 2019 2:19
To: devel@edk2.groups.io; Krzysztof Koch 
Cc: Carsey, Jaben ; Ni, Ray ; Sami 
Mujawar ; Matteo Carlini ; nd 

Subject: RE: [edk2-devel] [PATCH v1 05/11] ShellPkg: acpiview: SLIT: Validate 
System Locality count



> -Original Message-
> From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of 
> Krzysztof Koch
> Sent: Thursday, August 15, 2019 9:11 PM
> To: devel@edk2.groups.io
> Cc: Carsey, Jaben ; Ni, Ray 
> ; Gao, Zhichao ; 
> sami.muja...@arm.com; matteo.carl...@arm.com; n...@arm.com
> Subject: [edk2-devel] [PATCH v1 05/11] ShellPkg: acpiview: SLIT: 
> Validate System Locality count
> 
> 1. Check if the 'Number of System Localities' provided can be 
> represented in the SLIT table. The table 'Length' field is a 32-bit 
> value while the 'Number of System Localities' field is 64-bit long.
> 
> 2. Check if the SLIT matrix fits in the table buffer. If N is the SLIT 
> locality count, then the matrix used to represent the localities is 
> N*N bytes long. The ACPI table length must be big enough to fit the matrix.
> 
> 3. Remove (now) redundant 64x64 bit multiplication.

Why removing? This change is added to fixed the issue build error with IA32 
multiplication of two 64 bits data.
The change of #3 should be removed from the patch.
Keeping the variable size as UINT64 wouldn't affect the result.

Thanks,
Zhichao

[Krzysztof] If you look closely, in this patch I have removed the need to 64x64 
bit multiplication. As I explain in the commit message, the specification of 
the SLIT table has an error. The System Locality Count is a 64-bit value while 
the ACPI table length field is 32-bit long. 

Consequently, after the right checks are implemented (in this patch), it is 
possible to operate on 32-bit values only. I believe that now MultU64x64() is 
no longer needed so I reverted back to the '*' multiplication operator.

Please let me know what you think.

> 
> Signed-off-by: Krzysztof Koch 
> ---
> 
> Notes:
> v1:
> - Validate the 'Number of System Localities' Field [Krzysztof]
> - Remove redundant 64x64 bit multiplication [Krzysztof]
> 
>
> ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c 
> |
> 47 +---
>  1 file changed, 42 insertions(+), 5 deletions(-)
> 
> diff --git
> a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser
> .c 
> b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser
> .c
> index
> 17e2166a09d8615b714e0c51d4d93d293fcdf601..e4625ee8b13907893a9b6990
> ecb956baf91cc3b9 100644
> ---
> a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser
> .c
> +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitPa
> +++ rs
> +++ er.c
> @@ -30,7 +30,7 @@ STATIC CONST ACPI_PARSER SlitParser[] = {
>  /**
>Macro to get the value of a System Locality  **/ -#define 
> SLIT_ELEMENT(Ptr, i, j) *(Ptr + (MultU64x64 (i, LocalityCount)) + j)
> +#define SLIT_ELEMENT(Ptr, i, j) *(Ptr + (i * LocalityCount) + j)
> 
>  /**
>This function parses the ACPI SLIT table.
> @@ -57,9 +57,9 @@ ParseAcpiSlit (
>)
>  {
>UINT32 Offset;
> -  UINT64 Count;
> -  UINT64 Index;
> -  UINT64 LocalityCount;
> +  UINT32 Count;
> +  UINT32 Index;
> +  UINT32 LocalityCount;
>UINT8* LocalityPtr;
>CHAR16 Buffer[80];  // Used for AsciiName param of ParseAcpi
> 
> @@ -87,8 +87,45 @@ ParseAcpiSlit (
>  return;
>}
> 
> +  /*
> +Despite the 'Number of System Localities' being a 64-bit field in SLIT,
> +the maximum number of localities that can be represented in SLIT 
> + is
> limited
> +by the 'Length' field of the ACPI table.
> +
> +Since the ACPI table length field is 32-bit wide. The maximum number of
> +localities that can be represented in SLIT can be calculated as:
> +
> +MaxLocality = sqrt (MAX_UINT32 - sizeof
> (EFI_ACPI_6_3_SYSTEM_LOCALITY_DISTANCE_INFORMATION_TABLE_HEAD
> ER))
> += 65535
> += MAX_UINT16
> +  */
> +  if (*SlitSystemLocalityCount > MAX_UINT16) {
> +IncrementErrorCount ();
> +Print (
> +  L"ERROR: The Number of System Localities provided can't be
> represented " \
> +L"in the SLIT table. SlitSystemLocalityCount = %ld. " \
> +L"MaxLocalityCountAllowed = %d.\n",
> +  *SlitSystemLocalityCount,
> +  MAX_UINT16
> +  );
> +return;
> +  }
> +
> +  LocalityCount = (UINT32)*SlitS

[edk2-devel] [PATCH v2 03/11] ShellPkg: acpiview: FADT: Validate global pointer before use

2019-08-19 Thread Krzysztof Koch
Check if global pointers have been successfully updated before they
are used for further table parsing.

Signed-off-by: Krzysztof Koch 
---

Changes can be seen at: 
https://github.com/KrzysztofKoch1/edk2/tree/612_add_pointer_validation_v2

Notes:
v1:
- Test against NULL pointers [Krzysztof]

v2:
- Do not require FadtMinorRevision and X_DsdtAddress pointers to be
  valid in order to process the remaining ACPI tables [Zhichao]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c | 19 
++-
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c
index 
e40c9ef8ee4b3285faf8c6edf3cb6236ee367397..6859c4824c2866fd3eb9a789a8dfc950724b27ca
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c
@@ -204,9 +204,11 @@ ParseAcpiFadt (
 );
 
   if (Trace) {
-Print (L"\nSummary:\n");
-PrintFieldName (2, L"FADT Version");
-Print (L"%d.%d\n",  *AcpiHdrInfo.Revision, *FadtMinorRevision);
+if (FadtMinorRevision != NULL) {
+  Print (L"\nSummary:\n");
+  PrintFieldName (2, L"FADT Version");
+  Print (L"%d.%d\n",  *AcpiHdrInfo.Revision, *FadtMinorRevision);
+}
 
 if (*GetAcpiXsdtHeaderInfo ()->OemTableId != *AcpiHdrInfo.OemTableId) {
   IncrementErrorCount ();
@@ -214,21 +216,20 @@ ParseAcpiFadt (
 }
   }
 
-  // If X_DSDT is not zero then use X_DSDT and ignore DSDT,
-  // else use DSDT.
-  if (*X_DsdtAddress != 0) {
+  // If X_DSDT is valid then use X_DSDT and ignore DSDT, else use DSDT.
+  if ((X_DsdtAddress != NULL) && (*X_DsdtAddress != 0)) {
 DsdtPtr = (UINT8*)(UINTN)(*X_DsdtAddress);
-  } else if (*DsdtAddress != 0) {
+  } else if ((DsdtAddress != NULL) && (*DsdtAddress != 0)) {
 DsdtPtr = (UINT8*)(UINTN)(*DsdtAddress);
   } else {
-// Both DSDT and X_DSDT cannot be zero.
+// Both DSDT and X_DSDT cannot be invalid.
 #if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
 if (Trace) {
   // The DSDT Table is mandatory for ARM systems
   // as the CPU information MUST be presented in
   // the DSDT.
   IncrementErrorCount ();
-  Print (L"ERROR: Both X_DSDT and DSDT are NULL.\n");
+  Print (L"ERROR: Both X_DSDT and DSDT are invalid.\n");
 }
 #endif
 return;
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#46027): https://edk2.groups.io/g/devel/message/46027
Mute This Topic: https://groups.io/mt/32941781/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 03/11] ShellPkg: acpiview: RSDP: Make printing table checksum optional

2019-07-11 Thread Krzysztof Koch
1. Don't validate Root System Description Pointer (RSDP) structure
checksum if the '-q' command line flag is used with the acpiview UEFI
shell tool. This change makes the RSDP parser consistent with the
parsers for other ACPI tables.

2. Check if XsdtAddress pointer has been successfully updated before it
is used for further table parsing.

3. Remove redundant forward function declarations by repositioning
blocks of code.

Signed-off-by: Krzysztof Koch 
---

Changes can be seen at: 
https://github.com/KrzysztofKoch1/edk2/commit/73e6d7e117da244f8f4065620115a47f7f66d372

Notes:
v1:
- make RSDP parser behavior consistent with other tables [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c | 144 
+---
 1 file changed, 68 insertions(+), 76 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c
index 
586de7cbfb12f856c0c735b6e295c1cc32eb2ceb..952517cd09aaff601bb363fd73331c750a9e97ff
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c
@@ -1,7 +1,7 @@
 /** @file
   RSDP table parser
 
-  Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
+  Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
   @par Reference(s):
@@ -11,6 +11,7 @@
 #include 
 #include "AcpiParser.h"
 #include "AcpiTableParser.h"
+#include "AcpiView.h"
 
 // Local Variables
 STATIC CONST UINT64* XsdtAddress;
@@ -28,7 +29,27 @@ EFIAPI
 ValidateRsdtAddress (
   IN UINT8* Ptr,
   IN VOID*  Context
-  );
+  )
+{
+#if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
+  // Reference: Server Base Boot Requirements System Software on ARM Platforms
+  // Section: 4.2.1.1 RSDP
+  // Root System Description Pointer (RSDP), ACPI ? 5.2.5.
+  //   - Within the RSDP, the RsdtAddress field must be null (zero) and the
+  // XsdtAddresss MUST be a valid, non-null, 64-bit value.
+  UINT32 RsdtAddr;
+
+  RsdtAddr = *(UINT32*)Ptr;
+
+  if (RsdtAddr != 0) {
+IncrementErrorCount ();
+Print (
+  L"\nERROR: Rsdt Address = 0x%p. This must be NULL on ARM Platforms.",
+  RsdtAddr
+  );
+  }
+#endif
+}
 
 /**
   This function validates the XSDT Address.
@@ -43,7 +64,27 @@ EFIAPI
 ValidateXsdtAddress (
   IN UINT8* Ptr,
   IN VOID*  Context
-  );
+  )
+{
+#if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
+  // Reference: Server Base Boot Requirements System Software on ARM Platforms
+  // Section: 4.2.1.1 RSDP
+  // Root System Description Pointer (RSDP), ACPI ? 5.2.5.
+  //   - Within the RSDP, the RsdtAddress field must be null (zero) and the
+  // XsdtAddresss MUST be a valid, non-null, 64-bit value.
+  UINT64 XsdtAddr;
+
+  XsdtAddr = *(UINT64*)Ptr;
+
+  if (XsdtAddr == 0) {
+IncrementErrorCount ();
+Print (
+  L"\nERROR: Xsdt Address = 0x%p. This must not be NULL on ARM Platforms.",
+  XsdtAddr
+  );
+  }
+#endif
+}
 
 /**
   An array describing the ACPI RSDP Table.
@@ -61,76 +102,6 @@ STATIC CONST ACPI_PARSER RsdpParser[] = {
   {L"Reserved", 3, 33, L"%x %x %x", Dump3Chars, NULL, NULL, NULL}
 };
 
-/**
-  This function validates the RSDT Address.
-
-  @param [in] Ptr Pointer to the start of the field data.
-  @param [in] Context Pointer to context specific information e.g. this
-  could be a pointer to the ACPI table header.
-**/
-STATIC
-VOID
-EFIAPI
-ValidateRsdtAddress (
-  IN UINT8* Ptr,
-  IN VOID*  Context
-  )
-{
-#if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
-  // Reference: Server Base Boot Requirements System Software on ARM Platforms
-  // Section: 4.2.1.1 RSDP
-  // Root System Description Pointer (RSDP), ACPI ? 5.2.5.
-  //   - Within the RSDP, the RsdtAddress field must be null (zero) and the
-  // XsdtAddresss MUST be a valid, non-null, 64-bit value.
-  UINT32 RsdtAddr;
-
-  RsdtAddr = *(UINT32*)Ptr;
-
-  if (RsdtAddr != 0) {
-IncrementErrorCount ();
-Print (
-  L"\nERROR: Rsdt Address = 0x%p. This must be NULL on ARM Platforms.",
-  RsdtAddr
-  );
-  }
-#endif
-}
-
-/**
-  This function validates the XSDT Address.
-
-  @param [in] Ptr Pointer to the start of the field data.
-  @param [in] Context Pointer to context specific information e.g. this
-  could be a pointer to the ACPI table header.
-**/
-STATIC
-VOID
-EFIAPI
-ValidateXsdtAddress (
-  IN UINT8* Ptr,
-  IN VOID*  Context
-  )
-{
-#if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
-  // Reference: Server Base Boot Requirements System Software on ARM Platforms
-  // Section: 4.2.1.1 RSDP
-  // Root System Description Pointer (RSDP), ACPI ? 5.2.5.
-  //   - Within the RSDP, the RsdtAddress field must be null (z

[edk2-devel] [PATCH v1 00/11] Add security checks in the Acpiview table parsers

2019-07-11 Thread Krzysztof Koch
The following patches modify existing ACPI table parsers to add checks which
prevent many potential security issues. These include:
1. Entering infinite loops when ACPI structure lengths are zero.
2. Use of pointers which failed to be initialized because of invalid ACPI
table/structure lengths.
3. Buffer overruns caused by structures which have a too large value of the
'Length' field given the size of the buffer in which they are located.

Other changes added in this patchset include:
1. Removal of redundant forward STATIC function declarations for reducing
the code size.
2. Extension of the use of the -q flag to make ACPI table content validation
optional. ACPI table content consistency checks which do not affect the flow
control in the parsing logic can now be disabled. The remaining validation
checks are enforced as they also prevent the security issues listed above.

Changes can be seen at: 
https://github.com/KrzysztofKoch1/edk2/tree/612_enhance_parser_logic_v1

Krzysztof Koch (11):
  ShellPkg: acpiview: FADT: Validate global pointers before use
  ShellPkg: acpiview: SPCR: Remove redundant forward declaration
  ShellPkg: acpiview: RSDP: Make printing table checksum optional
  ShellPkg: acpiview: XSDT: Remove redundant ParseAcpi() call
  ShellPkg: acpiview: SLIT: Add error-checking in the parsing logic
  ShellPkg: acpiview: SRAT: Add error-checking in the parsing logic
  ShellPkg: acpiview: MADT: Add error-checking in the parsing logic
  ShellPkg: acpiview: PPTT: Add error-checking in the parsing logic
  ShellPkg: acpiview: IORT: Add error-checking in the parsing logic
  ShellPkg: acpiview: GTDT: Add error-checking in the parsing logic
  ShellPkg: acpiview: DBG2: Add error-checking in the parsing logic

 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c  |  26 +-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h  |   8 +-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c | 298 
+-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c | 131 
+++---
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c | 294 
--
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c | 419 
+---
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c | 187 
-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c |  95 
-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c | 144 
---
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c | 115 
--
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Spcr/SpcrParser.c |  98 
++---
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c | 113 
+++---
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c |  22 +-
 13 files changed, 1150 insertions(+), 800 deletions(-)

--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43640): https://edk2.groups.io/g/devel/message/43640
Mute This Topic: https://groups.io/mt/32439501/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 04/11] ShellPkg: acpiview: XSDT: Remove redundant ParseAcpi() call

2019-07-11 Thread Krzysztof Koch
1. Remove a call to ParseAcpi responsible for getting the XSDT table
length. This call is not needed because the ACPI table buffer length is
provided as an input argument to the ParseAcpiXsdt() function.

2. Use ParseAcpiXsdt function argument instead of a global variable to
check against table buffer overruns.

3. Allow suppressing errors about invalid ACPI table poiners inside the
XSDT table.

Signed-off-by: Krzysztof Koch 
---

Changes can be seen at: 
https://github.com/KrzysztofKoch1/edk2/commit/27b4ae23c4f230225d6bcb27598b42edcf329512

Notes:
v1:
- Remove a redundant call to ParseAcpi() [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c | 22 
+++-
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c
index 
4196168bff47d70c67f79f3fc1f4cdee302d460e..b7d8f4215a71ef429fb88d6f2d998d8f38250716
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c
@@ -1,7 +1,7 @@
 /** @file
   XSDT table parser
 
-  Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
+  Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
   @par Reference(s):
@@ -13,6 +13,7 @@
 #include 
 #include "AcpiParser.h"
 #include "AcpiTableParser.h"
+#include "AcpiView.h"
 
 // Local variables
 STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
@@ -60,22 +61,12 @@ ParseAcpiXsdt (
   UINTN EntryIndex;
   CHAR16Buffer[32];
 
-  // Parse the ACPI header to get the length
-  ParseAcpi (
-FALSE,
-0,
-"XSDT",
-Ptr,
-ACPI_DESCRIPTION_HEADER_LENGTH,
-PARSER_PARAMS (XsdtParser)
-);
-
   Offset = ParseAcpi (
  Trace,
  0,
  "XSDT",
  Ptr,
- *AcpiHdrInfo.Length,
+ AcpiTableLength,
  PARSER_PARAMS (XsdtParser)
  );
 
@@ -84,7 +75,7 @@ ParseAcpiXsdt (
   if (Trace) {
 EntryIndex = 0;
 TablePointer = (UINT64*)(Ptr + TableOffset);
-while (Offset < (*AcpiHdrInfo.Length)) {
+while (Offset < AcpiTableLength) {
   CONST UINT32* Signature;
   CONST UINT32* Length;
   CONST UINT8*  Revision;
@@ -124,7 +115,8 @@ ParseAcpiXsdt (
   Print (L"0x%lx\n", *TablePointer);
 
   // Validate the table pointers are not NULL
-  if ((UINT64*)(UINTN)(*TablePointer) == NULL) {
+  if (GetConsistencyChecking () &&
+  ((UINT64*)(UINTN)(*TablePointer) == NULL)) {
 IncrementErrorCount ();
 Print (
   L"ERROR: Invalid table entry at 0x%lx, table address is 0x%lx\n",
@@ -140,7 +132,7 @@ ParseAcpiXsdt (
   // Process the tables
   Offset = TableOffset;
   TablePointer = (UINT64*)(Ptr + TableOffset);
-  while (Offset < (*AcpiHdrInfo.Length)) {
+  while (Offset < AcpiTableLength) {
 if ((UINT64*)(UINTN)(*TablePointer) != NULL) {
   ProcessAcpiTable ((UINT8*)(UINTN)(*TablePointer));
 }
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43645): https://edk2.groups.io/g/devel/message/43645
Mute This Topic: https://groups.io/mt/32439507/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 02/11] ShellPkg: acpiview: SPCR: Remove redundant forward declaration

2019-07-11 Thread Krzysztof Koch
Reposition blocks of code to remove redundant forward function
declarations in order to reduce the code size.

Signed-off-by: Krzysztof Koch 
---

Changes can be seen at: 
https://github.com/KrzysztofKoch1/edk2/commit/9be55a64f804c3d99e7c692208c8086d5b9ca553

Notes:
v1:
- remove redundant forward declarations [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Spcr/SpcrParser.c | 98 
+++-
 1 file changed, 34 insertions(+), 64 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Spcr/SpcrParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Spcr/SpcrParser.c
index 
1974a9c046e4a3bc55cf758184af097b2420..3b06b05dee8c056c6e009b9e485ccd35d4194e95
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Spcr/SpcrParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Spcr/SpcrParser.c
@@ -1,7 +1,7 @@
 /** @file
   SPCR table parser
 
-  Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
+  Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
   @par Reference(s):
@@ -31,7 +31,23 @@ EFIAPI
 ValidateInterruptType (
   IN UINT8* Ptr,
   IN VOID*  Context
-  );
+  )
+{
+#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
+  UINT8 InterruptType;
+
+  InterruptType = *Ptr;
+
+  if (InterruptType !=
+EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_INTERRUPT_TYPE_GIC) {
+IncrementErrorCount ();
+Print (
+  L"\nERROR: InterruptType = %d. This must be 8 on ARM Platforms",
+  InterruptType
+  );
+  }
+#endif
+}
 
 /**
   This function validates the Irq.
@@ -46,7 +62,22 @@ EFIAPI
 ValidateIrq (
   IN UINT8* Ptr,
   IN VOID*  Context
-  );
+  )
+{
+#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
+  UINT8 Irq;
+
+  Irq = *Ptr;
+
+  if (Irq != 0) {
+IncrementErrorCount ();
+Print (
+  L"\nERROR: Irq = %d. This must be zero on ARM Platforms\n",
+  Irq
+  );
+  }
+#endif
+}
 
 /**
   An ACPI_PARSER array describing the ACPI SPCR Table.
@@ -76,67 +107,6 @@ STATIC CONST ACPI_PARSER SpcrParser[] = {
   {L"Reserved", 4, 76, L"%x", NULL, NULL, NULL, NULL}
 };
 
-/**
-  This function validates the Interrupt Type.
-
-  @param [in] Ptr Pointer to the start of the field data.
-  @param [in] Context Pointer to context specific information e.g. this
-  could be a pointer to the ACPI table header.
-**/
-STATIC
-VOID
-EFIAPI
-ValidateInterruptType (
-  IN UINT8* Ptr,
-  IN VOID*  Context
-  )
-{
-#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
-  UINT8 InterruptType;
-
-  InterruptType = *Ptr;
-
-  if (InterruptType !=
-EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_INTERRUPT_TYPE_GIC) {
-IncrementErrorCount ();
-Print (
-  L"\nERROR: InterruptType = %d. This must be 8 on ARM Platforms",
-  InterruptType
-  );
-  }
-#endif
-}
-
-/**
-  This function validates the Irq.
-
-  @param [in] Ptr Pointer to the start of the field data.
-  @param [in] Context Pointer to context specific information e.g. this
-  could be a pointer to the ACPI table header.
-**/
-STATIC
-VOID
-EFIAPI
-ValidateIrq (
-  IN UINT8* Ptr,
-  IN VOID*  Context
-  )
-{
-#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
-  UINT8 Irq;
-
-  Irq = *Ptr;
-
-  if (Irq != 0) {
-IncrementErrorCount ();
-Print (
-  L"\nERROR: Irq = %d. This must be zero on ARM Platforms\n",
-  Irq
-  );
-  }
-#endif
-}
-
 /**
   This function parses the ACPI SPCR table.
   When trace is enabled this function parses the SPCR table and
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43643): https://edk2.groups.io/g/devel/message/43643
Mute This Topic: https://groups.io/mt/32439504/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 01/11] ShellPkg: acpiview: FADT: Validate global pointers before use

2019-07-11 Thread Krzysztof Koch
1. Check if the global pointer have been successfully updated before
they are later used to control the parsing logic in the FADT acpiview
parser.

2. Remove redundant forward function declarations by repositioning
blocks of code.

3. Allow silencing ACPI table content validation errors which do not
cause table parsing to fail.

Signed-off-by: Krzysztof Koch 
---

Changes can be seen at: 
https://github.com/KrzysztofKoch1/edk2/commit/49cc41430775fb93205e302590a7d31f080c3952

Notes:
v1:
- improve the logic in the parser [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c | 131 

 1 file changed, 51 insertions(+), 80 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c
index 
cee7ee0770433da96d6042d2f5d687903f4b5495..600d3b16d7b22b61c1a1fd21ecb93f16c7f8fa1a
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c
@@ -1,7 +1,7 @@
 /** @file
   FADT table parser
 
-  Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
+  Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
   @par Reference(s):
@@ -12,6 +12,7 @@
 #include 
 #include "AcpiParser.h"
 #include "AcpiTableParser.h"
+#include "AcpiView.h"
 
 // Local variables
 STATIC CONST UINT32* DsdtAddress;
@@ -46,7 +47,17 @@ EFIAPI
 ValidateFirmwareCtrl (
   IN UINT8* Ptr,
   IN VOID*  Context
-  );
+)
+{
+#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
+  if (*(UINT32*)Ptr != 0) {
+IncrementErrorCount ();
+Print (
+  L"\nERROR: Firmware Control must be zero for ARM platforms."
+);
+  }
+#endif
+}
 
 /**
   This function validates the X_Firmware Control Field.
@@ -61,7 +72,17 @@ EFIAPI
 ValidateXFirmwareCtrl (
   IN UINT8* Ptr,
   IN VOID*  Context
-  );
+)
+{
+#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
+  if (*(UINT64*)Ptr != 0) {
+IncrementErrorCount ();
+Print (
+  L"\nERROR: X Firmware Control must be zero for ARM platforms."
+);
+  }
+#endif
+}
 
 /**
   This function validates the flags.
@@ -76,7 +97,17 @@ EFIAPI
 ValidateFlags (
   IN UINT8* Ptr,
   IN VOID*  Context
-  );
+)
+{
+#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
+  if (((*(UINT32*)Ptr) & HW_REDUCED_ACPI) == 0) {
+IncrementErrorCount ();
+Print (
+  L"\nERROR: HW_REDUCED_ACPI flag must be set for ARM platforms."
+);
+  }
+#endif
+}
 
 /**
   An ACPI_PARSER array describing the ACPI FADT Table.
@@ -142,81 +173,6 @@ STATIC CONST ACPI_PARSER FadtParser[] = {
   {L"Hypervisor VendorIdentity", 8, 268, L"%lx", NULL, NULL, NULL, NULL}
 };
 
-/**
-  This function validates the Firmware Control Field.
-
-  @param [in] Ptr Pointer to the start of the field data.
-  @param [in] Context Pointer to context specific information e.g. this
-  could be a pointer to the ACPI table header.
-**/
-STATIC
-VOID
-EFIAPI
-ValidateFirmwareCtrl (
-  IN UINT8* Ptr,
-  IN VOID*  Context
-)
-{
-#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
-  if (*(UINT32*)Ptr != 0) {
-IncrementErrorCount ();
-Print (
-  L"\nERROR: Firmware Control must be zero for ARM platforms."
-);
-  }
-#endif
-}
-
-/**
-  This function validates the X_Firmware Control Field.
-
-  @param [in] Ptr Pointer to the start of the field data.
-  @param [in] Context Pointer to context specific information e.g. this
-  could be a pointer to the ACPI table header.
-**/
-STATIC
-VOID
-EFIAPI
-ValidateXFirmwareCtrl (
-  IN UINT8* Ptr,
-  IN VOID*  Context
-)
-{
-#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
-  if (*(UINT64*)Ptr != 0) {
-IncrementErrorCount ();
-Print (
-  L"\nERROR: X Firmware Control must be zero for ARM platforms."
-);
-  }
-#endif
-}
-
-/**
-  This function validates the flags.
-
-  @param [in] Ptr Pointer to the start of the field data.
-  @param [in] Context Pointer to context specific information e.g. this
-  could be a pointer to the ACPI table header.
-**/
-STATIC
-VOID
-EFIAPI
-ValidateFlags (
-  IN UINT8* Ptr,
-  IN VOID*  Context
-)
-{
-#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
-  if (((*(UINT32*)Ptr) & HW_REDUCED_ACPI) == 0) {
-IncrementErrorCount ();
-Print (
-  L"\nERROR: HW_REDUCED_ACPI flag must be set for ARM platforms."
-);
-  }
-#endif
-}
-
 /**
   This function parses the ACPI FADT table.
   This function parses the FADT table and optionally traces the ACPI table 
fields.
@@ -248,12 +204,27 @@ ParseAcpiFadt (
 PARSER_PARAMS (FadtParser)
 );
 
+  // Check if the values used to control the parsing logic have been
+  // succes

[edk2-devel] [PATCH v1 05/11] ShellPkg: acpiview: SLIT: Add error-checking in the parsing logic

2019-07-11 Thread Krzysztof Koch
1. Check if the global pointers (in the scope of this ACPI table parser)
have been successfully updated before they are later used to control
the parsing logic.

2. Test against buffer overruns.

3. Allow silencing ACPI table content validation errors which do not
cause table parsing to fail.

4. Check if the 'Number of System Localities' provided can be
represented in a SLIT table. The table 'Length' field is a 32-bit value
while the 'Number of System Localities' is a 64-bit value.

Signed-off-by: Krzysztof Koch 
---

Changes can be seen at: 
https://github.com/KrzysztofKoch1/edk2/commit/2f1ffd1a74d06c23c01971be965d856f0a0e3ac4

Notes:
v1:
- improve the logic in the SLIT parser [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c | 115 
++--
 1 file changed, 83 insertions(+), 32 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c
index 
1f9dac66eea5b0f4366a7a9584ac6702a74beaac..dd5f039b67326acc710ee703a6b132a1e280dcaa
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c
@@ -1,7 +1,7 @@
 /** @file
   SLIT table parser
 
-  Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
+  Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
   @par Reference(s):
@@ -13,6 +13,7 @@
 #include 
 #include "AcpiParser.h"
 #include "AcpiTableParser.h"
+#include "AcpiView.h"
 
 // Local Variables
 STATIC CONST UINT64* SlitSystemLocalityCount;
@@ -59,7 +60,7 @@ ParseAcpiSlit (
   UINT32 Offset;
   UINT64 Count;
   UINT64 Index;
-  UINT64 LocalityCount;
+  UINT32 LocalityCount;
   UINT8* LocalityPtr;
   CHAR16 Buffer[80];  // Used for AsciiName param of ParseAcpi
 
@@ -77,7 +78,55 @@ ParseAcpiSlit (
  );
   LocalityPtr = Ptr + Offset;
 
-  LocalityCount = *SlitSystemLocalityCount;
+  // Check if the values used to control the parsing logic have been
+  // successfully read.
+  if (SlitSystemLocalityCount == NULL) {
+IncrementErrorCount ();
+Print (
+  L"ERROR: Insufficient table length. AcpiTableLength = %d.\n",
+  AcpiTableLength
+  );
+return;
+  }
+
+  /*
+Despite the 'Number of System Localities' being a 64-bit field in SLIT,
+the maximum number of localities that can be represented in SLIT is limited
+by the 'Length' field of the ACPI table.
+
+Since the ACPI table length field is 32-bit wide. The maximum number of
+localities that can be represented in SLIT can be calculated as:
+
+MaxLocality = sqrt (MAX_UINT32 - sizeof 
(EFI_ACPI_6_3_SYSTEM_LOCALITY_DISTANCE_INFORMATION_TABLE_HEADER))
+= 65535
+= MAX_UINT16
+  */
+  if (*SlitSystemLocalityCount > MAX_UINT16) {
+IncrementErrorCount ();
+Print (
+  L"ERROR: The Number of System Localities provided can't be represented " 
\
+L"in the SLIT table. SlitSystemLocalityCount = %ld. " \
+L"MaxLocalityCountAllowed = %d.\n",
+  *SlitSystemLocalityCount,
+  MAX_UINT16
+  );
+return;
+  }
+
+  LocalityCount = (UINT32)*SlitSystemLocalityCount;
+
+  // Make sure system localities fit in the table buffer provided
+  if (Offset + (LocalityCount * LocalityCount) > AcpiTableLength) {
+IncrementErrorCount ();
+Print (
+  L"ERROR: Invalid Number of System Localities. " \
+L"SlitSystemLocalityCount = %ld. AcpiTableLength = %d.\n",
+  *SlitSystemLocalityCount,
+  AcpiTableLength
+  );
+return;
+  }
+
   // We only print the Localities if the count is less than 16
   // If the locality count is more than 16 then refer to the
   // raw data dump.
@@ -96,7 +145,7 @@ ParseAcpiSlit (
   Print (L" (%3d) ", Index);
 }
 Print (L"\n");
-for (Count = 0; Count< LocalityCount; Count++) {
+for (Count = 0; Count < LocalityCount; Count++) {
   Print (L" (%3d) ", Count);
   for (Index = 0; Index < LocalityCount; Index++) {
 Print (L"  %3d  ", SLIT_ELEMENT (LocalityPtr, Count, Index));
@@ -106,34 +155,36 @@ ParseAcpiSlit (
   }
 
   // Validate
-  for (Count = 0; Count < LocalityCount; Count++) {
-for (Index = 0; Index < LocalityCount; Index++) {
-  // Element[x][x] must be equal to 10
-  if ((Count == Index) && (SLIT_ELEMENT (LocalityPtr, Count,Index) != 10)) 
{
-IncrementErrorCount ();
-Print (
-  L"ERROR: Diagonal Element[0x%lx][0x%lx] (%3d)."
-L" Normalized Value is not 10\n",
-  Count,
-  Index,
-  SLIT_ELEMENT (LocalityPtr, Count, Index)
-

[edk2-devel] [PATCH v1 09/11] ShellPkg: acpiview: IORT: Add error-checking in the parsing logic

2019-07-11 Thread Krzysztof Koch
1. Check if the global pointers (in the scope of this ACPI table parser)
have been successfully updated before they are later used to control
the parsing logic.

2. Remove redundant forward function declarations by repositioning
blocks of code.

3. Test against buffer overruns.

4. Allow silencing ACPI table content validation errors which do not
cause table parsing to fail.

5. Move ID mapping count validation for the PMCG node to the
IortNodePmcgParser[] ACPI_PARSER array. This check does not affect
the flow of IORT parsing and is limited to a single table field in
scope.

Signed-off-by: Krzysztof Koch 
---

Changes can be seen at: 
https://github.com/KrzysztofKoch1/edk2/commit/0b398f116f7aed99dbec4090b5c2c0ed93273ef7

Notes:
v1:
- improve the logic in the IORT parser [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c | 419 
+---
 1 file changed, 279 insertions(+), 140 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c
index 
93f78e1a9786ed53f6b5529f478b72a220b4f8df..f09e7aeeb34bf4c3d9564240b53539c8d6811f66
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c
@@ -13,6 +13,7 @@
 #include 
 #include "AcpiParser.h"
 #include "AcpiTableParser.h"
+#include "AcpiView.h"
 
 // Local variables
 STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
@@ -45,7 +46,35 @@ EFIAPI
 ValidateItsIdMappingCount (
   IN UINT8* Ptr,
   IN VOID*  Context
-  );
+  )
+{
+  if (*(UINT32*)Ptr != 0) {
+IncrementErrorCount ();
+Print (L"\nERROR: IORT ID Mapping count must be zero.");
+  }
+}
+
+/**
+  This function validates the ID Mapping array count for the Performance
+  Monitoring Counter Group (PMCG) node.
+
+  @param [in] Ptr Pointer to the start of the field data.
+  @param [in] Context Pointer to context specific information e.g. this
+  could be a pointer to the ACPI table header.
+**/
+STATIC
+VOID
+EFIAPI
+ValidatePmcgIdMappingCount (
+  IN UINT8* Ptr,
+  IN VOID*  Context
+  )
+{
+  if (*(UINT32*)Ptr > 1) {
+IncrementErrorCount ();
+Print (L"\nERROR: IORT ID Mapping count must not be greater than 1.");
+  }
+}
 
 /**
   This function validates the ID Mapping array offset for the ITS node.
@@ -60,7 +89,13 @@ EFIAPI
 ValidateItsIdArrayReference (
   IN UINT8* Ptr,
   IN VOID*  Context
-  );
+  )
+{
+  if (*(UINT32*)Ptr != 0) {
+IncrementErrorCount ();
+Print (L"\nERROR: IORT ID Mapping offset must be zero.");
+  }
+}
 
 /**
   Helper Macro for populating the IORT Node header in the ACPI_PARSER array.
@@ -204,95 +239,65 @@ STATIC CONST ACPI_PARSER IortNodeRootComplexParser[] = {
   An ACPI_PARSER array describing the IORT PMCG node.
 **/
 STATIC CONST ACPI_PARSER IortNodePmcgParser[] = {
-  PARSE_IORT_NODE_HEADER (NULL, NULL),
+  PARSE_IORT_NODE_HEADER (ValidatePmcgIdMappingCount, NULL),
   {L"Base Address", 8, 16, L"0x%lx", NULL, NULL, NULL, NULL},
   {L"Overflow interrupt GSIV", 4, 24, L"0x%x", NULL, NULL, NULL, NULL},
   {L"Node reference", 4, 28, L"0x%x", NULL, NULL, NULL, NULL},
 };
 
-/**
-  This function validates the ID Mapping array count for the ITS node.
-
-  @param [in] Ptr Pointer to the start of the field data.
-  @param [in] Context Pointer to context specific information e.g. this
-  could be a pointer to the ACPI table header.
-**/
-STATIC
-VOID
-EFIAPI
-ValidateItsIdMappingCount (
-  IN UINT8* Ptr,
-  IN VOID* Context
-  )
-{
-  if (*(UINT32*)Ptr != 0) {
-IncrementErrorCount ();
-Print (L"\nERROR: IORT ID Mapping count must be zero.");
-  }
-}
-
-/**
-  This function validates the ID Mapping array offset for the ITS node.
-
-  @param [in] Ptr Pointer to the start of the field data.
-  @param [in] Context Pointer to context specific information e.g. this
-  could be a pointer to the ACPI table header.
-**/
-STATIC
-VOID
-EFIAPI
-ValidateItsIdArrayReference (
-  IN UINT8* Ptr,
-  IN VOID*  Context
-  )
-{
-  if (*(UINT32*)Ptr != 0) {
-IncrementErrorCount ();
-Print (L"\nERROR: IORT ID Mapping offset must be zero.");
-  }
-}
-
 /**
   This function parses the IORT Node Id Mapping array.
 
-  @param [in] PtrPointer to the start of the IORT Table.
+  @param [in] PtrPointer to the start of the ID mapping array.
+  @param [in] Length Length of the buffer.
   @param [in] MappingCount   The ID Mapping count.
-  @param [in] MappingOffset  The offset of the ID Mapping array
- from the start of the IORT table.
 **/
 STATIC
 VOID
 DumpIortNodeIdMappings (
   IN UINT8* Ptr,
-  IN UINT32 MappingCount,
-  IN UINT32 Mapp

[edk2-devel] [PATCH v1 08/11] ShellPkg: acpiview: PPTT: Add error-checking in the parsing logic

2019-07-11 Thread Krzysztof Koch
1. Check if the global pointers (in the scope of this ACPI table parser)
have been successfully updated before they are later used to control
the parsing logic.

2. Give forward progress guarantee when parsing the PPTT table. Report
an error if a PPTT structure is too small to be valid. Without this
check, there is a possibility for the parser to enter an ifninite loop.

3. Test against buffer overruns.

4. Allow silencing ACPI table content validation errors which do not
cause table parsing to fail.

Signed-off-by: Krzysztof Koch 
---

Changes can be seen at: 
https://github.com/KrzysztofKoch1/edk2/commit/e4789351e111fa1ed6a2c55759f190166b08fc8c

Notes:
v1:
- improve the logic in the PPTT parser [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c | 95 

 1 file changed, 76 insertions(+), 19 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c
index 
cec57be55e77096f9448f637ea129af2b42111ad..8d8760940b493eb94c91da3d46f9a844930c1738
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c
@@ -252,7 +252,6 @@ DumpProcessorHierarchyNodeStructure (
   )
 {
   UINT32 Offset;
-  UINT8* PrivateResourcePtr;
   UINT32 Index;
   CHAR16 Buffer[OUTPUT_FIELD_COLUMN_WIDTH];
 
@@ -265,8 +264,34 @@ DumpProcessorHierarchyNodeStructure (
  PARSER_PARAMS (ProcessorHierarchyNodeStructureParser)
  );
 
-  PrivateResourcePtr = Ptr + Offset;
+  // Check if the values used to control the parsing logic have been
+  // successfully read.
+  if (NumberOfPrivateResources == NULL) {
+IncrementErrorCount ();
+Print (
+  L"ERROR: Insufficient Processor Hierarchy Node length. Length = %d.\n",
+  Length
+  );
+return;
+  }
+
+  // Make sure the Private Resource array lies inside this structure
+  if (Offset + (*NumberOfPrivateResources * sizeof (UINT32)) > Length) {
+IncrementErrorCount ();
+Print (
+  L"ERROR: Invalid Number of Private Resources. " \
+L"PrivateResourceCount = %d. RemainingBufferLength = %d. " \
+L"Parsing of this structure aborted.\n",
+  *NumberOfPrivateResources,
+  Length - Offset
+  );
+return;
+  }
+
   Index = 0;
+
+  // Parse the specified number of private resource references or the Processor
+  // Hierarchy Node length. Whichever is minimum.
   while (Index < *NumberOfPrivateResources) {
 UnicodeSPrint (
   Buffer,
@@ -278,10 +303,10 @@ DumpProcessorHierarchyNodeStructure (
 PrintFieldName (4, Buffer);
 Print (
   L"0x%x\n",
-  *((UINT32*) PrivateResourcePtr)
+  *((UINT32*)(Ptr + Offset))
   );
 
-PrivateResourcePtr += sizeof(UINT32);
+Offset += sizeof (UINT32);
 Index++;
   }
 }
@@ -373,6 +398,7 @@ ParseAcpiPptt (
  AcpiTableLength,
  PARSER_PARAMS (PpttParser)
  );
+
   ProcessorTopologyStructurePtr = Ptr + Offset;
 
   while (Offset < AcpiTableLength) {
@@ -382,19 +408,47 @@ ParseAcpiPptt (
   0,
   NULL,
   ProcessorTopologyStructurePtr,
-  4,  // Length of the processor topology structure header is 4 bytes
+  AcpiTableLength - Offset,
   PARSER_PARAMS (ProcessorTopologyStructureHeaderParser)
   );
 
-if ((Offset + (*ProcessorTopologyStructureLength)) > AcpiTableLength) {
+// Check if the values used to control the parsing logic have been
+// successfully read.
+if ((ProcessorTopologyStructureType == NULL) ||
+(ProcessorTopologyStructureLength == NULL)) {
   IncrementErrorCount ();
   Print (
-L"ERROR: Invalid processor topology structure length:"
-  L" Type = %d, Length = %d\n",
-*ProcessorTopologyStructureType,
-*ProcessorTopologyStructureLength
+L"ERROR: Insufficient remaining table buffer length to read the " \
+  L"processor topology structure header. Length = %d.\n",
+AcpiTableLength - Offset
 );
-  break;
+  return;
+}
+
+// Make sure forward progress is made.
+if (*ProcessorTopologyStructureLength < 2) {
+  IncrementErrorCount ();
+  Print (
+L"ERROR: Structure length is too small: " \
+  L"ProcessorTopologyStructureLength = %d. " \
+  L"ProcessorTopologyStructureType = %d. PPTT parsing aborted.\n",
+*ProcessorTopologyStructureLength,
+*ProcessorTopologyStructureType
+);
+  return;
+}
+
+// Make sure the PPTT structure lies inside the table
+if ((Offset + *ProcessorTopologyStructureLength) > AcpiTableLength) {
+  IncrementErrorCount ();
+  Print (
+L"ERROR: Invalid PPTT stru

[edk2-devel] [PATCH v1 07/11] ShellPkg: acpiview: MADT: Add error-checking in the parsing logic

2019-07-11 Thread Krzysztof Koch
1. Check if the global pointers (in the scope of this ACPI table parser)
have been successfully updated before they are later used to control
the parsing logic.

2. Give forward progress guarantee when parsing the MADT table. Report
an error if a MADT structure is too small to be valid. Without this
check, there is a possibility for the parser to enter an ifninite loop.

3. Test against buffer overruns.

4. Remove redundant forward function declarations by repositioning
blocks of code.

5. Allow silencing ACPI table content validation errors which do not
cause table parsing to fail.

Signed-off-by: Krzysztof Koch 
---

Changes can be seen at: 
https://github.com/KrzysztofKoch1/edk2/commit/ef11738efc94a9c3d7270d376a2cb273bbadbba2

Notes:
v1:
- improve the logic in the MADT parser [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c | 187 
++--
 1 file changed, 94 insertions(+), 93 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c
index 
59c3df0cc8a080497b517baf36fc63f1e4ab866f..54f9fddc5426de5383b747ec7afd21396bcccfc9
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c
@@ -15,6 +15,7 @@
 #include 
 #include "AcpiParser.h"
 #include "AcpiTableParser.h"
+#include "AcpiView.h"
 #include "MadtParser.h"
 
 // Local Variables
@@ -35,7 +36,15 @@ EFIAPI
 ValidateGICDSystemVectorBase (
   IN UINT8* Ptr,
   IN VOID*  Context
-  );
+)
+{
+  if (*(UINT32*)Ptr != 0) {
+IncrementErrorCount ();
+Print (
+  L"\nERROR: System Vector Base must be zero."
+);
+  }
+}
 
 /**
   This function validates the SPE Overflow Interrupt in the GICC.
@@ -50,7 +59,41 @@ EFIAPI
 ValidateSpeOverflowInterrupt (
   IN UINT8* Ptr,
   IN VOID*  Context
-  );
+  )
+{
+  UINT16 SpeOverflowInterrupt;
+
+  SpeOverflowInterrupt = *(UINT16*)Ptr;
+
+  // SPE not supported by this processor
+  if (SpeOverflowInterrupt == 0) {
+return;
+  }
+
+  if ((SpeOverflowInterrupt < ARM_PPI_ID_MIN) ||
+  ((SpeOverflowInterrupt > ARM_PPI_ID_MAX) &&
+   (SpeOverflowInterrupt < ARM_PPI_ID_EXTENDED_MIN)) ||
+  (SpeOverflowInterrupt > ARM_PPI_ID_EXTENDED_MAX)) {
+IncrementErrorCount ();
+Print (
+  L"\nERROR: SPE Overflow Interrupt ID of %d is not in the allowed PPI ID "
+L"ranges of %d-%d or %d-%d (for GICv3.1 or later).",
+  SpeOverflowInterrupt,
+  ARM_PPI_ID_MIN,
+  ARM_PPI_ID_MAX,
+  ARM_PPI_ID_EXTENDED_MIN,
+  ARM_PPI_ID_EXTENDED_MAX
+);
+  } else if (SpeOverflowInterrupt != ARM_PPI_ID_PMBIRQ) {
+IncrementWarningCount();
+Print (
+  L"\nWARNING: SPE Overflow Interrupt ID of %d is not compliant with SBSA "
+L"Level 3 PPI ID assignment: %d.",
+  SpeOverflowInterrupt,
+  ARM_PPI_ID_PMBIRQ
+);
+  }
+}
 
 /**
   An ACPI_PARSER array describing the GICC Interrupt Controller Structure.
@@ -158,78 +201,6 @@ STATIC CONST ACPI_PARSER 
MadtInterruptControllerHeaderParser[] = {
   {L"Reserved", 2, 2, NULL, NULL, NULL, NULL, NULL}
 };
 
-/**
-  This function validates the System Vector Base in the GICD.
-
-  @param [in] Ptr Pointer to the start of the field data.
-  @param [in] Context Pointer to context specific information e.g. this
-  could be a pointer to the ACPI table header.
-**/
-STATIC
-VOID
-EFIAPI
-ValidateGICDSystemVectorBase (
-  IN UINT8* Ptr,
-  IN VOID*  Context
-)
-{
-  if (*(UINT32*)Ptr != 0) {
-IncrementErrorCount ();
-Print (
-  L"\nERROR: System Vector Base must be zero."
-);
-  }
-}
-
-/**
-  This function validates the SPE Overflow Interrupt in the GICC.
-
-  @param [in] Ptr Pointer to the start of the field data.
-  @param [in] Context Pointer to context specific information e.g. this
-  could be a pointer to the ACPI table header.
-**/
-STATIC
-VOID
-EFIAPI
-ValidateSpeOverflowInterrupt (
-  IN UINT8* Ptr,
-  IN VOID*  Context
-  )
-{
-  UINT16 SpeOverflowInterrupt;
-
-  SpeOverflowInterrupt = *(UINT16*)Ptr;
-
-  // SPE not supported by this processor
-  if (SpeOverflowInterrupt == 0) {
-return;
-  }
-
-  if ((SpeOverflowInterrupt < ARM_PPI_ID_MIN) ||
-  ((SpeOverflowInterrupt > ARM_PPI_ID_MAX) &&
-   (SpeOverflowInterrupt < ARM_PPI_ID_EXTENDED_MIN)) ||
-  (SpeOverflowInterrupt > ARM_PPI_ID_EXTENDED_MAX)) {
-IncrementErrorCount ();
-Print (
-  L"\nERROR: SPE Overflow Interrupt ID of %d is not in the allowed PPI ID "
-L"ranges of %d-%d or %d-%d (for GICv3.1 or later).",
-  SpeOverflowInterrupt,
-  ARM_PPI_ID_MIN,
-  ARM_PPI_ID_MAX,
-  ARM_PPI_ID_EXTENDED_MIN,
-  ARM_PPI_ID_E

[edk2-devel] [PATCH v1 06/11] ShellPkg: acpiview: SRAT: Add error-checking in the parsing logic

2019-07-11 Thread Krzysztof Koch
1. Check if the global pointers (in the scope of this ACPI table parser)
have been successfully updated before they are later used to control
the parsing logic.

2. Give forward progress guarantee when parsing the SRAT table. Report
an error if a SRAT structure is too small to be valid. Without this
check, there is a possibility for the parser to enter an ifninite loop.

3. Test against buffer overruns.

4. Remove redundant forward function declarations by repositioning
blocks of code.

5. Allow silencing ACPI table content validation errors which do not
cause table parsing to fail.

Signed-off-by: Krzysztof Koch 
---

Changes can be seen at: 
https://github.com/KrzysztofKoch1/edk2/commit/d46d682d28654b1c6263be2f4fd961c35e80e5cb

Notes:
v1:
- improve the logic in the SRAT parser [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c | 113 
+++-
 1 file changed, 63 insertions(+), 50 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
index 
075ff2a141a82b522e8aaedb7ad79249aaf5eaac..a12aceb70d273a628387b72437819dc05ad7301e
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
@@ -1,7 +1,7 @@
 /** @file
   SRAT table parser
 
-  Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
+  Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
   @par Reference(s):
@@ -13,6 +13,7 @@
 #include 
 #include "AcpiParser.h"
 #include "AcpiTableParser.h"
+#include "AcpiView.h"
 
 // Local Variables
 STATIC CONST UINT8* SratRAType;
@@ -32,7 +33,13 @@ EFIAPI
 ValidateSratReserved (
   IN UINT8* Ptr,
   IN VOID*  Context
-  );
+  )
+{
+  if (*(UINT32*)Ptr != 1) {
+IncrementErrorCount ();
+Print (L"\nERROR: Reserved should be 1 for backward compatibility.\n");
+  }
+}
 
 /**
   This function traces the APIC Proximity Domain field.
@@ -44,9 +51,16 @@ STATIC
 VOID
 EFIAPI
 DumpSratApicProximity (
-  IN  CONST CHAR16*  Format,
-  IN  UINT8* Ptr
-  );
+ IN CONST CHAR16* Format,
+ IN UINT8*Ptr
+ )
+{
+  UINT32 ProximityDomain;
+
+  ProximityDomain = Ptr[0] | (Ptr[1] << 8) | (Ptr[2] << 16);
+
+  Print (Format, ProximityDomain);
+}
 
 /**
   An ACPI_PARSER array describing the SRAT Table.
@@ -139,47 +153,6 @@ STATIC CONST ACPI_PARSER SratX2ApciAffinityParser[] = {
   {L"Reserved", 4, 20, L"0x%x", NULL, NULL, NULL, NULL}
 };
 
-/** This function validates the Reserved field in the SRAT table header.
-
-  @param [in] Ptr Pointer to the start of the field data.
-  @param [in] Context Pointer to context specific information e.g. this
-  could be a pointer to the ACPI table header.
-**/
-STATIC
-VOID
-EFIAPI
-ValidateSratReserved (
-  IN UINT8* Ptr,
-  IN VOID*  Context
-  )
-{
-  if (*(UINT32*)Ptr != 1) {
-IncrementErrorCount ();
-Print (L"\nERROR: Reserved should be 1 for backward compatibility.\n");
-  }
-}
-
-/**
-  This function traces the APIC Proximity Domain field.
-
-  @param [in] Format  Format string for tracing the data.
-  @param [in] Ptr Pointer to the start of the buffer.
-**/
-STATIC
-VOID
-EFIAPI
-DumpSratApicProximity (
- IN CONST CHAR16* Format,
- IN UINT8*Ptr
- )
-{
-  UINT32 ProximityDomain;
-
-  ProximityDomain = Ptr[0] | (Ptr[1] << 8) | (Ptr[2] << 16);
-
-  Print (Format, ProximityDomain);
-}
-
 /**
   This function parses the ACPI SRAT table.
   When trace is enabled this function parses the SRAT table and
@@ -234,6 +207,7 @@ ParseAcpiSrat (
  AcpiTableLength,
  PARSER_PARAMS (SratParser)
  );
+
   ResourcePtr = Ptr + Offset;
 
   while (Offset < AcpiTableLength) {
@@ -242,10 +216,47 @@ ParseAcpiSrat (
   0,
   NULL,
   ResourcePtr,
-  2,  // The length is 1 byte at offset 1
+  AcpiTableLength - Offset,
   PARSER_PARAMS (SratResourceAllocationParser)
   );
 
+// Check if the values used to control the parsing logic have been
+// successfully read.
+if ((SratRAType == NULL) ||
+(SratRALength == NULL)) {
+  IncrementErrorCount ();
+  Print (
+L"ERROR: Insufficient remaining table buffer length to read the " \
+  L"Static Resource Allocation structure header. Length = %d.\n",
+AcpiTableLength - Offset
+);
+  return;
+}
+
+// Make sure forward progress is made.
+if (*SratRALength < 2) {
+  IncrementErrorCount ();
+  Print (
+L"ERROR: Structure length is too small: SratRALength = %d. " \
+  L"SratRAType = %d. SRAT parsing aborted.\n",
+*SratRALength,
+*SratRAType
+ 

[edk2-devel] [PATCH v1 10/11] ShellPkg: acpiview: GTDT: Add error-checking in the parsing logic

2019-07-11 Thread Krzysztof Koch
1. Check if the global pointers (in the scope of this ACPI table parser)
have been successfully updated before they are later used to control
the parsing logic.

2. Test against buffer overruns.

3. Allow silencing ACPI table content validation errors which do not
cause table parsing to fail.

4. Remove redundant forward function declarations by repositioning
blocks of code.

5. Convert a 'do-while' loop for parsing GTDT table body into a 'while'
block for consistency with other table parsers.

Signed-off-by: Krzysztof Koch 
---

Changes can be seen at: 
https://github.com/KrzysztofKoch1/edk2/commit/8c2ed18c7f1c44620eb86e1c9117cbccee8938ce

Notes:
v1:
- improve the logic in the GTDT parser [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c | 294 
+++-
 1 file changed, 170 insertions(+), 124 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c
index 
3b05ff3015d4a3af62dd9fab057c32369a456267..4e8e6f3eb50596823827d20dbb72314a583d0931
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c
@@ -12,6 +12,10 @@
 #include 
 #include "AcpiParser.h"
 #include "AcpiTableParser.h"
+#include "AcpiView.h"
+
+// "The number of GT Block Timers must be less than or equal to 8"
+#define GT_BLOCK_TIMER_COUNT_MAX 8
 
 // Local variables
 STATIC CONST UINT32* GtdtPlatformTimerCount;
@@ -20,7 +24,6 @@ STATIC CONST UINT8*  PlatformTimerType;
 STATIC CONST UINT16* PlatformTimerLength;
 STATIC CONST UINT32* GtBlockTimerCount;
 STATIC CONST UINT32* GtBlockTimerOffset;
-STATIC CONST UINT16* GtBlockLength;
 STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
 
 /**
@@ -36,7 +39,21 @@ EFIAPI
 ValidateGtBlockTimerCount (
   IN UINT8* Ptr,
   IN VOID*  Context
-  );
+  )
+{
+  UINT32 BlockTimerCount;
+
+  BlockTimerCount = *(UINT32*)Ptr;
+
+  if (BlockTimerCount > GT_BLOCK_TIMER_COUNT_MAX) {
+IncrementErrorCount ();
+Print (
+  L"\nERROR: Timer Count = %d. Max Timer Count is %d.",
+  BlockTimerCount,
+  GT_BLOCK_TIMER_COUNT_MAX
+  );
+  }
+}
 
 /**
   This function validates the GT Frame Number.
@@ -51,7 +68,21 @@ EFIAPI
 ValidateGtFrameNumber (
   IN UINT8* Ptr,
   IN VOID*  Context
-  );
+  )
+{
+  UINT8 FrameNumber;
+
+  FrameNumber = *(UINT8*)Ptr;
+
+  if (FrameNumber >= GT_BLOCK_TIMER_COUNT_MAX) {
+IncrementErrorCount ();
+Print (
+  L"\nERROR: GT Frame Number = %d. GT Frame Number must be in range 0-%d.",
+  FrameNumber,
+  GT_BLOCK_TIMER_COUNT_MAX - 1
+  );
+  }
+}
 
 /**
   An ACPI_PARSER array describing the ACPI GTDT Table.
@@ -96,7 +127,7 @@ STATIC CONST ACPI_PARSER GtPlatformTimerHeaderParser[] = {
 **/
 STATIC CONST ACPI_PARSER GtBlockParser[] = {
   {L"Type", 1, 0, L"%d", NULL, NULL, NULL, NULL},
-  {L"Length", 2, 1, L"%d", NULL, (VOID**)&GtBlockLength, NULL, NULL},
+  {L"Length", 2, 1, L"%d", NULL, NULL, NULL, NULL},
   {L"Reserved", 1, 3, L"%x", NULL, NULL, NULL, NULL},
   {L"Physical address (CntCtlBase)", 8, 4, L"0x%lx", NULL, NULL, NULL, NULL},
   {L"Timer Count", 4, 12, L"%d", NULL, (VOID**)&GtBlockTimerCount,
@@ -134,115 +165,71 @@ STATIC CONST ACPI_PARSER SBSAGenericWatchdogParser[] = {
   {L"Watchdog Timer Flags", 4, 24, L"0x%x", NULL, NULL, NULL, NULL}
 };
 
-/**
-  This function validates the GT Block timer count.
-
-  @param [in] Ptr Pointer to the start of the field data.
-  @param [in] Context Pointer to context specific information e.g. this
-  could be a pointer to the ACPI table header.
-**/
-STATIC
-VOID
-EFIAPI
-ValidateGtBlockTimerCount (
-  IN UINT8* Ptr,
-  IN VOID*  Context
-  )
-{
-  UINT32 BlockTimerCount;
-
-  BlockTimerCount = *(UINT32*)Ptr;
-
-  if (BlockTimerCount > 8) {
-IncrementErrorCount ();
-Print (
-  L"\nERROR: Timer Count = %d. Max Timer Count is 8.",
-  BlockTimerCount
-  );
-  }
-}
-
-/**
-  This function validates the GT Frame Number.
-
-  @param [in] Ptr Pointer to the start of the field data.
-  @param [in] Context Pointer to context specific information e.g. this
-  could be a pointer to the ACPI table header.
-**/
-STATIC
-VOID
-EFIAPI
-ValidateGtFrameNumber (
-  IN UINT8* Ptr,
-  IN VOID*  Context
-  )
-{
-  UINT8 FrameNumber;
-
-  FrameNumber = *(UINT8*)Ptr;
-
-  if (FrameNumber > 7) {
-IncrementErrorCount ();
-Print (
-  L"\nERROR: GT Frame Number = %d. GT Frame Number must be in range 0-7.",
-  FrameNumber
-  );
-  }
-}
-
 /**
   This function parses the Platform GT Block.
 
-  @param [in] Ptr Pointer to t

[edk2-devel] [PATCH v1 11/11] ShellPkg: acpiview: DBG2: Add error-checking in the parsing logic

2019-07-11 Thread Krzysztof Koch
1. Check if the global pointers (in the scope of this ACPI table parser)
have been successfully updated before they are later used to control
the parsing logic.

2. Remove redundant forward function declarations by repositioning
blocks of code.

3. Test against buffer overruns.

4. Introduce a ACPI_PARSER array for parsing the header of the debug
device information structure. This way, the length of the buffer
storing a debug device information structure instance can be passed to
DumpDbgDeviceInfo(). Consequently, the parsing logic becomes consistent
with other ACPI table parsers and tests against buffer overrruns are
simpler to implement.

5. Modify the signature of DumpGasStruct() function inside AcpiParser.c
to facilitate protection against buffer overruns in the DBG2 parser.

Signed-off-by: Krzysztof Koch 
---

Changes can be seen at: 
https://github.com/KrzysztofKoch1/edk2/commit/530b059a9fe4aa9f1df36b407f97d76acaab8b74

Notes:
v1:
- improve the logic in the DBG2 parser [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c  |  26 +-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h  |   8 +-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c | 298 
++--
 3 files changed, 225 insertions(+), 107 deletions(-)

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
index 
8b3153516d2b7d9b920ab2de0344c17798ac572c..2d6ff80e299eebe7853061d3db89332197c0dc0e
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
@@ -589,23 +589,27 @@ STATIC CONST ACPI_PARSER GasParser[] = {
 
   @param [in] Ptr Pointer to the start of the buffer.
   @param [in] Indent  Number of spaces to indent the output.
+  @param [in] Length  Length of the GAS structure buffer.
+
+  @retval Number of bytes parsed.
 **/
-VOID
+UINT32
 EFIAPI
 DumpGasStruct (
   IN UINT8*Ptr,
-  IN UINT32Indent
+  IN UINT32Indent,
+  IN UINT32Length
   )
 {
   Print (L"\n");
-  ParseAcpi (
-TRUE,
-Indent,
-NULL,
-Ptr,
-GAS_LENGTH,
-PARSER_PARAMS (GasParser)
-);
+  return ParseAcpi (
+   TRUE,
+   Indent,
+   NULL,
+   Ptr,
+   Length,
+   PARSER_PARAMS (GasParser)
+   );
 }
 
 /**
@@ -621,7 +625,7 @@ DumpGas (
   IN UINT8*Ptr
   )
 {
-  DumpGasStruct (Ptr, 2);
+  DumpGasStruct (Ptr, 2, GAS_LENGTH);
 }
 
 /**
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
index 
7657892d9fd2e2e14c6578611ff0cf1b6f6cd750..20ca358bddfa5953bfb1d1bebaebbf3079eaba01
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
@@ -405,12 +405,16 @@ ParseAcpi (
 
   @param [in] Ptr Pointer to the start of the buffer.
   @param [in] Indent  Number of spaces to indent the output.
+  @param [in] Length  Length of the GAS structure buffer.
+
+  @retval Number of bytes parsed.
 **/
-VOID
+UINT32
 EFIAPI
 DumpGasStruct (
   IN UINT8*Ptr,
-  IN UINT32Indent
+  IN UINT32Indent,
+  IN UINT32Length
   );
 
 /**
diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
index 
8de5ebf74775bab8e765849cba6ef4eb6f659a5a..2bbd622ffb7cec0a340de3e10bdcd01ba4d330df
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
@@ -12,6 +12,7 @@
 #include 
 #include "AcpiParser.h"
 #include "AcpiTableParser.h"
+#include "AcpiView.h"
 
 // Local variables pointing to the table fields
 STATIC CONST UINT32* OffsetDbgDeviceInfo;
@@ -27,7 +28,7 @@ STATIC CONST UINT16* AddrSizeOffset;
 STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
 
 /**
-  This function Validates the NameSpace string length.
+  This function validates the NameSpace string length.
 
   @param [in] Ptr Pointer to the start of the buffer.
   @param [in] Context Pointer to context specific information e.g. this
@@ -37,24 +38,23 @@ STATIC
 VOID
 EFIAPI
 ValidateNameSpaceStrLen (
-  IN  UINT8* Ptr,
-  IN  VOID*  Context
-  );
+  IN UINT8* Ptr,
+  IN VOID*  Context
+  )
+{
+  UINT16 NameSpaceStrLen;
 
-/**
-  This function parses the debug device information structure.
+  NameSpaceStrLen = *(UINT16*)Ptr;
 
-  @param [in]  Ptr Pointer to the start of the buffer.
-  @param [out] Length  Pointer in which the length of the debug
-   device information is returned.
-**/
-STATIC
-VOID
-EFIAPI
-DumpDbgDeviceInfo (
-  IN  UINT8*  Ptr,
-  OUT UINT32* Length
-  );
+  if (NameSpaceStrLen < 2) {
+IncrementE

Re: [edk2-devel] [PATCH v1 01/11] ShellPkg: acpiview: FADT: Validate global pointers before use

2019-07-17 Thread Krzysztof Koch
Hi Jaben,

I will split the changes into separate patch sets with each patch set having 
the same logical change made to every applicable acpiview table parser. The 
per-parser modifications will be separate commits as well.

Kind regards,

Krzysztof

-Original Message-
From: devel@edk2.groups.io  On Behalf Of Carsey, Jaben 
via Groups.Io
Sent: Friday, July 12, 2019 15:27
To: Krzysztof Koch ; devel@edk2.groups.io
Cc: Ni, Ray ; Gao, Zhichao ; Sami 
Mujawar ; Matteo Carlini ; nd 

Subject: Re: [edk2-devel] [PATCH v1 01/11] ShellPkg: acpiview: FADT: Validate 
global pointers before use

I think it would be easier to see/review these changes logically if the 
functional changes (1 and 3) were separate from the refactoring change (2).

Reviewed-by: Jaben Carsey 

> -Original Message-
> From: Krzysztof Koch [mailto:krzysztof.k...@arm.com]
> Sent: Thursday, July 11, 2019 11:53 PM
> To: devel@edk2.groups.io
> Cc: Carsey, Jaben ; Ni, Ray
> ; Gao, Zhichao ;
> sami.muja...@arm.com; matteo.carl...@arm.com; n...@arm.com
> Subject: [PATCH v1 01/11] ShellPkg: acpiview: FADT: Validate global
> pointers before use
>
> 1. Check if the global pointer have been successfully updated before
> they are later used to control the parsing logic in the FADT acpiview
> parser.
>
> 2. Remove redundant forward function declarations by repositioning
> blocks of code.
>
> 3. Allow silencing ACPI table content validation errors which do not
> cause table parsing to fail.
>
> Signed-off-by: Krzysztof Koch 
> ---
>
> Changes can be seen at:
> https://github.com/KrzysztofKoch1/edk2/commit/49cc41430775fb93205e302
> 590a7d31f080c3952
>
> Notes:
> v1:
> - improve the logic in the parser [Krzysztof]
>
>
> ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c
> | 131 
>  1 file changed, 51 insertions(+), 80 deletions(-)
>
> diff --git
> a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.
> c
> b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.
> c
> index
> cee7ee0770433da96d6042d2f5d687903f4b5495..600d3b16d7b22b61c1a1fd21
> ecb93f16c7f8fa1a 100644
> ---
> a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.
> c
> +++
> b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.
> c
> @@ -1,7 +1,7 @@
>  /** @file
>FADT table parser
>
> -  Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
> +  Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
>SPDX-License-Identifier: BSD-2-Clause-Patent
>
>@par Reference(s):
> @@ -12,6 +12,7 @@
>  #include 
>  #include "AcpiParser.h"
>  #include "AcpiTableParser.h"
> +#include "AcpiView.h"
>
>  // Local variables
>  STATIC CONST UINT32* DsdtAddress;
> @@ -46,7 +47,17 @@ EFIAPI
>  ValidateFirmwareCtrl (
>IN UINT8* Ptr,
>IN VOID*  Context
> -  );
> +)
> +{
> +#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
> +  if (*(UINT32*)Ptr != 0) {
> +IncrementErrorCount ();
> +Print (
> +  L"\nERROR: Firmware Control must be zero for ARM platforms."
> +);
> +  }
> +#endif
> +}
>
>  /**
>This function validates the X_Firmware Control Field.
> @@ -61,7 +72,17 @@ EFIAPI
>  ValidateXFirmwareCtrl (
>IN UINT8* Ptr,
>IN VOID*  Context
> -  );
> +)
> +{
> +#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
> +  if (*(UINT64*)Ptr != 0) {
> +IncrementErrorCount ();
> +Print (
> +  L"\nERROR: X Firmware Control must be zero for ARM platforms."
> +);
> +  }
> +#endif
> +}
>
>  /**
>This function validates the flags.
> @@ -76,7 +97,17 @@ EFIAPI
>  ValidateFlags (
>IN UINT8* Ptr,
>IN VOID*  Context
> -  );
> +)
> +{
> +#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
> +  if (((*(UINT32*)Ptr) & HW_REDUCED_ACPI) == 0) {
> +IncrementErrorCount ();
> +Print (
> +  L"\nERROR: HW_REDUCED_ACPI flag must be set for ARM platforms."
> +);
> +  }
> +#endif
> +}
>
>  /**
>An ACPI_PARSER array describing the ACPI FADT Table.
> @@ -142,81 +173,6 @@ STATIC CONST ACPI_PARSER FadtParser[] = {
>{L"Hypervisor VendorIdentity", 8, 268, L"%lx", NULL, NULL, NULL,
> NULL}  };
>
> -/**
> -  This function validates the Firmware Control Field.
> -
> -  @param [in] Ptr Pointer to the start of the field data.
> -  @param [in] Context Pointer to context specific information e.g. this
> -  could be a pointer to the ACPI table header.
> -**/
> -STATIC
> -VOID
> -EFIAPI
> -ValidateFirmwar

[edk2-devel] [PATCH v1 7/8] ShellPkg: acpiview: GTDT: Remove redundant forward declarations

2019-07-18 Thread Krzysztof Koch
Remove redundant forward function declarations by repositioning
blocks of code. This way the code structure is consistent across
ACPI table parsers and the code becomes more concise.

Replace multple use of literal values for GT Block Timer Frame
count/number validation with a macro definition.

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- remove redundant forward function declarations [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c | 91 
+++-
 1 file changed, 33 insertions(+), 58 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c
index 
3b05ff3015d4a3af62dd9fab057c32369a456267..1e5b5764f50a2d29aa904c889bc89af5bdc3af5c
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c
@@ -13,6 +13,9 @@
 #include "AcpiParser.h"
 #include "AcpiTableParser.h"
 
+// "The number of GT Block Timers must be less than or equal to 8"
+#define GT_BLOCK_TIMER_COUNT_MAX 8
+
 // Local variables
 STATIC CONST UINT32* GtdtPlatformTimerCount;
 STATIC CONST UINT32* GtdtPlatformTimerOffset;
@@ -36,7 +39,21 @@ EFIAPI
 ValidateGtBlockTimerCount (
   IN UINT8* Ptr,
   IN VOID*  Context
-  );
+  )
+{
+  UINT32 BlockTimerCount;
+
+  BlockTimerCount = *(UINT32*)Ptr;
+
+  if (BlockTimerCount > GT_BLOCK_TIMER_COUNT_MAX) {
+IncrementErrorCount ();
+Print (
+  L"\nERROR: Timer Count = %d. Max Timer Count is %d.",
+  BlockTimerCount,
+  GT_BLOCK_TIMER_COUNT_MAX
+  );
+  }
+}
 
 /**
   This function validates the GT Frame Number.
@@ -51,7 +68,21 @@ EFIAPI
 ValidateGtFrameNumber (
   IN UINT8* Ptr,
   IN VOID*  Context
-  );
+  )
+{
+  UINT8 FrameNumber;
+
+  FrameNumber = *(UINT8*)Ptr;
+
+  if (FrameNumber >= GT_BLOCK_TIMER_COUNT_MAX) {
+IncrementErrorCount ();
+Print (
+  L"\nERROR: GT Frame Number = %d. GT Frame Number must be in range 0-%d.",
+  FrameNumber,
+  GT_BLOCK_TIMER_COUNT_MAX - 1
+  );
+  }
+}
 
 /**
   An ACPI_PARSER array describing the ACPI GTDT Table.
@@ -134,62 +165,6 @@ STATIC CONST ACPI_PARSER SBSAGenericWatchdogParser[] = {
   {L"Watchdog Timer Flags", 4, 24, L"0x%x", NULL, NULL, NULL, NULL}
 };
 
-/**
-  This function validates the GT Block timer count.
-
-  @param [in] Ptr Pointer to the start of the field data.
-  @param [in] Context Pointer to context specific information e.g. this
-  could be a pointer to the ACPI table header.
-**/
-STATIC
-VOID
-EFIAPI
-ValidateGtBlockTimerCount (
-  IN UINT8* Ptr,
-  IN VOID*  Context
-  )
-{
-  UINT32 BlockTimerCount;
-
-  BlockTimerCount = *(UINT32*)Ptr;
-
-  if (BlockTimerCount > 8) {
-IncrementErrorCount ();
-Print (
-  L"\nERROR: Timer Count = %d. Max Timer Count is 8.",
-  BlockTimerCount
-  );
-  }
-}
-
-/**
-  This function validates the GT Frame Number.
-
-  @param [in] Ptr Pointer to the start of the field data.
-  @param [in] Context Pointer to context specific information e.g. this
-  could be a pointer to the ACPI table header.
-**/
-STATIC
-VOID
-EFIAPI
-ValidateGtFrameNumber (
-  IN UINT8* Ptr,
-  IN VOID*  Context
-  )
-{
-  UINT8 FrameNumber;
-
-  FrameNumber = *(UINT8*)Ptr;
-
-  if (FrameNumber > 7) {
-IncrementErrorCount ();
-Print (
-  L"\nERROR: GT Frame Number = %d. GT Frame Number must be in range 0-7.",
-  FrameNumber
-  );
-  }
-}
-
 /**
   This function parses the Platform GT Block.
 
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43927): https://edk2.groups.io/g/devel/message/43927
Mute This Topic: https://groups.io/mt/32513486/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 5/8] ShellPkg: acpiview: MADT: Remove redundant forward declarations

2019-07-18 Thread Krzysztof Koch
Remove redundant forward function declarations by repositioning
blocks of code. This way the code structure is consistent across
ACPI table parsers and the code becomes more concise.

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- remove redundant forward function declarations [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c | 118 

 1 file changed, 44 insertions(+), 74 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c
index 
59c3df0cc8a080497b517baf36fc63f1e4ab866f..338295d30e35c366a60505225cf57145a8e73d93
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c
@@ -35,7 +35,15 @@ EFIAPI
 ValidateGICDSystemVectorBase (
   IN UINT8* Ptr,
   IN VOID*  Context
-  );
+)
+{
+  if (*(UINT32*)Ptr != 0) {
+IncrementErrorCount ();
+Print (
+  L"\nERROR: System Vector Base must be zero."
+);
+  }
+}
 
 /**
   This function validates the SPE Overflow Interrupt in the GICC.
@@ -50,7 +58,41 @@ EFIAPI
 ValidateSpeOverflowInterrupt (
   IN UINT8* Ptr,
   IN VOID*  Context
-  );
+  )
+{
+  UINT16 SpeOverflowInterrupt;
+
+  SpeOverflowInterrupt = *(UINT16*)Ptr;
+
+  // SPE not supported by this processor
+  if (SpeOverflowInterrupt == 0) {
+return;
+  }
+
+  if ((SpeOverflowInterrupt < ARM_PPI_ID_MIN) ||
+  ((SpeOverflowInterrupt > ARM_PPI_ID_MAX) &&
+   (SpeOverflowInterrupt < ARM_PPI_ID_EXTENDED_MIN)) ||
+  (SpeOverflowInterrupt > ARM_PPI_ID_EXTENDED_MAX)) {
+IncrementErrorCount ();
+Print (
+  L"\nERROR: SPE Overflow Interrupt ID of %d is not in the allowed PPI ID "
+L"ranges of %d-%d or %d-%d (for GICv3.1 or later).",
+  SpeOverflowInterrupt,
+  ARM_PPI_ID_MIN,
+  ARM_PPI_ID_MAX,
+  ARM_PPI_ID_EXTENDED_MIN,
+  ARM_PPI_ID_EXTENDED_MAX
+);
+  } else if (SpeOverflowInterrupt != ARM_PPI_ID_PMBIRQ) {
+IncrementWarningCount();
+Print (
+  L"\nWARNING: SPE Overflow Interrupt ID of %d is not compliant with SBSA "
+L"Level 3 PPI ID assignment: %d.",
+  SpeOverflowInterrupt,
+  ARM_PPI_ID_PMBIRQ
+);
+  }
+}
 
 /**
   An ACPI_PARSER array describing the GICC Interrupt Controller Structure.
@@ -158,78 +200,6 @@ STATIC CONST ACPI_PARSER 
MadtInterruptControllerHeaderParser[] = {
   {L"Reserved", 2, 2, NULL, NULL, NULL, NULL, NULL}
 };
 
-/**
-  This function validates the System Vector Base in the GICD.
-
-  @param [in] Ptr Pointer to the start of the field data.
-  @param [in] Context Pointer to context specific information e.g. this
-  could be a pointer to the ACPI table header.
-**/
-STATIC
-VOID
-EFIAPI
-ValidateGICDSystemVectorBase (
-  IN UINT8* Ptr,
-  IN VOID*  Context
-)
-{
-  if (*(UINT32*)Ptr != 0) {
-IncrementErrorCount ();
-Print (
-  L"\nERROR: System Vector Base must be zero."
-);
-  }
-}
-
-/**
-  This function validates the SPE Overflow Interrupt in the GICC.
-
-  @param [in] Ptr Pointer to the start of the field data.
-  @param [in] Context Pointer to context specific information e.g. this
-  could be a pointer to the ACPI table header.
-**/
-STATIC
-VOID
-EFIAPI
-ValidateSpeOverflowInterrupt (
-  IN UINT8* Ptr,
-  IN VOID*  Context
-  )
-{
-  UINT16 SpeOverflowInterrupt;
-
-  SpeOverflowInterrupt = *(UINT16*)Ptr;
-
-  // SPE not supported by this processor
-  if (SpeOverflowInterrupt == 0) {
-return;
-  }
-
-  if ((SpeOverflowInterrupt < ARM_PPI_ID_MIN) ||
-  ((SpeOverflowInterrupt > ARM_PPI_ID_MAX) &&
-   (SpeOverflowInterrupt < ARM_PPI_ID_EXTENDED_MIN)) ||
-  (SpeOverflowInterrupt > ARM_PPI_ID_EXTENDED_MAX)) {
-IncrementErrorCount ();
-Print (
-  L"\nERROR: SPE Overflow Interrupt ID of %d is not in the allowed PPI ID "
-L"ranges of %d-%d or %d-%d (for GICv3.1 or later).",
-  SpeOverflowInterrupt,
-  ARM_PPI_ID_MIN,
-  ARM_PPI_ID_MAX,
-  ARM_PPI_ID_EXTENDED_MIN,
-  ARM_PPI_ID_EXTENDED_MAX
-);
-  } else if (SpeOverflowInterrupt != ARM_PPI_ID_PMBIRQ) {
-IncrementWarningCount();
-Print (
-  L"\nWARNING: SPE Overflow Interrupt ID of %d is not compliant with SBSA "
-L"Level 3 PPI ID assignment: %d.",
-  SpeOverflowInterrupt,
-  ARM_PPI_ID_PMBIRQ
-);
-  }
-}
-
 /**
   This function parses the ACPI MADT table.
   When trace is enabled this function parses the MADT table and
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43924): https://edk2.groups.io/g/devel/message/43924
Mute This Topic: https://groups.io/mt/32513483/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 1/8] ShellPkg: acpiview: RSDP: Remove redundant forward declarations

2019-07-18 Thread Krzysztof Koch
Remove redundant forward function declarations by repositioning
blocks of code. This way the code structure is consistent across
ACPI table parsers and the code becomes more concise.

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- remove redundant forward function declarations [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c | 116 

 1 file changed, 43 insertions(+), 73 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c
index 
586de7cbfb12f856c0c735b6e295c1cc32eb2ceb..4bf928139a507d0b8f203ed0cbf0863cc2ec5de5
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c
@@ -1,7 +1,7 @@
 /** @file
   RSDP table parser
 
-  Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
+  Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
   @par Reference(s):
@@ -28,7 +28,27 @@ EFIAPI
 ValidateRsdtAddress (
   IN UINT8* Ptr,
   IN VOID*  Context
-  );
+  )
+{
+#if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
+  // Reference: Server Base Boot Requirements System Software on ARM Platforms
+  // Section: 4.2.1.1 RSDP
+  // Root System Description Pointer (RSDP), ACPI ? 5.2.5.
+  //   - Within the RSDP, the RsdtAddress field must be null (zero) and the
+  // XsdtAddresss MUST be a valid, non-null, 64-bit value.
+  UINT32 RsdtAddr;
+
+  RsdtAddr = *(UINT32*)Ptr;
+
+  if (RsdtAddr != 0) {
+IncrementErrorCount ();
+Print (
+  L"\nERROR: Rsdt Address = 0x%p. This must be NULL on ARM Platforms.",
+  RsdtAddr
+  );
+  }
+#endif
+}
 
 /**
   This function validates the XSDT Address.
@@ -43,7 +63,27 @@ EFIAPI
 ValidateXsdtAddress (
   IN UINT8* Ptr,
   IN VOID*  Context
-  );
+  )
+{
+#if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
+  // Reference: Server Base Boot Requirements System Software on ARM Platforms
+  // Section: 4.2.1.1 RSDP
+  // Root System Description Pointer (RSDP), ACPI ? 5.2.5.
+  //   - Within the RSDP, the RsdtAddress field must be null (zero) and the
+  // XsdtAddresss MUST be a valid, non-null, 64-bit value.
+  UINT64 XsdtAddr;
+
+  XsdtAddr = *(UINT64*)Ptr;
+
+  if (XsdtAddr == 0) {
+IncrementErrorCount ();
+Print (
+  L"\nERROR: Xsdt Address = 0x%p. This must not be NULL on ARM Platforms.",
+  XsdtAddr
+  );
+  }
+#endif
+}
 
 /**
   An array describing the ACPI RSDP Table.
@@ -61,76 +101,6 @@ STATIC CONST ACPI_PARSER RsdpParser[] = {
   {L"Reserved", 3, 33, L"%x %x %x", Dump3Chars, NULL, NULL, NULL}
 };
 
-/**
-  This function validates the RSDT Address.
-
-  @param [in] Ptr Pointer to the start of the field data.
-  @param [in] Context Pointer to context specific information e.g. this
-  could be a pointer to the ACPI table header.
-**/
-STATIC
-VOID
-EFIAPI
-ValidateRsdtAddress (
-  IN UINT8* Ptr,
-  IN VOID*  Context
-  )
-{
-#if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
-  // Reference: Server Base Boot Requirements System Software on ARM Platforms
-  // Section: 4.2.1.1 RSDP
-  // Root System Description Pointer (RSDP), ACPI ? 5.2.5.
-  //   - Within the RSDP, the RsdtAddress field must be null (zero) and the
-  // XsdtAddresss MUST be a valid, non-null, 64-bit value.
-  UINT32 RsdtAddr;
-
-  RsdtAddr = *(UINT32*)Ptr;
-
-  if (RsdtAddr != 0) {
-IncrementErrorCount ();
-Print (
-  L"\nERROR: Rsdt Address = 0x%p. This must be NULL on ARM Platforms.",
-  RsdtAddr
-  );
-  }
-#endif
-}
-
-/**
-  This function validates the XSDT Address.
-
-  @param [in] Ptr Pointer to the start of the field data.
-  @param [in] Context Pointer to context specific information e.g. this
-  could be a pointer to the ACPI table header.
-**/
-STATIC
-VOID
-EFIAPI
-ValidateXsdtAddress (
-  IN UINT8* Ptr,
-  IN VOID*  Context
-  )
-{
-#if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
-  // Reference: Server Base Boot Requirements System Software on ARM Platforms
-  // Section: 4.2.1.1 RSDP
-  // Root System Description Pointer (RSDP), ACPI ? 5.2.5.
-  //   - Within the RSDP, the RsdtAddress field must be null (zero) and the
-  // XsdtAddresss MUST be a valid, non-null, 64-bit value.
-  UINT64 XsdtAddr;
-
-  XsdtAddr = *(UINT64*)Ptr;
-
-  if (XsdtAddr == 0) {
-IncrementErrorCount ();
-Print (
-  L"\nERROR: Xsdt Address = 0x%p. This must not be NULL on ARM Platforms.",
-  XsdtAddr
-  );
-  }
-#endif
-}
-
 /**
   This function parses the ACPI RSDP table.
 
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43926): https://edk2.groups.io/g/de

[edk2-devel] [PATCH v1 4/8] ShellPkg: acpiview: SRAT: Remove redundant forward declarations

2019-07-18 Thread Krzysztof Koch
Remove redundant forward function declarations by repositioning
blocks of code. This way the code structure is consistent across
ACPI table parsers and the code becomes more concise.

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- remove redundant forward function declarations [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c | 64 
++--
 1 file changed, 18 insertions(+), 46 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
index 
075ff2a141a82b522e8aaedb7ad79249aaf5eaac..03d28d52842040e4872e204fc10ae3dba7861936
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
@@ -1,7 +1,7 @@
 /** @file
   SRAT table parser
 
-  Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
+  Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
   @par Reference(s):
@@ -32,7 +32,13 @@ EFIAPI
 ValidateSratReserved (
   IN UINT8* Ptr,
   IN VOID*  Context
-  );
+  )
+{
+  if (*(UINT32*)Ptr != 1) {
+IncrementErrorCount ();
+Print (L"\nERROR: Reserved should be 1 for backward compatibility.\n");
+  }
+}
 
 /**
   This function traces the APIC Proximity Domain field.
@@ -44,9 +50,16 @@ STATIC
 VOID
 EFIAPI
 DumpSratApicProximity (
-  IN  CONST CHAR16*  Format,
-  IN  UINT8* Ptr
-  );
+ IN CONST CHAR16* Format,
+ IN UINT8*Ptr
+ )
+{
+  UINT32 ProximityDomain;
+
+  ProximityDomain = Ptr[0] | (Ptr[1] << 8) | (Ptr[2] << 16);
+
+  Print (Format, ProximityDomain);
+}
 
 /**
   An ACPI_PARSER array describing the SRAT Table.
@@ -139,47 +152,6 @@ STATIC CONST ACPI_PARSER SratX2ApciAffinityParser[] = {
   {L"Reserved", 4, 20, L"0x%x", NULL, NULL, NULL, NULL}
 };
 
-/** This function validates the Reserved field in the SRAT table header.
-
-  @param [in] Ptr Pointer to the start of the field data.
-  @param [in] Context Pointer to context specific information e.g. this
-  could be a pointer to the ACPI table header.
-**/
-STATIC
-VOID
-EFIAPI
-ValidateSratReserved (
-  IN UINT8* Ptr,
-  IN VOID*  Context
-  )
-{
-  if (*(UINT32*)Ptr != 1) {
-IncrementErrorCount ();
-Print (L"\nERROR: Reserved should be 1 for backward compatibility.\n");
-  }
-}
-
-/**
-  This function traces the APIC Proximity Domain field.
-
-  @param [in] Format  Format string for tracing the data.
-  @param [in] Ptr Pointer to the start of the buffer.
-**/
-STATIC
-VOID
-EFIAPI
-DumpSratApicProximity (
- IN CONST CHAR16* Format,
- IN UINT8*Ptr
- )
-{
-  UINT32 ProximityDomain;
-
-  ProximityDomain = Ptr[0] | (Ptr[1] << 8) | (Ptr[2] << 16);
-
-  Print (Format, ProximityDomain);
-}
-
 /**
   This function parses the ACPI SRAT table.
   When trace is enabled this function parses the SRAT table and
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43925): https://edk2.groups.io/g/devel/message/43925
Mute This Topic: https://groups.io/mt/32513484/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 0/8] Remove redundant forward declarations in acpiview

2019-07-18 Thread Krzysztof Koch
This patch series removes forward static function declarations in the
acpiview table parsers. After repositioning blocks of code, these forward
declarations are no longer needed and they increase the code size.

What is more, some of the existing ACPI table parsers don't have these
duplicate declarations, so this set of patches makes the code structure
consistent across all acpiview parsers.

Changes can be seen at: 
https://github.com/KrzysztofKoch1/edk2/tree/612_remove_forward_decl_v1

Krzysztof Koch (8):
  ShellPkg: acpiview: RSDP: Remove redundant forward declarations
  ShellPkg: acpiview: FADT: Remove redundant forward declarations
  ShellPkg: acpiview: SPCR: Remove redundant forward declaration
  ShellPkg: acpiview: SRAT: Remove redundant forward declarations
  ShellPkg: acpiview: MADT: Remove redundant forward declarations
  ShellPkg: acpiview: IORT: Remove redundant forward declarations
  ShellPkg: acpiview: GTDT: Remove redundant forward declarations
  ShellPkg: acpiview: DBG2: Remove redundant forward declarations

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c |  62 
+++---
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c | 113 
++-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c |  91 
++-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c |  58 
+++---
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c | 118 

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c | 116 
+++
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Spcr/SpcrParser.c |  98 
++--
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c |  64 
+++
 8 files changed, 236 insertions(+), 484 deletions(-)

--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43928): https://edk2.groups.io/g/devel/message/43928
Mute This Topic: https://groups.io/mt/32513487/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 3/8] ShellPkg: acpiview: SPCR: Remove redundant forward declaration

2019-07-18 Thread Krzysztof Koch
Reposition blocks of code to remove redundant forward function
declarations in order to reduce the code size.

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- remove redundant forward function declarations [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Spcr/SpcrParser.c | 98 
+++-
 1 file changed, 34 insertions(+), 64 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Spcr/SpcrParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Spcr/SpcrParser.c
index 
1974a9c046e4a3bc55cf758184af097b2420..3b06b05dee8c056c6e009b9e485ccd35d4194e95
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Spcr/SpcrParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Spcr/SpcrParser.c
@@ -1,7 +1,7 @@
 /** @file
   SPCR table parser
 
-  Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
+  Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
   @par Reference(s):
@@ -31,7 +31,23 @@ EFIAPI
 ValidateInterruptType (
   IN UINT8* Ptr,
   IN VOID*  Context
-  );
+  )
+{
+#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
+  UINT8 InterruptType;
+
+  InterruptType = *Ptr;
+
+  if (InterruptType !=
+EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_INTERRUPT_TYPE_GIC) {
+IncrementErrorCount ();
+Print (
+  L"\nERROR: InterruptType = %d. This must be 8 on ARM Platforms",
+  InterruptType
+  );
+  }
+#endif
+}
 
 /**
   This function validates the Irq.
@@ -46,7 +62,22 @@ EFIAPI
 ValidateIrq (
   IN UINT8* Ptr,
   IN VOID*  Context
-  );
+  )
+{
+#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
+  UINT8 Irq;
+
+  Irq = *Ptr;
+
+  if (Irq != 0) {
+IncrementErrorCount ();
+Print (
+  L"\nERROR: Irq = %d. This must be zero on ARM Platforms\n",
+  Irq
+  );
+  }
+#endif
+}
 
 /**
   An ACPI_PARSER array describing the ACPI SPCR Table.
@@ -76,67 +107,6 @@ STATIC CONST ACPI_PARSER SpcrParser[] = {
   {L"Reserved", 4, 76, L"%x", NULL, NULL, NULL, NULL}
 };
 
-/**
-  This function validates the Interrupt Type.
-
-  @param [in] Ptr Pointer to the start of the field data.
-  @param [in] Context Pointer to context specific information e.g. this
-  could be a pointer to the ACPI table header.
-**/
-STATIC
-VOID
-EFIAPI
-ValidateInterruptType (
-  IN UINT8* Ptr,
-  IN VOID*  Context
-  )
-{
-#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
-  UINT8 InterruptType;
-
-  InterruptType = *Ptr;
-
-  if (InterruptType !=
-EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_INTERRUPT_TYPE_GIC) {
-IncrementErrorCount ();
-Print (
-  L"\nERROR: InterruptType = %d. This must be 8 on ARM Platforms",
-  InterruptType
-  );
-  }
-#endif
-}
-
-/**
-  This function validates the Irq.
-
-  @param [in] Ptr Pointer to the start of the field data.
-  @param [in] Context Pointer to context specific information e.g. this
-  could be a pointer to the ACPI table header.
-**/
-STATIC
-VOID
-EFIAPI
-ValidateIrq (
-  IN UINT8* Ptr,
-  IN VOID*  Context
-  )
-{
-#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
-  UINT8 Irq;
-
-  Irq = *Ptr;
-
-  if (Irq != 0) {
-IncrementErrorCount ();
-Print (
-  L"\nERROR: Irq = %d. This must be zero on ARM Platforms\n",
-  Irq
-  );
-  }
-#endif
-}
-
 /**
   This function parses the ACPI SPCR table.
   When trace is enabled this function parses the SPCR table and
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43929): https://edk2.groups.io/g/devel/message/43929
Mute This Topic: https://groups.io/mt/32513489/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 2/8] ShellPkg: acpiview: FADT: Remove redundant forward declarations

2019-07-18 Thread Krzysztof Koch
Remove redundant forward function declarations by repositioning
blocks of code. This way the code structure is consistent across
ACPI table parsers and the code becomes more concise.

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- remove redundant forward function declarations [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c | 113 
++--
 1 file changed, 34 insertions(+), 79 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c
index 
cee7ee0770433da96d6042d2f5d687903f4b5495..e40c9ef8ee4b3285faf8c6edf3cb6236ee367397
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c
@@ -1,7 +1,7 @@
 /** @file
   FADT table parser
 
-  Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
+  Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
   @par Reference(s):
@@ -46,7 +46,17 @@ EFIAPI
 ValidateFirmwareCtrl (
   IN UINT8* Ptr,
   IN VOID*  Context
-  );
+)
+{
+#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
+  if (*(UINT32*)Ptr != 0) {
+IncrementErrorCount ();
+Print (
+  L"\nERROR: Firmware Control must be zero for ARM platforms."
+);
+  }
+#endif
+}
 
 /**
   This function validates the X_Firmware Control Field.
@@ -61,7 +71,17 @@ EFIAPI
 ValidateXFirmwareCtrl (
   IN UINT8* Ptr,
   IN VOID*  Context
-  );
+)
+{
+#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
+  if (*(UINT64*)Ptr != 0) {
+IncrementErrorCount ();
+Print (
+  L"\nERROR: X Firmware Control must be zero for ARM platforms."
+);
+  }
+#endif
+}
 
 /**
   This function validates the flags.
@@ -76,7 +96,17 @@ EFIAPI
 ValidateFlags (
   IN UINT8* Ptr,
   IN VOID*  Context
-  );
+)
+{
+#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
+  if (((*(UINT32*)Ptr) & HW_REDUCED_ACPI) == 0) {
+IncrementErrorCount ();
+Print (
+  L"\nERROR: HW_REDUCED_ACPI flag must be set for ARM platforms."
+);
+  }
+#endif
+}
 
 /**
   An ACPI_PARSER array describing the ACPI FADT Table.
@@ -142,81 +172,6 @@ STATIC CONST ACPI_PARSER FadtParser[] = {
   {L"Hypervisor VendorIdentity", 8, 268, L"%lx", NULL, NULL, NULL, NULL}
 };
 
-/**
-  This function validates the Firmware Control Field.
-
-  @param [in] Ptr Pointer to the start of the field data.
-  @param [in] Context Pointer to context specific information e.g. this
-  could be a pointer to the ACPI table header.
-**/
-STATIC
-VOID
-EFIAPI
-ValidateFirmwareCtrl (
-  IN UINT8* Ptr,
-  IN VOID*  Context
-)
-{
-#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
-  if (*(UINT32*)Ptr != 0) {
-IncrementErrorCount ();
-Print (
-  L"\nERROR: Firmware Control must be zero for ARM platforms."
-);
-  }
-#endif
-}
-
-/**
-  This function validates the X_Firmware Control Field.
-
-  @param [in] Ptr Pointer to the start of the field data.
-  @param [in] Context Pointer to context specific information e.g. this
-  could be a pointer to the ACPI table header.
-**/
-STATIC
-VOID
-EFIAPI
-ValidateXFirmwareCtrl (
-  IN UINT8* Ptr,
-  IN VOID*  Context
-)
-{
-#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
-  if (*(UINT64*)Ptr != 0) {
-IncrementErrorCount ();
-Print (
-  L"\nERROR: X Firmware Control must be zero for ARM platforms."
-);
-  }
-#endif
-}
-
-/**
-  This function validates the flags.
-
-  @param [in] Ptr Pointer to the start of the field data.
-  @param [in] Context Pointer to context specific information e.g. this
-  could be a pointer to the ACPI table header.
-**/
-STATIC
-VOID
-EFIAPI
-ValidateFlags (
-  IN UINT8* Ptr,
-  IN VOID*  Context
-)
-{
-#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
-  if (((*(UINT32*)Ptr) & HW_REDUCED_ACPI) == 0) {
-IncrementErrorCount ();
-Print (
-  L"\nERROR: HW_REDUCED_ACPI flag must be set for ARM platforms."
-);
-  }
-#endif
-}
-
 /**
   This function parses the ACPI FADT table.
   This function parses the FADT table and optionally traces the ACPI table 
fields.
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43931): https://edk2.groups.io/g/devel/message/43931
Mute This Topic: https://groups.io/mt/32513493/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 6/8] ShellPkg: acpiview: IORT: Remove redundant forward declarations

2019-07-18 Thread Krzysztof Koch
Remove redundant forward function declarations by repositioning
blocks of code. This way the code structure is consistent across
ACPI table parsers and the code becomes more concise.

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- remove redundant forward function declarations [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c | 58 
+---
 1 file changed, 14 insertions(+), 44 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c
index 
93f78e1a9786ed53f6b5529f478b72a220b4f8df..0461205b4f8bc02aa11ab1db1d0deb73bce053b7
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c
@@ -45,7 +45,13 @@ EFIAPI
 ValidateItsIdMappingCount (
   IN UINT8* Ptr,
   IN VOID*  Context
-  );
+  )
+{
+  if (*(UINT32*)Ptr != 0) {
+IncrementErrorCount ();
+Print (L"\nERROR: IORT ID Mapping count must be zero.");
+  }
+}
 
 /**
   This function validates the ID Mapping array offset for the ITS node.
@@ -60,7 +66,13 @@ EFIAPI
 ValidateItsIdArrayReference (
   IN UINT8* Ptr,
   IN VOID*  Context
-  );
+  )
+{
+  if (*(UINT32*)Ptr != 0) {
+IncrementErrorCount ();
+Print (L"\nERROR: IORT ID Mapping offset must be zero.");
+  }
+}
 
 /**
   Helper Macro for populating the IORT Node header in the ACPI_PARSER array.
@@ -210,48 +222,6 @@ STATIC CONST ACPI_PARSER IortNodePmcgParser[] = {
   {L"Node reference", 4, 28, L"0x%x", NULL, NULL, NULL, NULL},
 };
 
-/**
-  This function validates the ID Mapping array count for the ITS node.
-
-  @param [in] Ptr Pointer to the start of the field data.
-  @param [in] Context Pointer to context specific information e.g. this
-  could be a pointer to the ACPI table header.
-**/
-STATIC
-VOID
-EFIAPI
-ValidateItsIdMappingCount (
-  IN UINT8* Ptr,
-  IN VOID* Context
-  )
-{
-  if (*(UINT32*)Ptr != 0) {
-IncrementErrorCount ();
-Print (L"\nERROR: IORT ID Mapping count must be zero.");
-  }
-}
-
-/**
-  This function validates the ID Mapping array offset for the ITS node.
-
-  @param [in] Ptr Pointer to the start of the field data.
-  @param [in] Context Pointer to context specific information e.g. this
-  could be a pointer to the ACPI table header.
-**/
-STATIC
-VOID
-EFIAPI
-ValidateItsIdArrayReference (
-  IN UINT8* Ptr,
-  IN VOID*  Context
-  )
-{
-  if (*(UINT32*)Ptr != 0) {
-IncrementErrorCount ();
-Print (L"\nERROR: IORT ID Mapping offset must be zero.");
-  }
-}
-
 /**
   This function parses the IORT Node Id Mapping array.
 
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43932): https://edk2.groups.io/g/devel/message/43932
Mute This Topic: https://groups.io/mt/32513494/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 8/8] ShellPkg: acpiview: DBG2: Remove redundant forward declarations

2019-07-18 Thread Krzysztof Koch
Remove redundant forward function declarations by repositioning
blocks of code. This way the code structure is consistent across
ACPI table parsers and the code becomes more concise.

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- remove redundant forward function declarations [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c | 62 
+---
 1 file changed, 16 insertions(+), 46 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
index 
8de5ebf74775bab8e765849cba6ef4eb6f659a5a..1efcbd40f86efdabed2152540a415db8a950fb71
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
@@ -27,7 +27,7 @@ STATIC CONST UINT16* AddrSizeOffset;
 STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
 
 /**
-  This function Validates the NameSpace string length.
+  This function validates the NameSpace string length.
 
   @param [in] Ptr Pointer to the start of the buffer.
   @param [in] Context Pointer to context specific information e.g. this
@@ -37,24 +37,23 @@ STATIC
 VOID
 EFIAPI
 ValidateNameSpaceStrLen (
-  IN  UINT8* Ptr,
-  IN  VOID*  Context
-  );
+  IN UINT8* Ptr,
+  IN VOID*  Context
+  )
+{
+  UINT16 NameSpaceStrLen;
 
-/**
-  This function parses the debug device information structure.
+  NameSpaceStrLen = *(UINT16*)Ptr;
 
-  @param [in]  Ptr Pointer to the start of the buffer.
-  @param [out] Length  Pointer in which the length of the debug
-   device information is returned.
-**/
-STATIC
-VOID
-EFIAPI
-DumpDbgDeviceInfo (
-  IN  UINT8*  Ptr,
-  OUT UINT32* Length
-  );
+  if (NameSpaceStrLen < 2) {
+IncrementErrorCount ();
+Print (
+  L"\nERROR: NamespaceString Length = %d. If no Namespace device exists, " 
\
+L"NamespaceString[] must contain a period '.'",
+  NameSpaceStrLen
+  );
+  }
+}
 
 /// An ACPI_PARSER array describing the ACPI DBG2 table.
 STATIC CONST ACPI_PARSER Dbg2Parser[] = {
@@ -91,35 +90,6 @@ STATIC CONST ACPI_PARSER DbgDevInfoParser[] = {
(VOID**)&AddrSizeOffset, NULL, NULL}
 };
 
-/**
-  This function validates the NameSpace string length.
-
-  @param [in] Ptr Pointer to the start of the buffer.
-  @param [in] Context Pointer to context specific information e.g. this
-  could be a pointer to the ACPI table header.
-**/
-STATIC
-VOID
-EFIAPI
-ValidateNameSpaceStrLen (
-  IN UINT8* Ptr,
-  IN VOID*  Context
-  )
-{
-  UINT16 NameSpaceStrLen;
-
-  NameSpaceStrLen = *(UINT16*)Ptr;
-
-  if (NameSpaceStrLen < 2) {
-IncrementErrorCount ();
-Print (
-  L"\nERROR: NamespaceString Length = %d. If no Namespace device exists,\n"
-   L"then NamespaceString[] must contain a period '.'",
-  NameSpaceStrLen
-  );
-  }
-}
-
 /**
   This function parses the debug device information structure.
 
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43930): https://edk2.groups.io/g/devel/message/43930
Mute This Topic: https://groups.io/mt/32513492/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 1/6] ShellPkg: acpiview: Allow passing buffer length to DumpGasStruct()

2019-07-18 Thread Krzysztof Koch
Modify the signature of the DumpGasStruct() function to include the
buffer length parameter and to return the number of bytes parsed by
the function.

This way it becomes possible to prevent buffer overruns when dumping
Generic Address Structure's (GAS) fields in the acpiview table
parsers.

Update all existing DumpGasStruct() calls in acpiview to add the
length argument.

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- Modify DumpGasStruct() signature [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c  | 26 
+++-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h  |  8 
--
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c |  2 +-
 3 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
index 
8b3153516d2b7d9b920ab2de0344c17798ac572c..2d6ff80e299eebe7853061d3db89332197c0dc0e
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
@@ -589,23 +589,27 @@ STATIC CONST ACPI_PARSER GasParser[] = {
 
   @param [in] Ptr Pointer to the start of the buffer.
   @param [in] Indent  Number of spaces to indent the output.
+  @param [in] Length  Length of the GAS structure buffer.
+
+  @retval Number of bytes parsed.
 **/
-VOID
+UINT32
 EFIAPI
 DumpGasStruct (
   IN UINT8*Ptr,
-  IN UINT32Indent
+  IN UINT32Indent,
+  IN UINT32Length
   )
 {
   Print (L"\n");
-  ParseAcpi (
-TRUE,
-Indent,
-NULL,
-Ptr,
-GAS_LENGTH,
-PARSER_PARAMS (GasParser)
-);
+  return ParseAcpi (
+   TRUE,
+   Indent,
+   NULL,
+   Ptr,
+   Length,
+   PARSER_PARAMS (GasParser)
+   );
 }
 
 /**
@@ -621,7 +625,7 @@ DumpGas (
   IN UINT8*Ptr
   )
 {
-  DumpGasStruct (Ptr, 2);
+  DumpGasStruct (Ptr, 2, GAS_LENGTH);
 }
 
 /**
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
index 
7657892d9fd2e2e14c6578611ff0cf1b6f6cd750..20ca358bddfa5953bfb1d1bebaebbf3079eaba01
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
@@ -405,12 +405,16 @@ ParseAcpi (
 
   @param [in] Ptr Pointer to the start of the buffer.
   @param [in] Indent  Number of spaces to indent the output.
+  @param [in] Length  Length of the GAS structure buffer.
+
+  @retval Number of bytes parsed.
 **/
-VOID
+UINT32
 EFIAPI
 DumpGasStruct (
   IN UINT8*Ptr,
-  IN UINT32Indent
+  IN UINT32Indent,
+  IN UINT32Length
   );
 
 /**
diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
index 
8de5ebf74775bab8e765849cba6ef4eb6f659a5a..2c47a3f848aa2dd512c53343ecf1c3c285173dd6
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
@@ -164,7 +164,7 @@ DumpDbgDeviceInfo (
   AddrSize = (UINT32*)(Ptr + (*AddrSizeOffset));
   while (Index < (*GasCount)) {
 PrintFieldName (4, L"BaseAddressRegister");
-DumpGasStruct (DataPtr, 4);
+DumpGasStruct (DataPtr, 4, *DbgDevInfoLen);
 PrintFieldName (4, L"Address Size");
 Print (L"0x%x\n", AddrSize[Index]);
 DataPtr += GAS_LENGTH;
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43935): https://edk2.groups.io/g/devel/message/43935
Mute This Topic: https://groups.io/mt/32514379/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 0/6] Acpiview table parsers code style enhancements and refactoring

2019-07-18 Thread Krzysztof Koch
This set of patches consists of a number of changes which make the code
structure consistent across the existing ACPI table parsers. These are
all refactoring changes which do not modify the existing functionality
of the acpiview UEFI shell tool.

Changes can be seen at: 
https://github.com/KrzysztofKoch1/edk2/tree/612_acpiview_code_style_enhance_v1

Krzysztof Koch (6):
  ShellPkg: acpiview: Allow passing buffer length to DumpGasStruct()
  ShellPkg: acpiview: XSDT: Remove redundant ParseAcpi() call
  ShellPkg: acpiview: RSDP: Make code consistent with other parsers
  ShellPkg: acpiview: SRAT: Minor code style enhancements
  ShellPkg: acpiview: MADT: Split structure length validation
  ShellPkg: acpiview: IORT: Refactor PMCG node mapping count validation

 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c  | 26 
+---
 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h  |  8 
+++--
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c |  2 +-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c | 32 
++--
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c | 30 
+-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c | 11 
+--
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c |  3 +-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c | 18 
+++
 8 files changed, 82 insertions(+), 48 deletions(-)

--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43934): https://edk2.groups.io/g/devel/message/43934
Mute This Topic: https://groups.io/mt/32514378/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 3/6] ShellPkg: acpiview: RSDP: Make code consistent with other parsers

2019-07-18 Thread Krzysztof Koch
List ParseAcpi() function arguments one per line in order to make this
function call consistent with ParseAcpi() calls in other ACPI table
parsers.

Also, notify the user that XsdtAddress value of 0 results in RSDP
parsing being terminated and that the XSDT table will not be processed.

This effectively means that no more ACPI tables will be parsed because
of this RSDP table content error.

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- minor code style enhancements [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c | 11 
+--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c
index 
586de7cbfb12f856c0c735b6e295c1cc32eb2ceb..bceda91386b5c070b81b2beac83e2a0102a9b64e
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c
@@ -159,7 +159,14 @@ ParseAcpiRsdp (
 VerifyChecksum (TRUE, Ptr, AcpiTableLength);
   }
 
-  ParseAcpi (Trace, 0, "RSDP", Ptr, AcpiTableLength, PARSER_PARAMS 
(RsdpParser));
+  ParseAcpi (
+Trace,
+0,
+"RSDP",
+Ptr,
+AcpiTableLength,
+PARSER_PARAMS (RsdpParser)
+);
 
   // This code currently supports parsing of XSDT table only
   // and does not parse the RSDT table. Platforms provide the
@@ -167,7 +174,7 @@ ParseAcpiRsdp (
   // Therefore the RSDT should not be used on ARM platforms.
   if ((*XsdtAddress) == 0) {
 IncrementErrorCount ();
-Print (L"ERROR: XSDT Pointer is not set.\n");
+Print (L"ERROR: XSDT Pointer is not set. RSDP parsing aborted.\n");
 return;
   }
 
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43937): https://edk2.groups.io/g/devel/message/43937
Mute This Topic: https://groups.io/mt/32514381/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 2/6] ShellPkg: acpiview: XSDT: Remove redundant ParseAcpi() call

2019-07-18 Thread Krzysztof Koch
Remove a call to ParseAcpi() responsible for getting the XSDT table
length. This call is not needed because the ACPI table buffer length is
provided as an input argument to the ParseAcpiXsdt() function.

Modify remaining code to use the AcpiTableLength argument of the
ParseAcpiXsdt() function instead of a global static variable.

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- remove redundant ParseAcpi() call [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c | 18 
--
 1 file changed, 4 insertions(+), 14 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c
index 
4196168bff47d70c67f79f3fc1f4cdee302d460e..e39061f8e2612f2cce4aebf51a511b63b703662b
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c
@@ -1,7 +1,7 @@
 /** @file
   XSDT table parser
 
-  Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
+  Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
   @par Reference(s):
@@ -60,22 +60,12 @@ ParseAcpiXsdt (
   UINTN EntryIndex;
   CHAR16Buffer[32];
 
-  // Parse the ACPI header to get the length
-  ParseAcpi (
-FALSE,
-0,
-"XSDT",
-Ptr,
-ACPI_DESCRIPTION_HEADER_LENGTH,
-PARSER_PARAMS (XsdtParser)
-);
-
   Offset = ParseAcpi (
  Trace,
  0,
  "XSDT",
  Ptr,
- *AcpiHdrInfo.Length,
+ AcpiTableLength,
  PARSER_PARAMS (XsdtParser)
  );
 
@@ -84,7 +74,7 @@ ParseAcpiXsdt (
   if (Trace) {
 EntryIndex = 0;
 TablePointer = (UINT64*)(Ptr + TableOffset);
-while (Offset < (*AcpiHdrInfo.Length)) {
+while (Offset < AcpiTableLength) {
   CONST UINT32* Signature;
   CONST UINT32* Length;
   CONST UINT8*  Revision;
@@ -140,7 +130,7 @@ ParseAcpiXsdt (
   // Process the tables
   Offset = TableOffset;
   TablePointer = (UINT64*)(Ptr + TableOffset);
-  while (Offset < (*AcpiHdrInfo.Length)) {
+  while (Offset < AcpiTableLength) {
 if ((UINT64*)(UINTN)(*TablePointer) != NULL) {
   ProcessAcpiTable ((UINT8*)(UINTN)(*TablePointer));
 }
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43936): https://edk2.groups.io/g/devel/message/43936
Mute This Topic: https://groups.io/mt/32514380/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 6/6] ShellPkg: acpiview: IORT: Refactor PMCG node mapping count validation

2019-07-18 Thread Krzysztof Koch
Move Performance Monitoring Counter Group (PMCG) node ID mapping count
validation from the core IORT acpiview parser logic to a dedicated
function. Now, the pointer to the validation function is passed to the
IortNodePmcgParser[] ACPI_PARSER array.

This check does not affect the flow of IORT parsing and is limited to
a single table field in scope, therefore, it is better to keep it away
from the code responsible for traversing the table.

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- refactor PMCG node mapping count validation [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c | 32 
++--
 1 file changed, 23 insertions(+), 9 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c
index 
93f78e1a9786ed53f6b5529f478b72a220b4f8df..4d29ca2818804fb472bec0f632a87cd3c8a7cd48
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c
@@ -47,6 +47,28 @@ ValidateItsIdMappingCount (
   IN VOID*  Context
   );
 
+/**
+  This function validates the ID Mapping array count for the Performance
+  Monitoring Counter Group (PMCG) node.
+
+  @param [in] Ptr Pointer to the start of the field data.
+  @param [in] Context Pointer to context specific information e.g. this
+  could be a pointer to the ACPI table header.
+**/
+STATIC
+VOID
+EFIAPI
+ValidatePmcgIdMappingCount (
+  IN UINT8* Ptr,
+  IN VOID*  Context
+  )
+{
+  if (*(UINT32*)Ptr > 1) {
+IncrementErrorCount ();
+Print (L"\nERROR: IORT ID Mapping count must not be greater than 1.");
+  }
+}
+
 /**
   This function validates the ID Mapping array offset for the ITS node.
 
@@ -204,7 +226,7 @@ STATIC CONST ACPI_PARSER IortNodeRootComplexParser[] = {
   An ACPI_PARSER array describing the IORT PMCG node.
 **/
 STATIC CONST ACPI_PARSER IortNodePmcgParser[] = {
-  PARSE_IORT_NODE_HEADER (NULL, NULL),
+  PARSE_IORT_NODE_HEADER (ValidatePmcgIdMappingCount, NULL),
   {L"Base Address", 8, 16, L"0x%lx", NULL, NULL, NULL, NULL},
   {L"Overflow interrupt GSIV", 4, 24, L"0x%x", NULL, NULL, NULL, NULL},
   {L"Node reference", 4, 28, L"0x%x", NULL, NULL, NULL, NULL},
@@ -567,14 +589,6 @@ DumpIortNodePmcg (
   if (*IortIdMappingCount != 0) {
 DumpIortNodeIdMappings (Ptr, MappingCount, MappingOffset);
   }
-
-  if (*IortIdMappingCount > 1) {
-IncrementErrorCount ();
-Print (
-  L"ERROR: ID mapping must not be greater than 1. Id Mapping Count =%d\n",
-  *IortIdMappingCount
-  );
-  }
 }
 
 /**
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43940): https://edk2.groups.io/g/devel/message/43940
Mute This Topic: https://groups.io/mt/32514387/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 5/6] ShellPkg: acpiview: MADT: Split structure length validation

2019-07-18 Thread Krzysztof Koch
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 
---

Notes:
v1:
- split MADT structure length validation [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c | 30 
++--
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c
index 
59c3df0cc8a080497b517baf36fc63f1e4ab866f..52b71f37a40733de2029373306658ca08c78c42d
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c
@@ -290,16 +290,30 @@ ParseAcpiMadt (
   PARSER_PARAMS (MadtInterruptControllerHeaderParser)
   );
 
-if (((Offset + (*MadtInterruptControllerLength)) > AcpiTableLength) ||
-(*MadtInterruptControllerLength < 4)) {
+// Make sure forward progress is made.
+if (*MadtInterruptControllerLength < 2) {
   IncrementErrorCount ();
   Print (
- L"ERROR: Invalid Interrupt Controller Length,"
-  L" Type = %d, Length = %d\n",
- *MadtInterruptControllerType,
- *MadtInterruptControllerLength
- );
-  break;
+L"ERROR: Structure length is too small: " \
+  L"MadtInterruptControllerLength = %d. " \
+  L"MadtInterruptControllerType = %d. MADT parsing aborted.\n",
+*MadtInterruptControllerLength,
+*MadtInterruptControllerType
+);
+  return;
+}
+
+// Make sure the MADT structure lies inside the table
+if ((Offset + *MadtInterruptControllerLength) > AcpiTableLength) {
+  IncrementErrorCount ();
+  Print (
+L"ERROR: Invalid MADT structure length. " \
+  L"MadtInterruptControllerLength = %d. " \
+  L"RemainingTableBufferLength = %d. MADT parsing aborted.\n",
+*MadtInterruptControllerLength,
+AcpiTableLength - Offset
+);
+  return;
 }
 
 switch (*MadtInterruptControllerType) {
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43939): https://edk2.groups.io/g/devel/message/43939
Mute This Topic: https://groups.io/mt/32514386/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 4/6] ShellPkg: acpiview: SRAT: Minor code style enhancements

2019-07-18 Thread Krzysztof Koch
Minor changes to the SRAT parser code to conform with the EDKII coding
style and to make it consistent with other ACPI table parsers.

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- minor code style enhancements [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
index 
075ff2a141a82b522e8aaedb7ad79249aaf5eaac..d0011ca65c17788c5e2f2225380854e780fb
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
@@ -234,6 +234,7 @@ ParseAcpiSrat (
  AcpiTableLength,
  PARSER_PARAMS (SratParser)
  );
+
   ResourcePtr = Ptr + Offset;
 
   while (Offset < AcpiTableLength) {
@@ -278,7 +279,7 @@ ParseAcpiSrat (
   ResourcePtr,
   *SratRALength,
   PARSER_PARAMS (SratGicITSAffinityParser)
-);
+  );
 break;
 
   case EFI_ACPI_6_2_MEMORY_AFFINITY:
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43938): https://edk2.groups.io/g/devel/message/43938
Mute This Topic: https://groups.io/mt/32514385/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH v1 1/6] ShellPkg: acpiview: Allow passing buffer length to DumpGasStruct()

2019-07-19 Thread Krzysztof Koch
Hi Zhichao,

Sorry about private emails, I just mistakenly hit the wrong button. I forgot 
that the emails do not get sent to the mailing list unless I hit 'Reply all' 
(silly mistake).

I see your point. I will submit v2 of this patchset with:
> DumpGasStruct (DataPtr, 4, *DbgDevInfoLen);
Replaced with
> DumpGasStruct (DataPtr, 4, GAS_LENGTH);

Is that ok?

Kind regards,

Krzysztof


-Original Message-
From: Gao, Zhichao  
Sent: Friday, July 19, 2019 9:09
To: Krzysztof Koch 
Subject: RE: [PATCH v1 1/6] ShellPkg: acpiview: Allow passing buffer length to 
DumpGasStruct()

HI Krzysztof,

Why do you send the email to me only? I think it is fine to send to the 
community. It would let more people who are interest with this component join 
the discuss. Maybe not . :(

Then for your comments:
Sorry,  I missed the commit message before. But I don't think keeping an 
inappropriate code with a commit massage to explain that is OK. If you have a 
plan to fix that, it should combine into one patch.
Back to the code, I don't find out the possibility of overrun of buffer when 
use 'GAS_LENGTH'. And DataPtr + * DbgDevInfoLen definitely overflow.
DevInfoPtr DataPtr  
 EndDevInfoPtr
---|---|--|
 |<-- DbgDevInfoLen -> |

Thanks,
Zhichao

> -Original Message-
> From: Krzysztof Koch [mailto:krzysztof.k...@arm.com]
> Sent: Friday, July 19, 2019 3:39 PM
> To: Gao, Zhichao 
> Subject: RE: [PATCH v1 1/6] ShellPkg: acpiview: Allow passing buffer 
> length to
> DumpGasStruct()
> 
> Hi Zhichao,
> 
> Please see my comments inline marked as [Krzysztof]
> 
> Kind regards,
> 
> Krzysztof
> 
> -Original Message-
> From: Gao, Zhichao 
> Sent: Friday, July 19, 2019 2:15
> To: Krzysztof Koch ; devel@edk2.groups.io
> Cc: Carsey, Jaben ; Ni, Ray 
> ; Sami Mujawar ; Matteo 
> Carlini ; nd 
> Subject: RE: [PATCH v1 1/6] ShellPkg: acpiview: Allow passing buffer 
> length to
> DumpGasStruct()
> 
> 
> 
> > -Original Message-
> > From: Krzysztof Koch [mailto:krzysztof.k...@arm.com]
> > Sent: Thursday, July 18, 2019 8:32 PM
> > To: devel@edk2.groups.io
> > Cc: Carsey, Jaben ; Ni, Ray 
> > ; Gao, Zhichao ; 
> > sami.muja...@arm.com; matteo.carl...@arm.com; n...@arm.com
> > Subject: [PATCH v1 1/6] ShellPkg: acpiview: Allow passing buffer 
> > length to
> > DumpGasStruct()
> >
> > Modify the signature of the DumpGasStruct() function to include the 
> > buffer length parameter and to return the number of bytes parsed by 
> > the
> function.
> >
> > This way it becomes possible to prevent buffer overruns when dumping 
> > Generic Address Structure's (GAS) fields in the acpiview table parsers.
> >
> > Update all existing DumpGasStruct() calls in acpiview to add the 
> > length argument.
> >
> > Signed-off-by: Krzysztof Koch 
> > ---
> >
> > Notes:
> > v1:
> > - Modify DumpGasStruct() signature [Krzysztof]
> >
> >  ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c  | 26
> > +++-
> >  ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h  |  8
> > --
> >
> >
> ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
> > |  2 +-
> >  3 files changed, 22 insertions(+), 14 deletions(-)
> >
> > diff --git 
> > a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
> > b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
> > index
> >
> 8b3153516d2b7d9b920ab2de0344c17798ac572c..2d6ff80e299eebe7853061d3
> > db89332197c0dc0e 100644
> > --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
> > +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
> > @@ -589,23 +589,27 @@ STATIC CONST ACPI_PARSER GasParser[] = {
> >
> >@param [in] Ptr Pointer to the start of the buffer.
> >@param [in] Indent  Number of spaces to indent the output.
> > +  @param [in] Length  Length of the GAS structure buffer.
> > +
> > +  @retval Number of bytes parsed.
> >  **/
> > -VOID
> > +UINT32
> >  EFIAPI
> >  DumpGasStruct (
> >IN UINT8*Ptr,
> > -  IN UINT32Indent
> > +  IN UINT32Indent,
> > +  IN UINT32Length
> >)
> >  {
> >Print (L"\n");
> > -  ParseAcpi (
> > -TRUE,
> > -Indent,
> > -NULL,
> > -Ptr,
> > -GAS_LENGTH,
> > -PARS

[edk2-devel] [PATCH v2 2/6] ShellPkg: acpiview: XSDT: Remove redundant ParseAcpi() call

2019-07-22 Thread Krzysztof Koch
Remove a call to ParseAcpi() responsible for getting the XSDT table
length. This call is not needed because the ACPI table buffer length is
provided as an input argument to the ParseAcpiXsdt() function.

Modify remaining code to use the AcpiTableLength argument of the
ParseAcpiXsdt() function instead of a global static variable.

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- remove redundant ParseAcpi() call [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c | 18 
--
 1 file changed, 4 insertions(+), 14 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c
index 
4196168bff47d70c67f79f3fc1f4cdee302d460e..e39061f8e2612f2cce4aebf51a511b63b703662b
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c
@@ -1,7 +1,7 @@
 /** @file
   XSDT table parser
 
-  Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
+  Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
   @par Reference(s):
@@ -60,22 +60,12 @@ ParseAcpiXsdt (
   UINTN EntryIndex;
   CHAR16Buffer[32];
 
-  // Parse the ACPI header to get the length
-  ParseAcpi (
-FALSE,
-0,
-"XSDT",
-Ptr,
-ACPI_DESCRIPTION_HEADER_LENGTH,
-PARSER_PARAMS (XsdtParser)
-);
-
   Offset = ParseAcpi (
  Trace,
  0,
  "XSDT",
  Ptr,
- *AcpiHdrInfo.Length,
+ AcpiTableLength,
  PARSER_PARAMS (XsdtParser)
  );
 
@@ -84,7 +74,7 @@ ParseAcpiXsdt (
   if (Trace) {
 EntryIndex = 0;
 TablePointer = (UINT64*)(Ptr + TableOffset);
-while (Offset < (*AcpiHdrInfo.Length)) {
+while (Offset < AcpiTableLength) {
   CONST UINT32* Signature;
   CONST UINT32* Length;
   CONST UINT8*  Revision;
@@ -140,7 +130,7 @@ ParseAcpiXsdt (
   // Process the tables
   Offset = TableOffset;
   TablePointer = (UINT64*)(Ptr + TableOffset);
-  while (Offset < (*AcpiHdrInfo.Length)) {
+  while (Offset < AcpiTableLength) {
 if ((UINT64*)(UINTN)(*TablePointer) != NULL) {
   ProcessAcpiTable ((UINT8*)(UINTN)(*TablePointer));
 }
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#44107): https://edk2.groups.io/g/devel/message/44107
Mute This Topic: https://groups.io/mt/32556316/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v2 1/6] ShellPkg: acpiview: Allow passing buffer length to DumpGasStruct()

2019-07-22 Thread Krzysztof Koch
Modify the signature of the DumpGasStruct() function to include the
buffer length parameter and to return the number of bytes parsed by
the function.

This way it becomes possible to prevent buffer overruns when dumping
Generic Address Structure's (GAS) fields in the acpiview table
parsers.

Update all existing DumpGasStruct() calls in acpiview to add the
length argument.

Signed-off-by: Krzysztof Koch 
---

Notes:
v2:
- Pass GAS_LENGTH to DumpGasStruct() in DBG2 parser [Zhichao]

v1:
- Modify DumpGasStruct() signature [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c  | 26 
+++-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h  |  8 
--
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c |  2 +-
 3 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
index 
8b3153516d2b7d9b920ab2de0344c17798ac572c..2d6ff80e299eebe7853061d3db89332197c0dc0e
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
@@ -589,23 +589,27 @@ STATIC CONST ACPI_PARSER GasParser[] = {
 
   @param [in] Ptr Pointer to the start of the buffer.
   @param [in] Indent  Number of spaces to indent the output.
+  @param [in] Length  Length of the GAS structure buffer.
+
+  @retval Number of bytes parsed.
 **/
-VOID
+UINT32
 EFIAPI
 DumpGasStruct (
   IN UINT8*Ptr,
-  IN UINT32Indent
+  IN UINT32Indent,
+  IN UINT32Length
   )
 {
   Print (L"\n");
-  ParseAcpi (
-TRUE,
-Indent,
-NULL,
-Ptr,
-GAS_LENGTH,
-PARSER_PARAMS (GasParser)
-);
+  return ParseAcpi (
+   TRUE,
+   Indent,
+   NULL,
+   Ptr,
+   Length,
+   PARSER_PARAMS (GasParser)
+   );
 }
 
 /**
@@ -621,7 +625,7 @@ DumpGas (
   IN UINT8*Ptr
   )
 {
-  DumpGasStruct (Ptr, 2);
+  DumpGasStruct (Ptr, 2, GAS_LENGTH);
 }
 
 /**
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
index 
7657892d9fd2e2e14c6578611ff0cf1b6f6cd750..20ca358bddfa5953bfb1d1bebaebbf3079eaba01
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
@@ -405,12 +405,16 @@ ParseAcpi (
 
   @param [in] Ptr Pointer to the start of the buffer.
   @param [in] Indent  Number of spaces to indent the output.
+  @param [in] Length  Length of the GAS structure buffer.
+
+  @retval Number of bytes parsed.
 **/
-VOID
+UINT32
 EFIAPI
 DumpGasStruct (
   IN UINT8*Ptr,
-  IN UINT32Indent
+  IN UINT32Indent,
+  IN UINT32Length
   );
 
 /**
diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
index 
1efcbd40f86efdabed2152540a415db8a950fb71..c6929695a1032c57761ef85002d6c51b7800ce23
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
@@ -134,7 +134,7 @@ DumpDbgDeviceInfo (
   AddrSize = (UINT32*)(Ptr + (*AddrSizeOffset));
   while (Index < (*GasCount)) {
 PrintFieldName (4, L"BaseAddressRegister");
-DumpGasStruct (DataPtr, 4);
+DumpGasStruct (DataPtr, 4, GAS_LENGTH);
 PrintFieldName (4, L"Address Size");
 Print (L"0x%x\n", AddrSize[Index]);
 DataPtr += GAS_LENGTH;
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#44109): https://edk2.groups.io/g/devel/message/44109
Mute This Topic: https://groups.io/mt/32556318/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v2 3/6] ShellPkg: acpiview: RSDP: Make code consistent with other parsers

2019-07-22 Thread Krzysztof Koch
List ParseAcpi() function arguments one per line in order to make this
function call consistent with ParseAcpi() calls in other ACPI table
parsers.

Also, notify the user that XsdtAddress value of 0 results in RSDP
parsing being terminated and that the XSDT table will not be processed.

This effectively means that no more ACPI tables will be parsed because
of this RSDP table content error.

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- minor code style enhancements [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c | 11 
+--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c
index 
4bf928139a507d0b8f203ed0cbf0863cc2ec5de5..5a5c4b50c12e6eb0aa0efb1765df7e123f614da3
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c
@@ -129,7 +129,14 @@ ParseAcpiRsdp (
 VerifyChecksum (TRUE, Ptr, AcpiTableLength);
   }
 
-  ParseAcpi (Trace, 0, "RSDP", Ptr, AcpiTableLength, PARSER_PARAMS 
(RsdpParser));
+  ParseAcpi (
+Trace,
+0,
+"RSDP",
+Ptr,
+AcpiTableLength,
+PARSER_PARAMS (RsdpParser)
+);
 
   // This code currently supports parsing of XSDT table only
   // and does not parse the RSDT table. Platforms provide the
@@ -137,7 +144,7 @@ ParseAcpiRsdp (
   // Therefore the RSDT should not be used on ARM platforms.
   if ((*XsdtAddress) == 0) {
 IncrementErrorCount ();
-Print (L"ERROR: XSDT Pointer is not set.\n");
+Print (L"ERROR: XSDT Pointer is not set. RSDP parsing aborted.\n");
 return;
   }
 
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#44110): https://edk2.groups.io/g/devel/message/44110
Mute This Topic: https://groups.io/mt/32556319/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v2 0/6] Acpiview table parsers code style enhancements and refactoring

2019-07-22 Thread Krzysztof Koch
This set of patches consists of a number of changes which make the code
structure consistent across the existing ACPI table parsers. These are
all refactoring changes which do not modify the existing functionality
of the acpiview UEFI shell tool.

Changes can be seen at: 
https://github.com/KrzysztofKoch1/edk2/tree/612_acpiview_code_style_enhance_v2

Krzysztof Koch (6):
  ShellPkg: acpiview: Allow passing buffer length to DumpGasStruct()
  ShellPkg: acpiview: XSDT: Remove redundant ParseAcpi() call
  ShellPkg: acpiview: RSDP: Make code consistent with other parsers
  ShellPkg: acpiview: SRAT: Minor code style enhancements
  ShellPkg: acpiview: MADT: Split structure length validation
  ShellPkg: acpiview: IORT: Refactor PMCG node mapping count validation

 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c  | 26 
+---
 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h  |  8 
+++--
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c |  2 +-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c | 32 
++--
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c | 30 
+-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c | 11 
+--
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c |  3 +-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c | 18 
+++
 8 files changed, 82 insertions(+), 48 deletions(-)

--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#44108): https://edk2.groups.io/g/devel/message/44108
Mute This Topic: https://groups.io/mt/32556317/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v2 6/6] ShellPkg: acpiview: IORT: Refactor PMCG node mapping count validation

2019-07-22 Thread Krzysztof Koch
Move Performance Monitoring Counter Group (PMCG) node ID mapping count
validation from the core IORT acpiview parser logic to a dedicated
function. Now, the pointer to the validation function is passed to the
IortNodePmcgParser[] ACPI_PARSER array.

This check does not affect the flow of IORT parsing and is limited to
a single table field in scope, therefore, it is better to keep it away
from the code responsible for traversing the table.

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- refactor PMCG node mapping count validation [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c | 32 
++--
 1 file changed, 23 insertions(+), 9 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c
index 
0461205b4f8bc02aa11ab1db1d0deb73bce053b7..7c850b3813d5204775e2cc247cabf42358b25769
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c
@@ -53,6 +53,28 @@ ValidateItsIdMappingCount (
   }
 }
 
+/**
+  This function validates the ID Mapping array count for the Performance
+  Monitoring Counter Group (PMCG) node.
+
+  @param [in] Ptr Pointer to the start of the field data.
+  @param [in] Context Pointer to context specific information e.g. this
+  could be a pointer to the ACPI table header.
+**/
+STATIC
+VOID
+EFIAPI
+ValidatePmcgIdMappingCount (
+  IN UINT8* Ptr,
+  IN VOID*  Context
+  )
+{
+  if (*(UINT32*)Ptr > 1) {
+IncrementErrorCount ();
+Print (L"\nERROR: IORT ID Mapping count must not be greater than 1.");
+  }
+}
+
 /**
   This function validates the ID Mapping array offset for the ITS node.
 
@@ -216,7 +238,7 @@ STATIC CONST ACPI_PARSER IortNodeRootComplexParser[] = {
   An ACPI_PARSER array describing the IORT PMCG node.
 **/
 STATIC CONST ACPI_PARSER IortNodePmcgParser[] = {
-  PARSE_IORT_NODE_HEADER (NULL, NULL),
+  PARSE_IORT_NODE_HEADER (ValidatePmcgIdMappingCount, NULL),
   {L"Base Address", 8, 16, L"0x%lx", NULL, NULL, NULL, NULL},
   {L"Overflow interrupt GSIV", 4, 24, L"0x%x", NULL, NULL, NULL, NULL},
   {L"Node reference", 4, 28, L"0x%x", NULL, NULL, NULL, NULL},
@@ -537,14 +559,6 @@ DumpIortNodePmcg (
   if (*IortIdMappingCount != 0) {
 DumpIortNodeIdMappings (Ptr, MappingCount, MappingOffset);
   }
-
-  if (*IortIdMappingCount > 1) {
-IncrementErrorCount ();
-Print (
-  L"ERROR: ID mapping must not be greater than 1. Id Mapping Count =%d\n",
-  *IortIdMappingCount
-  );
-  }
 }
 
 /**
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#44111): https://edk2.groups.io/g/devel/message/44111
Mute This Topic: https://groups.io/mt/32556344/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v2 4/6] ShellPkg: acpiview: SRAT: Minor code style enhancements

2019-07-22 Thread Krzysztof Koch
Minor changes to the SRAT parser code to conform with the EDKII coding
style and to make it consistent with other ACPI table parsers.

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- minor code style enhancements [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
index 
03d28d52842040e4872e204fc10ae3dba7861936..59c77401eaab32b73a9f83fd4d63785221b3c222
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
@@ -206,6 +206,7 @@ ParseAcpiSrat (
  AcpiTableLength,
  PARSER_PARAMS (SratParser)
  );
+
   ResourcePtr = Ptr + Offset;
 
   while (Offset < AcpiTableLength) {
@@ -250,7 +251,7 @@ ParseAcpiSrat (
   ResourcePtr,
   *SratRALength,
   PARSER_PARAMS (SratGicITSAffinityParser)
-);
+  );
 break;
 
   case EFI_ACPI_6_2_MEMORY_AFFINITY:
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#44112): https://edk2.groups.io/g/devel/message/44112
Mute This Topic: https://groups.io/mt/32556345/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v2 5/6] ShellPkg: acpiview: MADT: Split structure length validation

2019-07-22 Thread Krzysztof Koch
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 
---

Notes:
v1:
- split MADT structure length validation [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c | 30 
++--
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c
index 
338295d30e35c366a60505225cf57145a8e73d93..d80ebd1a2bae7a4acffe687ca5ee7b4090f0e223
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c
@@ -260,16 +260,30 @@ ParseAcpiMadt (
   PARSER_PARAMS (MadtInterruptControllerHeaderParser)
   );
 
-if (((Offset + (*MadtInterruptControllerLength)) > AcpiTableLength) ||
-(*MadtInterruptControllerLength < 4)) {
+// Make sure forward progress is made.
+if (*MadtInterruptControllerLength < 2) {
   IncrementErrorCount ();
   Print (
- L"ERROR: Invalid Interrupt Controller Length,"
-  L" Type = %d, Length = %d\n",
- *MadtInterruptControllerType,
- *MadtInterruptControllerLength
- );
-  break;
+L"ERROR: Structure length is too small: " \
+  L"MadtInterruptControllerLength = %d. " \
+  L"MadtInterruptControllerType = %d. MADT parsing aborted.\n",
+*MadtInterruptControllerLength,
+*MadtInterruptControllerType
+);
+  return;
+}
+
+// Make sure the MADT structure lies inside the table
+if ((Offset + *MadtInterruptControllerLength) > AcpiTableLength) {
+  IncrementErrorCount ();
+  Print (
+L"ERROR: Invalid MADT structure length. " \
+  L"MadtInterruptControllerLength = %d. " \
+  L"RemainingTableBufferLength = %d. MADT parsing aborted.\n",
+*MadtInterruptControllerLength,
+AcpiTableLength - Offset
+);
+  return;
 }
 
 switch (*MadtInterruptControllerType) {
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#44113): https://edk2.groups.io/g/devel/message/44113
Mute This Topic: https://groups.io/mt/32556349/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH v2 0/6] Acpiview table parsers code style enhancements and refactoring

2019-07-22 Thread Krzysztof Koch
Hi Everyone,

Just to let you know, only "ShellPkg: acpiview: Allow passing buffer length to 
DumpGasStruct()" is changed compared to v1. I had a wrong understanding of how 
to post revised patches to the upstream community.

Kind regards,

Krzysztof

-Original Message-
From: devel@edk2.groups.io  On Behalf Of Krzysztof Koch 
via Groups.Io
Sent: Monday, July 22, 2019 8:50
To: devel@edk2.groups.io
Cc: jaben.car...@intel.com; ray...@intel.com; zhichao@intel.com; Sami 
Mujawar ; Matteo Carlini ; nd 

Subject: [edk2-devel] [PATCH v2 0/6] Acpiview table parsers code style 
enhancements and refactoring

This set of patches consists of a number of changes which make the code 
structure consistent across the existing ACPI table parsers. These are all 
refactoring changes which do not modify the existing functionality of the 
acpiview UEFI shell tool.

Changes can be seen at: 
https://github.com/KrzysztofKoch1/edk2/tree/612_acpiview_code_style_enhance_v2

Krzysztof Koch (6):
  ShellPkg: acpiview: Allow passing buffer length to DumpGasStruct()
  ShellPkg: acpiview: XSDT: Remove redundant ParseAcpi() call
  ShellPkg: acpiview: RSDP: Make code consistent with other parsers
  ShellPkg: acpiview: SRAT: Minor code style enhancements
  ShellPkg: acpiview: MADT: Split structure length validation
  ShellPkg: acpiview: IORT: Refactor PMCG node mapping count validation

 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c  | 26 
+---
 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h  |  8 
+++--
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c |  2 +- 
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c | 32 
++--  
ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c | 30 
+-  
ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c | 11 
+--  ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c 
|  3 +-  ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c 
| 18 +++
 8 files changed, 82 insertions(+), 48 deletions(-)

--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'






-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#44119): https://edk2.groups.io/g/devel/message/44119
Mute This Topic: https://groups.io/mt/32556317/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH v2 0/6] Acpiview table parsers code style enhancements and refactoring

2019-07-26 Thread Krzysztof Koch
Hi,

Is there any way I can help get this patch merged? I have a couple of small 
patch sets ready to submit but they are pending on this series. 

These small sets of patches are a result of me breaking down the "[PATCH v1 
00/11] Add security checks in the Acpiview table parsers" series into smaller 
functional units as requested in the review comments.

Kind regards,

Krzysztof

-Original Message-
From: Sami Mujawar  
Sent: Tuesday, July 23, 2019 10:57
To: Krzysztof Koch ; devel@edk2.groups.io
Cc: jaben.car...@intel.com; ray...@intel.com; zhichao@intel.com; nd 

Subject: RE: [edk2-devel] [PATCH v2 0/6] Acpiview table parsers code style 
enhancements and refactoring

Reviewed-by: Sami Mujawar 

-Original Message-----
From: Krzysztof Koch  
Sent: 22 July 2019 09:25 AM
To: devel@edk2.groups.io; Krzysztof Koch 
Cc: jaben.car...@intel.com; ray...@intel.com; zhichao@intel.com; Sami 
Mujawar ; nd 
Subject: RE: [edk2-devel] [PATCH v2 0/6] Acpiview table parsers code style 
enhancements and refactoring

Hi Everyone,

Just to let you know, only "ShellPkg: acpiview: Allow passing buffer length to 
DumpGasStruct()" is changed compared to v1. I had a wrong understanding of how 
to post revised patches to the upstream community.

Kind regards,

Krzysztof

-Original Message-
From: devel@edk2.groups.io  On Behalf Of Krzysztof Koch 
via Groups.Io
Sent: Monday, July 22, 2019 8:50
To: devel@edk2.groups.io
Cc: jaben.car...@intel.com; ray...@intel.com; zhichao@intel.com; Sami 
Mujawar ; Matteo Carlini ; nd 

Subject: [edk2-devel] [PATCH v2 0/6] Acpiview table parsers code style 
enhancements and refactoring

This set of patches consists of a number of changes which make the code 
structure consistent across the existing ACPI table parsers. These are all 
refactoring changes which do not modify the existing functionality of the 
acpiview UEFI shell tool.

Changes can be seen at: 
https://github.com/KrzysztofKoch1/edk2/tree/612_acpiview_code_style_enhance_v2

Krzysztof Koch (6):
  ShellPkg: acpiview: Allow passing buffer length to DumpGasStruct()
  ShellPkg: acpiview: XSDT: Remove redundant ParseAcpi() call
  ShellPkg: acpiview: RSDP: Make code consistent with other parsers
  ShellPkg: acpiview: SRAT: Minor code style enhancements
  ShellPkg: acpiview: MADT: Split structure length validation
  ShellPkg: acpiview: IORT: Refactor PMCG node mapping count validation

 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c  | 26 
+---
 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h  |  8 
+++--
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c |  2 +- 
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c | 32 
++--  
ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c | 30 
+-  
ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c | 11 
+--  ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c 
|  3 +-  ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c 
| 18 +++
 8 files changed, 82 insertions(+), 48 deletions(-)

--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'






-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#44463): https://edk2.groups.io/g/devel/message/44463
Mute This Topic: https://groups.io/mt/32556317/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 0/6] Prevent buffer overruns in acpiview table parsers

2019-08-01 Thread Krzysztof Koch
This patch series makes minor modifications to a number of ACPI table
parsers with a goal to minimize the risk of buffer overruns. Some of
these overruns can be caused by invalid ACPI table data.

Changes can be seet at: 
https://github.com/KrzysztofKoch1/edk2/tree/612_prevent_buffer_overruns_v1

Krzysztof Koch (6):
  ShellPkg: acpiview: DBG2: Prevent buffer overruns
  ShellPkg: acpiview: GTDT: Prevent buffer overruns
  ShellPkg: acpiview: IORT: Prevent buffer overruns
  ShellPkg: acpiview: MADT: Prevent buffer overruns
  ShellPkg: acpiview: PPTT: Prevent buffer overruns
  ShellPkg: acpiview: SRAT: Prevent buffer overruns

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c | 141 
++-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c | 147 
+++
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c | 191 
+++-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c |   2 +-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c |  38 
++--
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c |  14 +-
 6 files changed, 314 insertions(+), 219 deletions(-)

--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#44752): https://edk2.groups.io/g/devel/message/44752
Mute This Topic: https://groups.io/mt/32676829/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 2/6] ShellPkg: acpiview: GTDT: Prevent buffer overruns

2019-08-01 Thread Krzysztof Koch
Modify the GTDT table parsing logic to prevent reading past the ACPI
buffer lengths provided and to make it consistent with other table
parsers. This includes converting the do-while loop in ParseAcpiGtdt()
into a while loop.

Remove a check which ensures that the entire Platform GT Block
Structure buffer has been parsed. The ACPI specification does not ban
from defining buffers which are larger than the size indicated by the
count and sizes of substructures which constitute it.

Change the data type of the Length parameter to the DumpGTBlock()
function to reflect the width of the respective ACPI structure's
field.

References:
- ACPI 6.3, January 2019, Table 5-124

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- Prevent buffer overruns in GTDT acpiview parser [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c | 147 
++--
 1 file changed, 76 insertions(+), 71 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c
index 
1e5b5764f50a2d29aa904c889bc89af5bdc3af5c..57174e14c80072f12b90e1996ebe8f0002d0c404
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c
@@ -23,7 +23,6 @@ STATIC CONST UINT8*  PlatformTimerType;
 STATIC CONST UINT16* PlatformTimerLength;
 STATIC CONST UINT32* GtBlockTimerCount;
 STATIC CONST UINT32* GtBlockTimerOffset;
-STATIC CONST UINT16* GtBlockLength;
 STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
 
 /**
@@ -127,7 +126,7 @@ STATIC CONST ACPI_PARSER GtPlatformTimerHeaderParser[] = {
 **/
 STATIC CONST ACPI_PARSER GtBlockParser[] = {
   {L"Type", 1, 0, L"%d", NULL, NULL, NULL, NULL},
-  {L"Length", 2, 1, L"%d", NULL, (VOID**)&GtBlockLength, NULL, NULL},
+  {L"Length", 2, 1, L"%d", NULL, NULL, NULL, NULL},
   {L"Reserved", 1, 3, L"%x", NULL, NULL, NULL, NULL},
   {L"Physical address (CntCtlBase)", 8, 4, L"0x%lx", NULL, NULL, NULL, NULL},
   {L"Timer Count", 4, 12, L"%d", NULL, (VOID**)&GtBlockTimerCount,
@@ -168,56 +167,43 @@ STATIC CONST ACPI_PARSER SBSAGenericWatchdogParser[] = {
 /**
   This function parses the Platform GT Block.
 
-  @param [in] Ptr Pointer to the start of the GT Block data.
-  @param [in] Length  Length of the GT Block structure.
+  @param [in] Ptr   Pointer to the start of the GT Block data.
+  @param [in] LengthLength of the GT Block structure.
 **/
 STATIC
 VOID
 DumpGTBlock (
   IN UINT8* Ptr,
-  IN UINT32 Length
+  IN UINT16 Length
   )
 {
   UINT32 Index;
   UINT32 Offset;
-  UINT32 GTBlockTimerLength;
 
-  Offset = ParseAcpi (
- TRUE,
- 2,
- "GT Block",
- Ptr,
- Length,
- PARSER_PARAMS (GtBlockParser)
- );
-  GTBlockTimerLength = (*GtBlockLength - Offset) / (*GtBlockTimerCount);
-  Length -= Offset;
+  ParseAcpi (
+TRUE,
+2,
+"GT Block",
+Ptr,
+Length,
+PARSER_PARAMS (GtBlockParser)
+);
 
-  if (*GtBlockTimerCount != 0) {
-Ptr += (*GtBlockTimerOffset);
-Index = 0;
-while ((Index < (*GtBlockTimerCount)) && (Length >= GTBlockTimerLength)) {
-  Offset = ParseAcpi (
- TRUE,
- 2,
- "GT Block Timer",
- Ptr,
- GTBlockTimerLength,
- PARSER_PARAMS (GtBlockTimerParser)
- );
-  // Increment by GT Block Timer structure size
-  Ptr += Offset;
-  Length -= Offset;
-  Index++;
-}
+  Offset = *GtBlockTimerOffset;
+  Index = 0;
 
-if (Length != 0) {
-  IncrementErrorCount ();
-  Print (
-L"ERROR:GT Block Timer length mismatch. Unparsed %d bytes.\n",
-Length
-);
-}
+  // Parse the specified number of GT Block Timer Structures or the GT Block
+  // Structure buffer length. Whichever is minimum.
+  while ((Index++ < *GtBlockTimerCount) &&
+ (Offset < Length)) {
+Offset += ParseAcpi (
+TRUE,
+2,
+"GT Block Timer",
+Ptr + Offset,
+Length - Offset,
+PARSER_PARAMS (GtBlockTimerParser)
+);
   }
 }
 
@@ -270,6 +256,7 @@ ParseAcpiGtdt (
   )
 {
   UINT32 Index;
+  UINT32 Offset;
   UINT8* TimerPtr;
 
   if (!Trace) {
@@ -285,36 +272,54 @@ ParseAcpiGtdt (
 PARSER_PARAMS (GtdtParser)
 );
 
-  if (*GtdtPlatformTimerCount != 0) {
-TimerPtr = Ptr + (*GtdtPlatformTimerOffset);
-Index = 0;
-do {
-  // Parse the Platform Timer Header
-  ParseAcpi (
-FALSE,
-0,
-NULL,
-TimerPtr,
-4,  // GT Platform Timer st

[edk2-devel] [PATCH v1 4/6] ShellPkg: acpiview: MADT: Prevent buffer overruns

2019-08-01 Thread Krzysztof Koch
Modify the parsing logic to prevent reading past the MADT table buffer
length provided when parsing the Interrupt Controller Structure header.

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- Prevent buffer overruns in MADT acpiview parser [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c
index 
d80ebd1a2bae7a4acffe687ca5ee7b4090f0e223..90bdafea1970db522e8ed96de7c6e986cdaca5ba
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c
@@ -256,7 +256,7 @@ ParseAcpiMadt (
   0,
   NULL,
   InterruptContollerPtr,
-  2,  //  Length is 1 byte at offset 1
+  AcpiTableLength - Offset,
   PARSER_PARAMS (MadtInterruptControllerHeaderParser)
   );
 
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#44755): https://edk2.groups.io/g/devel/message/44755
Mute This Topic: https://groups.io/mt/32676839/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 1/6] ShellPkg: acpiview: DBG2: Prevent buffer overruns

2019-08-01 Thread Krzysztof Koch
Modify the DBG2 table parsing logic to prevent reading past the ACPI
buffer lengths provided.

Modify the signature of the DumpDbgDeviceInfo() function to make it
consistent with the ACPI structure processing functions in other
acpiview parsers. Now, the length of the Debug Device Information
Structure is read before the entire structure is dumped.

This refactoring change makes it easier to stop reading beyond the
DBG2 table buffer if the Debug Device Information Structure Buffer
does not fit in the DBG2 buffer.

For processing the first two fields of the Debug Device Information
Structure (to get the length) a new ACPI_PARSER array is defined.

References:
- Microsoft Debug Port Table 2 (DBG2), December 10, 2015

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- Prevent buffer overruns in DBG2 acpiview parser [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c | 141 
+---
 1 file changed, 92 insertions(+), 49 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
index 
c6929695a1032c57761ef85002d6c51b7800ce23..869e700b9beda4886bf7bc5ae4ced3ab9a59efa3
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
@@ -64,10 +64,17 @@ STATIC CONST ACPI_PARSER Dbg2Parser[] = {
(VOID**)&NumberDbgDeviceInfo, NULL, NULL}
 };
 
+/// An ACPI_PARSER array describing the debug device information structure
+/// header.
+STATIC CONST ACPI_PARSER DbgDevInfoHeaderParser[] = {
+  {L"Revision", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},
+  {L"Length", 2, 1, L"%d", NULL, (VOID**)&DbgDevInfoLen, NULL, NULL}
+};
+
 /// An ACPI_PARSER array describing the debug device information.
 STATIC CONST ACPI_PARSER DbgDevInfoParser[] = {
   {L"Revision", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},
-  {L"Length", 2, 1, L"%d", NULL, (VOID**)&DbgDevInfoLen, NULL, NULL},
+  {L"Length", 2, 1, L"%d", NULL, NULL, NULL, NULL},
 
   {L"Generic Address Registers Count", 1, 3, L"0x%x", NULL,
(VOID**)&GasCount, NULL, NULL},
@@ -93,76 +100,91 @@ STATIC CONST ACPI_PARSER DbgDevInfoParser[] = {
 /**
   This function parses the debug device information structure.
 
-  @param [in]  Ptr Pointer to the start of the buffer.
-  @param [out] Length  Pointer in which the length of the debug
-   device information is returned.
+  @param [in] Ptr Pointer to the start of the buffer.
+  @param [in] Length  Length of the debug device information structure.
 **/
 STATIC
 VOID
 EFIAPI
 DumpDbgDeviceInfo (
-  IN  UINT8*  Ptr,
-  OUT UINT32* Length
+  IN UINT8* Ptr,
+  IN UINT16 Length
   )
 {
   UINT16  Index;
-  UINT8*  DataPtr;
-  UINT32* AddrSize;
-
-  // Parse the debug device info to get the Length
-  ParseAcpi (
-FALSE,
-0,
-"Debug Device Info",
-Ptr,
-3,  // Length is 2 bytes starting at offset 1
-PARSER_PARAMS (DbgDevInfoParser)
-);
+  UINT16  Offset;
 
   ParseAcpi (
 TRUE,
 2,
 "Debug Device Info",
 Ptr,
-*DbgDevInfoLen,
+Length,
 PARSER_PARAMS (DbgDevInfoParser)
 );
 
-  // GAS and Address Size
+  // GAS
   Index = 0;
-  DataPtr = Ptr + (*BaseAddrRegOffset);
-  AddrSize = (UINT32*)(Ptr + (*AddrSizeOffset));
-  while (Index < (*GasCount)) {
+  Offset = *BaseAddrRegOffset;
+  while ((Index++ < *GasCount) &&
+ (Offset < Length)) {
 PrintFieldName (4, L"BaseAddressRegister");
-DumpGasStruct (DataPtr, 4, GAS_LENGTH);
+Offset += (UINT16)DumpGasStruct (
+Ptr + Offset,
+4,
+Length - Offset
+);
+  }
+
+  // Make sure the array of address sizes corresponding to each GAS fit in the
+  // Debug Device Information structure
+  if ((*AddrSizeOffset + (*GasCount * sizeof (UINT32))) > Length) {
+IncrementErrorCount ();
+Print (
+  L"ERROR: Invalid GAS count. GasCount = %d. RemainingBufferLength = %d. " 
\
+L"Parsing of the Debug Device Information structure aborted.\n",
+  *GasCount,
+  Length - *AddrSizeOffset
+  );
+return;
+  }
+
+  // Address Size
+  Index = 0;
+  Offset = *AddrSizeOffset;
+  while ((Index++ < *GasCount) &&
+ (Offset < Length)) {
 PrintFieldName (4, L"Address Size");
-Print (L"0x%x\n", AddrSize[Index]);
-DataPtr += GAS_LENGTH;
-Index++;
+Print (L"0x%x\n", *((UINT32*)(Ptr + Offset)));
+Offset += sizeof (UINT32);
   }
 
   // NameSpace String
   Index = 0;
-  DataPtr = Ptr + (*NameSpaceStringOffset);
+  Offset = *NameSpaceStringOffset;
   PrintFieldName (4, L"

[edk2-devel] [PATCH v1 3/6] ShellPkg: acpiview: IORT: Prevent buffer overruns

2019-08-01 Thread Krzysztof Koch
Modify the IORT table parsing logic to prevent reading past the buffer
lengths provided.

Change DumpIortNodeIdMappings() function's signature and implementation
to simplify buffer overrun prevention. Update all calls to this
function accordingly.

Modify the parser for each type of IORT node such that the offset from
the start of the node's buffer is tracked as the parsing function is
executed. Again, this change helps prevent buffer overruns.

Test that the IORT node buffer fits in the table buffer before the
node's buffer contents are dumped.

References:
- IO Remapping Table (Issue D), Platform Design Document, March 2018

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- Prevent buffer overruns in IORT acpiview parser [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c | 191 
+++-
 1 file changed, 105 insertions(+), 86 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c
index 
7c850b3813d5204775e2cc247cabf42358b25769..8912d415a755c7f892b5cd2edc532aae8964a42c
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c
@@ -247,42 +247,41 @@ STATIC CONST ACPI_PARSER IortNodePmcgParser[] = {
 /**
   This function parses the IORT Node Id Mapping array.
 
-  @param [in] PtrPointer to the start of the IORT Table.
+  @param [in] PtrPointer to the start of the ID mapping array.
+  @param [in] Length Length of the buffer.
   @param [in] MappingCount   The ID Mapping count.
-  @param [in] MappingOffset  The offset of the ID Mapping array
- from the start of the IORT table.
 **/
 STATIC
 VOID
 DumpIortNodeIdMappings (
   IN UINT8* Ptr,
-  IN UINT32 MappingCount,
-  IN UINT32 MappingOffset
+  IN UINT32 Length,
+  IN UINT32 MappingCount
   )
 {
-  UINT8* IdMappingPtr;
   UINT32 Index;
   UINT32 Offset;
   CHAR8  Buffer[40];  // Used for AsciiName param of ParseAcpi
 
-  IdMappingPtr = Ptr + MappingOffset;
   Index = 0;
-  while (Index < MappingCount) {
+  Offset = 0;
+
+  while ((Index < MappingCount) &&
+ (Offset < Length)) {
 AsciiSPrint (
   Buffer,
   sizeof (Buffer),
   "ID Mapping [%d]",
   Index
   );
-Offset = ParseAcpi (
-   TRUE,
-   4,
-   Buffer,
-   IdMappingPtr,
-   20,
-   PARSER_PARAMS (IortNodeIdMappingParser)
-   );
-IdMappingPtr += Offset;
+Offset += ParseAcpi (
+TRUE,
+4,
+Buffer,
+Ptr + Offset,
+Length - Offset,
+PARSER_PARAMS (IortNodeIdMappingParser)
+);
 Index++;
   }
 }
@@ -309,8 +308,6 @@ DumpIortNodeSmmuV1V2 (
   UINT32 Offset;
   CHAR8  Buffer[50];  // Used for AsciiName param of ParseAcpi
 
-  UINT8* ArrayPtr;
-
   ParseAcpi (
 TRUE,
 2,
@@ -320,51 +317,55 @@ DumpIortNodeSmmuV1V2 (
 PARSER_PARAMS (IortNodeSmmuV1V2Parser)
 );
 
-  ArrayPtr = Ptr + *InterruptContextOffset;
+  Offset = *InterruptContextOffset;
   Index = 0;
-  while (Index < *InterruptContextCount) {
+
+  while ((Index < *InterruptContextCount) &&
+ (Offset < Length)) {
 AsciiSPrint (
   Buffer,
   sizeof (Buffer),
   "Context Interrupts Array [%d]",
   Index
   );
-Offset = ParseAcpi (
-   TRUE,
-   4,
-   Buffer,
-   ArrayPtr,
-   8,
-   PARSER_PARAMS (InterruptArrayParser)
-   );
-ArrayPtr += Offset;
+Offset += ParseAcpi (
+TRUE,
+4,
+Buffer,
+Ptr + Offset,
+Length - Offset,
+PARSER_PARAMS (InterruptArrayParser)
+);
 Index++;
   }
 
-  ArrayPtr = Ptr + *PmuInterruptOffset;
+  Offset = *PmuInterruptOffset;
   Index = 0;
-  while (Index < *PmuInterruptCount) {
+
+  while ((Index < *PmuInterruptCount) &&
+ (Offset < Length)) {
 AsciiSPrint (
   Buffer,
   sizeof (Buffer),
   "PMU Interrupts Array [%d]",
   Index
   );
-Offset = ParseAcpi (
-   TRUE,
-   4,
-   Buffer,
-   ArrayPtr,
-   8,
-   PARSER_PARAMS (InterruptArrayParser)
-   );
-ArrayPtr += Offset;
+Offset += ParseAcpi (
+TRUE,
+4,
+Buffer,
+Ptr + Offset,
+Length - Offset,
+PARSER_PARAMS (InterruptArrayParser)
+);
 Index++;
   }
 
-  if (*IortIdMappingCount != 0) {
-DumpIortNodeIdMappings (Ptr, Mapp

[edk2-devel] [PATCH v1 5/6] ShellPkg: acpiview: PPTT: Prevent buffer overruns

2019-08-01 Thread Krzysztof Koch
Modify the PPTT table parsing logic to prevent reading past the ACPI
buffer lengths provided.

Check if the Number of Private Resources specified in the Processor
Hierarchy Node (Type 0) is possible given the Type 0 Structure's buffer
length.

Make sure that the processor topology structure's buffer fits in the
PPTT table buffer before its contents are dumped.

Prevent buffer overruns when reading the processor topology structure's
header.

References:
- ACPI 6.3, January 2019, Section 5.2.29

Signed-off-by: Krzysztof Koch 
---

Notes:
v1:
- Prevent buffer overruns in PPTT acpiview parser [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c | 38 
++--
 1 file changed, 27 insertions(+), 11 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c
index 
cec57be55e77096f9448f637ea129af2b42111ad..6254b9913fffb429fc54bb1301bf3e4b2e5bf161
 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c
@@ -252,7 +252,6 @@ DumpProcessorHierarchyNodeStructure (
   )
 {
   UINT32 Offset;
-  UINT8* PrivateResourcePtr;
   UINT32 Index;
   CHAR16 Buffer[OUTPUT_FIELD_COLUMN_WIDTH];
 
@@ -265,8 +264,23 @@ DumpProcessorHierarchyNodeStructure (
  PARSER_PARAMS (ProcessorHierarchyNodeStructureParser)
  );
 
-  PrivateResourcePtr = Ptr + Offset;
+  // Make sure the Private Resource array lies inside this structure
+  if (Offset + (*NumberOfPrivateResources * sizeof (UINT32)) > Length) {
+IncrementErrorCount ();
+Print (
+  L"ERROR: Invalid Number of Private Resources. " \
+L"PrivateResourceCount = %d. RemainingBufferLength = %d. " \
+L"Parsing of this structure aborted.\n",
+  *NumberOfPrivateResources,
+  Length - Offset
+  );
+return;
+  }
+
   Index = 0;
+
+  // Parse the specified number of private resource references or the Processor
+  // Hierarchy Node length. Whichever is minimum.
   while (Index < *NumberOfPrivateResources) {
 UnicodeSPrint (
   Buffer,
@@ -278,10 +292,10 @@ DumpProcessorHierarchyNodeStructure (
 PrintFieldName (4, Buffer);
 Print (
   L"0x%x\n",
-  *((UINT32*) PrivateResourcePtr)
+  *((UINT32*)(Ptr + Offset))
   );
 
-PrivateResourcePtr += sizeof(UINT32);
+Offset += sizeof (UINT32);
 Index++;
   }
 }
@@ -382,19 +396,21 @@ ParseAcpiPptt (
   0,
   NULL,
   ProcessorTopologyStructurePtr,
-  4,  // Length of the processor topology structure header is 4 bytes
+  AcpiTableLength - Offset,
   PARSER_PARAMS (ProcessorTopologyStructureHeaderParser)
   );
 
-if ((Offset + (*ProcessorTopologyStructureLength)) > AcpiTableLength) {
+// Make sure the PPTT structure lies inside the table
+if ((Offset + *ProcessorTopologyStructureLength) > AcpiTableLength) {
   IncrementErrorCount ();
   Print (
-L"ERROR: Invalid processor topology structure length:"
-  L" Type = %d, Length = %d\n",
-*ProcessorTopologyStructureType,
-*ProcessorTopologyStructureLength
+L"ERROR: Invalid PPTT structure length. " \
+  L"ProcessorTopologyStructureLength = %d. " \
+  L"RemainingTableBufferLength = %d. PPTT parsing aborted.\n",
+*ProcessorTopologyStructureLength,
+AcpiTableLength - Offset
 );
-  break;
+  return;
 }
 
 PrintFieldName (2, L"* Structure Offset *");
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#44759): https://edk2.groups.io/g/devel/message/44759
Mute This Topic: https://groups.io/mt/32676847/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v1 6/6] ShellPkg: acpiview: SRAT: Prevent buffer overruns

2019-08-01 Thread Krzysztof Koch
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 
---

Notes:
v1:
- Prevent buffer overruns in SRAT acpiview parser [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c | 14 
+-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
index 
59c77401eaab32b73a9f83fd4d63785221b3c222..a8aa420487bb6bf29fc38221d0b221573c64b8b3
 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 (
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#44761): https://edk2.groups.io/g/devel/message/44761
Mute This Topic: https://groups.io/mt/32676850/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH v1 1/6] ShellPkg: acpiview: DBG2: Prevent buffer overruns

2019-08-05 Thread Krzysztof Koch
Hi Zhichao,

The reason why processing of the Debug Device Information Structure is split 
into:
1. loading the header
2. dumping the entire structure

Is because we want to let the users control how much of the structure is 
dumped. This is important for backward compatibility of the acpiview tool with 
the ACPI specification (and other specs).

New ACPI table fields are appended at the end of structures/tables. If, for 
example, we are asked to parse an old version of Debug Device Information 
Structure, the 'Length' field will tell us to ignore some of the newly added 
fields. These fields do not make sense in the context of an old version of the 
corresponding spec.

The following code in Dbg2Parser.c:

// Make sure the Debug Device Information structure lies inside the table.
if ((Offset + *DbgDevInfoLen) > AcpiTableLength) {
  IncrementErrorCount ();
  Print (
L"ERROR: Invalid Debug Device Information structure length. " \
  L"DbgDevInfoLen = %d. RemainingTableBufferLength = %d. " \
  L"DBG2 parsing aborted.\n",
*DbgDevInfoLen,
AcpiTableLength - Offset
);
  return;
}

Makes sure that the user-provided structure length won't result in a buffer 
overrun with respect to the DBG2 table buffer. This way we allow users to 
specify how much of the structure they want to parse while still preventing 
buffer overruns.

In short, I'm not sure if getting rid of DbgDevInfoHeaderParser would work as 
you assume that the remaining table buffer length should be passed to 
ParseAcpi() as an argument, not the length of the Debug Device Information 
Structure. What do you think?

Kind regards,

Krzysztof

-Original Message-
From: Gao, Zhichao  
Sent: Monday, August 5, 2019 7:48
To: Krzysztof Koch ; devel@edk2.groups.io
Cc: Carsey, Jaben ; Ni, Ray ; Sami 
Mujawar ; Matteo Carlini ; nd 

Subject: RE: [PATCH v1 1/6] ShellPkg: acpiview: DBG2: Prevent buffer overruns

About DbgDevInfoHeaderParser and DbgDevInfoParser.
This patch would parse same DbgDevInfo twice, one for getting length, the other 
for dumping structure info.
How about the following?
Add one parameter for DumpDbgDeviceInfo

STATIC
VOID
EFIAPI
DumpDbgDeviceInfo (
  IN  UINT8*  Ptr,
  OUT UINT32* Length
  )

==>

STATIC
VOID
EFIAPI
DumpDbgDeviceInfo (
  IN  UINT8*  Ptr,
  IN  UINT32* Length// remain length of acpi struct to 
parse to make sure all operation is in a valid scope
  OUT UINT16* DbgDevInfoLength  // return pointer dbgdevinfo length
  )

Then we would not need an anditional DbgDevInfoHeaderParser and the header 
would be parsed for only once.

Any better comments, please let me know.

Thanks,
Zhichao

> -Original Message-
> From: Krzysztof Koch [mailto:krzysztof.k...@arm.com]
> Sent: Thursday, August 1, 2019 4:44 PM
> To: devel@edk2.groups.io
> Cc: Carsey, Jaben ; Ni, Ray 
> ; Gao, Zhichao ; 
> sami.muja...@arm.com; matteo.carl...@arm.com; n...@arm.com
> Subject: [PATCH v1 1/6] ShellPkg: acpiview: DBG2: Prevent buffer 
> overruns
> 
> Modify the DBG2 table parsing logic to prevent reading past the ACPI 
> buffer lengths provided.
> 
> Modify the signature of the DumpDbgDeviceInfo() function to make it 
> consistent with the ACPI structure processing functions in other 
> acpiview parsers. Now, the length of the Debug Device Information 
> Structure is read before the entire structure is dumped.
> 
> This refactoring change makes it easier to stop reading beyond the
> DBG2 table buffer if the Debug Device Information Structure Buffer 
> does not fit in the DBG2 buffer.
> 
> For processing the first two fields of the Debug Device Information 
> Structure (to get the length) a new ACPI_PARSER array is defined.
> 
> References:
> - Microsoft Debug Port Table 2 (DBG2), December 10, 2015
> 
> Signed-off-by: Krzysztof Koch 
> ---
> 
> Notes:
> v1:
> - Prevent buffer overruns in DBG2 acpiview parser [Krzysztof]
> 
> 
> ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
> | 141 +---
>  1 file changed, 92 insertions(+), 49 deletions(-)
> 
> diff --git
> a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parse
> r.c
> b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parse
> r.c
> index
> c6929695a1032c57761ef85002d6c51b7800ce23..869e700b9beda4886bf7bc5ae
> 4ced3ab9a59efa3 100644
> ---
> a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parse
> r.c
> +++
> b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Pars
> +++ er.c
> @@ -64,10 +64,17 @@ STATIC CONST ACPI_PARSER Dbg2Parser[] = {
> (VOID**)&NumberDbgDeviceInfo, NULL, NULL}  };
> 
> +/// An ACPI_PARSER array describing the debug device information 
> +structure /

Re: [edk2-devel] [PATCH v1 1/6] ShellPkg: acpiview: DBG2: Prevent buffer overruns

2019-08-06 Thread Krzysztof Koch
Hi Zhichao,

Thanks for the feedback. I had a look at your code and I have put comments 
inline (in GitHub) to describe why I think it does not achieve the same 
functionality as the patch I've submitted.

I copied my comments below as well, so that they're easier to access:

"""
The ParseAcpi() call (Line 113) will parse either the entire DbgDevInfoParser[] 
array or as much data as there is left in the ACPI table buffer. I agree this 
prevents buffer overruns with respect to the ACPI table buffer. However, the 
parser now ignores the length of the Debug Device Information Structure (loaded 
into the *DbgDevInfoLen variable) when dumping its contents.

Here is an example:
If the DBG2 table buffer is 100-byte long, and the Debug Device Information 
Structure is (let's say) located at offset 20 with a byte-size (as described in 
the 'Length' field) of only 10 bytes, then we have a problem.

The DbgDevInfoParser[] array says that 22 bytes should be parsed, however, the 
user-provided structure length is 10. I believe that only 10 bytes should be 
parsed to reflect what an OS would do in this situation.

This is why I created a new ACPI_PARSER array in my submitted patch to:
1. Read the Length of the Debug Device Information Structure
2. Validate the Length against the length of the DBG2 table buffer
3. Use the Length to control how many statements from DbgDevInfoParser[] should 
be executed.

If we print only as much data as the ACPI table writer has specified then any 
errors in the 'Length' field are easier to detect. You can easily see that some 
data is missing and this is due to the 'Length' field having wrong value.

Reading the 'Length' field before the whole structure is dumped is also 
important for our acpiview implementation for the sake of backward 
compatibility. As ACPI tables usually get updated by appending new fields to 
existing structures. If someone provides us with a Length that matches the old 
DBG2 version then we won't print the fields that got recently added to 
DbgDevInfoParser[] due to a spec update.

I understand there is still an issue of some variables not getting updated 
correctly because we haven't parsed enough of the DbgDevInfoParser[], for 
example, the AddrSizeOffset variable. But my next patch series adds code to 
detect NULL pointers in all parsers.
"""

Please let me know what you think.

Kind regards,

Krzysztof

-Original Message-
From: devel@edk2.groups.io  On Behalf Of Gao, Zhichao via 
Groups.Io
Sent: Tuesday, August 6, 2019 8:43
To: devel@edk2.groups.io; Krzysztof Koch 
Cc: Carsey, Jaben ; Ni, Ray ; Sami 
Mujawar ; Matteo Carlini ; nd 

Subject: Re: [edk2-devel] [PATCH v1 1/6] ShellPkg: acpiview: DBG2: Prevent 
buffer overruns

I got your point. How about this: 
https://github.com/ZhichaoGao/edk2/commit/112a41255cb775f5ebede089b8b07ba7b836ec44
I make a minor change of it. But I can't test it because I don't have a 
platform that implement DBG2 table.

Thanks,
Zhichao

> -----Original Message-
> From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of 
> Krzysztof Koch
> Sent: Monday, August 5, 2019 4:21 PM
> To: Gao, Zhichao ; devel@edk2.groups.io
> Cc: Carsey, Jaben ; Ni, Ray 
> ; Sami Mujawar ; Matteo 
> Carlini ; nd 
> Subject: Re: [edk2-devel] [PATCH v1 1/6] ShellPkg: acpiview: DBG2: 
> Prevent buffer overruns
> 
> Hi Zhichao,
> 
> The reason why processing of the Debug Device Information Structure is 
> split
> into:
> 1. loading the header
> 2. dumping the entire structure
> 
> Is because we want to let the users control how much of the structure 
> is dumped. This is important for backward compatibility of the 
> acpiview tool with the ACPI specification (and other specs).
> 
> New ACPI table fields are appended at the end of structures/tables. 
> If, for example, we are asked to parse an old version of Debug Device 
> Information Structure, the 'Length' field will tell us to ignore some 
> of the newly added fields. These fields do not make sense in the 
> context of an old version of the corresponding spec.
> 
> The following code in Dbg2Parser.c:
> 
> // Make sure the Debug Device Information structure lies inside the table.
> if ((Offset + *DbgDevInfoLen) > AcpiTableLength) {
>   IncrementErrorCount ();
>   Print (
> L"ERROR: Invalid Debug Device Information structure length. " \
>   L"DbgDevInfoLen = %d. RemainingTableBufferLength = %d. " \
>   L"DBG2 parsing aborted.\n",
> *DbgDevInfoLen,
> AcpiTableLength - Offset
> );
>   return;
> }
> 
> Makes sure that the user-provided structure length won't result in a 
> buffer overrun with respect to the DBG2 table b

[edk2-devel] [PATCH v1 1/1] DynamicTablesPkg: Add dynamic PPTT table generation support

2019-05-24 Thread Krzysztof Koch
The PPTT generator uses the configuration manager protocol to
obtain information about platform's processor topology and caches.
This data is then used to generate the PPTT table.

The table generator supports ACPI 6.3, PPTT table revision 2.

The dynamic PPTT generator also carries out extensive input
validation which includes cycle detection and MADT-PPTT
cross-validation. A number of architectural compliance checks
are also performed.

Signed-off-by: Krzysztof Koch 
---

The changes can be seen at: 
https://github.com/KrzysztofKoch1/edk2/tree/392_pptt_generator_v1

This patch is dependent on: 
https://github.com/KrzysztofKoch1/edk2/tree/479_find_duplicate_ids_v1

Notes:
v1:
- Add PPTT dynamic generator [Krzysztof]

 DynamicTablesPkg/DynamicTables.dsc.inc  |3 +-
 DynamicTablesPkg/Include/AcpiTableGenerator.h   |3 +
 DynamicTablesPkg/Include/ArmNameSpaceObjects.h  |   95 ++
 DynamicTablesPkg/Include/ConfigurationManagerObject.h   |   22 +-
 DynamicTablesPkg/Include/Library/TableHelperLib.h   |   48 +
 DynamicTablesPkg/Include/TableGenerator.h   |3 +-
 DynamicTablesPkg/Library/Acpi/Arm/AcpiPpttLibArm/AcpiPpttLibArm.inf |   29 +
 DynamicTablesPkg/Library/Acpi/Arm/AcpiPpttLibArm/PpttGenerator.c| 1528 

 DynamicTablesPkg/Library/Acpi/Arm/AcpiPpttLibArm/PpttGenerator.h|  190 +++
 DynamicTablesPkg/Library/Common/TableHelperLib/TableHelper.c|   64 +
 10 files changed, 1979 insertions(+), 6 deletions(-)

diff --git a/DynamicTablesPkg/DynamicTables.dsc.inc 
b/DynamicTablesPkg/DynamicTables.dsc.inc
index 
8ea5b0a7d917fa2197e7c6da74afa0cbeb4c7a8d..142832b9fa9c2cd4b73935abf4114c3fa7b26d95
 100644
--- a/DynamicTablesPkg/DynamicTables.dsc.inc
+++ b/DynamicTablesPkg/DynamicTables.dsc.inc
@@ -1,7 +1,7 @@
 ## @file
 #  Dsc include file for Dynamic Tables Framework.
 #
-#  Copyright (c) 2017 - 2018, ARM Limited. All rights reserved.
+#  Copyright (c) 2017 - 2019, ARM Limited. All rights reserved.
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -27,6 +27,7 @@ [Components.common]
   NULL|DynamicTablesPkg/Library/Acpi/Arm/AcpiIortLibArm/AcpiIortLibArm.inf
   NULL|DynamicTablesPkg/Library/Acpi/Arm/AcpiMadtLibArm/AcpiMadtLibArm.inf
   NULL|DynamicTablesPkg/Library/Acpi/Arm/AcpiMcfgLibArm/AcpiMcfgLibArm.inf
+  NULL|DynamicTablesPkg/Library/Acpi/Arm/AcpiPpttLibArm/AcpiPpttLibArm.inf
   NULL|DynamicTablesPkg/Library/Acpi/Arm/AcpiRawLibArm/AcpiRawLibArm.inf
   NULL|DynamicTablesPkg/Library/Acpi/Arm/AcpiSpcrLibArm/AcpiSpcrLibArm.inf
   }
diff --git a/DynamicTablesPkg/Include/AcpiTableGenerator.h 
b/DynamicTablesPkg/Include/AcpiTableGenerator.h
index 
c4ef05965fc02707307e59130e9caa359e66239b..7d6d3442276db7b4abaeb3b053ba489258adea0b
 100644
--- a/DynamicTablesPkg/Include/AcpiTableGenerator.h
+++ b/DynamicTablesPkg/Include/AcpiTableGenerator.h
@@ -51,6 +51,8 @@ The Dynamic Tables Framework implements the following ACPI 
table generators:
 from the Configuration Manager and builds the MCFG table.
   - IORT  : The IORT generator collates the IO Topology information from the
 Configuration Manager and builds the IORT table.
+  - PPTT  : The PPTT generator collates the processor topology information from
+the Configuration Manager and builds the PPTT table.
 */
 
 /** The ACPI_TABLE_GENERATOR_ID type describes ACPI table generator ID.
@@ -72,6 +74,7 @@ typedef enum StdAcpiTableId {
   EStdAcpiTableIdSpcr,  ///< SPCR Generator
   EStdAcpiTableIdMcfg,  ///< MCFG Generator
   EStdAcpiTableIdIort,  ///< IORT Generator
+  EStdAcpiTableIdPptt,  ///< PPTT Generator
   EStdAcpiTableIdMax
 } ESTD_ACPI_TABLE_ID;
 
diff --git a/DynamicTablesPkg/Include/ArmNameSpaceObjects.h 
b/DynamicTablesPkg/Include/ArmNameSpaceObjects.h
index 
bf70dc76cea044b9a8e8eb529d2ddbf892bafd58..6d6fdac5195021392a5310c32c1cacde44390c58
 100644
--- a/DynamicTablesPkg/Include/ArmNameSpaceObjects.h
+++ b/DynamicTablesPkg/Include/ArmNameSpaceObjects.h
@@ -48,6 +48,10 @@ typedef enum ArmObjectID {
   EArmObjGicItsIdentifierArray,   ///< 24 - GIC ITS Identifier Array
   EArmObjIdMappingArray,  ///< 25 - ID Mapping Array
   EArmObjSmmuInterruptArray,  ///< 26 - SMMU Interrupt Array
+  EArmObjProcHierarchyInfo,   ///< 27 - Processor Hierarchy Info
+  EArmObjCacheInfo,   ///< 28 - Cache Info
+  EArmObjProcNodeIdInfo,  ///< 29 - Processor Hierarchy Node ID 
Info
+  EArmObjCmRef,   ///< 30 - CM Object Reference
   EArmObjMax
 } EARM_OBJECT_ID;
 
@@ -621,6 +625,97 @@ typedef struct CmArmSmmuInterrupt {
   UINT32Flags;
 } CM_ARM_SMMU_INTERRUPT;
 
+/** A structure that describes the Processor Hierarchy Node (Type 0) in PP

  1   2   >