From nobody Fri Apr 26 18:37:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+43642+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1562914409; cv=none; d=zoho.com; s=zohoarc; b=USgeY51VjuA+2+FNtXod/LR8N5zgTM7DKgLpaTkZPsluLQ4LEWsM5be+46q19V6BJo091ilFXywFBJgMH+LxJWmyy6yGqirDYjnxOeOBCd7RY/pi8TzJ+rDD0GGP3VCHozJC8EcoJ2n9llomv715dEtOPVmQD0uhMQgVORSTBPs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562914409; h=Content-Type:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To:ARC-Authentication-Results; bh=4JZKD718irALbzxhktOg70VA8TvGDUxP9ckJWdtcr1U=; b=mOAnn9WlAn6iLEshOlyFS2B/rKrJQxglRXBu6L/52iU1kVBnFTC1saF4EBTKsKO1riuYSb3oHZ1B8QrW8VEYFm5+/rxjXb7DcMgnc5StFN/YouTQD4rMos2m8/8eyOpwwiqEhCmNXNeCqXyi1ZQG0SFArlo9Do9TtVKA4D9EuUY= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+43642+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1562914409785713.5045274915612; Thu, 11 Jul 2019 23:53:29 -0700 (PDT) Return-Path: X-Received: from EUR04-HE1-obe.outbound.protection.outlook.com (EUR04-HE1-obe.outbound.protection.outlook.com [40.107.7.45]) by groups.io with SMTP; Thu, 11 Jul 2019 23:53:28 -0700 X-Received: from VI1PR08CA0147.eurprd08.prod.outlook.com (2603:10a6:800:d5::25) by VI1PR0802MB2608.eurprd08.prod.outlook.com (2603:10a6:800:ae::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2052.19; Fri, 12 Jul 2019 06:53:24 +0000 X-Received: from DB5EUR03FT040.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e0a::201) by VI1PR08CA0147.outlook.office365.com (2603:10a6:800:d5::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2073.11 via Frontend Transport; Fri, 12 Jul 2019 06:53:24 +0000 Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+43642+1787277+3901457@groups.io; helo=web01.groups.io; Received-SPF: TempError (protection.outlook.com: error in processing during lookup of arm.com: DNS Timeout) X-Received: from nebula.arm.com (40.67.248.234) by DB5EUR03FT040.mail.protection.outlook.com (10.152.20.243) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.2052.18 via Frontend Transport; Fri, 12 Jul 2019 06:53:22 +0000 X-Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1415.2; Fri, 12 Jul 2019 06:53:15 +0000 X-Received: from E119924.Arm.com (10.37.8.167) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.1415.2 via Frontend Transport; Fri, 12 Jul 2019 06:53:14 +0000 From: "Krzysztof Koch" To: CC: , , , , , Subject: [edk2-devel] [PATCH v1 01/11] ShellPkg: acpiview: FADT: Validate global pointers before use Date: Fri, 12 Jul 2019 07:52:33 +0100 Message-ID: <20190712065243.3812-2-krzysztof.koch@arm.com> In-Reply-To: <20190712065243.3812-1-krzysztof.koch@arm.com> References: <20190712065243.3812-1-krzysztof.koch@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3d292c97-2e97-4b68-d023-08d70695a182 X-MS-TrafficTypeDiagnostic: VI1PR0802MB2608: X-MS-Exchange-PUrlCount: 1 X-Microsoft-Antispam-PRVS: NoDisclaimer: True X-MS-Oob-TLC-OOBClassifiers: OLM:3383; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: hT7OkivdAQi5mhkNjVpO0n7BJkDJuV3gygI5giEYApOLg9rbE6Q6J5faXoCYL5tJoeRH1s+XZTbyEj//3sSRqBgBf7IOQx3EzbBsBRcFR25BKs22tp8Tp6f1mbrCOBBYBhNDOM6iRao0nO0v/E8WW1PrRoZyIe1gf1ufWR36YOIG4mxzQjRSo0yf1nKB13CLHagke8zUP/FuqFgdc3VRT6kafOqjLkrgZbIVE8mSKnj8w3jXtsAsv71k0YHhw6gzKUMNZEvmfQwqNTqFa8/Ks6LjM+1ib89dLpMAakxUw/p179WOYs83G4BoZ/V38TiA1WRyhmyTzFj4u0iL4+NJPZZ7bcCrwW0CQRY2FNv5uD+TyFBj6kzgpK7m6/2bgmCgjisWdX9NrEP38kw0D6YM3A6fVBbMp3CPzcHPblizixw= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jul 2019 06:53:22.5702 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3d292c97-2e97-4b68-d023-08d70695a182 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[40.67.248.234];Helo=[nebula.arm.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0802MB2608 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,krzysztof.koch@arm.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1562914409; bh=TnaPax0RjFUee7S+W8UFlpb691YhjwhZRTrtu4rkIk4=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=GGmIpOnESRiR0ts6LLRYiMQgdHCgcw0g/bkgv5ZzqLreSmShSeAefBvxWdnhY52zcMO 6iYgUT1SCR90l7ZVYbGptnj5Ng/s46WUGwwZ7ffhdBSjyKEyNmFgAPM4VbEInOjxlbahk QEAWkPRQa5Egx+183+7bmAZXBoxoXEXLcmM= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Alexei Fedorov Reviewed-by: Jaben Carsey --- Changes can be seen at: https://github.com/KrzysztofKoch1/edk2/commit/49cc4= 1430775fb93205e302590a7d31f080c3952 Notes: v1: - improve the logic in the parser [Krzysztof] ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c | 1= 31 ++++++++------------ 1 file changed, 51 insertions(+), 80 deletions(-) diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/Fadt= Parser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtPa= rser.c index cee7ee0770433da96d6042d2f5d687903f4b5495..600d3b16d7b22b61c1a1fd21ecb= 93f16c7f8fa1a 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 =20 - 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 =20 @par Reference(s): @@ -12,6 +12,7 @@ #include #include "AcpiParser.h" #include "AcpiTableParser.h" +#include "AcpiView.h" =20 // 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 !=3D 0) { + IncrementErrorCount (); + Print ( + L"\nERROR: Firmware Control must be zero for ARM platforms." + ); + } +#endif +} =20 /** 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 !=3D 0) { + IncrementErrorCount (); + Print ( + L"\nERROR: X Firmware Control must be zero for ARM platforms." + ); + } +#endif +} =20 /** 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) =3D=3D 0) { + IncrementErrorCount (); + Print ( + L"\nERROR: HW_REDUCED_ACPI flag must be set for ARM platforms." + ); + } +#endif +} =20 /** An ACPI_PARSER array describing the ACPI FADT Table. @@ -142,81 +173,6 @@ STATIC CONST ACPI_PARSER FadtParser[] =3D { {L"Hypervisor VendorIdentity", 8, 268, L"%lx", NULL, NULL, NULL, NULL} }; =20 -/** - 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 !=3D 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 !=3D 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) =3D=3D 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) ); =20 + // Check if the values used to control the parsing logic have been + // successfully read. + if ((DsdtAddress =3D=3D NULL) || + (FadtMinorRevision =3D=3D NULL) || + (X_DsdtAddress =3D=3D NULL)) { + IncrementErrorCount (); + Print ( + L"ERROR: Insufficient table length. AcpiTableLength =3D %d. " \ + L"FADT parsing aborted.\n", + AcpiTableLength + ); + return; + } + if (Trace) { Print (L"\nSummary:\n"); PrintFieldName (2, L"FADT Version"); Print (L"%d.%d\n", *AcpiHdrInfo.Revision, *FadtMinorRevision); =20 - if (*GetAcpiXsdtHeaderInfo ()->OemTableId !=3D *AcpiHdrInfo.OemTableId= ) { + if (GetConsistencyChecking () && + (*GetAcpiXsdtHeaderInfo ()->OemTableId !=3D *AcpiHdrInfo.OemTableI= d)) { IncrementErrorCount (); Print (L"ERROR: OEM Table Id does not match with RSDT/XSDT.\n"); } -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)' -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#43642): https://edk2.groups.io/g/devel/message/43642 Mute This Topic: https://groups.io/mt/32439503/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri Apr 26 18:37:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+43643+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1562914412; cv=none; d=zoho.com; s=zohoarc; b=Va2GZmw/R8MmZvlMF4rpalLD3UXBj6xwo7RlCzcP+oVn9ibw9TfhUYpA2Cq16rPOtTwPoo479X9qqAEeixERY86+6k5uro/VFsN4MymrORGc0ijJRcAGrdqKJVetsxkqSsnLV8+AGBEENVxDqst4rYNxKcSABHgJdZ6eDuo2Qdg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562914412; h=Content-Type:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To:ARC-Authentication-Results; bh=cIMucT399fScsiXoixT4z3q48oyI7P8LDCk5bikce3s=; b=VGBbp6mkcHfPEpd8pQlA+8detvPhzs0wvCSegxLZQ9FkzeNWqqej8ieSwCxRutrAm9PkjrwvtYzx+ay1ZwPwk53QxzDq1rpSivKfzWxyTWj2KxXH/qriNfJjQbHGGP3zEEY8FGJTy4dmUSMOpoK+VPRlAtpM9o1ZZQ1qt/+hkio= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+43643+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1562914412439877.3760669870979; Thu, 11 Jul 2019 23:53:32 -0700 (PDT) Return-Path: X-Received: from EUR02-VE1-obe.outbound.protection.outlook.com (EUR02-VE1-obe.outbound.protection.outlook.com [40.107.2.53]) by groups.io with SMTP; Thu, 11 Jul 2019 23:53:31 -0700 X-Received: from VI1PR08CA0148.eurprd08.prod.outlook.com (2603:10a6:800:d5::26) by DB8PR08MB4954.eurprd08.prod.outlook.com (2603:10a6:10:bf::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2052.18; Fri, 12 Jul 2019 06:53:27 +0000 X-Received: from DB5EUR03FT040.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e0a::203) by VI1PR08CA0148.outlook.office365.com (2603:10a6:800:d5::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2073.11 via Frontend Transport; Fri, 12 Jul 2019 06:53:27 +0000 Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+43643+1787277+3901457@groups.io; helo=web01.groups.io; Received-SPF: TempError (protection.outlook.com: error in processing during lookup of arm.com: DNS Timeout) X-Received: from nebula.arm.com (40.67.248.234) by DB5EUR03FT040.mail.protection.outlook.com (10.152.20.243) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.2052.18 via Frontend Transport; Fri, 12 Jul 2019 06:53:25 +0000 X-Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1415.2; Fri, 12 Jul 2019 06:53:16 +0000 X-Received: from E119924.Arm.com (10.37.8.167) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.1415.2 via Frontend Transport; Fri, 12 Jul 2019 06:53:16 +0000 From: "Krzysztof Koch" To: CC: , , , , , Subject: [edk2-devel] [PATCH v1 02/11] ShellPkg: acpiview: SPCR: Remove redundant forward declaration Date: Fri, 12 Jul 2019 07:52:34 +0100 Message-ID: <20190712065243.3812-3-krzysztof.koch@arm.com> In-Reply-To: <20190712065243.3812-1-krzysztof.koch@arm.com> References: <20190712065243.3812-1-krzysztof.koch@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6e8600ba-9fd5-4e1d-b6c5-08d70695a380 X-MS-TrafficTypeDiagnostic: DB8PR08MB4954: X-MS-Exchange-PUrlCount: 1 X-Microsoft-Antispam-PRVS: NoDisclaimer: True X-MS-Oob-TLC-OOBClassifiers: OLM:2657; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: g0+fxBlLBxSpJLJDOBUaLVx2fWDPAaPiEVu7eZkdQSkKsmUgeqEa3YAsmb9VPVmCM4jN91zooNy9LQGMKWzP2dL4OGmxn6ZTGD5KPxPrwFLaLu1Msh4UiH/vR7IOBR7G6KPml+3pLEWUwQ55DmxOh0M6gQTdLUrVgHxTIhfAHOWUC+tH53UftPcETViS4xTvEoyFzwfPzy9qzTo1DoTTccFfXLRgbsO+Gl3xtMRHAdyCHt7AutmGM7UCBLaCHw07m4COhu42f12bfoULt8bMLmWGZzOVBzjT816LKfn+UWVweUxisvv4+tc9vT6AjCwPp98cgUXvVakyhevirWxwMIDfhWo/IpAsQQHjnNoeUTk2iTr1cZd3zoZMMHGSvYkDTcMSPSd2dDSzPcOR3w4Z5QY2F6MVpA+8GaD4/NAJBYs= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jul 2019 06:53:25.9109 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6e8600ba-9fd5-4e1d-b6c5-08d70695a380 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[40.67.248.234];Helo=[nebula.arm.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR08MB4954 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,krzysztof.koch@arm.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1562914412; bh=fOlJcqoaM4nV35W+LD1YwDFStjEHxddrlVNGYfpSBHA=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=d5jbiu06oBKohi3+bkeAagQrtmL1pU3vI4wVbHJuweTHipaVoYpEQhwAOkAn1b78YW7 XQXdCLBBh08KicNSWmJZT9S1rpDGflQBPyW4gG+Nm8ZqYBRBTZG9uw8DqOumuidD3qiS8 y/x5YZOCGlicvJHvje20S8ENJX3ufFU7BsA= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Reposition blocks of code to remove redundant forward function declarations in order to reduce the code size. Signed-off-by: Krzysztof Koch Reviewed-by: Alexei Fedorov --- Changes can be seen at: https://github.com/KrzysztofKoch1/edk2/commit/9be55= a64f804c3d99e7c692208c8086d5b9ca553 Notes: v1: - remove redundant forward declarations [Krzysztof] ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Spcr/SpcrParser.c | 9= 8 +++++++------------- 1 file changed, 34 insertions(+), 64 deletions(-) diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Spcr/Spcr= Parser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Spcr/SpcrPa= rser.c index 1974a9c046e4a3bccccc55cf758184af097b2420..3b06b05dee8c056c6e009b9e485= ccd35d4194e95 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 =20 - 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 =20 @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 =3D *Ptr; + + if (InterruptType !=3D + EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_INTERRUPT_TYPE_GIC)= { + IncrementErrorCount (); + Print ( + L"\nERROR: InterruptType =3D %d. This must be 8 on ARM Platforms", + InterruptType + ); + } +#endif +} =20 /** 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 =3D *Ptr; + + if (Irq !=3D 0) { + IncrementErrorCount (); + Print ( + L"\nERROR: Irq =3D %d. This must be zero on ARM Platforms\n", + Irq + ); + } +#endif +} =20 /** An ACPI_PARSER array describing the ACPI SPCR Table. @@ -76,67 +107,6 @@ STATIC CONST ACPI_PARSER SpcrParser[] =3D { {L"Reserved", 4, 76, L"%x", NULL, NULL, NULL, NULL} }; =20 -/** - 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 =3D *Ptr; - - if (InterruptType !=3D - EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_INTERRUPT_TYPE_GIC)= { - IncrementErrorCount (); - Print ( - L"\nERROR: InterruptType =3D %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 =3D *Ptr; - - if (Irq !=3D 0) { - IncrementErrorCount (); - Print ( - L"\nERROR: Irq =3D %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)' -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- 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/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri Apr 26 18:37:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+43644+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1562914416; cv=none; d=zoho.com; s=zohoarc; b=OBRPIcHDPx/ukMXVhE9oU5d/9Kimi4+mG/6/+DX4fd/FxoRo1YlVcGJNldr+HWSCxZjkYLrwi5/jL1qZikC/wkaVTgHU8OPeVPbhHmimpDtX1UI/izH8uwtz20h32CShXnRBL4ypz+m6k4gQPwQtitQNRBRRgOU8xADxY6NP1J4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562914416; h=Content-Type:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To:ARC-Authentication-Results; bh=e2HT16Hx4pKkYwqsMFXgd3vjToJDbSfmq5lH4R7hX1U=; b=dIz7veLjaReFkNNgZoWgoCjFk5Q8642PUGW+2qAEztSiAJxuZVhyKDW5DQbJcJJsSFdy7hrKHswESBXqospsI/AnCGo6A7IltT64qDbJ9HC8OSZpw/R/WXpRMHrBfPOSMnncZhlSagYGODpsON3EpW7aNxySz9I+dEfSDNKxyl4= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+43644+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1562914416518490.6146139445218; Thu, 11 Jul 2019 23:53:36 -0700 (PDT) Return-Path: X-Received: from EUR01-HE1-obe.outbound.protection.outlook.com (EUR01-HE1-obe.outbound.protection.outlook.com [40.107.13.53]) by groups.io with SMTP; Thu, 11 Jul 2019 23:53:35 -0700 X-Received: from VI1PR08CA0151.eurprd08.prod.outlook.com (2603:10a6:800:d5::29) by AM5PR0802MB2594.eurprd08.prod.outlook.com (2603:10a6:203:99::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2052.16; Fri, 12 Jul 2019 06:53:31 +0000 X-Received: from DB5EUR03FT040.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e0a::200) by VI1PR08CA0151.outlook.office365.com (2603:10a6:800:d5::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2073.14 via Frontend Transport; Fri, 12 Jul 2019 06:53:31 +0000 Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+43644+1787277+3901457@groups.io; helo=web01.groups.io; Received-SPF: TempError (protection.outlook.com: error in processing during lookup of arm.com: DNS Timeout) X-Received: from nebula.arm.com (40.67.248.234) by DB5EUR03FT040.mail.protection.outlook.com (10.152.20.243) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.2052.18 via Frontend Transport; Fri, 12 Jul 2019 06:53:29 +0000 X-Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1415.2; Fri, 12 Jul 2019 06:53:17 +0000 X-Received: from E119924.Arm.com (10.37.8.167) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.1415.2 via Frontend Transport; Fri, 12 Jul 2019 06:53:16 +0000 From: "Krzysztof Koch" To: CC: , , , , , Subject: [edk2-devel] [PATCH v1 03/11] ShellPkg: acpiview: RSDP: Make printing table checksum optional Date: Fri, 12 Jul 2019 07:52:35 +0100 Message-ID: <20190712065243.3812-4-krzysztof.koch@arm.com> In-Reply-To: <20190712065243.3812-1-krzysztof.koch@arm.com> References: <20190712065243.3812-1-krzysztof.koch@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: dad75a3a-17e2-47b8-625d-08d70695a5d1 X-MS-TrafficTypeDiagnostic: AM5PR0802MB2594: X-MS-Exchange-PUrlCount: 1 X-Microsoft-Antispam-PRVS: NoDisclaimer: True X-MS-Oob-TLC-OOBClassifiers: OLM:3826; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: hdxzlUBHL7z6NVFZc9OiDOJ7EI5pR06Wb2d/OgVqs9GGYATif4q4ItWJAsfTq4iXsSx5YM0PgUOVrPahlsy6UvO2dvapmKyzPWVfbG0cI5HHoPdd+BoOyuk8f7qMHAEDdy2f8mDsZQqmsrNLMCrROyhdXjT2Bv7Jkg841IZe3U/0DeYZJbkFgqcolc0mEyXDoE03eGbE5DprYNf9y7v1PzNG+5ZoF2RUQGpuIhwMDzJWq/lhmZN4qqnCVyySMCmvU1UYZu1P0+bloptSUOlty4Bg8084rkaJ0Wauqgjsv7o5rNvlNrKKDT23/QsaEPdboYccck6AfCOD2puR/rD7LGg2oeKcBQBn+9VBjGTghx6bOv/blk1GgLcM9xbNWfewhK2ddcOYC5hqsRyengrerqwY6o67HWPYgc+NUkCbk4o= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jul 2019 06:53:29.7941 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dad75a3a-17e2-47b8-625d-08d70695a5d1 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[40.67.248.234];Helo=[nebula.arm.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0802MB2594 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,krzysztof.koch@arm.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1562914416; bh=qQavICRIpAu0aAUbst4Mb4VBzcn1dozdu2wrPXqYavw=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=MXj8ljcSy2wHF4ENY5tQKlA4CaIq1tkNzN+C/xKprfb/TQJk7ik5FmCTBsNaDvEvC0Q CBq+G/FlIIgEaDnGmRTUrFGLCIBB5HJrvMku/blj96LZOWpSyDz4nblXLq+73JHS42paV 0ToE8h6R9z2lWK4Ioa5U7Jg729MYvL7hG0o= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Alexei Fedorov --- Changes can be seen at: https://github.com/KrzysztofKoch1/edk2/commit/73e6d= 7e117da244f8f4065620115a47f7f66d372 Notes: v1: - make RSDP parser behavior consistent with other tables [Krzysztof] ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c | 1= 44 +++++++++----------- 1 file changed, 68 insertions(+), 76 deletions(-) diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/Rsdp= Parser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpPa= rser.c index 586de7cbfb12f856c0c735b6e295c1cc32eb2ceb..952517cd09aaff601bb363fd733= 31c750a9e97ff 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 =20 - 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 =20 @par Reference(s): @@ -11,6 +11,7 @@ #include #include "AcpiParser.h" #include "AcpiTableParser.h" +#include "AcpiView.h" =20 // 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 Platf= orms + // 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 =3D *(UINT32*)Ptr; + + if (RsdtAddr !=3D 0) { + IncrementErrorCount (); + Print ( + L"\nERROR: Rsdt Address =3D 0x%p. This must be NULL on ARM Platforms= .", + RsdtAddr + ); + } +#endif +} =20 /** 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 Platf= orms + // 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 =3D *(UINT64*)Ptr; + + if (XsdtAddr =3D=3D 0) { + IncrementErrorCount (); + Print ( + L"\nERROR: Xsdt Address =3D 0x%p. This must not be NULL on ARM Platf= orms.", + XsdtAddr + ); + } +#endif +} =20 /** An array describing the ACPI RSDP Table. @@ -61,76 +102,6 @@ STATIC CONST ACPI_PARSER RsdpParser[] =3D { {L"Reserved", 3, 33, L"%x %x %x", Dump3Chars, NULL, NULL, NULL} }; =20 -/** - 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 Platf= orms - // 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 =3D *(UINT32*)Ptr; - - if (RsdtAddr !=3D 0) { - IncrementErrorCount (); - Print ( - L"\nERROR: Rsdt Address =3D 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 Platf= orms - // 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 =3D *(UINT64*)Ptr; - - if (XsdtAddr =3D=3D 0) { - IncrementErrorCount (); - Print ( - L"\nERROR: Xsdt Address =3D 0x%p. This must not be NULL on ARM Platf= orms.", - XsdtAddr - ); - } -#endif -} - /** This function parses the ACPI RSDP table. =20 @@ -156,10 +127,31 @@ ParseAcpiRsdp ( { if (Trace) { DumpRaw (Ptr, AcpiTableLength); - VerifyChecksum (TRUE, Ptr, AcpiTableLength); + if (GetConsistencyChecking ()) { + VerifyChecksum (TRUE, Ptr, AcpiTableLength); + } } =20 - ParseAcpi (Trace, 0, "RSDP", Ptr, AcpiTableLength, PARSER_PARAMS (RsdpPa= rser)); + ParseAcpi ( + Trace, + 0, + "RSDP", + Ptr, + AcpiTableLength, + PARSER_PARAMS (RsdpParser) + ); + + // Check if the values used to control the parsing logic have been + // successfully read. + if (XsdtAddress =3D=3D NULL) { + IncrementErrorCount (); + Print ( + L"ERROR: Insufficient table length. AcpiTableLength =3D %d." \ + L"RSDP parsing aborted.\n", + AcpiTableLength + ); + return; + } =20 // This code currently supports parsing of XSDT table only // and does not parse the RSDT table. Platforms provide the @@ -167,7 +159,7 @@ ParseAcpiRsdp ( // Therefore the RSDT should not be used on ARM platforms. if ((*XsdtAddress) =3D=3D 0) { IncrementErrorCount (); - Print (L"ERROR: XSDT Pointer is not set.\n"); + Print (L"ERROR: XSDT Pointer is not set. RSDP parsing aborted.\n"); return; } =20 -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)' -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#43644): https://edk2.groups.io/g/devel/message/43644 Mute This Topic: https://groups.io/mt/32439506/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri Apr 26 18:37:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+43645+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1562914421376111.11260954669831; Thu, 11 Jul 2019 23:53:41 -0700 (PDT) Return-Path: X-Received: from EUR04-HE1-obe.outbound.protection.outlook.com (EUR04-HE1-obe.outbound.protection.outlook.com [40.107.7.75]) by groups.io with SMTP; Thu, 11 Jul 2019 23:53:39 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VWPGyQ9xW8B+fvTF3vHN2uLKGhAglxYVCuiBEjPyRnN3o/Em0FVyoqTmmhszEVRLjR94YbNM4fX8Q9jMKrhXTlekJwIgNDfLz1G1NeO83rHP7OQlb5e3AnKZigKhl7BhI/ryg7MLl075mOcXe5iDn4ogXfDLUrX10Fi1L/YewuX1BB1WbKrO3N02iOVaKB/efagiF51TYG8+D2gyfJn86Ia5G19t7xBSeVUEslCtSuke9RbzCVfssnPhcdCCHyVblSm/QcZNI4Gx77jDXwUe1RnIuXYCwm81pz9GKMbImmcVSnzUp/eWodLxV5TExML2o3lkEOLPSR6bUPHqyvXymQ== 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=+0H1GzoAIa47QCjHdNGtwp7Uuv8V/jaL8qnZyT0KtU4=; b=AM2jT/dD/QQ3k4r9j0dDBgTIeqzvQ/yDfdFir4rhTn08qK7EkSlJoRmlTW2mOTlRoFOIx1V94IWeuklBoSNjHa0x1UgsZAEtB2DIH6WP+rcfBTpzMYHfwlLtWr2DrBK+jbZUW2TGI0Yt32u4haFpOeb7j2QdxJww8FyStthGhCBTE63v+WvxdJQPEgbiXQEZXwCGLd/v6+wfqqeROdoFFxC3xOlnXpNWtUkR2qQIB5voY4FoA4UvzQqcniLF3aKt5Z7y1QiZcHf9U2f5MNfTPjw26u0/k1ocz8zHGoM51S7o5Vgdrs36jgGcGt56lfr5MRSb3ekf9cAAvZwtC0rppQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1;spf=temperror (sender ip is 40.67.248.234) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=arm.com;dmarc=temperror action=none header.from=arm.com;dkim=none (message not signed);arc=none X-Received: from VI1PR08CA0148.eurprd08.prod.outlook.com (2603:10a6:800:d5::26) by HE1PR0802MB2601.eurprd08.prod.outlook.com (2603:10a6:3:d8::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2073.14; Fri, 12 Jul 2019 06:53:35 +0000 X-Received: from DB5EUR03FT040.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e0a::203) by VI1PR08CA0148.outlook.office365.com (2603:10a6:800:d5::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2073.11 via Frontend Transport; Fri, 12 Jul 2019 06:53:35 +0000 Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+43645+1787277+3901457@groups.io; helo=web01.groups.io; Received-SPF: TempError (protection.outlook.com: error in processing during lookup of arm.com: DNS Timeout) X-Received: from nebula.arm.com (40.67.248.234) by DB5EUR03FT040.mail.protection.outlook.com (10.152.20.243) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.2052.18 via Frontend Transport; Fri, 12 Jul 2019 06:53:34 +0000 X-Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1415.2; Fri, 12 Jul 2019 06:53:18 +0000 X-Received: from E119924.Arm.com (10.37.8.167) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.1415.2 via Frontend Transport; Fri, 12 Jul 2019 06:53:18 +0000 From: "Krzysztof Koch" To: CC: , , , , , Subject: [edk2-devel] [PATCH v1 04/11] ShellPkg: acpiview: XSDT: Remove redundant ParseAcpi() call Date: Fri, 12 Jul 2019 07:52:36 +0100 Message-ID: <20190712065243.3812-5-krzysztof.koch@arm.com> In-Reply-To: <20190712065243.3812-1-krzysztof.koch@arm.com> References: <20190712065243.3812-1-krzysztof.koch@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d6eb6ec3-b290-4a5e-7577-08d70695a85d X-MS-TrafficTypeDiagnostic: HE1PR0802MB2601: X-MS-Exchange-PUrlCount: 1 X-Microsoft-Antispam-PRVS: NoDisclaimer: True X-MS-Oob-TLC-OOBClassifiers: OLM:4125; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: 38FxzdzHAU5001ZN3P3pczQcphpAbL9QrYG3jjTr1TYnl7UYLB1/Xn9xXlgmzdd0hKHobGNc4eE91JdTHLuJcEYveAc5mjaqB0dykCDLwozHNRAh3TwQi2L4WZFHk5mnKkSScldUc3NRSgrm7cFvo8/GxkzwcPu8tjE6sYMOISNKTTZscDnz8GTTkBOMI1LaczdSoI+HrAK2glXd4AL6wNtssg1LALy/8wB03CMUQvzcuiQMm3m1kTu7tcvqITkhElz8gSiXPSGACBs1TbpeZfB6F4WHaWXZZBiGei+koOCl+rnUTLnwIHiRKAVakGios080rywxd6gtZKUG0sbFyY1+f9zPxRORKVo2Em1ts01klS4khzUS50zOCuWPThTfOO6SampkIrnFum/U5i7sfZYA8xWC7nx9XRm8LG2wkjY= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jul 2019 06:53:34.0675 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d6eb6ec3-b290-4a5e-7577-08d70695a85d X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[40.67.248.234];Helo=[nebula.arm.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0802MB2601 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,krzysztof.koch@arm.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1562914419; bh=7NlSaGQqspdezdFpP0hSxKGMP4DLVklDfA5MCeuh3uE=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=Zv5P5R8Q00TuQZPRHY92yLKeac4pAr0xSZwrEGP6/Wux/nwcCoRxaf+oQJBWBKU9FUU uj+A6HlZAkb7RfRO3PQozhxI2tWtZZz2DBmwVIJEd927Y0+UWse74X868m6uVQk3wm3CD CXxfxqt+OnWAmOGOIPJHdOO01102cE3RLs4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Alexei Fedorov --- Changes can be seen at: https://github.com/KrzysztofKoch1/edk2/commit/27b4a= e23c4f230225d6bcb27598b42edcf329512 Notes: v1: - Remove a redundant call to ParseAcpi() [Krzysztof] ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c | 2= 2 +++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/Xsdt= Parser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtPa= rser.c index 4196168bff47d70c67f79f3fc1f4cdee302d460e..b7d8f4215a71ef429fb88d6f2d9= 98d8f38250716 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 =20 - 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 =20 @par Reference(s): @@ -13,6 +13,7 @@ #include #include "AcpiParser.h" #include "AcpiTableParser.h" +#include "AcpiView.h" =20 // Local variables STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo; @@ -60,22 +61,12 @@ ParseAcpiXsdt ( UINTN EntryIndex; CHAR16 Buffer[32]; =20 - // Parse the ACPI header to get the length - ParseAcpi ( - FALSE, - 0, - "XSDT", - Ptr, - ACPI_DESCRIPTION_HEADER_LENGTH, - PARSER_PARAMS (XsdtParser) - ); - Offset =3D ParseAcpi ( Trace, 0, "XSDT", Ptr, - *AcpiHdrInfo.Length, + AcpiTableLength, PARSER_PARAMS (XsdtParser) ); =20 @@ -84,7 +75,7 @@ ParseAcpiXsdt ( if (Trace) { EntryIndex =3D 0; TablePointer =3D (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); =20 // Validate the table pointers are not NULL - if ((UINT64*)(UINTN)(*TablePointer) =3D=3D NULL) { + if (GetConsistencyChecking () && + ((UINT64*)(UINTN)(*TablePointer) =3D=3D 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 =3D TableOffset; TablePointer =3D (UINT64*)(Ptr + TableOffset); - while (Offset < (*AcpiHdrInfo.Length)) { + while (Offset < AcpiTableLength) { if ((UINT64*)(UINTN)(*TablePointer) !=3D NULL) { ProcessAcpiTable ((UINT8*)(UINTN)(*TablePointer)); } -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)' -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- 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/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri Apr 26 18:37:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+43641+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1562914408; cv=none; d=zoho.com; s=zohoarc; b=M9ZBbFZh7nvgXUTbcRJsvKNXb1USORUDs0Y4HbcUHC/ZcdXdx1FkoExA0ZSVUhoIFdZVxAnglWjROv4/p94H5Mqq4aVY/LF19fZ2Qxm4+B4+wz4rzeUvscJPRl0jK0GdgYjNJD272gJlAoHLeseSk1rfurqJb/3bPN5ktaf0cto= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562914408; h=Content-Type:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To:ARC-Authentication-Results; bh=c3TbI6W7KMQRxGZ9yWOhckPlAkIypzhA14MmSGVIiPM=; b=gKd2SggSrNFUsIFgPRisLGN8hnSy8BxoHTN4LuEpodSDNHX7bwLBDsnkeC997WkpXfoNyoGGs9eRZVc0lI7oMy6VOPeRWbLadzIwR9olNDachm2DiuECTRNe7ms04pvTiVAKilUiLr9EeVUQTGvXoo9mAxjP2VxfvcIWY7OgTAg= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+43641+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1562914408891898.2975731364335; Thu, 11 Jul 2019 23:53:28 -0700 (PDT) Return-Path: X-Received: from EUR03-AM5-obe.outbound.protection.outlook.com (EUR03-AM5-obe.outbound.protection.outlook.com [40.107.3.64]) by groups.io with SMTP; Thu, 11 Jul 2019 23:53:27 -0700 X-Received: from HE1PR08CA0073.eurprd08.prod.outlook.com (2603:10a6:7:2a::44) by DB8PR08MB4954.eurprd08.prod.outlook.com (2603:10a6:10:bf::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2052.18; Fri, 12 Jul 2019 06:53:24 +0000 X-Received: from VE1EUR03FT064.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e09::206) by HE1PR08CA0073.outlook.office365.com (2603:10a6:7:2a::44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2073.14 via Frontend Transport; Fri, 12 Jul 2019 06:53:23 +0000 Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+43641+1787277+3901457@groups.io; helo=web01.groups.io; Received-SPF: TempError (protection.outlook.com: error in processing during lookup of arm.com: DNS Timeout) X-Received: from nebula.arm.com (40.67.248.234) by VE1EUR03FT064.mail.protection.outlook.com (10.152.19.210) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.2052.18 via Frontend Transport; Fri, 12 Jul 2019 06:53:22 +0000 X-Received: from AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1415.2; Fri, 12 Jul 2019 06:53:19 +0000 X-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.1415.2; Fri, 12 Jul 2019 06:53:19 +0000 X-Received: from E119924.Arm.com (10.37.8.167) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.1415.2 via Frontend Transport; Fri, 12 Jul 2019 06:53:19 +0000 From: "Krzysztof Koch" To: CC: , , , , , Subject: [edk2-devel] [PATCH v1 05/11] ShellPkg: acpiview: SLIT: Add error-checking in the parsing logic Date: Fri, 12 Jul 2019 07:52:37 +0100 Message-ID: <20190712065243.3812-6-krzysztof.koch@arm.com> In-Reply-To: <20190712065243.3812-1-krzysztof.koch@arm.com> References: <20190712065243.3812-1-krzysztof.koch@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0772ef94-c092-4d12-65e1-08d70695a15f X-MS-TrafficTypeDiagnostic: DB8PR08MB4954: X-MS-Exchange-PUrlCount: 1 X-Microsoft-Antispam-PRVS: NoDisclaimer: True X-MS-Oob-TLC-OOBClassifiers: OLM:2000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: BUQjvZHsggh1HBCPLiVGIY9K1LozOOGmW7+bWzfn10J/io8VxYjjjFKmPZtcZjtcbl7gKVIenCX9ouO5r+GxWR57+vtTJN1l8FzPfJCVtYFlfI8dVDKlCO0fthEi6uFCfd6km6teTu5dLDN8TrXgUZTINF3/Pgb7YBamjV4Z+q+QiSCmk17In+ZbtzrVKU3MBpYWA1HVoXn/Z478nAjKdeodzFG95EH7Rr3VVJ+BlV2v139Y8FQaNSYidmm2ZZLQsV88M5Pi5AfAenXvZOHCVndTi2VONLhPIZ5IMyLQ83UE/iy6hLrnrNjYNjPniI1Vm+mILvWAXiMY5evMdyz6nkxVdzdkd2RwJfCnWYrnUTXJrM7ljsrgXnOh04sCOak+oT2gkFknedgRd2T5DhycQyJv66XeaYb5X45apxNyTYo= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jul 2019 06:53:22.1920 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0772ef94-c092-4d12-65e1-08d70695a15f X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[40.67.248.234];Helo=[nebula.arm.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR08MB4954 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,krzysztof.koch@arm.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1562914408; bh=i84cewWilBIrz+0SJcARl8klfYWRbzVkqYFMUluvmGw=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=ooYAyAMeKikJfIJQsofF45iuYpA7b7iRxE1bvJcYBQusvGZvZ9BGWeVir7BfotWL4jK /ntOF4nnB5AF/MDjXLON404vCeCxxuM89TcgH36mtS1cifmcq9iM/buZfkMRFTv62So9L 9v6lBzNTck7n1IJYgqyVSVpYt3aRDdvqzuI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Alexei Fedorov --- Changes can be seen at: https://github.com/KrzysztofKoch1/edk2/commit/2f1ff= d1a74d06c23c01971be965d856f0a0e3ac4 Notes: v1: - improve the logic in the SLIT parser [Krzysztof] ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c | 1= 15 ++++++++++++++------ 1 file changed, 83 insertions(+), 32 deletions(-) diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/Slit= Parser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitPa= rser.c index 1f9dac66eea5b0f4366a7a9584ac6702a74beaac..dd5f039b67326acc710ee703a6b= 132a1e280dcaa 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 =20 - 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 =20 @par Reference(s): @@ -13,6 +13,7 @@ #include #include "AcpiParser.h" #include "AcpiTableParser.h" +#include "AcpiView.h" =20 // 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 =20 @@ -77,7 +78,55 @@ ParseAcpiSlit ( ); LocalityPtr =3D Ptr + Offset; =20 - LocalityCount =3D *SlitSystemLocalityCount; + // Check if the values used to control the parsing logic have been + // successfully read. + if (SlitSystemLocalityCount =3D=3D NULL) { + IncrementErrorCount (); + Print ( + L"ERROR: Insufficient table length. AcpiTableLength =3D %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 li= mited + 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 =3D sqrt (MAX_UINT32 - sizeof (EFI_ACPI_6_3_SYSTEM_LOCALIT= Y_DISTANCE_INFORMATION_TABLE_HEADER)) + =3D 65535 + =3D MAX_UINT16 + */ + if (*SlitSystemLocalityCount > MAX_UINT16) { + IncrementErrorCount (); + Print ( + L"ERROR: The Number of System Localities provided can't be represent= ed " \ + L"in the SLIT table. SlitSystemLocalityCount =3D %ld. " \ + L"MaxLocalityCountAllowed =3D %d.\n", + *SlitSystemLocalityCount, + MAX_UINT16 + ); + return; + } + + LocalityCount =3D (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 =3D %ld. AcpiTableLength =3D %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 =3D 0; Count< LocalityCount; Count++) { + for (Count =3D 0; Count < LocalityCount; Count++) { Print (L" (%3d) ", Count); for (Index =3D 0; Index < LocalityCount; Index++) { Print (L" %3d ", SLIT_ELEMENT (LocalityPtr, Count, Index)); @@ -106,34 +155,36 @@ ParseAcpiSlit ( } =20 // Validate - for (Count =3D 0; Count < LocalityCount; Count++) { - for (Index =3D 0; Index < LocalityCount; Index++) { - // Element[x][x] must be equal to 10 - if ((Count =3D=3D Index) && (SLIT_ELEMENT (LocalityPtr, Count,Index)= !=3D 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) - ); - } - // Element[i][j] must be equal to Element[j][i] - if (SLIT_ELEMENT (LocalityPtr, Count, Index) !=3D - SLIT_ELEMENT (LocalityPtr, Index, Count)) { - IncrementErrorCount (); - Print ( - L"ERROR: Relative distances for Element[0x%lx][0x%lx] (%3d) and = \n" - L"Element[0x%lx][0x%lx] (%3d) do not match.\n", - Count, - Index, - SLIT_ELEMENT (LocalityPtr, Count, Index), - Index, - Count, - SLIT_ELEMENT (LocalityPtr, Index, Count) - ); + if (GetConsistencyChecking ()) { + for (Count =3D 0; Count < LocalityCount; Count++) { + for (Index =3D 0; Index < LocalityCount; Index++) { + // Element[x][x] must be equal to 10 + if ((Count =3D=3D Index) && (SLIT_ELEMENT (LocalityPtr, Count,Inde= x) !=3D 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) + ); + } + // Element[i][j] must be equal to Element[j][i] + if (SLIT_ELEMENT (LocalityPtr, Count, Index) !=3D + SLIT_ELEMENT (LocalityPtr, Index, Count)) { + IncrementErrorCount (); + Print ( + L"ERROR: Relative distances for Element[0x%lx][0x%lx] (%3d) an= d \n" + L"Element[0x%lx][0x%lx] (%3d) do not match.\n", + Count, + Index, + SLIT_ELEMENT (LocalityPtr, Count, Index), + Index, + Count, + SLIT_ELEMENT (LocalityPtr, Index, Count) + ); + } } } - } + } // if (GetConsistencyChecking ()) } -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)' -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#43641): https://edk2.groups.io/g/devel/message/43641 Mute This Topic: https://groups.io/mt/32439502/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri Apr 26 18:37:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+43646+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1562914455; cv=none; d=zoho.com; s=zohoarc; b=WivxRxpWUquCQKViAcNlAOretIdXMQw43ZwfORJylGBwwQUMmlnSb516iwN6+ohWnOnHQMeQjyABmBXcEUeBHk3x7a2yaGbaipGoviy7p/wClNGM+yxcHE2caBiX9xiXBGs6/FtfHpeRADdGacC3Fz3LTZCnLuNc/A1nsL8eeJQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562914455; h=Content-Type:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To:ARC-Authentication-Results; bh=3fuWeEa/vMF/wYa9sb30gDtg780w5a9zz+kdYGDAORk=; b=e6cSOYIiPv8Dq4uCaWxIQyfFaQ2yydYwLwHYPUuTtV/Zj44d/0be+GrwShRV7ep6ZXJ4IrCa3res+L65oUVb+3M8R1qJ14wVy2Xnvs2mT49UPXlkUyJntoUA5V3/UDZJW0Uad46e22XaMcSUeOYOEIFSXeHc60sZPcZq5Kz7+cs= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+43646+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1562914455930710.9056241667889; Thu, 11 Jul 2019 23:54:15 -0700 (PDT) Return-Path: X-Received: from EUR04-VI1-obe.outbound.protection.outlook.com (EUR04-VI1-obe.outbound.protection.outlook.com [40.107.8.78]) by groups.io with SMTP; Thu, 11 Jul 2019 23:54:15 -0700 X-Received: from VI1PR0802CA0041.eurprd08.prod.outlook.com (2603:10a6:800:a9::27) by VI1PR0802MB2605.eurprd08.prod.outlook.com (2603:10a6:800:b0::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2052.19; Fri, 12 Jul 2019 06:54:11 +0000 X-Received: from DB5EUR03FT029.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e0a::207) by VI1PR0802CA0041.outlook.office365.com (2603:10a6:800:a9::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2073.10 via Frontend Transport; Fri, 12 Jul 2019 06:54:11 +0000 Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+43646+1787277+3901457@groups.io; helo=web01.groups.io; Received-SPF: TempError (protection.outlook.com: error in processing during lookup of arm.com: DNS Timeout) X-Received: from nebula.arm.com (40.67.248.234) by DB5EUR03FT029.mail.protection.outlook.com (10.152.20.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.2052.18 via Frontend Transport; Fri, 12 Jul 2019 06:54:10 +0000 X-Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1415.2; Fri, 12 Jul 2019 06:53:20 +0000 X-Received: from E119924.Arm.com (10.37.8.167) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.1415.2 via Frontend Transport; Fri, 12 Jul 2019 06:53:19 +0000 From: "Krzysztof Koch" To: CC: , , , , , Subject: [edk2-devel] [PATCH v1 06/11] ShellPkg: acpiview: SRAT: Add error-checking in the parsing logic Date: Fri, 12 Jul 2019 07:52:38 +0100 Message-ID: <20190712065243.3812-7-krzysztof.koch@arm.com> In-Reply-To: <20190712065243.3812-1-krzysztof.koch@arm.com> References: <20190712065243.3812-1-krzysztof.koch@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5abbb643-a4fc-4e46-ac03-08d70695bdcc X-MS-TrafficTypeDiagnostic: VI1PR0802MB2605: X-MS-Exchange-PUrlCount: 1 X-Microsoft-Antispam-PRVS: NoDisclaimer: True X-MS-Oob-TLC-OOBClassifiers: OLM:4125; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: kLHu5uG23wzB979VfqttVVQwZNA1zQzbLWN9Ipao1mg1VZJV8PqfdWuRS9DnECnxKQvmmdVOxRwm7v4zsxXJKrGJCXAVEz7NEl17pzqbK93EU4A+2yTd0yALIOgG1wh0h/ddyAEcQ4yNwIMg2WfgauHjIJHecSTH47UUDolnLg0csk0V9zz6jaVLdEuW/eoofbEpNxCkB2rd2RikD0uQfXwhtBLwFTX7kUb12aH2Sp7GOPcMfujgXwvUrBWcANLNIvpubnBE8DXa61qQQHmggHVFlJB766OSUN0T5tnH+V7qq1R+R9KYj6xM/kB6eD29Lx+CFEzd6Q9MWNJHFo6dnjbjMwNRG0inHmTTBNckSfTfC0zrZKWvfdiSOI3ssCVDdrajcya2M3pNMDjoiy2xd0RvCTkckxxK5k7t02CTuoU= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jul 2019 06:54:10.0295 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5abbb643-a4fc-4e46-ac03-08d70695bdcc X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[40.67.248.234];Helo=[nebula.arm.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0802MB2605 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,krzysztof.koch@arm.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1562914455; bh=mqMFKovAUp2UH4XuTmngFaShfPCbiakPujk6bHsLMk8=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=YyuUDHOZ25EY1zPi0eSOohVKgwiljnmWRtiwmYVOekHMzKHfm+WYl5apQ5lpxmzXD8p lWyEaYrx9r0WYKTY8GUEnXqlWTx5W4YNDYSp+1buhNLR6RdlWsxYHsT3AlMUwsTRu/7z8 FKNnhFe4a7MHFiLRHxiZUvcIL4xO/c+4Gmk= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Alexei Fedorov --- Changes can be seen at: https://github.com/KrzysztofKoch1/edk2/commit/d46d6= 82d28654b1c6263be2f4fd961c35e80e5cb Notes: v1: - improve the logic in the SRAT parser [Krzysztof] ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c | 1= 13 +++++++++++--------- 1 file changed, 63 insertions(+), 50 deletions(-) diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/Srat= Parser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratPa= rser.c index 075ff2a141a82b522e8aaedb7ad79249aaf5eaac..a12aceb70d273a628387b724378= 19dc05ad7301e 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 =20 - 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 =20 @par Reference(s): @@ -13,6 +13,7 @@ #include #include "AcpiParser.h" #include "AcpiTableParser.h" +#include "AcpiView.h" =20 // Local Variables STATIC CONST UINT8* SratRAType; @@ -32,7 +33,13 @@ EFIAPI ValidateSratReserved ( IN UINT8* Ptr, IN VOID* Context - ); + ) +{ + if (*(UINT32*)Ptr !=3D 1) { + IncrementErrorCount (); + Print (L"\nERROR: Reserved should be 1 for backward compatibility.\n"); + } +} =20 /** 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 =3D Ptr[0] | (Ptr[1] << 8) | (Ptr[2] << 16); + + Print (Format, ProximityDomain); +} =20 /** An ACPI_PARSER array describing the SRAT Table. @@ -139,47 +153,6 @@ STATIC CONST ACPI_PARSER SratX2ApciAffinityParser[] = =3D { {L"Reserved", 4, 20, L"0x%x", NULL, NULL, NULL, NULL} }; =20 -/** 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 !=3D 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 =3D 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 =3D Ptr + Offset; =20 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) ); =20 + // Check if the values used to control the parsing logic have been + // successfully read. + if ((SratRAType =3D=3D NULL) || + (SratRALength =3D=3D NULL)) { + IncrementErrorCount (); + Print ( + L"ERROR: Insufficient remaining table buffer length to read the " \ + L"Static Resource Allocation structure header. Length =3D %d.\n", + AcpiTableLength - Offset + ); + return; + } + + // Make sure forward progress is made. + if (*SratRALength < 2) { + IncrementErrorCount (); + Print ( + L"ERROR: Structure length is too small: SratRALength =3D %d. " \ + L"SratRAType =3D %d. SRAT parsing aborted.\n", + *SratRALength, + *SratRAType + ); + return; + } + + // Make sure the SRAT structure lies inside the table + if ((Offset + *SratRALength) > AcpiTableLength) { + IncrementErrorCount (); + Print ( + L"ERROR: Invalid SRAT structure length. SratRALength =3D %d. " \ + L"RemainingTableBufferLength =3D %d. SRAT parsing aborted.\n", + *SratRALength, + AcpiTableLength - Offset + ); + return; + } + switch (*SratRAType) { case EFI_ACPI_6_2_GICC_AFFINITY: AsciiSPrint ( @@ -278,7 +289,7 @@ ParseAcpiSrat ( ResourcePtr, *SratRALength, PARSER_PARAMS (SratGicITSAffinityParser) - ); + ); break; =20 case EFI_ACPI_6_2_MEMORY_AFFINITY: @@ -333,8 +344,10 @@ ParseAcpiSrat ( break; =20 default: - IncrementErrorCount (); - Print (L"ERROR: Unknown SRAT Affinity type =3D 0x%x\n", *SratRATyp= e); + if (GetConsistencyChecking ()) { + IncrementErrorCount (); + Print (L"ERROR: Unknown SRAT Affinity type =3D 0x%x\n", *SratRAT= ype); + } break; } =20 -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)' -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#43646): https://edk2.groups.io/g/devel/message/43646 Mute This Topic: https://groups.io/mt/32439509/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri Apr 26 18:37:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+43647+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1562914457509883.6555893213967; Thu, 11 Jul 2019 23:54:17 -0700 (PDT) Return-Path: X-Received: from EUR04-HE1-obe.outbound.protection.outlook.com (EUR04-HE1-obe.outbound.protection.outlook.com [40.107.7.40]) by groups.io with SMTP; Thu, 11 Jul 2019 23:54:16 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V0FhfulshAfEVFGDXoW1KIS//QnXBn863ENllt4cQ2Bu2xzOs5/srNCWbxCWg8zTGY5JsZ4olK33/A+Hn5VxyUwN0YTZ8vuxiPY7S85Pm/WK8Fp8/VwT+c6CDlsE5XG02SmmlGP7xnFWwEftFKVRq47jUx77gPOE1Lzu1s1wmRIPk3Hq9Q18VxE63XWPPZx8x9bvTKrvlh56YESWq6UpGA588zxli9BfhpSMuehAjDp4Kx8v2Xlk2/tbkrBOsQ/wsaiIsCJcpcizQ/ArakJ7GmfPiAhS4vgMmtrcTjgxF9LI4eenYPN/5YZ8vaVyqixPCkNKeDq46dstl5zPvFWP9w== 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=U/XIvfXg2CULTzoWAZxzZgTzpH/jLmP55LpF9KEsAGs=; b=W4jv/Khty0+ORHJOaEshQJY1icbN92bNb06c5zuvBUipnFl/bX/KZzS6SIYnYGX/pP/zJHvj5cOfU2+9H+ZDVcDfj7FUS1/fBEquUbcG2ZSe6+7GhXUH4T8hvl70HNmJKCFf38DNHayn3QQg/jvppE9y8IABK3XhGbDSZKZ6AloeogSPbNDTjixZqILcY7hBEsaKnxF/YkeP1kQ1CuTSZEmKZ1EQKAWcZyb9yeJYBnz9W3DxROADsu6RjjJLDHYK9rkK26x9j6xNFutGH9l7VljIa2N6MSgszNQgFJY2d1fP4T/i8EzWUssqZgqQ3JCDqbufpUmxnQBHBYeNd2tA6A== ARC-Authentication-Results: i=1; mx.microsoft.com 1;spf=temperror (sender ip is 40.67.248.234) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=arm.com;dmarc=temperror action=none header.from=arm.com;dkim=none (message not signed);arc=none X-Received: from VI1PR08CA0176.eurprd08.prod.outlook.com (2603:10a6:800:d1::30) by HE1PR0802MB2601.eurprd08.prod.outlook.com (2603:10a6:3:d8::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2073.14; Fri, 12 Jul 2019 06:54:12 +0000 X-Received: from DB5EUR03FT010.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e0a::209) by VI1PR08CA0176.outlook.office365.com (2603:10a6:800:d1::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2073.11 via Frontend Transport; Fri, 12 Jul 2019 06:54:12 +0000 Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+43647+1787277+3901457@groups.io; helo=web01.groups.io; Received-SPF: TempError (protection.outlook.com: error in processing during lookup of arm.com: DNS Timeout) X-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_CBC_SHA256) id 15.20.2052.18 via Frontend Transport; Fri, 12 Jul 2019 06:54:11 +0000 X-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; Fri, 12 Jul 2019 06:53:21 +0000 X-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.1415.2; Fri, 12 Jul 2019 06:53:20 +0000 X-Received: from E119924.Arm.com (10.37.8.167) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.1415.2 via Frontend Transport; Fri, 12 Jul 2019 06:53:20 +0000 From: "Krzysztof Koch" To: CC: , , , , , Subject: [edk2-devel] [PATCH v1 07/11] ShellPkg: acpiview: MADT: Add error-checking in the parsing logic Date: Fri, 12 Jul 2019 07:52:39 +0100 Message-ID: <20190712065243.3812-8-krzysztof.koch@arm.com> In-Reply-To: <20190712065243.3812-1-krzysztof.koch@arm.com> References: <20190712065243.3812-1-krzysztof.koch@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0b731d10-ad98-442a-dfbd-08d70695bec4 X-MS-TrafficTypeDiagnostic: HE1PR0802MB2601: X-MS-Exchange-PUrlCount: 1 X-Microsoft-Antispam-PRVS: NoDisclaimer: True X-MS-Oob-TLC-OOBClassifiers: OLM:4125; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: rfIJh/fAZx3QplNOzFmr9qIS/GVVoIqqcxJIUGWk/EjqIPLx5nsKiYCf7tc/ncHzfFjTjH+At7KUxnYznawBqON3t7u1SfGCdSgdpO1bOy8SRQ7bVlCZphqkdGD+lf/cVQW8UUEl0w0IP9TjboyiHe81zM2PpXpmZKvFUQlnR74Hy67RqyE4nMWb0pW66/pg0PuYWNPnG2Uk6tQKVFvBF3GbF/aEwb+ZA9ShxoAFNsTge6G/czt6y9SQDIwCc/3mwsCz4PAHk70QdC/HDuWEA7HDOFsSxqYpp5s7IhOo9f5TUFizmlNjc4AoWmUnwBU55Rlngq/jeHdAEvegqrt0VQeXRQFpsAj8bp93myeoX2nDZRlyp2Q8+NUOgv8TazEtgFeSO7y9Y1MJqB0Dy1fknMBEE9fm5/E16HMybyz5taw= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jul 2019 06:54:11.6551 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0b731d10-ad98-442a-dfbd-08d70695bec4 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[40.67.248.234];Helo=[nebula.arm.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0802MB2601 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,krzysztof.koch@arm.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1562914457; bh=TLUGDqeqwOMNNUHE4zyESNQpngnCDXfX3TD4PrIn9nM=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=SBSnOJV9kXXp9egEIal17ahAqF/Pk6DNwTem7zV8AQzeFkSckW6Lni68ozY1aqAES6f 9A9hf7IT0y8VeiUl+bi62+wXjPH0+JFLE4QyNlcZcnOgOedzC/eG4Qg3PFDKmotZ/KH3p BaQYf35uvR1ltUlt+DVYpx5UmWHgF8b/DJo= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Alexei Fedorov --- Changes can be seen at: https://github.com/KrzysztofKoch1/edk2/commit/ef117= 38efc94a9c3d7270d376a2cb273bbadbba2 Notes: v1: - improve the logic in the MADT parser [Krzysztof] ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c | 1= 87 ++++++++++---------- 1 file changed, 94 insertions(+), 93 deletions(-) diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/Madt= Parser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtPa= rser.c index 59c3df0cc8a080497b517baf36fc63f1e4ab866f..54f9fddc5426de5383b747ec7af= d21396bcccfc9 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" =20 // Local Variables @@ -35,7 +36,15 @@ EFIAPI ValidateGICDSystemVectorBase ( IN UINT8* Ptr, IN VOID* Context - ); +) +{ + if (*(UINT32*)Ptr !=3D 0) { + IncrementErrorCount (); + Print ( + L"\nERROR: System Vector Base must be zero." + ); + } +} =20 /** 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 =3D *(UINT16*)Ptr; + + // SPE not supported by this processor + if (SpeOverflowInterrupt =3D=3D 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 !=3D ARM_PPI_ID_PMBIRQ) { + IncrementWarningCount(); + Print ( + L"\nWARNING: SPE Overflow Interrupt ID of %d is not compliant with S= BSA " + L"Level 3 PPI ID assignment: %d.", + SpeOverflowInterrupt, + ARM_PPI_ID_PMBIRQ + ); + } +} =20 /** An ACPI_PARSER array describing the GICC Interrupt Controller Structure. @@ -158,78 +201,6 @@ STATIC CONST ACPI_PARSER MadtInterruptControllerHeader= Parser[] =3D { {L"Reserved", 2, 2, NULL, NULL, NULL, NULL, NULL} }; =20 -/** - 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 !=3D 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 =3D *(UINT16*)Ptr; - - // SPE not supported by this processor - if (SpeOverflowInterrupt =3D=3D 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 !=3D ARM_PPI_ID_PMBIRQ) { - IncrementWarningCount(); - Print ( - L"\nWARNING: SPE Overflow Interrupt ID of %d is not compliant with S= BSA " - 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 @@ -286,20 +257,47 @@ ParseAcpiMadt ( 0, NULL, InterruptContollerPtr, - 2, // Length is 1 byte at offset 1 + AcpiTableLength - Offset, PARSER_PARAMS (MadtInterruptControllerHeaderParser) ); =20 - if (((Offset + (*MadtInterruptControllerLength)) > AcpiTableLength) || - (*MadtInterruptControllerLength < 4)) { + // Check if the values used to control the parsing logic have been + // successfully read. + if ((MadtInterruptControllerType =3D=3D NULL) || + (MadtInterruptControllerLength =3D=3D NULL)) { IncrementErrorCount (); Print ( - L"ERROR: Invalid Interrupt Controller Length," - L" Type =3D %d, Length =3D %d\n", - *MadtInterruptControllerType, - *MadtInterruptControllerLength - ); - break; + L"ERROR: Insufficient remaining table buffer length to read the " \ + L"Interrupt Controller Structure header. Length =3D %d.\n", + AcpiTableLength - Offset + ); + return; + } + + // Make sure forward progress is made. + if (*MadtInterruptControllerLength < 2) { + IncrementErrorCount (); + Print ( + L"ERROR: Structure length is too small: " \ + L"MadtInterruptControllerLength =3D %d. " \ + L"MadtInterruptControllerType =3D %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 =3D %d. " \ + L"RemainingTableBufferLength =3D %d. MADT parsing aborted.\n", + *MadtInterruptControllerLength, + AcpiTableLength - Offset + ); + return; } =20 switch (*MadtInterruptControllerType) { @@ -316,11 +314,11 @@ ParseAcpiMadt ( } =20 case EFI_ACPI_6_3_GICD: { - if (++GICDCount > 1) { + if (GetConsistencyChecking() && + (++GICDCount > 1)) { IncrementErrorCount (); Print ( - L"ERROR: Only one GICD must be present," - L" GICDCount =3D %d\n", + L"ERROR: Only one GICD must be present. GICDCount =3D %d\n", GICDCount ); } @@ -372,13 +370,16 @@ ParseAcpiMadt ( } =20 default: { - IncrementErrorCount (); - Print ( - L"ERROR: Unknown Interrupt Controller Structure," - L" Type =3D %d, Length =3D %d\n", - *MadtInterruptControllerType, - *MadtInterruptControllerLength - ); + if (GetConsistencyChecking ()) { + IncrementErrorCount (); + Print ( + L"ERROR: Unknown Interrupt Controller Structure," + L" Type =3D %d, Length =3D %d\n", + *MadtInterruptControllerType, + *MadtInterruptControllerLength + ); + } + break; } } // switch =20 -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)' -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#43647): https://edk2.groups.io/g/devel/message/43647 Mute This Topic: https://groups.io/mt/32439510/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri Apr 26 18:37:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+43648+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1562914498; cv=none; d=zoho.com; s=zohoarc; b=cGg48mOHPSjXvw6fubvoFrFB9T4DFIs8iijiRwC4bpamEvQuWMtjO+6FxS2PgsmNrxrytKwQoNfQHAl6aH/L+Gm9IdYRil3VW98UCxgCR5ExuYxtAB01Kpe818POYhRiUCGwt4eryhMbnVYQ+k9tFNB1jAwsp0gU8rqxTxXYM0E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562914498; h=Content-Type:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To:ARC-Authentication-Results; bh=QczkpmruP2Tfy5dpIQm1BPtQ6M/y0ZT/3LyLEeOOckU=; b=kR2kDvrvu21CXgA2+6S1CIZUDz9TD6+TICj1Vlrs8c/1UE9Ds3oAEyHfBqc+oaRz8NHmI9JPbywMlud8v3O3P/+90VlQWvS2agFVNk1MGbNLMh4zukHo46jA0xYeLIHvSZSxqPLf5538hnON3enbGL1+kJEepMxYgJt1l5JUaJY= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+43648+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1562914498250163.6077472344956; Thu, 11 Jul 2019 23:54:58 -0700 (PDT) Return-Path: X-Received: from EUR01-DB5-obe.outbound.protection.outlook.com (EUR01-DB5-obe.outbound.protection.outlook.com [40.107.15.50]) by groups.io with SMTP; Thu, 11 Jul 2019 23:54:57 -0700 X-Received: from VI1PR08CA0165.eurprd08.prod.outlook.com (2603:10a6:800:d1::19) by VE1PR08MB4957.eurprd08.prod.outlook.com (2603:10a6:803:110::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2052.19; Fri, 12 Jul 2019 06:54:52 +0000 X-Received: from DB5EUR03FT010.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e0a::207) by VI1PR08CA0165.outlook.office365.com (2603:10a6:800:d1::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2073.10 via Frontend Transport; Fri, 12 Jul 2019 06:54:52 +0000 Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+43648+1787277+3901457@groups.io; helo=web01.groups.io; Received-SPF: TempError (protection.outlook.com: error in processing during lookup of arm.com: DNS Timeout) X-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_CBC_SHA256) id 15.20.2052.18 via Frontend Transport; Fri, 12 Jul 2019 06:54:50 +0000 X-Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1415.2; Fri, 12 Jul 2019 06:53:21 +0000 X-Received: from E119924.Arm.com (10.37.8.167) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.1415.2 via Frontend Transport; Fri, 12 Jul 2019 06:53:21 +0000 From: "Krzysztof Koch" To: CC: , , , , , Subject: [edk2-devel] [PATCH v1 08/11] ShellPkg: acpiview: PPTT: Add error-checking in the parsing logic Date: Fri, 12 Jul 2019 07:52:40 +0100 Message-ID: <20190712065243.3812-9-krzysztof.koch@arm.com> In-Reply-To: <20190712065243.3812-1-krzysztof.koch@arm.com> References: <20190712065243.3812-1-krzysztof.koch@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 358243bc-00a3-40bd-6fa8-08d70695d62a X-MS-TrafficTypeDiagnostic: VE1PR08MB4957: X-MS-Exchange-PUrlCount: 1 X-Microsoft-Antispam-PRVS: NoDisclaimer: True X-MS-Oob-TLC-OOBClassifiers: OLM:3276; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: MMBTn1ZrIqJyjmajuQgG5yO2S6skmyZW+J6XVLuKRL6xzBVxXY17ULopop57gBTnl3ajkvWOQ47hE8qt9R6L/yWjghjDVnE/wMZn53pl5o+5V3EMqLwrtPpAQE38bSs91n2VfEH3BO4wKs3BIxvJFDe26aXsm/6+j5CWOpHEWofnuiD35A4hEc4iC8hUkybR596XEIMgfahDwbKOAqq7qjNCXs/9zhCIsrMW17n6pQrvzaSJxh4obIXGQa4tE7BO/N1VkiY4ATsAqct6+QRjHOe/IeefahFjs4wRepWC85b/GnXibYcnkpyOBUaievcoabZe+Kw5KxtE88SrPpS5uo2Xu8g9toWbA2NvV7zVqOMzDCejn56jBdDz8lPVZnhxlS6uOqSw43tPe7vVYihkIFjvk8lcJdbvGIxP8jwAayU= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jul 2019 06:54:50.9093 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 358243bc-00a3-40bd-6fa8-08d70695d62a X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[40.67.248.234];Helo=[nebula.arm.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR08MB4957 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,krzysztof.koch@arm.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1562914497; bh=NzZjOUve2ZDXKaU93k7/sT557NcJEeHrNPIw2FDc5N0=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=Z6DFVyNO2LYelRqykzZ/ggKTHvR1b/UE2iOPTaJEMAx8RKclCUz6nF45MHBQ2s4lP49 3wQpx4JhOICVj+3OtEkjEkEiBGduYOYABm9/Kftx0QkfCMy7H2nbPHRlAAPPZwR/5UmOF pTySVn3aawfeP8YcXqYaZoEFG1nodCugQBc= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Alexei Fedorov --- Changes can be seen at: https://github.com/KrzysztofKoch1/edk2/commit/e4789= 351e111fa1ed6a2c55759f190166b08fc8c Notes: v1: - improve the logic in the PPTT parser [Krzysztof] ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c | 9= 5 ++++++++++++++++---- 1 file changed, 76 insertions(+), 19 deletions(-) diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/Pptt= Parser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttPa= rser.c index cec57be55e77096f9448f637ea129af2b42111ad..8d8760940b493eb94c91da3d46f= 9a844930c1738 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]; =20 @@ -265,8 +264,34 @@ DumpProcessorHierarchyNodeStructure ( PARSER_PARAMS (ProcessorHierarchyNodeStructureParser) ); =20 - PrivateResourcePtr =3D Ptr + Offset; + // Check if the values used to control the parsing logic have been + // successfully read. + if (NumberOfPrivateResources =3D=3D NULL) { + IncrementErrorCount (); + Print ( + L"ERROR: Insufficient Processor Hierarchy Node length. Length =3D %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 =3D %d. RemainingBufferLength =3D %d. " \ + L"Parsing of this structure aborted.\n", + *NumberOfPrivateResources, + Length - Offset + ); + return; + } + Index =3D 0; + + // Parse the specified number of private resource references or the Proc= essor + // 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)) ); =20 - PrivateResourcePtr +=3D sizeof(UINT32); + Offset +=3D sizeof (UINT32); Index++; } } @@ -373,6 +398,7 @@ ParseAcpiPptt ( AcpiTableLength, PARSER_PARAMS (PpttParser) ); + ProcessorTopologyStructurePtr =3D Ptr + Offset; =20 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) ); =20 - if ((Offset + (*ProcessorTopologyStructureLength)) > AcpiTableLength) { + // Check if the values used to control the parsing logic have been + // successfully read. + if ((ProcessorTopologyStructureType =3D=3D NULL) || + (ProcessorTopologyStructureLength =3D=3D NULL)) { IncrementErrorCount (); Print ( - L"ERROR: Invalid processor topology structure length:" - L" Type =3D %d, Length =3D %d\n", - *ProcessorTopologyStructureType, - *ProcessorTopologyStructureLength + L"ERROR: Insufficient remaining table buffer length to read the " \ + L"processor topology structure header. Length =3D %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 =3D %d. " \ + L"ProcessorTopologyStructureType =3D %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 structure length. " \ + L"ProcessorTopologyStructureLength =3D %d. " \ + L"RemainingTableBufferLength =3D %d. PPTT parsing aborted.\n", + *ProcessorTopologyStructureLength, + AcpiTableLength - Offset + ); + return; } =20 PrintFieldName (2, L"* Structure Offset *"); @@ -420,14 +474,17 @@ ParseAcpiPptt ( ); break; default: - IncrementErrorCount (); - Print ( - L"ERROR: Unknown processor topology structure:" - L" Type =3D %d, Length =3D %d\n", - *ProcessorTopologyStructureType, - *ProcessorTopologyStructureLength - ); - } + if (GetConsistencyChecking ()) { + IncrementErrorCount (); + Print ( + L"ERROR: Unknown processor topology structure:" + L" Type =3D %d, Length =3D %d\n", + *ProcessorTopologyStructureType, + *ProcessorTopologyStructureLength + ); + } + break; + } // switch =20 ProcessorTopologyStructurePtr +=3D *ProcessorTopologyStructureLength; Offset +=3D *ProcessorTopologyStructureLength; -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)' -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#43648): https://edk2.groups.io/g/devel/message/43648 Mute This Topic: https://groups.io/mt/32439512/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri Apr 26 18:37:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+43649+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1562914500; cv=none; d=zoho.com; s=zohoarc; b=ADbdrmVxKBgsOQFkxMaqAZDXks4wxbGtsjcapRHvJLLRSZoDAoJIsZCi/4cUNGueRro302WCDUKQqqwzYFWezyI/sgbs7ZYBOA4vHBU0UIsjsTCV+DCLKfV33oXiV42rLtxm0skelDdisGEYHKMHUokSJuxOrlxoSENyUrlbRzQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562914500; h=Content-Type:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To:ARC-Authentication-Results; bh=TwokXja43Ta+Y0nI6vHGetJ1GTsI/bX/3KCOUPucDe0=; b=feedoovghpbSq7su71ROk8IHkF0p9nICrLM6rQSQwdX+3Q8Ntr0ir72q5GHDX0wq44KqUn2c34Gzh4MNLIWT1Bg9NkMSIsvk17YCmdwh/VyBAUlu1PgR4xxBJ/wFP5cKVnVd5O4mvogRKEXqP1SEqO95tb0cCtUBASeuK8vz+8k= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+43649+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 156291450056479.31006255905265; Thu, 11 Jul 2019 23:55:00 -0700 (PDT) Return-Path: X-Received: from EUR04-HE1-obe.outbound.protection.outlook.com (EUR04-HE1-obe.outbound.protection.outlook.com [40.107.7.48]) by groups.io with SMTP; Thu, 11 Jul 2019 23:54:59 -0700 X-Received: from VI1PR08CA0178.eurprd08.prod.outlook.com (2603:10a6:800:d1::32) by AM0PR08MB4947.eurprd08.prod.outlook.com (2603:10a6:208:158::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2052.17; Fri, 12 Jul 2019 06:54:54 +0000 X-Received: from DB5EUR03FT010.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e0a::207) by VI1PR08CA0178.outlook.office365.com (2603:10a6:800:d1::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2073.11 via Frontend Transport; Fri, 12 Jul 2019 06:54:54 +0000 Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+43649+1787277+3901457@groups.io; helo=web01.groups.io; Received-SPF: TempError (protection.outlook.com: error in processing during lookup of arm.com: DNS Timeout) X-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_CBC_SHA256) id 15.20.2052.18 via Frontend Transport; Fri, 12 Jul 2019 06:54:52 +0000 X-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; Fri, 12 Jul 2019 06:53:22 +0000 X-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.1415.2; Fri, 12 Jul 2019 06:53:22 +0000 X-Received: from E119924.Arm.com (10.37.8.167) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.1415.2 via Frontend Transport; Fri, 12 Jul 2019 06:53:21 +0000 From: "Krzysztof Koch" To: CC: , , , , , Subject: [edk2-devel] [PATCH v1 09/11] ShellPkg: acpiview: IORT: Add error-checking in the parsing logic Date: Fri, 12 Jul 2019 07:52:41 +0100 Message-ID: <20190712065243.3812-10-krzysztof.koch@arm.com> In-Reply-To: <20190712065243.3812-1-krzysztof.koch@arm.com> References: <20190712065243.3812-1-krzysztof.koch@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d4eeaf44-afa4-463d-3444-08d70695d75f X-MS-TrafficTypeDiagnostic: AM0PR08MB4947: X-MS-Exchange-PUrlCount: 1 X-Microsoft-Antispam-PRVS: NoDisclaimer: True X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: tEwwAdAuTTBs1+F7AuFzqlUZQqh5shBKsFq+Ui3XrdeE53l+McZ1dmQNSyosUMTP5U7LmfEshXGksz2/Ny/i8fL6qLlVJ7kTmHx3D3pgn7P8ECxdptU5FLoFvCOp0LneMHmPjUqpAEyeZfW/VCeMZv9nSvCUHceszBw2H42QVx0l7Tm0Dvi/tJCrQG4X+0iVUz8l8hNcO8lNuX4PUe3i2tqy1ASyb6MSg7ADTSnJn3iqshNOgfx0EtxtqCjN17eNAGbGATARoREEaHrYo7hp0WAQWoQrXb9VhNSm+JtIdcN0X5fghn5jinmft4FF/KmvsqxN34HfsnfQXOr5Z1qEHnVPkdRg4/r7r7nykJX4pLIKns6UQEGbXo9zssVkUW8kop7ebmSBeY43kQ25BG07nboRT4H35rSqRolCsL9E+SM= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jul 2019 06:54:52.9328 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d4eeaf44-afa4-463d-3444-08d70695d75f X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[40.67.248.234];Helo=[nebula.arm.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB4947 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,krzysztof.koch@arm.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1562914500; bh=iwBHNwoAvpZnAspOc8WKagxNwcHVYXkshgMLbfRIWRQ=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=RbI17oGowT5I+gXiIT5sgetQbaQzcpOIKGDdQADip49/ddgzQUXNYpfFPnhsCJ1VNX0 oLqOVx4DsqG9WcY1FyfL4OBrQB9dFqED4CZxc04A4B26qenMUT9kUswnWXWItdK3zcqbN aOp3V9lFK+jFaQG2GsNobhEY3f/YEdKgudU= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Alexei Fedorov --- Changes can be seen at: https://github.com/KrzysztofKoch1/edk2/commit/0b398= f116f7aed99dbec4090b5c2c0ed93273ef7 Notes: v1: - improve the logic in the IORT parser [Krzysztof] ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c | 4= 19 +++++++++++++------- 1 file changed, 279 insertions(+), 140 deletions(-) diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/Iort= Parser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortPa= rser.c index 93f78e1a9786ed53f6b5529f478b72a220b4f8df..f09e7aeeb34bf4c3d9564240b53= 539c8d6811f66 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" =20 // Local variables STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo; @@ -45,7 +46,35 @@ EFIAPI ValidateItsIdMappingCount ( IN UINT8* Ptr, IN VOID* Context - ); + ) +{ + if (*(UINT32*)Ptr !=3D 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."); + } +} =20 /** 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 !=3D 0) { + IncrementErrorCount (); + Print (L"\nERROR: IORT ID Mapping offset must be zero."); + } +} =20 /** Helper Macro for populating the IORT Node header in the ACPI_PARSER arra= y. @@ -204,95 +239,65 @@ STATIC CONST ACPI_PARSER IortNodeRootComplexParser[] = =3D { An ACPI_PARSER array describing the IORT PMCG node. **/ STATIC CONST ACPI_PARSER IortNodePmcgParser[] =3D { - 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}, }; =20 -/** - 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 !=3D 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 !=3D 0) { - IncrementErrorCount (); - Print (L"\nERROR: IORT ID Mapping offset must be zero."); - } -} - /** This function parses the IORT Node Id Mapping array. =20 - @param [in] Ptr Pointer to the start of the IORT Table. + @param [in] Ptr Pointer 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 =20 - IdMappingPtr =3D Ptr + MappingOffset; Index =3D 0; - while (Index < MappingCount) { + Offset =3D 0; + + while ((Index < MappingCount) && + (Offset < Length)) { AsciiSPrint ( Buffer, sizeof (Buffer), "ID Mapping [%d]", Index ); - Offset =3D ParseAcpi ( - TRUE, - 4, - Buffer, - IdMappingPtr, - 20, - PARSER_PARAMS (IortNodeIdMappingParser) - ); - IdMappingPtr +=3D Offset; + Offset +=3D ParseAcpi ( + TRUE, + 4, + Buffer, + Ptr + Offset, + Length - Offset, + PARSER_PARAMS (IortNodeIdMappingParser) + ); Index++; } + + // Cross-check the substructure count with the length of the encapsulati= ng + // buffer + if (GetConsistencyChecking () && + (Index < MappingCount)) { + IncrementErrorCount (); + Print ( + L"ERROR: Invalid ID Mapping Count. IdMappingCount =3D %d. " \ + L"IdMappingBufferSize =3D %d.\n", + MappingCount, + Length + ); + } } =20 /** @@ -317,8 +322,6 @@ DumpIortNodeSmmuV1V2 ( UINT32 Offset; CHAR8 Buffer[50]; // Used for AsciiName param of ParseAcpi =20 - UINT8* ArrayPtr; - ParseAcpi ( TRUE, 2, @@ -328,51 +331,97 @@ DumpIortNodeSmmuV1V2 ( PARSER_PARAMS (IortNodeSmmuV1V2Parser) ); =20 - ArrayPtr =3D Ptr + *InterruptContextOffset; + // Check if the values used to control the parsing logic have been + // successfully read. + if ((InterruptContextCount =3D=3D NULL) || + (InterruptContextOffset =3D=3D NULL) || + (PmuInterruptCount =3D=3D NULL) || + (PmuInterruptOffset =3D=3D NULL)) { + IncrementErrorCount (); + Print ( + L"ERROR: Insufficient SMMUv1/2 node length. Length =3D %d\n", + Length + ); + return; + } + + Offset =3D *InterruptContextOffset; Index =3D 0; - while (Index < *InterruptContextCount) { + + while ((Index < *InterruptContextCount) && + (Offset < Length)) { AsciiSPrint ( Buffer, sizeof (Buffer), "Context Interrupts Array [%d]", Index ); - Offset =3D ParseAcpi ( - TRUE, - 4, - Buffer, - ArrayPtr, - 8, - PARSER_PARAMS (InterruptArrayParser) - ); - ArrayPtr +=3D Offset; + Offset +=3D ParseAcpi ( + TRUE, + 4, + Buffer, + Ptr + Offset, + Length - Offset, + PARSER_PARAMS (InterruptArrayParser) + ); Index++; } =20 - ArrayPtr =3D Ptr + *PmuInterruptOffset; + // Cross-check the substructure count with the length of the encapsulati= ng + // buffer + if (GetConsistencyChecking () && + (Index < *InterruptContextCount)) { + IncrementErrorCount (); + Print ( + L"ERROR: Invalid Context Interrupt count. InterruptContextCount =3D = %d. " \ + L"SMMUv1v2BufferSize =3D %d.\n", + *InterruptContextCount, + Length + ); + return; + } + + Offset =3D *PmuInterruptOffset; Index =3D 0; - while (Index < *PmuInterruptCount) { + + while ((Index < *PmuInterruptCount) && + (Offset < Length)) { AsciiSPrint ( Buffer, sizeof (Buffer), "PMU Interrupts Array [%d]", Index ); - Offset =3D ParseAcpi ( - TRUE, - 4, - Buffer, - ArrayPtr, - 8, - PARSER_PARAMS (InterruptArrayParser) - ); - ArrayPtr +=3D Offset; + Offset +=3D ParseAcpi ( + TRUE, + 4, + Buffer, + Ptr + Offset, + Length - Offset, + PARSER_PARAMS (InterruptArrayParser) + ); Index++; } =20 - if (*IortIdMappingCount !=3D 0) { - DumpIortNodeIdMappings (Ptr, MappingCount, MappingOffset); + // Cross-check the substructure count with the length of the encapsulati= ng + // buffer + if (GetConsistencyChecking () && + (Index < *PmuInterruptCount)) { + IncrementErrorCount (); + Print ( + L"ERROR: Invalid PMU Interrupt count. PmuInterruptCount =3D %d. " \ + L"SMMUv1v2BufferSize =3D %d.\n", + *PmuInterruptCount, + Length + ); + return; } + + DumpIortNodeIdMappings ( + Ptr + MappingOffset, + Length - MappingOffset, + MappingCount + ); } =20 /** @@ -402,9 +451,11 @@ DumpIortNodeSmmuV3 ( PARSER_PARAMS (IortNodeSmmuV3Parser) ); =20 - if (*IortIdMappingCount !=3D 0) { - DumpIortNodeIdMappings (Ptr, MappingCount, MappingOffset); - } + DumpIortNodeIdMappings ( + Ptr + MappingOffset, + Length - MappingOffset, + MappingCount + ); } =20 /** @@ -422,40 +473,64 @@ DumpIortNodeIts ( { UINT32 Offset; UINT32 Index; - UINT8* ItsIdPtr; CHAR8 Buffer[80]; // Used for AsciiName param of ParseAcpi =20 Offset =3D ParseAcpi ( - TRUE, - 2, - "ITS Node", - Ptr, - Length, - PARSER_PARAMS (IortNodeItsParser) - ); + TRUE, + 2, + "ITS Node", + Ptr, + Length, + PARSER_PARAMS (IortNodeItsParser) + ); + + // Check if the values used to control the parsing logic have been + // successfully read. + if (ItsCount =3D=3D NULL) { + IncrementErrorCount (); + Print ( + L"ERROR: Insufficient ITS group length. Length =3D %d.\n", + Length + ); + return; + } =20 - ItsIdPtr =3D Ptr + Offset; Index =3D 0; - while (Index < *ItsCount) { + + while ((Index < *ItsCount) && + (Offset < Length)) { AsciiSPrint ( Buffer, sizeof (Buffer), "GIC ITS Identifier Array [%d]", Index ); - Offset =3D ParseAcpi ( - TRUE, - 4, - Buffer, - ItsIdPtr, - 4, - PARSER_PARAMS (ItsIdParser) - ); - ItsIdPtr +=3D Offset; + Offset +=3D ParseAcpi ( + TRUE, + 4, + Buffer, + Ptr + Offset, + Length - Offset, + PARSER_PARAMS (ItsIdParser) + ); Index++; } =20 + // Cross-check the substructure count with the length of the encapsulati= ng + // buffer + if (GetConsistencyChecking () && + (Index < *ItsCount)) { + IncrementErrorCount (); + Print ( + L"ERROR: Invalid GIC ITS identifier count. ItsCount =3D %d. " \ + L"ItsGroupBufferSize =3D %d.\n", + *ItsCount, + Length + ); + } + // Note: ITS does not have the ID Mappings Array + } =20 /** @@ -478,8 +553,6 @@ DumpIortNodeNamedComponent ( { UINT32 Offset; UINT32 Index; - UINT8* DeviceNamePtr; - UINT32 DeviceNameLength; =20 Offset =3D ParseAcpi ( TRUE, @@ -490,19 +563,35 @@ DumpIortNodeNamedComponent ( PARSER_PARAMS (IortNodeNamedComponentParser) ); =20 - DeviceNamePtr =3D Ptr + Offset; // Estimate the Device Name length - DeviceNameLength =3D Length - Offset - (MappingCount * 20); PrintFieldName (2, L"Device Object Name"); Index =3D 0; - while ((Index < DeviceNameLength) && (DeviceNamePtr[Index] !=3D 0)) { - Print (L"%c", DeviceNamePtr[Index++]); + + while ((*(Ptr + Offset) !=3D 0) && + (Offset < Length)) { + Print (L"%c", *(Ptr + Offset)); + Offset++; } Print (L"\n"); =20 - if (*IortIdMappingCount !=3D 0) { - DumpIortNodeIdMappings (Ptr, MappingCount, MappingOffset); + // Cross-check the string length with the size of the encapsulating + // buffer + if (GetConsistencyChecking () && + (*(Ptr + Offset) !=3D '\0')) { + IncrementErrorCount (); + Print ( + L"ERROR: Invalid Device object name string. " \ + L"NamedComponentBufferSize =3D %d.\n", + Length + ); + return; } + + DumpIortNodeIdMappings ( + Ptr + MappingOffset, + Length - MappingOffset, + MappingCount + ); } =20 /** @@ -532,9 +621,11 @@ DumpIortNodeRootComplex ( PARSER_PARAMS (IortNodeRootComplexParser) ); =20 - if (*IortIdMappingCount !=3D 0) { - DumpIortNodeIdMappings (Ptr, MappingCount, MappingOffset); - } + DumpIortNodeIdMappings ( + Ptr + MappingOffset, + Length - MappingOffset, + MappingCount + ); } =20 /** @@ -562,19 +653,13 @@ DumpIortNodePmcg ( Ptr, Length, PARSER_PARAMS (IortNodePmcgParser) - ); + ); =20 - if (*IortIdMappingCount !=3D 0) { - DumpIortNodeIdMappings (Ptr, MappingCount, MappingOffset); - } - - if (*IortIdMappingCount > 1) { - IncrementErrorCount (); - Print ( - L"ERROR: ID mapping must not be greater than 1. Id Mapping Count =3D= %d\n", - *IortIdMappingCount - ); - } + DumpIortNodeIdMappings ( + Ptr + MappingOffset, + Length - MappingOffset, + MappingCount + ); } =20 /** @@ -621,23 +706,61 @@ ParseAcpiIort ( AcpiTableLength, PARSER_PARAMS (IortParser) ); + + // Check if the values used to control the parsing logic have been + // successfully read. + if ((IortNodeCount =3D=3D NULL) || + (IortNodeOffset =3D=3D NULL)) { + IncrementErrorCount (); + Print ( + L"ERROR: Insufficient table length. AcpiTableLength =3D %d.\n", + AcpiTableLength + ); + return; + } + Offset =3D *IortNodeOffset; NodePtr =3D Ptr + Offset; Index =3D 0; =20 - while ((Index < *IortNodeCount) && (Offset < AcpiTableLength)) { + // Parse the specified number of IORT nodes or the IORT table buffer len= gth. + // Whichever is minimum. + while ((Index++ < *IortNodeCount) && + (Offset < AcpiTableLength)) { // Parse the IORT Node Header ParseAcpi ( FALSE, 0, "IORT Node Header", NodePtr, - 16, + AcpiTableLength - Offset, PARSER_PARAMS (IortNodeHeaderParser) ); - if (*IortNodeLength =3D=3D 0) { + + // Check if the values used to control the parsing logic have been + // successfully read. + if ((IortNodeType =3D=3D NULL) || + (IortNodeLength =3D=3D NULL) || + (IortIdMappingCount =3D=3D NULL) || + (IortIdMappingOffset =3D=3D NULL)) { IncrementErrorCount (); - Print (L"ERROR: Parser error. Invalid table data.\n"); + Print ( + L"ERROR: Insufficient remaining table buffer length to read the " \ + L"IORT node header. Length =3D %d.\n", + AcpiTableLength - Offset + ); + return; + } + + // Make sure the IORT Node is inside the table + if ((Offset + (*IortNodeLength)) > AcpiTableLength) { + IncrementErrorCount (); + Print ( + L"ERROR: Invalid IORT node length. IortNodeLength =3D %d. " \ + L"RemainingTableBufferLength =3D %d. IORT parsing aborted.\n", + *IortNodeLength, + AcpiTableLength - Offset + ); return; } =20 @@ -689,15 +812,31 @@ ParseAcpiIort ( *IortNodeLength, *IortIdMappingCount, *IortIdMappingOffset - ); + ); break; =20 default: - IncrementErrorCount (); - Print (L"ERROR: Unsupported IORT Node type =3D %d\n", *IortNodeTyp= e); + if (GetConsistencyChecking ()) { + IncrementErrorCount (); + Print (L"ERROR: Unsupported IORT Node type =3D %d\n", *IortNodeT= ype); + } + break; } // switch =20 NodePtr +=3D (*IortNodeLength); Offset +=3D (*IortNodeLength); } // while + + // Cross-check the substructure count with the length of the encapsulati= ng + // buffer + if (GetConsistencyChecking () && + (Index < *IortNodeCount)) { + IncrementErrorCount (); + Print ( + L"ERROR: Invalid IORT node count. IortNodeCount =3D %d. " \ + L"AcpiTableLength =3D %d.\n", + *IortNodeCount, + AcpiTableLength + ); + } } -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)' -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#43649): https://edk2.groups.io/g/devel/message/43649 Mute This Topic: https://groups.io/mt/32439513/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri Apr 26 18:37:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+43650+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1562914530; cv=none; d=zoho.com; s=zohoarc; b=oGhHbtSPEjIGOp/4HMOL6uzSE+jMVHDRIOCoucAm7VWcnh1SOo6t0FKpSpApE8zQ0km7tGBJ+fQXQP3rcal7xzakXU7y/ZU7DNz3Vw75nQngA/HulGWxPSBy2H5Ll5nTM+/p+2oiL/yXI6EmzHBIQcUieQApiSQijlRQMZW4BmE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562914530; h=Content-Type:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To:ARC-Authentication-Results; bh=Bx9ozCV56s8/LOlkCfoMJKEjY+nuoJ1RenSst8iKIW4=; b=FKFVJIYWIXxO1Jt/gewA8/s798FSyWlq8dUNTWvsoRFSAwZig8q7jsG/uZIAiWr6YMXJby8NJ79HQww5USBNXdH3WsTip6U84BtvcK+skEjSYxR5XUUwkZI8WT25cUyrNOl+uXgU7oYavcYc9MsqALkixkLGewD85mXwi5pnx/E= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+43650+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1562914530727641.5518703790704; Thu, 11 Jul 2019 23:55:30 -0700 (PDT) Return-Path: X-Received: from EUR03-VE1-obe.outbound.protection.outlook.com (EUR03-VE1-obe.outbound.protection.outlook.com [40.107.5.80]) by groups.io with SMTP; Thu, 11 Jul 2019 23:55:29 -0700 X-Received: from VI1PR08CA0094.eurprd08.prod.outlook.com (2603:10a6:800:d3::20) by AM5PR0802MB2593.eurprd08.prod.outlook.com (2603:10a6:203:94::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2052.16; Fri, 12 Jul 2019 06:55:25 +0000 X-Received: from DB5EUR03FT060.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e0a::203) by VI1PR08CA0094.outlook.office365.com (2603:10a6:800:d3::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2073.10 via Frontend Transport; Fri, 12 Jul 2019 06:55:24 +0000 Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+43650+1787277+3901457@groups.io; helo=web01.groups.io; Received-SPF: TempError (protection.outlook.com: error in processing during lookup of arm.com: DNS Timeout) X-Received: from nebula.arm.com (40.67.248.234) by DB5EUR03FT060.mail.protection.outlook.com (10.152.21.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.2052.18 via Frontend Transport; Fri, 12 Jul 2019 06:55:23 +0000 X-Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1415.2; Fri, 12 Jul 2019 06:53:23 +0000 X-Received: from E119924.Arm.com (10.37.8.167) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.1415.2 via Frontend Transport; Fri, 12 Jul 2019 06:53:22 +0000 From: "Krzysztof Koch" To: CC: , , , , , Subject: [edk2-devel] [PATCH v1 10/11] ShellPkg: acpiview: GTDT: Add error-checking in the parsing logic Date: Fri, 12 Jul 2019 07:52:42 +0100 Message-ID: <20190712065243.3812-11-krzysztof.koch@arm.com> In-Reply-To: <20190712065243.3812-1-krzysztof.koch@arm.com> References: <20190712065243.3812-1-krzysztof.koch@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1471643a-c935-4bd5-cfe1-08d70695e95a X-MS-TrafficTypeDiagnostic: AM5PR0802MB2593: X-MS-Exchange-PUrlCount: 1 X-Microsoft-Antispam-PRVS: NoDisclaimer: True X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: +R9nIMYsw8dCl6Sh9kkQJ/4UZj3v6g0ZeGe8fY3l2K3pBgQli4g8IscVuK5C0OmUyHLiHMFWBlwN0TYtKDQUp8zIOC7O8WnT87syLABdUJbHFtyKRA3G5z5WtS79AqIQBtnvtFdYxLbQNFZ9/SVzlJnlM5/7Btub4JUIqFICcc4FeEjYBR0hs5ye0aae1MFOLV9OjB+mN9GQB+9EdQM/IyNEMQsn5+ZHsrP0RdVOLCt9qwY0uZdzUTuQMM0itFVZMMo9cmJSURGMZhXmIN96tzOKOrJrjuAkkcZcd4k0mFOu45Qn7gse+BGKk812gQcCNWtCdPV6I9l2ax02oYfeBygM76kSLHCtePl3CbKG24n3miwGSEXDIHL1m3KfVIAfqrh4KgfANAOY66iOfoW5eZzcmOFWCAIP5naDBG/e9qI= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jul 2019 06:55:23.1020 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1471643a-c935-4bd5-cfe1-08d70695e95a X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[40.67.248.234];Helo=[nebula.arm.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0802MB2593 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,krzysztof.koch@arm.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1562914530; bh=ajvCKV025QTRxpaHFw1pZStTtmxsgIEIZCzTVAXDakM=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=jZrCm58VXdA3H5c1OlYxV0j4+h5ZVz8iOzdBhvLK6eOrqktabbWljpoTPzOVUKDsypC ufLQpWuXdyB1D45wikvF/YNAU9BaXZITNe9TGXk6KUSJLfCjXm/tRFSFZjZtsyRehrifu ftMy/tLimD3tmYDG1FWg2aiLDf4SuSWmVNs= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Alexei Fedorov --- Changes can be seen at: https://github.com/KrzysztofKoch1/edk2/commit/8c2ed= 18c7f1c44620eb86e1c9117cbccee8938ce Notes: v1: - improve the logic in the GTDT parser [Krzysztof] ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c | 2= 94 +++++++++++--------- 1 file changed, 170 insertions(+), 124 deletions(-) diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/Gtdt= Parser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtPa= rser.c index 3b05ff3015d4a3af62dd9fab057c32369a456267..4e8e6f3eb50596823827d20dbb7= 2314a583d0931 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 =20 // 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; =20 /** @@ -36,7 +39,21 @@ EFIAPI ValidateGtBlockTimerCount ( IN UINT8* Ptr, IN VOID* Context - ); + ) +{ + UINT32 BlockTimerCount; + + BlockTimerCount =3D *(UINT32*)Ptr; + + if (BlockTimerCount > GT_BLOCK_TIMER_COUNT_MAX) { + IncrementErrorCount (); + Print ( + L"\nERROR: Timer Count =3D %d. Max Timer Count is %d.", + BlockTimerCount, + GT_BLOCK_TIMER_COUNT_MAX + ); + } +} =20 /** This function validates the GT Frame Number. @@ -51,7 +68,21 @@ EFIAPI ValidateGtFrameNumber ( IN UINT8* Ptr, IN VOID* Context - ); + ) +{ + UINT8 FrameNumber; + + FrameNumber =3D *(UINT8*)Ptr; + + if (FrameNumber >=3D GT_BLOCK_TIMER_COUNT_MAX) { + IncrementErrorCount (); + Print ( + L"\nERROR: GT Frame Number =3D %d. GT Frame Number must be in range = 0-%d.", + FrameNumber, + GT_BLOCK_TIMER_COUNT_MAX - 1 + ); + } +} =20 /** An ACPI_PARSER array describing the ACPI GTDT Table. @@ -96,7 +127,7 @@ STATIC CONST ACPI_PARSER GtPlatformTimerHeaderParser[] = =3D { **/ STATIC CONST ACPI_PARSER GtBlockParser[] =3D { {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, NUL= L}, {L"Timer Count", 4, 12, L"%d", NULL, (VOID**)&GtBlockTimerCount, @@ -134,115 +165,71 @@ STATIC CONST ACPI_PARSER SBSAGenericWatchdogParser[]= =3D { {L"Watchdog Timer Flags", 4, 24, L"0x%x", NULL, NULL, NULL, NULL} }; =20 -/** - 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 =3D *(UINT32*)Ptr; - - if (BlockTimerCount > 8) { - IncrementErrorCount (); - Print ( - L"\nERROR: Timer Count =3D %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 =3D *(UINT8*)Ptr; - - if (FrameNumber > 7) { - IncrementErrorCount (); - Print ( - L"\nERROR: GT Frame Number =3D %d. GT Frame Number must be in range = 0-7.", - FrameNumber - ); - } -} - /** This function parses the Platform GT Block. =20 - @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] Length Length of the GT Block structure. **/ STATIC VOID DumpGTBlock ( IN UINT8* Ptr, - IN UINT32 Length + IN UINT16 Length ) { UINT32 Index; UINT32 Offset; - UINT32 GTBlockTimerLength; =20 - Offset =3D ParseAcpi ( - TRUE, - 2, - "GT Block", - Ptr, - Length, - PARSER_PARAMS (GtBlockParser) - ); - GTBlockTimerLength =3D (*GtBlockLength - Offset) / (*GtBlockTimerCount); - Length -=3D Offset; + ParseAcpi ( + TRUE, + 2, + "GT Block", + Ptr, + Length, + PARSER_PARAMS (GtBlockParser) + ); =20 - if (*GtBlockTimerCount !=3D 0) { - Ptr +=3D (*GtBlockTimerOffset); - Index =3D 0; - while ((Index < (*GtBlockTimerCount)) && (Length >=3D GTBlockTimerLeng= th)) { - Offset =3D ParseAcpi ( - TRUE, - 2, - "GT Block Timer", - Ptr, - GTBlockTimerLength, - PARSER_PARAMS (GtBlockTimerParser) - ); - // Increment by GT Block Timer structure size - Ptr +=3D Offset; - Length -=3D Offset; - Index++; - } + // Check if the values used to control the parsing logic have been + // successfully read. + if ((GtBlockTimerCount =3D=3D NULL) || + (GtBlockTimerOffset =3D=3D NULL)) { + IncrementErrorCount (); + Print ( + L"ERROR: Insufficient GT Block Structure length. Length =3D %d.\n", + Length + ); + return; + } =20 - if (Length !=3D 0) { - IncrementErrorCount (); - Print ( - L"ERROR:GT Block Timer length mismatch. Unparsed %d bytes.\n", - Length - ); - } + Offset =3D *GtBlockTimerOffset; + Index =3D 0; + + // Parse the specified number of GT Block Timer Structures or the GT Blo= ck + // Structure buffer length. Whichever is minimum. + while ((Index++ < *GtBlockTimerCount) && + (Offset < Length)) { + Offset +=3D ParseAcpi ( + TRUE, + 2, + "GT Block Timer", + Ptr + Offset, + Length - Offset, + PARSER_PARAMS (GtBlockTimerParser) + ); + } + + // Cross-check the substructure count with the length of the encapsulati= ng + // buffer + if (GetConsistencyChecking () && + (Index < *GtBlockTimerCount)) { + IncrementErrorCount (); + Print ( + L"ERROR: Invalid GT Block Timer count. GtBlockTimerCount =3D %d. " \ + L"GtBlockBufferSize =3D %d.\n", + *GtBlockTimerCount, + Length + ); } } =20 @@ -295,6 +282,7 @@ ParseAcpiGtdt ( ) { UINT32 Index; + UINT32 Offset; UINT8* TimerPtr; =20 if (!Trace) { @@ -310,36 +298,94 @@ ParseAcpiGtdt ( PARSER_PARAMS (GtdtParser) ); =20 - if (*GtdtPlatformTimerCount !=3D 0) { - TimerPtr =3D Ptr + (*GtdtPlatformTimerOffset); - Index =3D 0; - do { - // Parse the Platform Timer Header - ParseAcpi ( - FALSE, - 0, - NULL, - TimerPtr, - 4, // GT Platform Timer structure header length. - PARSER_PARAMS (GtPlatformTimerHeaderParser) + // Check if the values used to control the parsing logic have been + // successfully read. + if ((GtdtPlatformTimerCount =3D=3D NULL) || + (GtdtPlatformTimerOffset =3D=3D NULL)) { + IncrementErrorCount (); + Print ( + L"ERROR: Insufficient table length. AcpiTableLength =3D %d.\n", + AcpiTableLength + ); + return; + } + + TimerPtr =3D Ptr + *GtdtPlatformTimerOffset; + Offset =3D *GtdtPlatformTimerOffset; + Index =3D 0; + + // Parse the specified number of Platform Timer Structures or the GTDT + // buffer length. Whichever is minimum. + while ((Index++ < *GtdtPlatformTimerCount) && + (Offset < AcpiTableLength)) { + // Parse the Platform Timer Header to obtain Length and Type + ParseAcpi ( + FALSE, + 0, + NULL, + TimerPtr, + AcpiTableLength - Offset, + PARSER_PARAMS (GtPlatformTimerHeaderParser) + ); + + // Check if the values used to control the parsing logic have been + // successfully read. + if ((PlatformTimerType =3D=3D NULL) || + (PlatformTimerLength =3D=3D NULL)) { + IncrementErrorCount (); + Print ( + L"ERROR: Insufficient remaining table buffer length to read the " \ + L"Platform Timer Structure header. Length =3D %d.\n", + AcpiTableLength - Offset ); - switch (*PlatformTimerType) { - case EFI_ACPI_6_2_GTDT_GT_BLOCK: - DumpGTBlock (TimerPtr, *PlatformTimerLength); - break; - case EFI_ACPI_6_2_GTDT_SBSA_GENERIC_WATCHDOG: - DumpWatchdogTimer (TimerPtr, *PlatformTimerLength); - break; - default: + return; + } + + // Make sure the Platform Timer is inside the table. + if ((Offset + *PlatformTimerLength) > AcpiTableLength) { + IncrementErrorCount (); + Print ( + L"ERROR: Invalid Platform Timer Structure length. " \ + L"PlatformTimerLength =3D %d. RemainingTableBufferLength =3D %d.= " \ + L"GTDT parsing aborted.\n", + *PlatformTimerLength, + AcpiTableLength - Offset + ); + return; + } + + switch (*PlatformTimerType) { + case EFI_ACPI_6_3_GTDT_GT_BLOCK: + DumpGTBlock (TimerPtr, *PlatformTimerLength); + break; + case EFI_ACPI_6_3_GTDT_SBSA_GENERIC_WATCHDOG: + DumpWatchdogTimer (TimerPtr, *PlatformTimerLength); + break; + default: + if (GetConsistencyChecking ()) { IncrementErrorCount (); Print ( - L"ERROR: INVALID Platform Timer Type =3D %d\n", + L"ERROR: Invalid Platform Timer Type =3D %d\n", *PlatformTimerType ); - break; - } // switch - TimerPtr +=3D (*PlatformTimerLength); - Index++; - } while (Index < *GtdtPlatformTimerCount); + } + break; + } // switch + + TimerPtr +=3D *PlatformTimerLength; + Offset +=3D *PlatformTimerLength; + } // while + + // Cross-check the substructure count with the length of the encapsulati= ng + // buffer + if (GetConsistencyChecking () && + (Index < *GtdtPlatformTimerCount)) { + IncrementErrorCount (); + Print ( + L"ERROR: Invalid Platform Timer Structure count. " \ + L"GtdtPlatformTimerCount =3D %d. AcpiTableLength =3D %d.\n", + *GtdtPlatformTimerCount, + AcpiTableLength + ); } } -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)' -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#43650): https://edk2.groups.io/g/devel/message/43650 Mute This Topic: https://groups.io/mt/32439515/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri Apr 26 18:37:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+43651+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1562914532; cv=none; d=zoho.com; s=zohoarc; b=NksS6kcq6VWqKUk10SjRap/4UowTbrlgt8sH4fzpwE6Honv0OWmWPJurZ9bFnIez1t6OGvK3gc7KldGpyk+6JGIaKVHeq/iulhegMk479hhtQOR/d0Yrf7ZLyNrJ2TwrnjXbTrZiVX2rVb/NOkLYM0GKsjY2sPjb9tdmw6TriaQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562914532; h=Content-Type:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To:ARC-Authentication-Results; bh=Sd64oHTLhcN5iJFBr/enKQ3KuZZ2TTTJEN458eHIAaM=; b=WoC24l+MBbX3llUhXhV3svkbr+GObVEmOxahCqEkLkkblHb4eRrCb/1ror+I+ZlN/TsQGbbCLPlKnkB83KtEz70Cz+qCrur43aMw2W+5b/xJ+UEgQELxvDvLyug2tlfPcpudTA9Xo2ba4RmOXJ6Wrk68y8wmMc9xf750GDqioC8= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+43651+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1562914532691485.03160072272; Thu, 11 Jul 2019 23:55:32 -0700 (PDT) Return-Path: X-Received: from EUR02-HE1-obe.outbound.protection.outlook.com (EUR02-HE1-obe.outbound.protection.outlook.com [40.107.1.44]) by groups.io with SMTP; Thu, 11 Jul 2019 23:55:31 -0700 X-Received: from VI1PR08CA0094.eurprd08.prod.outlook.com (2603:10a6:800:d3::20) by VE1PR08MB4958.eurprd08.prod.outlook.com (2603:10a6:803:110::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2052.18; Fri, 12 Jul 2019 06:55:26 +0000 X-Received: from DB5EUR03FT060.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e0a::203) by VI1PR08CA0094.outlook.office365.com (2603:10a6:800:d3::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2073.10 via Frontend Transport; Fri, 12 Jul 2019 06:55:26 +0000 Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+43651+1787277+3901457@groups.io; helo=web01.groups.io; Received-SPF: TempError (protection.outlook.com: error in processing during lookup of arm.com: DNS Timeout) X-Received: from nebula.arm.com (40.67.248.234) by DB5EUR03FT060.mail.protection.outlook.com (10.152.21.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.2052.18 via Frontend Transport; Fri, 12 Jul 2019 06:55:25 +0000 X-Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1415.2; Fri, 12 Jul 2019 06:53:23 +0000 X-Received: from E119924.Arm.com (10.37.8.167) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.1415.2 via Frontend Transport; Fri, 12 Jul 2019 06:53:23 +0000 From: "Krzysztof Koch" To: CC: , , , , , Subject: [edk2-devel] [PATCH v1 11/11] ShellPkg: acpiview: DBG2: Add error-checking in the parsing logic Date: Fri, 12 Jul 2019 07:52:43 +0100 Message-ID: <20190712065243.3812-12-krzysztof.koch@arm.com> In-Reply-To: <20190712065243.3812-1-krzysztof.koch@arm.com> References: <20190712065243.3812-1-krzysztof.koch@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 778f16d0-f326-4d54-5bec-08d70695eaaf X-MS-TrafficTypeDiagnostic: VE1PR08MB4958: X-MS-Exchange-PUrlCount: 1 X-Microsoft-Antispam-PRVS: NoDisclaimer: True X-MS-Oob-TLC-OOBClassifiers: OLM:462; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: z4OjgNt1qAktcEufM77AG3RGoPhEfZfZOsWu4do90llBdAvXlr70Bzeh3/5GNNwlS84auoG/f66TJjpoMz7qPIww4Ro6GNgPJD2lkFhp+RMDcUFMcokuwj2trhrxt1lQuPetz9FKwbJUblrXwvoFVKHvuxjW1bh2FPVLFoUsu0vCXm1ocLTBF0PH26XuESEvRlHSzHKvQoLDcaA3FAoc3aDKLLNow1KKQoh0JbYGuKrF4TT5d3xBY9whtXbkNSU92EfvnSuIiRnuQtyI+Hl4jWP0WSzJI7bohoTlkr0ShmAjGod2TsVJyVfvRwyVtBTPk498kbKfpmHb2kaIO8pMSlfBklmzeeDyrubVdN+WERAiSAkyG8oDj1xW71l5YhaPz3ONLHouRpo3H82ZLDuRNVXOk6IfSYO4OTgrJWYuNI4= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jul 2019 06:55:25.3339 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 778f16d0-f326-4d54-5bec-08d70695eaaf X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[40.67.248.234];Helo=[nebula.arm.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR08MB4958 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,krzysztof.koch@arm.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1562914532; bh=xUDbvBHmcpkvhA9cB6y9iRfJuf4Z3AP8q4MuWqapnrM=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=p1OJKP8yL/10+zgRGtfLZvhFuOx2zUcfSG3JMCxQ1W7Lgw9k2PqKgLwxmCU3mTzA65L F7j2D4wPaT3QG4OKctA3C5XSIRFS2G25ANpZSWf0z0MGHd2yhC/3j9KeJNZGXSLgy2EkY AVJNC3lpkcBSrkw1D40YmnjFOWkz4A+zOJA= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Alexei Fedorov --- Changes can be seen at: https://github.com/KrzysztofKoch1/edk2/commit/530b0= 59a9fe4aa9f1df36b407f97d76acaab8b74 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 | 2= 98 ++++++++++++++------ 3 files changed, 225 insertions(+), 107 deletions(-) diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c b/Sh= ellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c index 8b3153516d2b7d9b920ab2de0344c17798ac572c..2d6ff80e299eebe7853061d3db8= 9332197c0dc0e 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c @@ -589,23 +589,27 @@ STATIC CONST ACPI_PARSER GasParser[] =3D { =20 @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 UINT32 Indent + IN UINT32 Indent, + IN UINT32 Length ) { Print (L"\n"); - ParseAcpi ( - TRUE, - Indent, - NULL, - Ptr, - GAS_LENGTH, - PARSER_PARAMS (GasParser) - ); + return ParseAcpi ( + TRUE, + Indent, + NULL, + Ptr, + Length, + PARSER_PARAMS (GasParser) + ); } =20 /** @@ -621,7 +625,7 @@ DumpGas ( IN UINT8* Ptr ) { - DumpGasStruct (Ptr, 2); + DumpGasStruct (Ptr, 2, GAS_LENGTH); } =20 /** diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h b/Sh= ellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h index 7657892d9fd2e2e14c6578611ff0cf1b6f6cd750..20ca358bddfa5953bfb1d1bebae= bbf3079eaba01 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h @@ -405,12 +405,16 @@ ParseAcpi ( =20 @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 UINT32 Indent + IN UINT32 Indent, + IN UINT32 Length ); =20 /** diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2= Parser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Pa= rser.c index 8de5ebf74775bab8e765849cba6ef4eb6f659a5a..2bbd622ffb7cec0a340de3e10bd= cd01ba4d330df 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" =20 // 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; =20 /** - This function Validates the NameSpace string length. + This function validates the NameSpace string length. =20 @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; =20 -/** - This function parses the debug device information structure. + NameSpaceStrLen =3D *(UINT16*)Ptr; =20 - @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 =3D %d. If no Namespace device exi= sts, " \ + L"NamespaceString[] must contain a period '.'", + NameSpaceStrLen + ); + } +} =20 /// An ACPI_PARSER array describing the ACPI DBG2 table. STATIC CONST ACPI_PARSER Dbg2Parser[] =3D { @@ -65,10 +65,17 @@ STATIC CONST ACPI_PARSER Dbg2Parser[] =3D { (VOID**)&NumberDbgDeviceInfo, NULL, NULL} }; =20 +/// An ACPI_PARSER array describing the debug device information structure +/// header. +STATIC CONST ACPI_PARSER DbgDevInfoHeaderParser[] =3D { + {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[] =3D { {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}, =20 {L"Generic Address Registers Count", 1, 3, L"0x%x", NULL, (VOID**)&GasCount, NULL, NULL}, @@ -91,108 +98,152 @@ STATIC CONST ACPI_PARSER DbgDevInfoParser[] =3D { (VOID**)&AddrSizeOffset, NULL, NULL} }; =20 -/** - 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 =3D *(UINT16*)Ptr; - - if (NameSpaceStrLen < 2) { - IncrementErrorCount (); - Print ( - L"\nERROR: NamespaceString Length =3D %d. If no Namespace device exi= sts,\n" - L" then NamespaceString[] must contain a period '.'", - NameSpaceStrLen - ); - } -} - /** This function parses the debug device information structure. =20 - @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; =20 ParseAcpi ( TRUE, 2, "Debug Device Info", Ptr, - *DbgDevInfoLen, + Length, PARSER_PARAMS (DbgDevInfoParser) ); =20 - // GAS and Address Size + // Check if the values used to control the parsing logic have been + // successfully read. + if ((GasCount =3D=3D NULL) || + (NameSpaceStringLength =3D=3D NULL) || + (NameSpaceStringOffset =3D=3D NULL) || + (OEMDataLength =3D=3D NULL) || + (OEMDataOffset =3D=3D NULL) || + (BaseAddrRegOffset =3D=3D NULL) || + (AddrSizeOffset =3D=3D NULL)) { + IncrementErrorCount (); + Print ( + L"ERROR: Insufficient Debug Device Information Structure length. " \ + L"Length =3D %d.\n", + Length + ); + return; + } + + // GAS Index =3D 0; - DataPtr =3D Ptr + (*BaseAddrRegOffset); - AddrSize =3D (UINT32*)(Ptr + (*AddrSizeOffset)); - while (Index < (*GasCount)) { + Offset =3D *BaseAddrRegOffset; + while ((Index++ < *GasCount) && + (Offset < Length)) { PrintFieldName (4, L"BaseAddressRegister"); - DumpGasStruct (DataPtr, 4); + Offset +=3D (UINT16)DumpGasStruct ( + Ptr + Offset, + 4, + Length - Offset + ); + } + + // Cross-check the substructure count with the length of the encapsulati= ng + // buffer + if (GetConsistencyChecking () && + (Index < *GasCount)) { + IncrementErrorCount (); + Print ( + L"ERROR: Invalid GAS count. GasCount =3D %d. DbgDevInfoLen =3D %d.\n= ", + *GasCount, + Length + ); + return; + } + + // 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 =3D %d. RemainingBufferLength = =3D %d. " \ + L"Parsing of the Debug Device Information structure aborted.\n", + *GasCount, + Length - *AddrSizeOffset + ); + return; + } + + // Address Size + Index =3D 0; + Offset =3D *AddrSizeOffset; + while ((Index++ < *GasCount) && + (Offset < Length)) { PrintFieldName (4, L"Address Size"); - Print (L"0x%x\n", AddrSize[Index]); - DataPtr +=3D GAS_LENGTH; - Index++; + Print (L"0x%x\n", *((UINT32*)(Ptr + Offset))); + Offset +=3D sizeof (UINT32); } =20 // NameSpace String Index =3D 0; - DataPtr =3D Ptr + (*NameSpaceStringOffset); + Offset =3D *NameSpaceStringOffset; PrintFieldName (4, L"NameSpace String"); - while (Index < (*NameSpaceStringLength)) { - Print (L"%c", DataPtr[Index++]); + while ((Index++ < *NameSpaceStringLength) && + (Offset < Length)) { + Print (L"%c", *(Ptr + Offset)); + Offset++; } Print (L"\n"); =20 + // Cross-check the string length with the size of the encapsulating + // buffer + if (GetConsistencyChecking () && + (Index < *NameSpaceStringLength)) { + IncrementErrorCount (); + Print ( + L"ERROR: Invalid NameSpaceString length. NameSpaceStringLength =3D %= d. " \ + L"DbgDevInfoLen =3D %d.\n", + *NameSpaceStringLength, + Length + ); + return; + } + // OEM Data - Index =3D 0; - DataPtr =3D Ptr + (*OEMDataOffset); - PrintFieldName (4, L"OEM Data"); - while (Index < (*OEMDataLength)) { - Print (L"%x ", DataPtr[Index++]); - if ((Index & 7) =3D=3D 0) { - Print (L"\n%-*s ", OUTPUT_FIELD_COLUMN_WIDTH, L""); + if (*OEMDataOffset !=3D 0) { + Index =3D 0; + Offset =3D *OEMDataOffset; + PrintFieldName (4, L"OEM Data"); + while ((Index++ < *OEMDataLength) && + (Offset < Length)) { + Print (L"%x ", *(Ptr + Offset)); + if ((Index & 7) =3D=3D 0) { + Print (L"\n%-*s ", OUTPUT_FIELD_COLUMN_WIDTH, L""); + } + Offset++; } + Print (L"\n"); } - Print (L"\n"); =20 - *Length =3D *DbgDevInfoLen; + // Cross-check the OEM data length with the size of the encapsulating + // buffer + if (GetConsistencyChecking () && + (Index < *OEMDataLength)) { + IncrementErrorCount (); + Print ( + L"ERROR: Invalid OEM Data size. OEMDataLength =3D %d. " \ + L"DbgDevInfoLen =3D %d.\n", + *OEMDataLength, + Length + ); + } } =20 /** @@ -217,8 +268,7 @@ ParseAcpiDbg2 ( ) { UINT32 Offset; - UINT32 DbgDeviceInfoLength; - UINT8* DevInfoPtr; + UINT32 Index; =20 if (!Trace) { return; @@ -232,14 +282,74 @@ ParseAcpiDbg2 ( AcpiTableLength, PARSER_PARAMS (Dbg2Parser) ); - DevInfoPtr =3D Ptr + Offset; =20 - while (Offset < AcpiTableLength) { - DumpDbgDeviceInfo ( - DevInfoPtr, - &DbgDeviceInfoLength + // Check if the values used to control the parsing logic have been + // successfully read. + if ((OffsetDbgDeviceInfo =3D=3D NULL) || + (NumberDbgDeviceInfo =3D=3D NULL)) { + IncrementErrorCount (); + Print ( + L"ERROR: Insufficient table length. AcpiTableLength =3D %d\n", + AcpiTableLength + ); + return; + } + + Offset =3D *OffsetDbgDeviceInfo; + Index =3D 0; + + while (Index++ < *NumberDbgDeviceInfo) { + + // Parse the Debug Device Information Structure header to obtain Length + ParseAcpi ( + FALSE, + 0, + NULL, + Ptr + Offset, + AcpiTableLength - Offset, + PARSER_PARAMS (DbgDevInfoHeaderParser) + ); + + // Check if the values used to control the parsing logic have been + // successfully read. + if (DbgDevInfoLen =3D=3D NULL) { + IncrementErrorCount (); + Print ( + L"ERROR: Insufficient remaining table buffer length to read the " \ + L"Debug Device Information structure's 'Length' field. " \ + L"RemainingTableBufferLength =3D %d.\n", + AcpiTableLength - Offset + ); + return; + } + + // Make sure the Debug Device Information structure lies inside the ta= ble. + if ((Offset + *DbgDevInfoLen) > AcpiTableLength) { + IncrementErrorCount (); + Print ( + L"ERROR: Invalid Debug Device Information structure length. " \ + L"DbgDevInfoLen =3D %d. RemainingTableBufferLength =3D %d. " \ + L"DBG2 parsing aborted.\n", + *DbgDevInfoLen, + AcpiTableLength - Offset + ); + return; + } + + DumpDbgDeviceInfo (Ptr + Offset, (*DbgDevInfoLen)); + Offset +=3D (*DbgDevInfoLen); + } + + // Cross-check the substructure count with the length of the encapsulati= ng + // buffer + if (GetConsistencyChecking () && + (Index < *NumberDbgDeviceInfo)) { + IncrementErrorCount (); + Print ( + L"ERROR: Invalid Debug Device Information structure count. " \ + L"NumberDbgDeviceInfo =3D %d. AcpiTableLength =3D %d.\n", + *NumberDbgDeviceInfo, + AcpiTableLength ); - Offset +=3D DbgDeviceInfoLength; - DevInfoPtr +=3D DbgDeviceInfoLength; } } -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)' -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#43651): https://edk2.groups.io/g/devel/message/43651 Mute This Topic: https://groups.io/mt/32439516/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-