From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (EUR05-DB8-obe.outbound.protection.outlook.com [40.107.20.49]) by mx.groups.io with SMTP id smtpd.web09.9174.1579518866770659972 for ; Mon, 20 Jan 2020 03:14:27 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=xK2KPUXC; spf=pass (domain: arm.com, ip: 40.107.20.49, mailfrom: krzysztof.koch@arm.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ybphBi9uaecLemE7uspD+F42tyIQldsmHr+yDocKAxs=; b=xK2KPUXCfaueRgCIA53s16ykzcTmpvvrhjcEae1mXd8teanUbDVr8Kt9IQplm50mGV+m6hjxwaXVaIGQSMYoDcFvkoAiMZroTnnSyyVWStIz0bgNIyZg+fghnHBWkzk90tgG/vt9n4drmc4MAsaGy6o1Mzap7Hue2nRtlYdY3Ww= Received: from VI1PR08CA0135.eurprd08.prod.outlook.com (2603:10a6:800:d5::13) by AM0PR08MB5265.eurprd08.prod.outlook.com (2603:10a6:208:160::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.19; Mon, 20 Jan 2020 11:14:24 +0000 Received: from VE1EUR03FT042.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e09::206) by VI1PR08CA0135.outlook.office365.com (2603:10a6:800:d5::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.18 via Frontend Transport; Mon, 20 Jan 2020 11:14:24 +0000 Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; edk2.groups.io; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;edk2.groups.io; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT042.mail.protection.outlook.com (10.152.19.62) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.23 via Frontend Transport; Mon, 20 Jan 2020 11:14:24 +0000 Received: ("Tessian outbound ba41a0333779:v40"); Mon, 20 Jan 2020 11:14:24 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: f0239ccfdd5d073c X-CR-MTA-TID: 64aa7808 Received: from 9c6fe757eb45.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 9871D083-3A00-4424-9DC7-6A39C9BACEB1.1; Mon, 20 Jan 2020 11:14:18 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 9c6fe757eb45.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 20 Jan 2020 11:14:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=knEjJ4kfkE0DpkA8M9p7m6YaQn3AyP1NawDrl5vLyh8sk6Ad4yQXF5Xkjp+7FLhVZhStJRwmkLnUGBpuXrrXSGYeZg7nVL/7qYzUgzDrqLUltitI4aveIHykHEpHWIBJF5Rsyiiga46yjph5a6zgJpfazXn0MSjMXs5R7lbXxfaHKnd0j8pXr3rAHBOOBI4nToXlanJPCZ2Pms6LXmXwr48QzbxqcpivZS2vaexn2A/aa7WXPVnarUkFqFTcublP4GKxoNMt1YaYkvYbxY0iTm20A7to7CPDUaymfJNd48A+raDP+//0z7ENAMQjUnBvmDad5/U/WfIkt5dBx2adoQ== 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=ybphBi9uaecLemE7uspD+F42tyIQldsmHr+yDocKAxs=; b=RwZd/gHe6DxGTZfI/K3uk8GfLzDeIZXJ0BYi1xVsaNOkKQNvdEnV9pA3zX/wEJFZEzlJ+nPvLFdXlS2KQgKaC6iQuW1h4Ut2xw0hlPv5sDgri66ASw6ySqng0h5PFoJafC2zyKTInbJsSnJ1YdzfxXcWyJWLVyjvFsG0cwG4vEzOAz6FOB8qPu2lHZD8RSAN7ixRXwl/+wbCm8KSvxMB5xCqSo68rNrgOGFLJN3z3kLPEu1x6ZzCEhN3wX/bnaMkc2MEscb5rV07c8wSBPafDtdhNM9LPmzE3IQek66ZpQxvdsCpZun/lqncgF+Gloxzt4jeYtsFSChmj5LObayLXA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=arm.com; dmarc=bestguesspass action=none header.from=arm.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ybphBi9uaecLemE7uspD+F42tyIQldsmHr+yDocKAxs=; b=xK2KPUXCfaueRgCIA53s16ykzcTmpvvrhjcEae1mXd8teanUbDVr8Kt9IQplm50mGV+m6hjxwaXVaIGQSMYoDcFvkoAiMZroTnnSyyVWStIz0bgNIyZg+fghnHBWkzk90tgG/vt9n4drmc4MAsaGy6o1Mzap7Hue2nRtlYdY3Ww= Received: from VI1PR0802CA0024.eurprd08.prod.outlook.com (2603:10a6:800:aa::34) by AM6PR08MB4982.eurprd08.prod.outlook.com (2603:10a6:20b:e9::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.18; Mon, 20 Jan 2020 11:14:16 +0000 Received: from VE1EUR03FT059.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e09::209) by VI1PR0802CA0024.outlook.office365.com (2603:10a6:800:aa::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.20 via Frontend Transport; Mon, 20 Jan 2020 11:14:15 +0000 Authentication-Results-Original: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; Received: from nebula.arm.com (40.67.248.234) by VE1EUR03FT059.mail.protection.outlook.com (10.152.19.60) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.2644.23 via Frontend Transport; Mon, 20 Jan 2020 11:14:15 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) 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; Mon, 20 Jan 2020 11:14:06 +0000 Received: from E119924.Arm.com (10.37.9.56) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.1415.2 via Frontend Transport; Mon, 20 Jan 2020 11:14:05 +0000 From: "Krzysztof Koch" To: CC: , , , , Subject: [PATCH v3 05/11] ShellPkg: acpiview: SLIT: Validate System Locality count Date: Mon, 20 Jan 2020 11:13:45 +0000 Message-ID: <20200120111351.29184-6-krzysztof.koch@arm.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: <20200120111351.29184-1-krzysztof.koch@arm.com> References: <20200120111351.29184-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:;CTRY:IE;EFV:NLI;SFV:NSPM;SFS:(10009020)(4636009)(346002)(376002)(396003)(136003)(39860400002)(199004)(189003)(36756003)(2906002)(2616005)(70586007)(54906003)(70206006)(1076003)(15650500001)(6916009)(356004)(6666004)(7696005)(86362001)(5660300002)(8676002)(426003)(4326008)(81166006)(26005)(186003)(316002)(336012)(478600001)(8936002)(44832011)(81156014);DIR:OUT;SFP:1101;SCL:1;SRVR:AM6PR08MB4982;H:nebula.arm.com;FPR:;SPF:Pass;LANG:en;PTR:InfoDomainNonexistent;A:1;MX:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 59bbe369-5bb7-4011-d0f0-08d79d99e7f2 X-MS-TrafficTypeDiagnostic: AM6PR08MB4982:|AM0PR08MB5265: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: True X-MS-Oob-TLC-OOBClassifiers: OLM:6790;OLM:6790; X-Forefront-PRVS: 0288CD37D9 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 9tPzUY/KWFoadmbcmypoHYv8Kbf/DUMZo6ajxGsb18jPS4d/bIhuS+tm38ZL1VEzL1LS4s1SvI5O9Nw0K5edW6ZhDvF8mKvQUuvfSK4FQbzkG/Gpu8vBkVHZWWt2WG67O7C3neH1ETrhGsepEVpSxATsvcVtH7lcU11Z6RqPwL11HKv0a/DXZ2XhUy8Mx66vl40sOka7ORbdGoARSrgwxhVpYZ4OWfM3rwGPxMT6WR0qtMnIWIYHrLz5CNpXGLFIPTJwM/Yo11vB1R9gUct1OdMCWoH41PjImcyAYYP9HOiPRUsSC2zjnlbFqUt7eqcKvvI6GEfKji+bVdKyHJB0ESq4/WZ20pFBTxleVgYKpe/l8JG+XnaGIn6eefAfnAnY5MbFHMR+atD6iEhV8BGqE/jN536vfvc0IasWRd2hsPfITWrvVbC3TmtiS8EgE08c X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4982 Original-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=bestguesspass action=none header.from=arm.com; Return-Path: Krzysztof.Koch@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT042.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)(396003)(376002)(39860400002)(189003)(199004)(2616005)(26826003)(8936002)(4326008)(7696005)(478600001)(86362001)(2906002)(81166006)(44832011)(54906003)(336012)(316002)(70586007)(81156014)(36906005)(186003)(70206006)(426003)(8676002)(1076003)(6916009)(5660300002)(15650500001)(36756003)(26005)(6666004);DIR:OUT;SFP:1101;SCL:1;SRVR:AM0PR08MB5265;H:64aa7808-outbound-1.mta.getcheckrecipient.com;FPR:;SPF:Pass;LANG:en;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;MX:1;A:1; X-MS-Office365-Filtering-Correlation-Id-Prvs: 2ff077c6-3a59-4ec5-2899-08d79d99e2f2 X-Forefront-PRVS: 0288CD37D9 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OZl+GXIfICyT2dlEHkBDnHcBfEgB6yJ5T8rLuHQqrNwawcCYorHz9g/hNTV88T0bJ4kOkBlGmeClWfVbov5b2tc3D/utuiSX+SAvsdavq6WEhFaE8Ak5REql/SWmy59zYIRpedgGvhWfef28f/LPHd6TnSb0ZnAMzzn/NaUynj9RE2RL0B6v5Y5GGthL6kNtnssjVqrKwEYmMk3gu7dgkOPKNyfjoIyjMzMJ7ZjJQ3SVAWnfO/Bgrke7IAxQCc3JPajviIedceMfrSCLGM1SvYH56B93LTu8VW9tL7HCNRdMrLjgGO1VMs5L98rM6A3DhxWPuWMT6tMeCL7k0lwiymOpB7rACzzc3qx/SUgzAMuU3zZ/X0oqJnH1jXzMvXnQDrAZOjE9Uo6Cg/vTgdtMpOyhKbSBUsH5fGxSJFDoSm0NiKe2mh+tzErg2R+n6LSo X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jan 2020 11:14:24.2130 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 59bbe369-5bb7-4011-d0f0-08d79d99e7f2 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: AM0PR08MB5265 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: v3: - Rebase on latest master [Krzysztof] 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)'