From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=oBp7hDSJ; spf=pass (domain: arm.com, ip: 40.107.0.62, mailfrom: krzysztof.koch@arm.com) Received: from EUR02-AM5-obe.outbound.protection.outlook.com (EUR02-AM5-obe.outbound.protection.outlook.com [40.107.0.62]) by groups.io with SMTP; Thu, 15 Aug 2019 06:12:47 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=q9kUs9ziDNmfQqfeyxwQHzWW6UA8K+SfdQmGMYlQCs4=; b=oBp7hDSJFnX7ROloBg5BXJssQd4s8uS7c+hroVlg5UhydOlbTQB8gEBo3W3UP/O7avDc48wnODilCF4Q+nvgESBAXoWW3JMA7eZHwKCVSklcoJde3NcfmvnUPjxvqI9SwFjD3E5/E9jvND1nBR1Q95xEEY3HWTGA5vvtK0IXszY= Received: from VI1PR08CA0099.eurprd08.prod.outlook.com (10.175.228.25) by VE1PR08MB4958.eurprd08.prod.outlook.com (10.255.158.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2157.16; Thu, 15 Aug 2019 13:12:43 +0000 Received: from DB5EUR03FT047.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e0a::205) by VI1PR08CA0099.outlook.office365.com (2603:10a6:800:d3::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2157.18 via Frontend Transport; Thu, 15 Aug 2019 13:12:43 +0000 Authentication-Results: spf=temperror (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; edk2.groups.io; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;edk2.groups.io; dmarc=temperror action=none header.from=arm.com; Received-SPF: TempError (protection.outlook.com: error in processing during lookup of arm.com: DNS Timeout) Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT047.mail.protection.outlook.com (10.152.21.232) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2178.16 via Frontend Transport; Thu, 15 Aug 2019 13:12:41 +0000 Received: ("Tessian outbound a1fd2c3cfdb0:v26"); Thu, 15 Aug 2019 13:12:41 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 8b6d67feabe564ca X-CR-MTA-TID: 64aa7808 Received: from 7c663dce1b7e.1 (cr-mta-lb-1.cr-mta-net [104.47.12.50]) by 64aa7808-outbound-1.mta.getcheckrecipient.com id AE257A80-32EF-4C26-ACE9-ED52D32CBAB5.1; Thu, 15 Aug 2019 13:12:35 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04lp2050.outbound.protection.outlook.com [104.47.12.50]) by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 7c663dce1b7e.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 15 Aug 2019 13:12:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DTpVNfS3FNjrptvhfXtUUXb7DGhKcZpmy8rw6vGCbVQ+RbOyvi1uTY5/S2pvPE8cyNvRjRr3kUYSniQvYNWoxhnpQ4g7BO0bP72Jp6DmIE1ET3kSkYrzgSgiv8esc9jF1pPPlNbwmW0ddi/NDNP9brWiVz5b/g1uoU1OSNc3s3eTl4BVoGjEy5SOrkPyP0BMJjKl+VbPRMWqPPZ0C/QEra+ngveOqW2k5dy5cxbRoPWofSdPeaKALSSOBahZWxr5adKb72Fjws8TCxhgmiPCzC0rQUVNjhDr+nU0IBrali58hU37KTLnGmAxnCZ31mt6xmBMdNNcww5A+BP0d8/rNg== 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=q9kUs9ziDNmfQqfeyxwQHzWW6UA8K+SfdQmGMYlQCs4=; b=UC6vDaMYenQJfzgM9LmVaVGMVu9DdQvTBn8YjdWESGktg7TYjpFenSo97hDmyqYJz567Hcz9n9H9MoILpevT3XFbouXrDJcZpvJVnAVg0ypFcaeEbrJBzb5uy0HsNDKc3BY1DRnRg+0RwdlJD/vyBaISI3DovHbODzVysDevC44vqurxgoEIYJEEbwDn1JKX5bSabn2lhWvpy2bXDiylwWVSZWqaS3c3uEDzhnozJ6/9Dk0quBAbS/tLjvXNUiPCTzHojOAYzrxV0EhWhz1DyOKcTK1LlayRQ25gYwwh9U2fWtTtjnEtPemKnNoNJe1sGUSWOxYhrQMvFxuOjaLWWw== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=q9kUs9ziDNmfQqfeyxwQHzWW6UA8K+SfdQmGMYlQCs4=; b=oBp7hDSJFnX7ROloBg5BXJssQd4s8uS7c+hroVlg5UhydOlbTQB8gEBo3W3UP/O7avDc48wnODilCF4Q+nvgESBAXoWW3JMA7eZHwKCVSklcoJde3NcfmvnUPjxvqI9SwFjD3E5/E9jvND1nBR1Q95xEEY3HWTGA5vvtK0IXszY= Received: from HE1PR0802CA0006.eurprd08.prod.outlook.com (2603:10a6:3:bd::16) by AM0PR08MB4945.eurprd08.prod.outlook.com (2603:10a6:208:157::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2157.14; Thu, 15 Aug 2019 13:12:33 +0000 Received: from DB5EUR03FT027.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e0a::205) by HE1PR0802CA0006.outlook.office365.com (2603:10a6:3:bd::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2157.16 via Frontend Transport; Thu, 15 Aug 2019 13:12:32 +0000 Authentication-Results-Original: spf=temperror (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=temperror action=none header.from=arm.com; Received-SPF: TempError (protection.outlook.com: error in processing during lookup of arm.com: DNS Timeout) Received: from nebula.arm.com (40.67.248.234) by DB5EUR03FT027.mail.protection.outlook.com (10.152.20.121) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.2178.16 via Frontend Transport; Thu, 15 Aug 2019 13:12:30 +0000 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; Thu, 15 Aug 2019 13:11:36 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) 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; Thu, 15 Aug 2019 13:11:35 +0000 Received: from E119924.Arm.com (10.1.199.124) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.1415.2 via Frontend Transport; Thu, 15 Aug 2019 13:11:35 +0000 From: "Krzysztof Koch" To: CC: , , , , , Subject: [PATCH v1 05/11] ShellPkg: acpiview: SLIT: Validate System Locality count Date: Thu, 15 Aug 2019 14:11:15 +0100 Message-ID: <20190815131121.52644-6-krzysztof.koch@arm.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: <20190815131121.52644-1-krzysztof.koch@arm.com> References: <20190815131121.52644-1-krzysztof.koch@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234;IPV:NLI;CTRY:IE;EFV:NLI;SFV:NSPM;SFS:(10009020)(4636009)(136003)(346002)(376002)(39860400002)(396003)(2980300002)(199004)(189003)(70586007)(11346002)(4326008)(16586007)(14444005)(446003)(15650500001)(6666004)(8676002)(54906003)(47776003)(36756003)(476003)(81156014)(5660300002)(70206006)(126002)(486006)(2906002)(44832011)(50226002)(81166006)(53936002)(86362001)(26005)(53416004)(305945005)(478600001)(2616005)(1076003)(48376002)(50466002)(51416003)(336012)(7696005)(6916009)(356004)(8936002)(426003)(2351001)(186003)(63350400001)(63370400001)(316002)(76176011);DIR:OUT;SFP:1101;SCL:1;SRVR:AM0PR08MB4945;H:nebula.arm.com;FPR:;SPF:TempError;LANG:en;PTR:InfoDomainNonexistent;A:1;MX:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 668a5785-dd7d-4fcd-6616-08d7218240cd X-Microsoft-Antispam-Untrusted: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(2017052603328);SRVR:AM0PR08MB4945; X-MS-TrafficTypeDiagnostic: AM0PR08MB4945:|VE1PR08MB4958: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true X-MS-Oob-TLC-OOBClassifiers: OLM:6430;OLM:6430; X-Forefront-PRVS: 01304918F3 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info-Original: 5AWsxyQavXru4btOTHKzYiy3ru3ySNr/Uc5hvsA5cWR2gs/WhGvvNdFvSFcyPaqCkMxceGX9MEgGx6N7NSARAKiOf/fEoAntmdVkLhJEUuBMWRWqActRJJUMe+a+Y3X40kE8LdnO0UVt3YlBF8NWf8JXjU91tcX+dVlsFVgsxGTHvYadV330iCkC7JVouA99FYQbKCaErz3WgaqVulYWbshF/bJc3lKqwYvkVRe+kKABXtSi574nt5KCTyERPF/Lg2HToldLsG6JFmpCybP0Q9vLv3tFO0tBzbyicMwJL8O1Cye3kL+Tbzf0COxZex887EifiL9or9eiWDopDvKZg1ieSWW7xH6SZC3FH78WppqCopFcTsGH1oVZZN+hKhYhL3JlReyE7PSAxqIkxNuD3Eqz3TeqrWqxyrlk03ONg40= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB4945 Original-Authentication-Results: spf=temperror (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=temperror action=none header.from=arm.com; Return-Path: Krzysztof.Koch@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT047.eop-EUR03.prod.protection.outlook.com X-Forefront-Antispam-Report: CIP:63.35.35.123;IPV:CAL;SCL:-1;CTRY:IE;EFV:NLI;SFV:NSPM;SFS:(10009020)(4636009)(346002)(136003)(39860400002)(396003)(376002)(2980300002)(199004)(189003)(4326008)(53416004)(6666004)(478600001)(86362001)(26826003)(15650500001)(2906002)(305945005)(186003)(8676002)(2351001)(26005)(36756003)(5660300002)(6916009)(2616005)(81156014)(76176011)(51416003)(16586007)(11346002)(63370400001)(63350400001)(7696005)(54906003)(316002)(14444005)(50226002)(476003)(81166006)(446003)(47776003)(50466002)(1076003)(70206006)(22756006)(44832011)(426003)(48376002)(76130400001)(486006)(336012)(126002)(70586007)(8936002);DIR:OUT;SFP:1101;SCL:1;SRVR:VE1PR08MB4958;H:64aa7808-outbound-1.mta.getcheckrecipient.com;FPR:;SPF:TempError;LANG:en;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;A:1;MX:1; X-MS-Office365-Filtering-Correlation-Id-Prvs: e8fb2f1a-f7d3-4db2-06ac-08d721823a92 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(710020)(711020)(4605104)(1401327)(2017052603328);SRVR:VE1PR08MB4958; NoDisclaimer: True X-Forefront-PRVS: 01304918F3 X-Microsoft-Antispam-Message-Info: mC5PFZq/2097t+4kbBPN0vu2QK47bqKySurP2IiVBBVFc4C8DMd3ML+ChNFR4ThkdCRgOIhJDq8PJSSrFnILwbKTs8ZE8OTdkjpVhZH1vTyYmJWg5hOarMHnbWyQfZXFZmmJ5jhh28zsgJuln8M3gg9sr6d/y6CG1+lEdeDIlV2YkYRZfO7Ds8+lRH6DKMlMmXW/x3opV69oDZpM+Jh16MMEthj9xAQEZ0kZRkt81D+qC0QA4hrO7zm3kiTpbtJfkMraUFxPKkTNPIDN6cY26kX4yFfKhtE2RXx3ZSp1DW8PBRQlyF8oqwfeZE8nJCeBk+Z0yvy/dd2/wAPYNTQ66brGNhF4yeFZhj6kGPVqqXPglbef8g1aHaV5jQQUn0riBvmLMAaaXY54CojhXKzYocNGHEksw1s2v2kM8EEXAnw= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Aug 2019 13:12:41.2332 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 668a5785-dd7d-4fcd-6616-08d7218240cd X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR08MB4958 Content-Type: text/plain 1. Check if the 'Number of System Localities' provided can be represented in the SLIT table. The table 'Length' field is a 32-bit value while the 'Number of System Localities' field is 64-bit long. 2. Check if the SLIT matrix fits in the table buffer. If N is the SLIT locality count, then the matrix used to represent the localities is N*N bytes long. The ACPI table length must be big enough to fit the matrix. 3. Remove (now) redundant 64x64 bit multiplication. Signed-off-by: Krzysztof Koch --- Notes: v1: - Validate the 'Number of System Localities' Field [Krzysztof] - Remove redundant 64x64 bit multiplication [Krzysztof] ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c | 47 +++++++++++++++++--- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c index 17e2166a09d8615b714e0c51d4d93d293fcdf601..e4625ee8b13907893a9b6990ecb956baf91cc3b9 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c @@ -30,7 +30,7 @@ STATIC CONST ACPI_PARSER SlitParser[] = { /** Macro to get the value of a System Locality **/ -#define SLIT_ELEMENT(Ptr, i, j) *(Ptr + (MultU64x64 (i, LocalityCount)) + j) +#define SLIT_ELEMENT(Ptr, i, j) *(Ptr + (i * LocalityCount) + j) /** This function parses the ACPI SLIT table. @@ -57,9 +57,9 @@ ParseAcpiSlit ( ) { UINT32 Offset; - UINT64 Count; - UINT64 Index; - UINT64 LocalityCount; + UINT32 Count; + UINT32 Index; + UINT32 LocalityCount; UINT8* LocalityPtr; CHAR16 Buffer[80]; // Used for AsciiName param of ParseAcpi @@ -87,8 +87,45 @@ ParseAcpiSlit ( return; } + /* + Despite the 'Number of System Localities' being a 64-bit field in SLIT, + the maximum number of localities that can be represented in SLIT is limited + by the 'Length' field of the ACPI table. + + Since the ACPI table length field is 32-bit wide. The maximum number of + localities that can be represented in SLIT can be calculated as: + + MaxLocality = sqrt (MAX_UINT32 - sizeof (EFI_ACPI_6_3_SYSTEM_LOCALITY_DISTANCE_INFORMATION_TABLE_HEADER)) + = 65535 + = MAX_UINT16 + */ + if (*SlitSystemLocalityCount > MAX_UINT16) { + IncrementErrorCount (); + Print ( + L"ERROR: The Number of System Localities provided can't be represented " \ + L"in the SLIT table. SlitSystemLocalityCount = %ld. " \ + L"MaxLocalityCountAllowed = %d.\n", + *SlitSystemLocalityCount, + MAX_UINT16 + ); + return; + } + + LocalityCount = (UINT32)*SlitSystemLocalityCount; + + // Make sure system localities fit in the table buffer provided + if (Offset + (LocalityCount * LocalityCount) > AcpiTableLength) { + IncrementErrorCount (); + Print ( + L"ERROR: Invalid Number of System Localities. " \ + L"SlitSystemLocalityCount = %ld. AcpiTableLength = %d.\n", + *SlitSystemLocalityCount, + AcpiTableLength + ); + return; + } + LocalityPtr = Ptr + Offset; - LocalityCount = *SlitSystemLocalityCount; // We only print the Localities if the count is less than 16 // If the locality count is more than 16 then refer to the -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'