From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (EUR05-VI1-obe.outbound.protection.outlook.com [40.107.21.82]) by mx.groups.io with SMTP id smtpd.web10.10287.1582107834847373709 for ; Wed, 19 Feb 2020 02:23:55 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=BMOar1GH; spf=pass (domain: arm.com, ip: 40.107.21.82, mailfrom: krzysztof.koch@arm.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NDO74wuJaACodVh0rf01kDC24sZCgPPOwZo3/Jmuqi8=; b=BMOar1GHW6k8aARN54hnUxFYHQyqE8zk4EVr6B45Vw8NswAnRzkUkxW4JUgnizXNh/88CGihZpIPisKZuukNnTjthXwC6UpdxsvTZmYS9HZyTvaG8izUncfx4rCAcOgBMthQi494t0CaSkWPSy7FrEb1D0WWmAH9fDTTpUjZaT4= Received: from VI1PR08CA0123.eurprd08.prod.outlook.com (2603:10a6:800:d4::25) by HE1PR0802MB2172.eurprd08.prod.outlook.com (2603:10a6:3:cb::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2729.24; Wed, 19 Feb 2020 10:23:51 +0000 Received: from DB5EUR03FT010.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e0a::201) by VI1PR08CA0123.outlook.office365.com (2603:10a6:800:d4::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2729.25 via Frontend Transport; Wed, 19 Feb 2020 10:23:51 +0000 Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; edk2.groups.io; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;edk2.groups.io; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT010.mail.protection.outlook.com (10.152.20.96) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2750.17 via Frontend Transport; Wed, 19 Feb 2020 10:23:51 +0000 Received: ("Tessian outbound 3a0cbd311638:v42"); Wed, 19 Feb 2020 10:23:50 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: d600ae43a5d536d3 X-CR-MTA-TID: 64aa7808 Received: from d25f6fe4f422.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 8BCB4078-E99D-4EB9-9196-163822844025.1; Wed, 19 Feb 2020 10:23:44 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id d25f6fe4f422.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 19 Feb 2020 10:23:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MmC5DTn0dyn0kpnRPb78RpG/mzAhK/1XD+BfZNRPcQSWoUolWCw/hYQ+FEGeYnN9DI2MCpClt1dC84z2tRTUQ2RxgNHrL4Y1DfvshTzcFUw9BGXfNMRrntLf9DoIhlvsd8xs/F8xTW79c+tXGpjajn+4EvNsvxBzydG3ybneEuBb7Ogy0/a4S06dVd7Lfppt3vDev10kfOng8FWrOKG4NTT7E0LvahewpwlVTgYksmLLYyK3XOhPfHtEEvPfERyftCuBs0cP0z8uQlcl+kvs/LGWXUrUm7KdiVTt1b+zXG+mgG4Vi49hYqVBj0MFyTRV+N7LVvdNppierayA75rfww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NDO74wuJaACodVh0rf01kDC24sZCgPPOwZo3/Jmuqi8=; b=IzmxCkbFRxgmKvJWhsDSHnhvMPK3FsFKUlgBWR6wQOXCND3Pu9e/gVOIq1Lktvvlbguq0u5+OLS7Ff1z4wuDbzOIW3LrbAE7yqgU6AByNcH5ISHsJdT1zA7S+Nt/24YSbDmNhIorCgS/rPczRLnDka7qE+8DGkQpyrtvpKgQi2sQMtjaNC8EdRIXQUF5XKl4GhZ2tqzy8uKKQg53vGufLzwNYXctNjgfeClnl2QYdpwjb3Pt29vWSIWW7UYI7ZSasou2sOgH6MhsuNpWrH1dm/vpbW7Ooq/Y15iDKlnTY24A03q7OoybkjYKbmiCSyjEMrNx0xswaSx42cggLfmJFg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=arm.com; dmarc=bestguesspass action=none header.from=arm.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NDO74wuJaACodVh0rf01kDC24sZCgPPOwZo3/Jmuqi8=; b=BMOar1GHW6k8aARN54hnUxFYHQyqE8zk4EVr6B45Vw8NswAnRzkUkxW4JUgnizXNh/88CGihZpIPisKZuukNnTjthXwC6UpdxsvTZmYS9HZyTvaG8izUncfx4rCAcOgBMthQi494t0CaSkWPSy7FrEb1D0WWmAH9fDTTpUjZaT4= Received: from VI1PR08CA0118.eurprd08.prod.outlook.com (2603:10a6:800:d4::20) by DB7PR08MB3241.eurprd08.prod.outlook.com (2603:10a6:5:1f::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2729.22; Wed, 19 Feb 2020 10:23:42 +0000 Received: from DB5EUR03FT010.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e0a::207) by VI1PR08CA0118.outlook.office365.com (2603:10a6:800:d4::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2729.25 via Frontend Transport; Wed, 19 Feb 2020 10:23:41 +0000 Authentication-Results-Original: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; Received: from nebula.arm.com (40.67.248.234) by DB5EUR03FT010.mail.protection.outlook.com (10.152.20.96) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.2750.17 via Frontend Transport; Wed, 19 Feb 2020 10:23:41 +0000 Received: from AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1415.2; Wed, 19 Feb 2020 10:23:39 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1779.2; Wed, 19 Feb 2020 10:23:39 +0000 Received: from E119924.Arm.com (10.1.199.55) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.1415.2 via Frontend Transport; Wed, 19 Feb 2020 10:23:38 +0000 From: "Krzysztof Koch" To: CC: , , , , Subject: [PATCH v2 1/1] ShellPkg: acpiview: Prevent infinite loop if structure length is 0 Date: Wed, 19 Feb 2020 10:23:38 +0000 Message-ID: <20200219102338.272-1-krzysztof.koch@arm.com> X-Mailer: git-send-email 2.16.2.windows.1 MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234;IPV:;CTRY:IE;EFV:NLI;SFV:NSPM;SFS:(10009020)(4636009)(136003)(39860400002)(396003)(346002)(376002)(199004)(189003)(2906002)(7696005)(54906003)(81156014)(1076003)(336012)(81166006)(8936002)(26005)(70586007)(70206006)(426003)(8676002)(44832011)(356004)(5660300002)(6916009)(186003)(478600001)(86362001)(4326008)(2616005)(316002)(966005)(36756003);DIR:OUT;SFP:1101;SCL:1;SRVR:DB7PR08MB3241;H:nebula.arm.com;FPR:;SPF:Pass;LANG:en;PTR:InfoDomainNonexistent;A:1;MX:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 80e5755d-de5d-4136-4c4e-08d7b525d05f X-MS-TrafficTypeDiagnostic: DB7PR08MB3241:|HE1PR0802MB2172: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:124;OLM:124; X-Forefront-PRVS: 0318501FAE X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: HO7X7xLGX6CJScSnyIk1YT0YZ16aAkdy3LJaM/dZRsEX/vI/Ry/cl/qR/5SxRL60QeqfdmdZxKKDD8u7wMGZvdPK2SNeH7L9R9cAluUwuWaG7wCIg7trxtthYHOwuhzSO28B0i559gKTihlW+5Cwe7ZJr+V58UpVKuYt4fpziq0SfV8/HD72kcdeGES+LZ3PlffuTko0Nsib+ujJNoQFQI+hre48aVqIZdErIMNKVCcSttrBitT31ztp9+mthMwkIWkng2qpku1fgt1kybbhSGY/ejMof0I61pfkQgDpW/a2NbnQ9G5BGiYX9BU5fOFZLk0uwn25O4Dm+YC8n8krVXYnenRDbg4qH03nC8MfAJoLFuZeIpbhK90jKoU/ADXu7oMTCe37rLIi+4fBxtyYP/iP2BmRNjVGUchej71HOcVIvXjlW5OWyMUaGwOUNVWu1GQqjxDYnLojq7tvd+qR7BGr8n7vz5lLYr4GlzHkkr0iveU2rHWKNGdgEzIPhFIyqVt1+cYXT1DlOw2azZamEg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR08MB3241 Original-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=bestguesspass action=none header.from=arm.com; Return-Path: Krzysztof.Koch@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT010.eop-EUR03.prod.protection.outlook.com X-Forefront-Antispam-Report: CIP:63.35.35.123;IPV:CAL;SCL:-1;CTRY:IE;EFV:NLI;SFV:NSPM;SFS:(10009020)(4636009)(376002)(396003)(136003)(346002)(39860400002)(189003)(199004)(8936002)(81156014)(426003)(2616005)(8676002)(316002)(186003)(4326008)(70586007)(81166006)(44832011)(36756003)(70206006)(5660300002)(7696005)(1076003)(26826003)(86362001)(6916009)(336012)(54906003)(26005)(966005)(2906002)(478600001);DIR:OUT;SFP:1101;SCL:1;SRVR:HE1PR0802MB2172;H:64aa7808-outbound-1.mta.getcheckrecipient.com;FPR:;SPF:Pass;LANG:en;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;MX:1;A:1; X-MS-Office365-Filtering-Correlation-Id-Prvs: e003fa8f-1ed4-4b31-f802-08d7b525cab3 X-Forefront-PRVS: 0318501FAE X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ILZ/tIP8+2lfsR3204m/MiyXLh32Oe/uSq5a3AnXnBzPHDc79uzAoOR0NKZOf99QHFkE1A3Mq6YPLMCSIksB7P6ZmhD1uW3Zm/ePlG/eJhSUSR5ytKGgdbpbFNLRf1EQjEVQ4RvuLZ40vPrwySPcSnpfl1uYH0HMCbdelQM6OFZXgU13GO5f/P87bcyj7qz0LwdPa32aN0N8c4fqbgg50b/bE8hU6jyaLVp38jS3/iFz52QsKesew9CkVz76Y3CiNNcPM0Kp9F8nSw4RuWAWB6NqmGm/yrBzT8GVRh/qzrvkaGF7HYiTmbC6o9JFZxt8AANoZm8R0KR/CQtySshOTRzIYi05bTS2nWwNm6Bfoq7LrVC1mS9FWj4M81HPjzGdNh4kw1elwX8fHcZNmBImUVR7VtJjZ8G5lyxTVTmdiGUY0dJ+zn06YHdfUC/CeAdZ9VkJ0CgYeby11d/w2M+Ucov1hZe0fBer0Y+yFfd8yaUmBdmhACdBCG4epArzB5jHm0sshB1EnFLzXkTWGNy08w== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Feb 2020 10:23:51.0468 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 80e5755d-de5d-4136-4c4e-08d7b525d05f X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0802MB2172 Content-Type: text/plain 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/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c @@ -1,7 +1,7 @@ /** @file IORT 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): @@ -687,14 +687,16 @@ ParseAcpiIort ( return; } - // Make sure the IORT Node is inside the table - if ((Offset + (*IortNodeLength)) > AcpiTableLength) { + // Validate IORT Node length + if ((*IortNodeLength == 0) || + ((Offset + (*IortNodeLength)) > AcpiTableLength)) { IncrementErrorCount (); Print ( - L"ERROR: Invalid IORT node length. IortNodeLength = %d. " \ - L"RemainingTableBufferLength = %d. IORT parsing aborted.\n", + L"ERROR: Invalid IORT Node length. " \ + L"Length = %d. Offset = %d. AcpiTableLength = %d.\n", *IortNodeLength, - AcpiTableLength - Offset + Offset, + AcpiTableLength ); return; } diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c index 438905cb24f58b8b82e8fe61280e72f765d578d8..f85d2b36532cfc5db36fe7bef9830cccc64969cc 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c @@ -1,7 +1,7 @@ /** @file MADT 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): @@ -273,28 +273,16 @@ ParseAcpiMadt ( return; } - // Make sure forward progress is made. - if (*MadtInterruptControllerLength < 2) { + // Validate Interrupt Controller Structure length + if ((*MadtInterruptControllerLength == 0) || + ((Offset + (*MadtInterruptControllerLength)) > AcpiTableLength)) { IncrementErrorCount (); Print ( - L"ERROR: Structure length is too small: " \ - L"MadtInterruptControllerLength = %d. " \ - L"MadtInterruptControllerType = %d. MADT parsing aborted.\n", + L"ERROR: Invalid Interrupt Controller Structure length. " \ + L"Length = %d. Offset = %d. AcpiTableLength = %d.\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 + Offset, + AcpiTableLength ); return; } diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c index 675ba75f02b367cd5ad9f2ac23c30ed0ab58f286..0db272c16af0ad8824c8da4c88dd409c8550112a 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c @@ -1,7 +1,7 @@ /** @file PPTT table parser - Copyright (c) 2019, ARM Limited. All rights reserved. + Copyright (c) 2019 - 2020, ARM Limited. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent @par Reference(s): @@ -425,15 +425,16 @@ ParseAcpiPptt ( return; } - // Make sure the PPTT structure lies inside the table - if ((Offset + *ProcessorTopologyStructureLength) > AcpiTableLength) { + // Validate Processor Topology Structure length + if ((*ProcessorTopologyStructureLength == 0) || + ((Offset + (*ProcessorTopologyStructureLength)) > AcpiTableLength)) { IncrementErrorCount (); Print ( - L"ERROR: Invalid PPTT structure length. " \ - L"ProcessorTopologyStructureLength = %d. " \ - L"RemainingTableBufferLength = %d. PPTT parsing aborted.\n", + L"ERROR: Invalid Processor Topology Structure length. " \ + L"Length = %d. Offset = %d. AcpiTableLength = %d.\n", *ProcessorTopologyStructureLength, - AcpiTableLength - Offset + Offset, + AcpiTableLength ); return; } diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c index 3613900ae322483fdd3d3383de4e22ba75b2128b..6f66be68cc0bed14811a0432c61a79fd47c54890 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 - 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): @@ -412,14 +412,16 @@ ParseAcpiSrat ( return; } - // Make sure the SRAT structure lies inside the table - if ((Offset + *SratRALength) > AcpiTableLength) { + // Validate Static Resource Allocation Structure length + if ((*SratRALength == 0) || + ((Offset + (*SratRALength)) > AcpiTableLength)) { IncrementErrorCount (); Print ( - L"ERROR: Invalid SRAT structure length. SratRALength = %d. " \ - L"RemainingTableBufferLength = %d. SRAT parsing aborted.\n", + L"ERROR: Invalid Static Resource Allocation Structure length. " \ + L"Length = %d. Offset = %d. AcpiTableLength = %d.\n", *SratRALength, - AcpiTableLength - Offset + Offset, + AcpiTableLength ); return; } -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'