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=iaNkhwyz; spf=pass (domain: arm.com, ip: 40.107.1.82, mailfrom: sami.mujawar@arm.com) Received: from EUR02-HE1-obe.outbound.protection.outlook.com (EUR02-HE1-obe.outbound.protection.outlook.com [40.107.1.82]) by groups.io with SMTP; Mon, 19 Aug 2019 02:30:51 -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=HgREBK6oWfzssLwvOASmUjEl+eXQe0WKQo1Q1SWv2vQ=; b=iaNkhwyzw5Jin0C94enRVeqAMkTzK6VOhRto0Ms6sj8qGR649T6oEdNHUBMSNwdabael9gI95Lk1MmvE/LzD+Mm5+JSXdueU43ojGqZnp7ZE7Him1NMCqRX3q1JWOQJVSL5551lekRvKR937w7KNXzM1JmT+/1Ylt810av+SKns= Received: from VI1PR08CA0150.eurprd08.prod.outlook.com (2603:10a6:800:d5::28) by DB6PR0801MB1846.eurprd08.prod.outlook.com (2603:10a6:4:35::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2178.16; Mon, 19 Aug 2019 09:30:42 +0000 Received: from AM5EUR03FT003.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e08::208) by VI1PR08CA0150.outlook.office365.com (2603:10a6:800:d5::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2178.16 via Frontend Transport; Mon, 19 Aug 2019 09:30:42 +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 AM5EUR03FT003.mail.protection.outlook.com (10.152.16.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2178.16 via Frontend Transport; Mon, 19 Aug 2019 09:30:40 +0000 Received: ("Tessian outbound 220137ab7b0b:v26"); Mon, 19 Aug 2019 09:30:39 +0000 X-CR-MTA-TID: 64aa7808 Received: from 930dde5161b4.3 (cr-mta-lb-1.cr-mta-net [104.47.9.59]) by 64aa7808-outbound-1.mta.getcheckrecipient.com id 610B0E73-6A8C-4291-83D5-0281CDEB6C1B.1; Mon, 19 Aug 2019 09:30:34 +0000 Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-ve1eur03lp2059.outbound.protection.outlook.com [104.47.9.59]) by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 930dde5161b4.3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384); Mon, 19 Aug 2019 09:30:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dnbZB9+lOHyPEPpH3LjV4aH8Xd5Dj3DSvReU82tZzWAjQGrMtgEjJIxv2FOFhDSzZ6r7vLgKS8w/6MnoPsdKs9HEqzD0NZMrsnwQvetNjekYISJ7SgNI7DfXEkJhqats+X5hWePgpvZsWUTMvlY9Ca5kZY8AR+gGR+T/bkuuwFei2jSbjo+uqumSjxZr8LVTAuA6oemioKtn41Qe2WLUhFwTEr0sdk9Mh1KubU6nkFV8WtkTJrNNAijOpFryaUBI+HBNrJFP9RXdjiil+kiKcXSer9PFiYJpGe6pPsmSUUPaLhZGQeIcQCZYIzqVfO6eTlpWAguiu9sQD8vzHT+AIA== 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=HgREBK6oWfzssLwvOASmUjEl+eXQe0WKQo1Q1SWv2vQ=; b=Uu20PNmpHiJLS7kgP4CcgXD27b7sJslka48YmXEy5/YbDNOxsGV+jK8EMT7aQvyvwBnu+55R4oaqBUpiNWbFqHGdZWM2WRIgsScAC14z7G1EXR9/iHt8b9uIenMFD4WGkYBuGL5u8BJD5tFjpC1W0LJiN4njdT7TBQ63ySuz6UesbtVbrnuI0FshBvZn1fUsEFz63FrDzHI0zTpMcISnP0x4g2I+ytVP37fuiOLTlDW/L29UcRA6UY3RuDWae3P3uB6yGplDL1mF3b5/dx1XH22ru8UEvacyOguak91MsRzPJhAhHlcBvVJF1M2+fW1NFA8IbApX1qMHXfaIzRxEoQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; 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=HgREBK6oWfzssLwvOASmUjEl+eXQe0WKQo1Q1SWv2vQ=; b=iaNkhwyzw5Jin0C94enRVeqAMkTzK6VOhRto0Ms6sj8qGR649T6oEdNHUBMSNwdabael9gI95Lk1MmvE/LzD+Mm5+JSXdueU43ojGqZnp7ZE7Him1NMCqRX3q1JWOQJVSL5551lekRvKR937w7KNXzM1JmT+/1Ylt810av+SKns= Received: from DB6PR0802MB2375.eurprd08.prod.outlook.com (10.172.228.142) by DB6PR0802MB2440.eurprd08.prod.outlook.com (10.172.251.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2178.18; Mon, 19 Aug 2019 09:30:31 +0000 Received: from DB6PR0802MB2375.eurprd08.prod.outlook.com ([fe80::88a4:74c4:c4b7:aa1a]) by DB6PR0802MB2375.eurprd08.prod.outlook.com ([fe80::88a4:74c4:c4b7:aa1a%5]) with mapi id 15.20.2178.018; Mon, 19 Aug 2019 09:30:31 +0000 From: "Sami Mujawar" To: Krzysztof Koch , "devel@edk2.groups.io" CC: "jaben.carsey@intel.com" , "ray.ni@intel.com" , "zhichao.gao@intel.com" , Matteo Carlini , nd Subject: Re: [PATCH v1 05/11] ShellPkg: acpiview: SLIT: Validate System Locality count Thread-Topic: [PATCH v1 05/11] ShellPkg: acpiview: SLIT: Validate System Locality count Thread-Index: AQHVU2sfG7rRNTodmUSSTmHwOS64+acCOnow Date: Mon, 19 Aug 2019 09:30:31 +0000 Message-ID: References: <20190815131121.52644-1-krzysztof.koch@arm.com> <20190815131121.52644-6-krzysztof.koch@arm.com> In-Reply-To: <20190815131121.52644-6-krzysztof.koch@arm.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ts-tracking-id: d816b893-c7a7-4fb0-98e4-f690f9e5e8e0.1 x-checkrecipientchecked: true Authentication-Results-Original: spf=none (sender IP is ) smtp.mailfrom=Sami.Mujawar@arm.com; x-originating-ip: [217.140.96.140] x-ms-publictraffictype: Email X-MS-Office365-Filtering-Correlation-Id: c094458d-6707-4f9e-2163-08d72487e6dd X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam-Untrusted: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020);SRVR:DB6PR0802MB2440; X-MS-TrafficTypeDiagnostic: DB6PR0802MB2440:|DB6PR0801MB1846: x-ms-exchange-transport-forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true x-ms-oob-tlc-oobclassifiers: OLM:6430;OLM:6430; x-forefront-prvs: 0134AD334F X-Forefront-Antispam-Report-Untrusted: SFV:NSPM;SFS:(10009020)(979002)(4636009)(366004)(136003)(346002)(396003)(376002)(39860400002)(189003)(199004)(13464003)(476003)(486006)(99286004)(305945005)(446003)(14444005)(229853002)(11346002)(8936002)(8676002)(76176011)(71190400001)(6436002)(53546011)(86362001)(6506007)(186003)(71200400001)(7696005)(256004)(81166006)(74316002)(81156014)(26005)(55016002)(7736002)(66556008)(52536014)(102836004)(66066001)(5660300002)(76116006)(66946007)(4326008)(66476007)(25786009)(66446008)(9686003)(110136005)(478600001)(33656002)(64756008)(2501003)(6116002)(3846002)(54906003)(14454004)(2906002)(316002)(15650500001)(53936002)(6246003)(969003)(989001)(999001)(1009001)(1019001);DIR:OUT;SFP:1101;SCL:1;SRVR:DB6PR0802MB2440;H:DB6PR0802MB2375.eurprd08.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info-Original: xQJVva6Gl6ShHLA1Ik/hrwqOssgUCkWKBbsz6JfLbDuvNlCfmO3Wggrl2nVt2W/kJPwVKqo7MXrwMtk0BMteIck5H4RC5dEC8DzpfTYhVW39C6r+dZenJAnGFdQNGr0X3PojUSgiL8aWyXpOg6AujmUZLVT7VgcnWPzt+9dS55VF+fxbIryETy0Ai3bviLJdBwpX7+nNUl7LC+FrDEI08IF1LjRIttedmKIAkdsvl2f7Cn6f3Nk+7DOc3T+Ag08PIYAzN6Gu66OXl4yTNzUmoAlIOU/A60AEPnNnoW8rQOzxTxd79Lglpt1PGCE4HyTce/18cru2aT2CTJdpuR4x7Qftj6kDKhMgmjk5W+nO0m3lYj2cW5N/WXY9pYeYGHvGCg4WVH35aP41stnmNErzoxU4HXdsXbBdJGbvY5CHrYA= MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0802MB2440 Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Sami.Mujawar@arm.com; Return-Path: Sami.Mujawar@arm.com X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT003.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)(979002)(4636009)(396003)(39860400002)(346002)(136003)(376002)(2980300002)(189003)(199004)(13464003)(2906002)(356004)(26826003)(14444005)(15650500001)(52536014)(36906005)(76176011)(476003)(22756006)(99286004)(81156014)(316002)(8676002)(7696005)(5660300002)(66066001)(110136005)(81166006)(54906003)(53546011)(6506007)(6246003)(4326008)(8746002)(102836004)(8936002)(97756001)(70206006)(70586007)(14454004)(305945005)(50466002)(186003)(25786009)(11346002)(2501003)(33656002)(74316002)(47776003)(229853002)(76130400001)(63350400001)(63370400001)(26005)(336012)(46406003)(9686003)(486006)(3846002)(6116002)(478600001)(126002)(23726003)(55016002)(446003)(7736002)(86362001)(969003)(989001)(999001)(1009001)(1019001);DIR:OUT;SFP:1101;SCL:1;SRVR:DB6PR0801MB1846;H:64aa7808-outbound-1.mta.getcheckrecipient.com;FPR:;SPF:TempError;LANG:en;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;MX:1;A:1; X-MS-Office365-Filtering-Correlation-Id-Prvs: 36bd6c88-d64e-42a9-adf2-08d72487e17d X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(710020)(711020)(4605104)(1401327)(2017052603328)(7193020);SRVR:DB6PR0801MB1846; NoDisclaimer: True X-Forefront-PRVS: 0134AD334F X-Microsoft-Antispam-Message-Info: VuDe2ETqACpYS7HALTPworN8d/ei1+hc0F7qESTxTQgv/Y1yjhE3S+9DTBJFAY0+QJcon2CRjJ8+2Gp6aGUL0VIxByRTuYmbV0kMj2Ac8VrY4UYZk4qMxercMG5oi3OLUShANUU4ZOIHtVGKQxcmQlaB52vWD923CTfN/Uv85yMljRgqWJyRq+RnCBW0KwH+3aN6Gfdmms8nIkUEl2jB3I/7PC8x/61MauMiUKUAYxh2+Wrrs4x7O6x0Pv7vGRWMyAeK3NdaR1qsp5H2rZMm1EH455v30M2nBNgQqLPtItspXdmF7NTov2GA2fTj5Imu1yN10/Qfzao4R/P2Z6Qx9AUm9aEbUoyn2ZFBBRwRSVQMWKvvvzNWyL+wGPDug//NtylnXHPVyg53u5zpOlRWQ9Dq/+5ko1DMI69z73A2dYg= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Aug 2019 09:30:40.7700 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c094458d-6707-4f9e-2163-08d72487e6dd 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: DB6PR0801MB1846 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Sami Mujawar Regards, Sami Mujawar -----Original Message----- From: Krzysztof Koch =20 Sent: 15 August 2019 02:11 PM To: devel@edk2.groups.io Cc: jaben.carsey@intel.com; ray.ni@intel.com; zhichao.gao@intel.com; Sami M= ujawar ; Matteo Carlini ; nd = Subject: [PATCH v1 05/11] ShellPkg: acpiview: SLIT: Validate System Localit= y count 1. Check if the 'Number of System Localities' provided can be represented i= n the SLIT table. The table 'Length' field is a 32-bit value while the 'Num= ber of System Localities' field is 64-bit long. 2. Check if the SLIT matrix fits in the table buffer. If N is the SLIT loca= lity count, then the matrix used to represent the localities is N*N bytes l= ong. 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 | 4= 7 +++++++++++++++++--- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/Slit= Parser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitPa= rser.c index 17e2166a09d8615b714e0c51d4d93d293fcdf601..e4625ee8b13907893a9b6990ecb= 956baf91cc3b9 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.= c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitPars +++ er.c @@ -30,7 +30,7 @@ STATIC CONST ACPI_PARSER SlitParser[] =3D { /** Macro to get the value of a System Locality **/ -#define SLIT_ELEMENT(P= tr, i, j) *(Ptr + (MultU64x64 (i, LocalityCount)) + j) +#define SLIT_ELEMENT(Ptr, i, j) *(Ptr + (i * LocalityCount) + j) =20 /** 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 =20 @@ -87,8 +87,45 @@ ParseAcpiSlit ( return; } =20 + /* + 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 o= f + 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=20 + (Offset + (LocalityCount * LocalityCount) > AcpiTableLength) { + IncrementErrorCount (); + Print ( + L"ERROR: Invalid Number of System Localities. " \ + L"SlitSystemLocalityCount =3D %ld. AcpiTableLength =3D %d.\n", + *SlitSystemLocalityCount, + AcpiTableLength + ); + return; + } + LocalityPtr =3D Ptr + Offset; - LocalityCount =3D *SlitSystemLocalityCount; =20 // 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)'