From nobody Fri Apr 26 22:57:59 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-