From: "Krzysztof Koch" <krzysztof.koch@arm.com>
To: <devel@edk2.groups.io>
Cc: <jaben.carsey@intel.com>, <ray.ni@intel.com>,
<zhichao.gao@intel.com>, <Sami.Mujawar@arm.com>,
<Matteo.Carlini@arm.com>, <nd@arm.com>
Subject: [PATCH v1 09/11] ShellPkg: acpiview: IORT: Validate global pointers before use
Date: Thu, 15 Aug 2019 14:11:19 +0100 [thread overview]
Message-ID: <20190815131121.52644-10-krzysztof.koch@arm.com> (raw)
In-Reply-To: <20190815131121.52644-1-krzysztof.koch@arm.com>
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 <krzysztof.koch@arm.com>
---
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)'
next prev parent reply other threads:[~2019-08-15 13:12 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-15 13:11 [PATCH v1 00/11] Test against invalid pointers in acpiview Krzysztof Koch
2019-08-15 13:11 ` [PATCH v1 01/11] ShellPkg: acpiview: Set ItemPtr to NULL for unprocessed table fields Krzysztof Koch
2019-08-15 13:11 ` [PATCH v1 02/11] ShellPkg: acpiview: RSDP: Validate global pointer before use Krzysztof Koch
2019-08-15 13:11 ` [PATCH v1 03/11] ShellPkg: acpiview: FADT: " Krzysztof Koch
2019-08-16 7:34 ` Gao, Zhichao
2019-08-16 10:25 ` Krzysztof Koch
2019-08-15 13:11 ` [PATCH v1 04/11] ShellPkg: acpiview: SLIT: " Krzysztof Koch
2019-08-15 13:11 ` [PATCH v1 05/11] ShellPkg: acpiview: SLIT: Validate System Locality count Krzysztof Koch
2019-08-19 1:18 ` [edk2-devel] " Gao, Zhichao
2019-08-19 6:28 ` Krzysztof Koch
2019-08-19 7:16 ` Gao, Zhichao
2019-08-19 9:30 ` Sami Mujawar
2019-08-15 13:11 ` [PATCH v1 06/11] ShellPkg: acpiview: SRAT: Validate global pointers before use Krzysztof Koch
2019-08-15 13:11 ` [PATCH v1 07/11] ShellPkg: acpiview: MADT: " Krzysztof Koch
2019-08-15 13:11 ` [PATCH v1 08/11] ShellPkg: acpiview: PPTT: " Krzysztof Koch
2019-08-15 13:11 ` Krzysztof Koch [this message]
2019-08-15 13:11 ` [PATCH v1 10/11] ShellPkg: acpiview: GTDT: " Krzysztof Koch
2019-08-15 13:11 ` [PATCH v1 11/11] ShellPkg: acpiview: DBG2: " Krzysztof Koch
2019-08-16 4:02 ` [edk2-devel] [PATCH v1 00/11] Test against invalid pointers in acpiview Liming Gao
2019-08-16 7:21 ` Krzysztof Koch
2019-08-19 9:29 ` Sami Mujawar
2019-08-21 1:46 ` [edk2-devel] " Gao, Zhichao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190815131121.52644-10-krzysztof.koch@arm.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox