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=yxDdQK70; spf=pass (domain: arm.com, ip: 40.107.7.49, mailfrom: alexei.fedorov@arm.com) Received: from EUR04-HE1-obe.outbound.protection.outlook.com (EUR04-HE1-obe.outbound.protection.outlook.com [40.107.7.49]) by groups.io with SMTP; Fri, 23 Aug 2019 04:52:34 -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=kT+3ZvpTASdC2nH+PyleeSwbeaoP7le7OIN91ygR7Ag=; b=yxDdQK70AmtXW5tLF/qJiCIoAiDp7IW0C6qo+jERM+tRZ/8hLjlJTa6IoBu/5iqaRikOqsq5Kv01Z3g8HpgtF1tDBe44bvBC1rktsySGTceBhnFvIOVxDZA0ZXM50NhYOC/7NMd4W8z0SfoWTc6FwExWFB1WVgGrHIv1M5/lHuk= Received: from VI1PR08CA0158.eurprd08.prod.outlook.com (2603:10a6:800:d1::12) by AM5PR0801MB1843.eurprd08.prod.outlook.com (2603:10a6:203:3a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.19; Fri, 23 Aug 2019 11:52:29 +0000 Received: from AM5EUR03FT015.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e08::202) by VI1PR08CA0158.outlook.office365.com (2603:10a6:800:d1::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2199.14 via Frontend Transport; Fri, 23 Aug 2019 11:52:28 +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 AM5EUR03FT015.mail.protection.outlook.com (10.152.16.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2199.13 via Frontend Transport; Fri, 23 Aug 2019 11:52:27 +0000 Received: ("Tessian outbound 8b8b6ad907d7:v27"); Fri, 23 Aug 2019 11:52:27 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 5d26bcb62b071c8a X-CR-MTA-TID: 64aa7808 Received: from 9ee2a318f802.2 (ip-172-16-0-2.eu-west-1.compute.internal [104.47.5.54]) by 64aa7808-outbound-1.mta.getcheckrecipient.com id 08C1DF05-115B-4A1B-9CE1-8FDF7F0BA4EF.1; Fri, 23 Aug 2019 11:52:21 +0000 Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-he1eur02lp2054.outbound.protection.outlook.com [104.47.5.54]) by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 9ee2a318f802.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 23 Aug 2019 11:52:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ocY7ogXacNuKBFbXz/TYUDBVNrt2JxqeUV7y4HqLFqav08UexrtSZya5pSwsXI6CljxqmX1UGm25dAN1P2/9PujYO7Hsd++9UT06scmLV52/HRAHi6cylmmK+IoyQRhksB6i4Y5whemzFO3bNzK4OPgvvPQtJ9g10y9QhJ4N+NkIBhUnkvnMKT/N8kceVWENmtvjSEfOJ10Y9aqg4+Vi9BlgSxG0kmkamTNVxP3vGjVqfp4Zw/GD0D2/v9G8+oKUUeRwg+hoWAqvveaGdP85P83hGsSjDkiW+8wsBJvEAESJ205hU7OAUkJM3DaC4x1eRaQ85x01PMyYyTH9Cmsb+g== 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=DmxB1o5WGToUeX2ihI9yg8QNcTgdoGI8Beq861JFoN8=; b=MzYu2XRdGxhJaLK4RAxBTBSqsXJNGUiD/VpikcdG8inVQ1dVBB21xusOn/xXRVGQRQT3QW/de/e8UATQnSxs9cFHklhJAHtlSiRTuje/4KnLlgUSA/7EjCR9SENoCXrcYewFFbHnecVjjEslHzf3ZJ3+I7P4DTw8tavbbnR2qNCzjCpn8uJFixB+tPZ4MXRYnZWsK1CxypaHzd8/gV/vKWBLJW51kvzzNbRmobpV7gdYRBwJo1bmLS58mtGa760SWxxnjYWNVa2Tpa72mT9aRlUOIxZB8N56Vk1H/lQma0JuQJ6TWaf5HpTzcEuD9WE5s1reEQkFbQjfjgTvyqLreA== 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=DmxB1o5WGToUeX2ihI9yg8QNcTgdoGI8Beq861JFoN8=; b=I97SuwxtYbsl3wTWU3w9d5NAeah3StpSeljcVQJDfMh83dj2K4wnhpI4GMCIkHbWQOCO9XadXs442nXenCm9RrzLJKcC2zcIDI5p4wLSBmGzajAxE5kJAHBgIx6Nr7wbNuQqb1FeGzC2dR92q8NW9u8r8hKWMsUyyhzqF5dPjtc= Received: from AM5PR0801MB1732.eurprd08.prod.outlook.com (10.169.244.21) by AM5PR0801MB1906.eurprd08.prod.outlook.com (10.168.156.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2178.18; Fri, 23 Aug 2019 11:52:20 +0000 Received: from AM5PR0801MB1732.eurprd08.prod.outlook.com ([fe80::50d7:cef5:ee39:2e83]) by AM5PR0801MB1732.eurprd08.prod.outlook.com ([fe80::50d7:cef5:ee39:2e83%9]) with mapi id 15.20.2178.020; Fri, 23 Aug 2019 11:52:20 +0000 From: "Alexei Fedorov" To: Sami Mujawar , "devel@edk2.groups.io" Subject: Re: [PATCH v1 12/19] DynamicTablesPkg: Fix IORT node length assignment Thread-Topic: [PATCH v1 12/19] DynamicTablesPkg: Fix IORT node length assignment Thread-Index: AQHVWaGPi/MjnhbAcUSLsM9MwAqjyacInx42 Date: Fri, 23 Aug 2019 11:52:20 +0000 Message-ID: References: <20190823105539.13260-1-sami.mujawar@arm.com>,<20190823105539.13260-13-sami.mujawar@arm.com> In-Reply-To: <20190823105539.13260-13-sami.mujawar@arm.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: Authentication-Results-Original: spf=none (sender IP is ) smtp.mailfrom=Alexei.Fedorov@arm.com; x-originating-ip: [217.140.106.49] x-ms-publictraffictype: Email X-MS-Office365-Filtering-Correlation-Id: fc2e2fad-13ae-4d96-c799-08d727c05ebb X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam-Untrusted: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020);SRVR:AM5PR0801MB1906; X-MS-TrafficTypeDiagnostic: AM5PR0801MB1906:|AM5PR0801MB1843: x-ms-exchange-transport-forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true x-ms-oob-tlc-oobclassifiers: OLM:9508;OLM:9508; x-forefront-prvs: 0138CD935C X-Forefront-Antispam-Report-Untrusted: SFV:NSPM;SFS:(10009020)(4636009)(346002)(396003)(136003)(376002)(39860400002)(366004)(189003)(199004)(76176011)(19627405001)(26005)(2501003)(9686003)(66066001)(186003)(53946003)(3846002)(102836004)(25786009)(105004)(6116002)(2906002)(55016002)(99286004)(66946007)(476003)(14444005)(53546011)(7696005)(446003)(76116006)(66446008)(478600001)(256004)(11346002)(66476007)(66556008)(64756008)(8936002)(8676002)(53936002)(52536014)(229853002)(486006)(33656002)(6506007)(19627235002)(81166006)(74316002)(6246003)(316002)(7736002)(71190400001)(71200400001)(54896002)(5660300002)(81156014)(86362001)(110136005)(30864003)(14454004)(6436002)(579004)(559001);DIR:OUT;SFP:1101;SCL:1;SRVR:AM5PR0801MB1906;H:AM5PR0801MB1732.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: 3cyLi+hMuv8mUMClxxwfrxrQzA3tzuDBmEO7vX8oIKRl4LWnxPo+ibK559Qsm0h0rRsUgem1fww/mfDPvYZ13VzjZz3aqwJAJBole3Tx4x4oVfsh+2ywLf9CxcU6RlIPf5rM6/y6Op/6ojbjBASGQKzQABEglW3n1jLIPjAg5N70J9n6VjykfHXV399Eqd+szMFYpkTgxaXGScNAY7U22lhSddzjhw26p/69fDPv1DA5J3fbT6omdwRZmdBN3A/KDtP8dIIvcu66WmDORMltGMPy12UOdOy2CLMAbbs57i7Uq7VA53w6EbzABIcBRxzdMbGCI7AlsTIC0Za8bv3WOq0HZ6DpQLOQ+xs6Fxxx4IVE1BH5ZNUMz4LNSzZY7I70m8nBuQNwxGUykH/p/6Gut/T93jKb+xVK5IuepgtgnqI= MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1906 Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Alexei.Fedorov@arm.com; Return-Path: Alexei.Fedorov@arm.com X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT015.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)(136003)(396003)(346002)(376002)(39860400002)(2980300002)(40434004)(199004)(189003)(14454004)(186003)(6116002)(476003)(126002)(26005)(102836004)(71190400001)(105004)(81156014)(8676002)(9686003)(81166006)(7696005)(76176011)(6506007)(2906002)(26826003)(30864003)(53546011)(2501003)(3846002)(25786009)(63370400001)(446003)(336012)(11346002)(63350400001)(478600001)(99286004)(486006)(5660300002)(36906005)(6246003)(70206006)(70586007)(66066001)(7736002)(53946003)(74316002)(5024004)(16586007)(19627405001)(110136005)(8936002)(55016002)(76130400001)(86362001)(14444005)(19627235002)(52536014)(33656002)(54896002)(229853002)(22756006)(356004)(316002)(559001)(579004)(569006);DIR:OUT;SFP:1101;SCL:1;SRVR:AM5PR0801MB1843;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: f52253c0-75c8-440f-c042-08d727c05a7f X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(710020)(711020)(4605104)(1401327)(2017052603328)(7193020);SRVR:AM5PR0801MB1843; X-Forefront-PRVS: 0138CD935C X-Microsoft-Antispam-Message-Info: gjIjmAmwkRk6GewbTbdvcr/e9LJqF6JoFhD/Ta4qhAXI1bUUZ3mnUfKIktYpXtCyJRvktDcTvI7tLxrLyfAcbDVy6Rr8mg/cFm+xT3jdjlyS8mOPyQ0Vkx8P4C/vZ+dvi2qRmTJBVgr110I+84rPrEAjWy0Z9ETRZ8EORwxWZEwwiuQR1wObTts87Ss+gFneD7d5R3TBu6gmxF0WWpNfTSDCKKX0oyhDc6ljplaEQSO5W3OiInsjXnMoBQxt41a+7Lzzni/dh/jU0Qle+id1MskSRDCNJXxke59Q0p+18OjH8godI3GrLmM/1UfkqdyDSrzXyQ+zFJ4xn3J6ewGN2I0/9JJyGLS81F4RVjVCJOWzVDBIfgOLHdVvejZecymSFH6PPkVqnP357w7huE/Oq1iFdi/yOUOXJEUGwcosv0M= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2019 11:52:27.1812 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fc2e2fad-13ae-4d96-c799-08d727c05ebb 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: AM5PR0801MB1843 Content-Language: en-GB Content-Type: multipart/alternative; boundary="_000_AM5PR0801MB17325DECC1C13DD30E8CE1819AA40AM5PR0801MB1732_" --_000_AM5PR0801MB17325DECC1C13DD30E8CE1819AA40AM5PR0801MB1732_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Alexei Fedorov Alexei ________________________________ From: Sami Mujawar Sent: 23 August 2019 11:55 To: devel@edk2.groups.io Cc: Sami Mujawar ; Alexei Fedorov ; leif.lindholm@linaro.org ; Matteo Carlini = ; nd Subject: [PATCH v1 12/19] DynamicTablesPkg: Fix IORT node length assignment The VS2017 compiler reports 'warning C4267: 'return': conversion from 'size_t' to 'UINT32', possible loss of data' for a number of functions that compute the IORT node length. Similarly, it reports warnings for IORT node length field assignments as the length field is 16-bit wide. This patch adds type casts at appropriate places and also implements validations to ensure that the max width of the respective fields is not exceeded. This patch also fixes a typo in one of the local variable names. Signed-off-by: Sami Mujawar --- DynamicTablesPkg/Library/Acpi/Arm/AcpiIortLibArm/IortGenerator.c | 352 +++= +++++++++++------ 1 file changed, 253 insertions(+), 99 deletions(-) diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiIortLibArm/IortGenerator= .c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiIortLibArm/IortGenerator.c index f303e9f29cc700634d236c08505cab91b9d62cb8..bd71220ca19679792de2bb6d88e= ed8d1913a7600 100644 --- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiIortLibArm/IortGenerator.c +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiIortLibArm/IortGenerator.c @@ -140,8 +140,8 @@ GetItsGroupNodeSize ( /* Size of ITS Group Node + Size of ITS Identifier array */ - return sizeof (EFI_ACPI_6_0_IO_REMAPPING_ITS_NODE) + - (Node->ItsIdCount * sizeof (UINT32)); + return (UINT32)(sizeof (EFI_ACPI_6_0_IO_REMAPPING_ITS_NODE) + + (Node->ItsIdCount * sizeof (UINT32))); } /** Returns the total size required for the ITS Group nodes and @@ -160,7 +160,7 @@ GetItsGroupNodeSize ( @retval Total size of the ITS Group Nodes. **/ STATIC -UINT32 +UINT64 GetSizeofItsGroupNodes ( IN CONST UINT32 NodeStartOffset, IN CONST CM_ARM_ITS_GROUP_NODE * NodeList, @@ -168,7 +168,7 @@ GetSizeofItsGroupNodes ( IN OUT IORT_NODE_INDEXER ** CONST NodeIndexer ) { - UINT32 Size; + UINT64 Size; ASSERT (NodeList !=3D NULL); @@ -176,7 +176,7 @@ GetSizeofItsGroupNodes ( while (NodeCount-- !=3D 0) { (*NodeIndexer)->Token =3D NodeList->Token; (*NodeIndexer)->Object =3D (VOID*)NodeList; - (*NodeIndexer)->Offset =3D Size + NodeStartOffset; + (*NodeIndexer)->Offset =3D (UINT32)(Size + NodeStartOffset); DEBUG (( DEBUG_INFO, "IORT: Node Indexer =3D %p, Token =3D %p, Object =3D %p, Offset =3D = 0x%x\n", @@ -211,10 +211,10 @@ GetNamedComponentNodeSize ( Size of ID mapping array + Size of ASCII string + 'padding to 32-bit word aligned'. */ - return sizeof (EFI_ACPI_6_0_IO_REMAPPING_NAMED_COMP_NODE) + - (Node->IdMappingCount * - sizeof (EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE)) + - ALIGN_VALUE (AsciiStrSize (Node->ObjectName), 4); + return (UINT32)(sizeof (EFI_ACPI_6_0_IO_REMAPPING_NAMED_COMP_NODE) + + (Node->IdMappingCount * + sizeof (EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE)) + + ALIGN_VALUE (AsciiStrSize (Node->ObjectName), 4)); } /** Returns the total size required for the Named Component nodes and @@ -233,7 +233,7 @@ GetNamedComponentNodeSize ( @retval Total size of the Named Component nodes. **/ STATIC -UINT32 +UINT64 GetSizeofNamedComponentNodes ( IN CONST UINT32 NodeStartOffset, IN CONST CM_ARM_NAMED_COMPONENT_NODE * NodeList, @@ -241,7 +241,7 @@ GetSizeofNamedComponentNodes ( IN OUT IORT_NODE_INDEXER ** CONST NodeIndexer ) { - UINT32 Size; + UINT64 Size; ASSERT (NodeList !=3D NULL); @@ -249,7 +249,7 @@ GetSizeofNamedComponentNodes ( while (NodeCount-- !=3D 0) { (*NodeIndexer)->Token =3D NodeList->Token; (*NodeIndexer)->Object =3D (VOID*)NodeList; - (*NodeIndexer)->Offset =3D Size + NodeStartOffset; + (*NodeIndexer)->Offset =3D (UINT32)(Size + NodeStartOffset); DEBUG (( DEBUG_INFO, "IORT: Node Indexer =3D %p, Token =3D %p, Object =3D %p, Offset =3D = 0x%x\n", @@ -284,9 +284,9 @@ GetRootComplexNodeSize ( /* Size of Root Complex node + Size of ID mapping array */ - return sizeof (EFI_ACPI_6_0_IO_REMAPPING_RC_NODE) + - (Node->IdMappingCount * - sizeof (EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE)); + return (UINT32)(sizeof (EFI_ACPI_6_0_IO_REMAPPING_RC_NODE) + + (Node->IdMappingCount * + sizeof (EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE))); } /** Returns the total size required for the Root Complex nodes and @@ -305,7 +305,7 @@ GetRootComplexNodeSize ( @retval Total size of the Root Complex nodes. **/ STATIC -UINT32 +UINT64 GetSizeofRootComplexNodes ( IN CONST UINT32 NodeStartOffset, IN CONST CM_ARM_ROOT_COMPLEX_NODE * NodeList, @@ -313,7 +313,7 @@ GetSizeofRootComplexNodes ( IN OUT IORT_NODE_INDEXER ** CONST NodeIndexer ) { - UINT32 Size; + UINT64 Size; ASSERT (NodeList !=3D NULL); @@ -321,7 +321,7 @@ GetSizeofRootComplexNodes ( while (NodeCount-- !=3D 0) { (*NodeIndexer)->Token =3D NodeList->Token; (*NodeIndexer)->Object =3D (VOID*)NodeList; - (*NodeIndexer)->Offset =3D Size + NodeStartOffset; + (*NodeIndexer)->Offset =3D (UINT32)(Size + NodeStartOffset); DEBUG (( DEBUG_INFO, "IORT: Node Indexer =3D %p, Token =3D %p, Object =3D %p, Offset =3D = 0x%x\n", @@ -358,13 +358,13 @@ GetSmmuV1V2NodeSize ( Size of context interrupt array + Size of PMU interrupt array */ - return sizeof (EFI_ACPI_6_0_IO_REMAPPING_SMMU_NODE) + - (Node->IdMappingCount * - sizeof (EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE)) + - (Node->ContextInterruptCount * - sizeof (EFI_ACPI_6_0_IO_REMAPPING_SMMU_INT)) + - (Node->PmuInterruptCount * - sizeof (EFI_ACPI_6_0_IO_REMAPPING_SMMU_INT)); + return (UINT32)(sizeof (EFI_ACPI_6_0_IO_REMAPPING_SMMU_NODE) + + (Node->IdMappingCount * + sizeof (EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE)) + + (Node->ContextInterruptCount * + sizeof (EFI_ACPI_6_0_IO_REMAPPING_SMMU_INT)) + + (Node->PmuInterruptCount * + sizeof (EFI_ACPI_6_0_IO_REMAPPING_SMMU_INT))); } /** Returns the total size required for the SMMUv1/SMMUv2 nodes and @@ -383,7 +383,7 @@ GetSmmuV1V2NodeSize ( @retval Total size of the SMMUv1/SMMUv2 nodes. **/ STATIC -UINT32 +UINT64 GetSizeofSmmuV1V2Nodes ( IN CONST UINT32 NodeStartOffset, IN CONST CM_ARM_SMMUV1_SMMUV2_NODE * NodeList, @@ -391,7 +391,7 @@ GetSizeofSmmuV1V2Nodes ( IN OUT IORT_NODE_INDEXER ** CONST NodeIndexer ) { - UINT32 Size; + UINT64 Size; ASSERT (NodeList !=3D NULL); @@ -399,7 +399,7 @@ GetSizeofSmmuV1V2Nodes ( while (NodeCount-- !=3D 0) { (*NodeIndexer)->Token =3D NodeList->Token; (*NodeIndexer)->Object =3D (VOID*)NodeList; - (*NodeIndexer)->Offset =3D Size + NodeStartOffset; + (*NodeIndexer)->Offset =3D (UINT32)(Size + NodeStartOffset); DEBUG (( DEBUG_INFO, "IORT: Node Indexer =3D %p, Token =3D %p, Object =3D %p, Offset =3D = 0x%x\n", @@ -433,9 +433,9 @@ GetSmmuV3NodeSize ( /* Size of SMMU v1/SMMU v2 node + Size of ID mapping array */ - return sizeof (EFI_ACPI_6_0_IO_REMAPPING_SMMU3_NODE) + - (Node->IdMappingCount * - sizeof (EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE)); + return (UINT32)(sizeof (EFI_ACPI_6_0_IO_REMAPPING_SMMU3_NODE) + + (Node->IdMappingCount * + sizeof (EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE))); } /** Returns the total size required for the SMMUv3 nodes and @@ -454,7 +454,7 @@ GetSmmuV3NodeSize ( @retval Total size of the SMMUv3 nodes. **/ STATIC -UINT32 +UINT64 GetSizeofSmmuV3Nodes ( IN CONST UINT32 NodeStartOffset, IN CONST CM_ARM_SMMUV3_NODE * NodeList, @@ -462,7 +462,7 @@ GetSizeofSmmuV3Nodes ( IN OUT IORT_NODE_INDEXER ** CONST NodeIndexer ) { - UINT32 Size; + UINT64 Size; ASSERT (NodeList !=3D NULL); @@ -470,7 +470,7 @@ GetSizeofSmmuV3Nodes ( while (NodeCount-- !=3D 0) { (*NodeIndexer)->Token =3D NodeList->Token; (*NodeIndexer)->Object =3D (VOID*)NodeList; - (*NodeIndexer)->Offset =3D Size + NodeStartOffset; + (*NodeIndexer)->Offset =3D (UINT32)(Size + NodeStartOffset); DEBUG (( DEBUG_INFO, "IORT: Node Indexer =3D %p, Token =3D %p, Object =3D %p, Offset =3D = 0x%x\n", @@ -504,9 +504,9 @@ GetPmcgNodeSize ( /* Size of PMCG node + Size of ID mapping array */ - return sizeof (EFI_ACPI_6_0_IO_REMAPPING_PMCG_NODE) + - (Node->IdMappingCount * - sizeof (EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE)); + return (UINT32)(sizeof (EFI_ACPI_6_0_IO_REMAPPING_PMCG_NODE) + + (Node->IdMappingCount * + sizeof (EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE))); } /** Returns the total size required for the PMCG nodes and @@ -525,7 +525,7 @@ GetPmcgNodeSize ( @retval Total size of the PMCG nodes. **/ STATIC -UINT32 +UINT64 GetSizeofPmcgNodes ( IN CONST UINT32 NodeStartOffset, IN CONST CM_ARM_PMCG_NODE * NodeList, @@ -533,7 +533,7 @@ GetSizeofPmcgNodes ( IN OUT IORT_NODE_INDEXER ** CONST NodeIndexer ) { - UINT32 Size; + UINT64 Size; ASSERT (NodeList !=3D NULL); @@ -541,7 +541,7 @@ GetSizeofPmcgNodes ( while (NodeCount-- !=3D 0) { (*NodeIndexer)->Token =3D NodeList->Token; (*NodeIndexer)->Object =3D (VOID*)NodeList; - (*NodeIndexer)->Offset =3D Size + NodeStartOffset; + (*NodeIndexer)->Offset =3D (UINT32)(Size + NodeStartOffset); DEBUG (( DEBUG_INFO, "IORT: Node Indexer =3D %p, Token =3D %p, Object =3D %p, Offset =3D = 0x%x\n", @@ -735,6 +735,7 @@ AddItsGroupNodes ( CM_ARM_ITS_IDENTIFIER * ItsIdentifier; UINT32 ItsIdentifierCount; UINT32 IdIndex; + UINT64 NodeLength; ASSERT (Iort !=3D NULL); @@ -742,9 +743,22 @@ AddItsGroupNodes ( NodesStartOffset); while (NodeCount-- !=3D 0) { + NodeLength =3D GetItsGroupNodeSize (NodeList); + if (NodeLength > MAX_UINT16) { + Status =3D EFI_INVALID_PARAMETER; + DEBUG (( + DEBUG_ERROR, + "ERROR: IORT: ITS Id Array Node length 0x%lx > MAX_UINT16." + " Status =3D %r\n", + NodeLength, + Status + )); + return Status; + } + // Populate the node header ItsGroupNode->Node.Type =3D EFI_ACPI_IORT_TYPE_ITS_GROUP; - ItsGroupNode->Node.Length =3D GetItsGroupNodeSize (NodeList); + ItsGroupNode->Node.Length =3D (UINT16)NodeLength; ItsGroupNode->Node.Revision =3D 0; ItsGroupNode->Node.Reserved =3D EFI_ACPI_RESERVED_DWORD; ItsGroupNode->Node.NumIdMappings =3D 0; @@ -825,8 +839,9 @@ AddNamedComponentNodes ( EFI_STATUS Status; EFI_ACPI_6_0_IO_REMAPPING_NAMED_COMP_NODE * NcNode; EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE * IdMapArray; - UINT32 ObjectNameLenght; CHAR8 * ObjectName; + UINTN ObjectNameLength; + UINT64 NodeLength; ASSERT (Iort !=3D NULL); @@ -834,18 +849,30 @@ AddNamedComponentNodes ( NodesStartOffset); while (NodeCount-- !=3D 0) { + NodeLength =3D GetNamedComponentNodeSize (NodeList); + if (NodeLength > MAX_UINT16) { + Status =3D EFI_INVALID_PARAMETER; + DEBUG (( + DEBUG_ERROR, + "ERROR: IORT: Named Component Node length 0x%lx > MAX_UINT16." + " Status =3D %r\n", + NodeLength, + Status + )); + return Status; + } + // Populate the node header NcNode->Node.Type =3D EFI_ACPI_IORT_TYPE_NAMED_COMP; - NcNode->Node.Length =3D - GetNamedComponentNodeSize (NodeList); + NcNode->Node.Length =3D (UINT16)NodeLength; NcNode->Node.Revision =3D 2; NcNode->Node.Reserved =3D EFI_ACPI_RESERVED_DWORD; NcNode->Node.NumIdMappings =3D NodeList->IdMappingCount; - ObjectNameLenght =3D AsciiStrLen (NodeList->ObjectName) + 1; + ObjectNameLength =3D AsciiStrLen (NodeList->ObjectName) + 1; NcNode->Node.IdReference =3D - sizeof (EFI_ACPI_6_0_IO_REMAPPING_NAMED_COMP_NODE) + - (ALIGN_VALUE (ObjectNameLenght, 4)); + (UINT32)(sizeof (EFI_ACPI_6_0_IO_REMAPPING_NAMED_COMP_NODE) + + (ALIGN_VALUE (ObjectNameLength, 4))); // Named Component specific data NcNode->Flags =3D NodeList->Flags; @@ -860,7 +887,7 @@ AddNamedComponentNodes ( sizeof (EFI_ACPI_6_0_IO_REMAPPING_NAMED_COMP_NODE)); Status =3D AsciiStrCpyS ( ObjectName, - ObjectNameLenght, + ObjectNameLength, NodeList->ObjectName ); if (EFI_ERROR (Status)) { @@ -936,6 +963,7 @@ AddRootComplexNodes ( EFI_STATUS Status; EFI_ACPI_6_0_IO_REMAPPING_RC_NODE * RcNode; EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE * IdMapArray; + UINT64 NodeLength; ASSERT (Iort !=3D NULL); @@ -943,9 +971,22 @@ AddRootComplexNodes ( NodesStartOffset); while (NodeCount-- !=3D 0) { + NodeLength =3D GetRootComplexNodeSize (NodeList); + if (NodeLength > MAX_UINT16) { + Status =3D EFI_INVALID_PARAMETER; + DEBUG (( + DEBUG_ERROR, + "ERROR: IORT: Root Complex Node length 0x%lx > MAX_UINT16." + " Status =3D %r\n", + NodeLength, + Status + )); + return Status; + } + // Populate the node header RcNode->Node.Type =3D EFI_ACPI_IORT_TYPE_ROOT_COMPLEX; - RcNode->Node.Length =3D GetRootComplexNodeSize (NodeList); + RcNode->Node.Length =3D (UINT16)NodeLength; RcNode->Node.Revision =3D 1; RcNode->Node.Reserved =3D EFI_ACPI_RESERVED_DWORD; RcNode->Node.NumIdMappings =3D NodeList->IdMappingCount; @@ -1093,6 +1134,7 @@ AddSmmuV1V2Nodes ( EFI_ACPI_6_0_IO_REMAPPING_SMMU_INT * ContextInterruptArray; EFI_ACPI_6_0_IO_REMAPPING_SMMU_INT * PmuInterruptArray; + UINT64 NodeLength; ASSERT (Iort !=3D NULL); @@ -1100,9 +1142,21 @@ AddSmmuV1V2Nodes ( NodesStartOffset); while (NodeCount-- !=3D 0) { + NodeLength =3D GetSmmuV1V2NodeSize (NodeList); + if (NodeLength > MAX_UINT16) { + Status =3D EFI_INVALID_PARAMETER; + DEBUG (( + DEBUG_ERROR, + "ERROR: IORT: SMMU V1/V2 Node length 0x%lx > MAX_UINT16. Status = =3D %r\n", + NodeLength, + Status + )); + return Status; + } + // Populate the node header SmmuNode->Node.Type =3D EFI_ACPI_IORT_TYPE_SMMUv1v2; - SmmuNode->Node.Length =3D GetSmmuV1V2NodeSize (NodeList); + SmmuNode->Node.Length =3D (UINT16)NodeLength; SmmuNode->Node.Revision =3D 0; SmmuNode->Node.Reserved =3D EFI_ACPI_RESERVED_DWORD; SmmuNode->Node.NumIdMappings =3D NodeList->IdMappingCount; @@ -1239,6 +1293,7 @@ AddSmmuV3Nodes ( EFI_STATUS Status; EFI_ACPI_6_0_IO_REMAPPING_SMMU3_NODE * SmmuV3Node; EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE * IdMapArray; + UINT64 NodeLength; ASSERT (Iort !=3D NULL); @@ -1246,9 +1301,21 @@ AddSmmuV3Nodes ( NodesStartOffset); while (NodeCount-- !=3D 0) { + NodeLength =3D GetSmmuV3NodeSize (NodeList); + if (NodeLength > MAX_UINT16) { + Status =3D EFI_INVALID_PARAMETER; + DEBUG (( + DEBUG_ERROR, + "ERROR: IORT: SMMU V3 Node length 0x%lx > MAX_UINT16. Status =3D %= r\n", + NodeLength, + Status + )); + return Status; + } + // Populate the node header SmmuV3Node->Node.Type =3D EFI_ACPI_IORT_TYPE_SMMUv3; - SmmuV3Node->Node.Length =3D GetSmmuV3NodeSize (NodeList); + SmmuV3Node->Node.Length =3D (UINT16)NodeLength; SmmuV3Node->Node.Revision =3D 2; SmmuV3Node->Node.Reserved =3D EFI_ACPI_RESERVED_DWORD; SmmuV3Node->Node.NumIdMappings =3D NodeList->IdMappingCount; @@ -1344,6 +1411,7 @@ AddPmcgNodes ( EFI_ACPI_6_0_IO_REMAPPING_PMCG_NODE * PmcgNode; EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE * IdMapArray; ACPI_IORT_GENERATOR * Generator; + UINT64 NodeLength; ASSERT (Iort !=3D NULL); @@ -1352,9 +1420,21 @@ AddPmcgNodes ( NodesStartOffset); while (NodeCount-- !=3D 0) { + NodeLength =3D GetPmcgNodeSize (NodeList); + if (NodeLength > MAX_UINT16) { + Status =3D EFI_INVALID_PARAMETER; + DEBUG (( + DEBUG_ERROR, + "ERROR: IORT: PMCG Node length 0x%lx > MAX_UINT16. Status =3D %r\n= ", + NodeLength, + Status + )); + return Status; + } + // Populate the node header PmcgNode->Node.Type =3D EFI_ACPI_IORT_TYPE_PMCG; - PmcgNode->Node.Length =3D GetPmcgNodeSize (NodeList); + PmcgNode->Node.Length =3D (UINT16)NodeLength; PmcgNode->Node.Revision =3D 1; PmcgNode->Node.Reserved =3D EFI_ACPI_RESERVED_DWORD; PmcgNode->Node.NumIdMappings =3D NodeList->IdMappingCount; @@ -1448,9 +1528,11 @@ BuildIortTable ( ) { EFI_STATUS Status; - UINT32 TableSize; + + UINT64 TableSize; + UINT64 NodeSize; + UINT32 IortNodeCount; - UINT32 ItsGroupNodeCount; UINT32 NamedComponentNodeCount; UINT32 RootComplexNodeCount; @@ -1638,81 +1720,141 @@ BuildIortTable ( // ITS Group Nodes if (ItsGroupNodeCount > 0) { - ItsGroupOffset =3D TableSize; + ItsGroupOffset =3D (UINT32)TableSize; // Size of ITS Group node list. - TableSize +=3D GetSizeofItsGroupNodes ( - ItsGroupOffset, - ItsGroupNodeList, - ItsGroupNodeCount, - &NodeIndexer - ); + NodeSize =3D GetSizeofItsGroupNodes ( + ItsGroupOffset, + ItsGroupNodeList, + ItsGroupNodeCount, + &NodeIndexer + ); + if (NodeSize > MAX_UINT32) { + Status =3D EFI_INVALID_PARAMETER; + DEBUG (( + DEBUG_ERROR, + "ERROR: IORT: Invalid Size of Group Nodes. Status =3D %r\n", + Status + )); + goto error_handler; + } + TableSize +=3D NodeSize; } // Named Component Nodes if (NamedComponentNodeCount > 0) { - NamedComponentOffset =3D TableSize; + NamedComponentOffset =3D (UINT32)TableSize; // Size of Named Component node list. - TableSize +=3D GetSizeofNamedComponentNodes ( - NamedComponentOffset, - NamedComponentNodeList, - NamedComponentNodeCount, - &NodeIndexer - ); + NodeSize =3D GetSizeofNamedComponentNodes ( + NamedComponentOffset, + NamedComponentNodeList, + NamedComponentNodeCount, + &NodeIndexer + ); + if (NodeSize > MAX_UINT32) { + Status =3D EFI_INVALID_PARAMETER; + DEBUG (( + DEBUG_ERROR, + "ERROR: IORT: Invalid Size of Named Component Nodes. Status =3D %r= \n", + Status + )); + goto error_handler; + } + TableSize +=3D NodeSize; } // Root Complex Nodes if (RootComplexNodeCount > 0) { - RootComplexOffset =3D TableSize; + RootComplexOffset =3D (UINT32)TableSize; // Size of Root Complex node list. - TableSize +=3D GetSizeofRootComplexNodes ( - RootComplexOffset, - RootComplexNodeList, - RootComplexNodeCount, - &NodeIndexer - ); + NodeSize =3D GetSizeofRootComplexNodes ( + RootComplexOffset, + RootComplexNodeList, + RootComplexNodeCount, + &NodeIndexer + ); + if (NodeSize > MAX_UINT32) { + Status =3D EFI_INVALID_PARAMETER; + DEBUG (( + DEBUG_ERROR, + "ERROR: IORT: Invalid Size of Root Complex Nodes. Status =3D %r\n"= , + Status + )); + goto error_handler; + } + TableSize +=3D NodeSize; } // SMMUv1/SMMUv2 Nodes if (SmmuV1V2NodeCount > 0) { - SmmuV1V2Offset =3D TableSize; + SmmuV1V2Offset =3D (UINT32)TableSize; // Size of SMMUv1/SMMUv2 node list. - TableSize +=3D GetSizeofSmmuV1V2Nodes ( - SmmuV1V2Offset, - SmmuV1V2NodeList, - SmmuV1V2NodeCount, - &NodeIndexer - ); + NodeSize =3D GetSizeofSmmuV1V2Nodes ( + SmmuV1V2Offset, + SmmuV1V2NodeList, + SmmuV1V2NodeCount, + &NodeIndexer + ); + if (NodeSize > MAX_UINT32) { + Status =3D EFI_INVALID_PARAMETER; + DEBUG (( + DEBUG_ERROR, + "ERROR: IORT: Invalid Size of SMMUv1/v2 Nodes. Status =3D %r\n", + Status + )); + goto error_handler; + } + TableSize +=3D NodeSize; } // SMMUv3 Nodes if (SmmuV3NodeCount > 0) { - SmmuV3Offset =3D TableSize; + SmmuV3Offset =3D (UINT32)TableSize; // Size of SMMUv3 node list. - TableSize +=3D GetSizeofSmmuV3Nodes ( - SmmuV3Offset, - SmmuV3NodeList, - SmmuV3NodeCount, - &NodeIndexer - ); + NodeSize =3D GetSizeofSmmuV3Nodes ( + SmmuV3Offset, + SmmuV3NodeList, + SmmuV3NodeCount, + &NodeIndexer + ); + if (NodeSize > MAX_UINT32) { + Status =3D EFI_INVALID_PARAMETER; + DEBUG (( + DEBUG_ERROR, + "ERROR: IORT: Invalid Size of SMMUv3 Nodes. Status =3D %r\n", + Status + )); + goto error_handler; + } + TableSize +=3D NodeSize; } // PMCG Nodes if (PmcgNodeCount > 0) { - PmcgOffset =3D TableSize; + PmcgOffset =3D (UINT32)TableSize; // Size of PMCG node list. - TableSize +=3D GetSizeofPmcgNodes ( - PmcgOffset, - PmcgNodeList, - PmcgNodeCount, - &NodeIndexer - ); + NodeSize =3D GetSizeofPmcgNodes ( + PmcgOffset, + PmcgNodeList, + PmcgNodeCount, + &NodeIndexer + ); + if (NodeSize > MAX_UINT32) { + Status =3D EFI_INVALID_PARAMETER; + DEBUG (( + DEBUG_ERROR, + "ERROR: IORT: Invalid Size of PMCG Nodes. Status =3D %r\n", + Status + )); + goto error_handler; + } + TableSize +=3D NodeSize; } DEBUG (( DEBUG_INFO, "INFO: IORT:\n" \ " IortNodeCount =3D %d\n" \ - " TableSize =3D %d\n", + " TableSize =3D 0x%lx\n", IortNodeCount, TableSize )); @@ -1765,6 +1907,18 @@ BuildIortTable ( PmcgOffset )); + if (TableSize > MAX_UINT32) { + Status =3D EFI_INVALID_PARAMETER; + DEBUG (( + DEBUG_ERROR, + "ERROR: IORT: IORT Table Size 0x%lx > MAX_UINT32," \ + " Status =3D %r\n", + TableSize, + Status + )); + goto error_handler; + } + // Allocate the Buffer for IORT table *Table =3D (EFI_ACPI_DESCRIPTION_HEADER*)AllocateZeroPool (TableSize); if (*Table =3D=3D NULL) { @@ -1783,7 +1937,7 @@ BuildIortTable ( DEBUG (( DEBUG_INFO, - "IORT: Iort =3D 0x%p TableSize =3D 0x%x\n", + "IORT: Iort =3D 0x%p TableSize =3D 0x%lx\n", Iort, TableSize )); @@ -1793,7 +1947,7 @@ BuildIortTable ( This, &Iort->Header, AcpiTableInfo, - TableSize + (UINT32)TableSize ); if (EFI_ERROR (Status)) { DEBUG (( -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)' IMPORTANT NOTICE: The contents of this email and any attachments are confid= ential and may also be privileged. If you are not the intended recipient, p= lease notify the sender immediately and do not disclose the contents to any= other person, use it for any purpose, or store or copy the information in = any medium. Thank you. --_000_AM5PR0801MB17325DECC1C13DD30E8CE1819AA40AM5PR0801MB1732_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable
Reviewed-by: Alexei Fedorov <Alexei.Fedorov@arm.com>

Alexei


From: Sami Mujawar <sami= .mujawar@arm.com>
Sent: 23 August 2019 11:55
To: devel@edk2.groups.io <devel@edk2.groups.io>
Cc: Sami Mujawar <Sami.Mujawar@arm.com>; Alexei Fedorov <Al= exei.Fedorov@arm.com>; leif.lindholm@linaro.org <leif.lindholm@linaro= .org>; Matteo Carlini <Matteo.Carlini@arm.com>; nd <nd@arm.com&= gt;
Subject: [PATCH v1 12/19] DynamicTablesPkg: Fix IORT node length ass= ignment
 
The VS2017 compiler reports 'warning C4267: 'retur= n': conversion
from 'size_t' to 'UINT32', possible loss of data' for a number of
functions that compute the IORT node length. Similarly, it reports
warnings for IORT node length field assignments as the length
field is 16-bit wide.

This patch adds type casts at appropriate places and also implements
validations to ensure that the max width of the respective fields
is not exceeded.

This patch also fixes a typo in one of the local variable names.

Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
---
 DynamicTablesPkg/Library/Acpi/Arm/AcpiIortLibArm/IortGenerator.c | 35= 2 ++++++++++++++---= ---
 1 file changed, 253 insertions(+), 99 deletions(-)

diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiIortLibArm/IortGenerator= .c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiIortLibArm/IortGenerator.c
index f303e9f29cc700634d236c08505cab91b9d62cb8..bd71220ca19679792de2bb6d88e= ed8d1913a7600 100644
--- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiIortLibArm/IortGenerator.c
+++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiIortLibArm/IortGene= rator.c
@@ -140,8 +140,8 @@ GetItsGroupNodeSize (
   /* Size of ITS Group Node +
      Size of ITS Identifier array
   */
-  return sizeof (EFI_ACPI_6_0_IO_REMAPPING_ITS_NODE) +
-           (Node->Its= IdCount * sizeof (UINT32));
+  return (UINT32)(sizeof (EFI_ACPI_6_0_IO_REMAPPING_ITS_NODE) = 3;
+           &nbs= p;        (Node->ItsIdCount * sizeof = (UINT32)));
 }
 
 /** Returns the total size required for the ITS Group nodes and
@@ -160,7 +160,7 @@ GetItsGroupNodeSize (
     @retval Total size of the ITS Group Nodes.
 **/
 STATIC
-UINT32
+UINT64
 GetSizeofItsGroupNodes (
   IN      CONST UINT32   = ;            &n= bsp;         NodeStartOffset,
   IN      CONST CM_ARM_ITS_GROUP_NODE&n= bsp; *       NodeList,
@@ -168,7 +168,7 @@ GetSizeofItsGroupNodes (
   IN OUT        IORT_NODE_IND= EXER     ** CONST NodeIndexer
   )
 {
-  UINT32  Size;
+  UINT64  Size;
 
   ASSERT (NodeList !=3D NULL);
 
@@ -176,7 +176,7 @@ GetSizeofItsGroupNodes (
   while (NodeCount-- !=3D 0) {
     (*NodeIndexer)->Token =3D NodeList->Token;      (*NodeIndexer)->Object =3D (VOID*)NodeList;
-    (*NodeIndexer)->Offset =3D Size + NodeStartOffse= t;
+    (*NodeIndexer)->Offset =3D (UINT32)(Size + N= odeStartOffset);
     DEBUG ((
       DEBUG_INFO,
       "IORT: Node Indexer =3D %p, Token= =3D %p, Object =3D %p, Offset =3D 0x%x\n",
@@ -211,10 +211,10 @@ GetNamedComponentNodeSize (
      Size of ID mapping array +
      Size of ASCII string + 'padding to 32-bi= t word aligned'.
   */
-  return sizeof (EFI_ACPI_6_0_IO_REMAPPING_NAMED_COMP_NODE) +
-            (Node-&= gt;IdMappingCount *
-             s= izeof (EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE)) +
-            ALIGN_V= ALUE (AsciiStrSize (Node->ObjectName), 4);
+  return (UINT32)(sizeof (EFI_ACPI_6_0_IO_REMAPPING_NAMED_COMP_NO= DE) +
+           &nbs= p;        (Node->IdMappingCount *
+           &nbs= p;         sizeof (EFI_ACPI_6_0_IO_= REMAPPING_ID_TABLE)) +
+           &nbs= p;        ALIGN_VALUE (AsciiStrSize (Nod= e->ObjectName), 4));
 }
 
 /** Returns the total size required for the Named Component nodes and=
@@ -233,7 +233,7 @@ GetNamedComponentNodeSize (
     @retval Total size of the Named Component nodes.  **/
 STATIC
-UINT32
+UINT64
 GetSizeofNamedComponentNodes (
   IN      CONST UINT32   = ;            &n= bsp;            = ;  NodeStartOffset,
   IN      CONST CM_ARM_NAMED_COMPONENT_= NODE *       NodeList,
@@ -241,7 +241,7 @@ GetSizeofNamedComponentNodes (
   IN OUT        IORT_NODE_IND= EXER          ** CONST NodeInd= exer
   )
 {
-  UINT32  Size;
+  UINT64  Size;
 
   ASSERT (NodeList !=3D NULL);
 
@@ -249,7 +249,7 @@ GetSizeofNamedComponentNodes (
   while (NodeCount-- !=3D 0) {
     (*NodeIndexer)->Token =3D NodeList->Token;      (*NodeIndexer)->Object =3D (VOID*)NodeList;
-    (*NodeIndexer)->Offset =3D Size + NodeStartOffse= t;
+    (*NodeIndexer)->Offset =3D (UINT32)(Size + N= odeStartOffset);
     DEBUG ((
       DEBUG_INFO,
       "IORT: Node Indexer =3D %p, Token= =3D %p, Object =3D %p, Offset =3D 0x%x\n",
@@ -284,9 +284,9 @@ GetRootComplexNodeSize (
   /* Size of Root Complex node +
      Size of ID mapping array
   */
-  return sizeof (EFI_ACPI_6_0_IO_REMAPPING_RC_NODE) +
-           (Node->IdM= appingCount *
-            sizeof = (EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE));
+  return (UINT32)(sizeof (EFI_ACPI_6_0_IO_REMAPPING_RC_NODE) += ;
+           &nbs= p;        (Node->IdMappingCount *
+           &nbs= p;         sizeof (EFI_ACPI_6_0_IO_= REMAPPING_ID_TABLE)));
 }
 
 /** Returns the total size required for the Root Complex nodes and @@ -305,7 +305,7 @@ GetRootComplexNodeSize (
     @retval Total size of the Root Complex nodes.
 **/
 STATIC
-UINT32
+UINT64
 GetSizeofRootComplexNodes (
   IN      CONST UINT32   = ;            &n= bsp;            = ;  NodeStartOffset,
   IN      CONST CM_ARM_ROOT_COMPLEX_NOD= E    *       NodeList,
@@ -313,7 +313,7 @@ GetSizeofRootComplexNodes (
   IN OUT        IORT_NODE_IND= EXER          ** CONST NodeInd= exer
   )
 {
-  UINT32  Size;
+  UINT64  Size;
 
   ASSERT (NodeList !=3D NULL);
 
@@ -321,7 +321,7 @@ GetSizeofRootComplexNodes (
   while (NodeCount-- !=3D 0) {
     (*NodeIndexer)->Token =3D NodeList->Token;      (*NodeIndexer)->Object =3D (VOID*)NodeList;
-    (*NodeIndexer)->Offset =3D Size + NodeStartOffse= t;
+    (*NodeIndexer)->Offset =3D (UINT32)(Size + N= odeStartOffset);
     DEBUG ((
       DEBUG_INFO,
       "IORT: Node Indexer =3D %p, Token= =3D %p, Object =3D %p, Offset =3D 0x%x\n",
@@ -358,13 +358,13 @@ GetSmmuV1V2NodeSize (
      Size of context interrupt array +
      Size of PMU interrupt array
   */
-  return sizeof (EFI_ACPI_6_0_IO_REMAPPING_SMMU_NODE) +
-           (Node->IdM= appingCount *
-            sizeof = (EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE)) +
-           (Node->Con= textInterruptCount *
-            sizeof = (EFI_ACPI_6_0_IO_REMAPPING_SMMU_INT)) +
-           (Node->Pmu= InterruptCount *
-            sizeof = (EFI_ACPI_6_0_IO_REMAPPING_SMMU_INT));
+  return (UINT32)(sizeof (EFI_ACPI_6_0_IO_REMAPPING_SMMU_NODE) &#= 43;
+           &nbs= p;        (Node->IdMappingCount *
+           &nbs= p;         sizeof (EFI_ACPI_6_0_IO_= REMAPPING_ID_TABLE)) +
+           &nbs= p;        (Node->ContextInterruptCoun= t *
+           &nbs= p;         sizeof (EFI_ACPI_6_0_IO_= REMAPPING_SMMU_INT)) +
+           &nbs= p;        (Node->PmuInterruptCount *<= br> +           &nbs= p;         sizeof (EFI_ACPI_6_0_IO_= REMAPPING_SMMU_INT)));
 }
 
 /** Returns the total size required for the SMMUv1/SMMUv2 nodes and @@ -383,7 +383,7 @@ GetSmmuV1V2NodeSize (
     @retval Total size of the SMMUv1/SMMUv2 nodes.
 **/
 STATIC
-UINT32
+UINT64
 GetSizeofSmmuV1V2Nodes (
   IN      CONST UINT32   = ;            &n= bsp;            = ;  NodeStartOffset,
   IN      CONST CM_ARM_SMMUV1_SMMUV2_NO= DE   *       NodeList,
@@ -391,7 +391,7 @@ GetSizeofSmmuV1V2Nodes (
   IN OUT        IORT_NODE_IND= EXER          ** CONST NodeInd= exer
   )
 {
-  UINT32  Size;
+  UINT64  Size;
 
   ASSERT (NodeList !=3D NULL);
 
@@ -399,7 +399,7 @@ GetSizeofSmmuV1V2Nodes (
   while (NodeCount-- !=3D 0) {
     (*NodeIndexer)->Token =3D NodeList->Token;      (*NodeIndexer)->Object =3D (VOID*)NodeList;
-    (*NodeIndexer)->Offset =3D Size + NodeStartOffse= t;
+    (*NodeIndexer)->Offset =3D (UINT32)(Size + N= odeStartOffset);
     DEBUG ((
       DEBUG_INFO,
       "IORT: Node Indexer =3D %p, Token= =3D %p, Object =3D %p, Offset =3D 0x%x\n",
@@ -433,9 +433,9 @@ GetSmmuV3NodeSize (
   /* Size of SMMU v1/SMMU v2 node +
      Size of ID mapping array
   */
-  return sizeof (EFI_ACPI_6_0_IO_REMAPPING_SMMU3_NODE) +
-           (Node->IdM= appingCount *
-            sizeof = (EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE));
+  return (UINT32)(sizeof (EFI_ACPI_6_0_IO_REMAPPING_SMMU3_NODE) &= #43;
+           &nbs= p;        (Node->IdMappingCount *
+           &nbs= p;         sizeof (EFI_ACPI_6_0_IO_= REMAPPING_ID_TABLE)));
 }
 
 /** Returns the total size required for the SMMUv3 nodes and
@@ -454,7 +454,7 @@ GetSmmuV3NodeSize (
     @retval Total size of the SMMUv3 nodes.
 **/
 STATIC
-UINT32
+UINT64
 GetSizeofSmmuV3Nodes (
   IN      CONST UINT32   = ;            &n= bsp;       NodeStartOffset,
   IN      CONST CM_ARM_SMMUV3_NODE = ;  *       NodeList,
@@ -462,7 +462,7 @@ GetSizeofSmmuV3Nodes (
   IN OUT        IORT_NODE_IND= EXER   ** CONST NodeIndexer
   )
 {
-  UINT32  Size;
+  UINT64  Size;
 
   ASSERT (NodeList !=3D NULL);
 
@@ -470,7 +470,7 @@ GetSizeofSmmuV3Nodes (
   while (NodeCount-- !=3D 0) {
     (*NodeIndexer)->Token =3D NodeList->Token;      (*NodeIndexer)->Object =3D (VOID*)NodeList;
-    (*NodeIndexer)->Offset =3D Size + NodeStartOffse= t;
+    (*NodeIndexer)->Offset =3D (UINT32)(Size + N= odeStartOffset);
     DEBUG ((
       DEBUG_INFO,
       "IORT: Node Indexer =3D %p, Token= =3D %p, Object =3D %p, Offset =3D 0x%x\n",
@@ -504,9 +504,9 @@ GetPmcgNodeSize (
   /* Size of PMCG node +
      Size of ID mapping array
   */
-  return sizeof (EFI_ACPI_6_0_IO_REMAPPING_PMCG_NODE) +
-           (Node->IdM= appingCount *
-            sizeof = (EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE));
+  return (UINT32)(sizeof (EFI_ACPI_6_0_IO_REMAPPING_PMCG_NODE) &#= 43;
+           &nbs= p;        (Node->IdMappingCount *
+           &nbs= p;         sizeof (EFI_ACPI_6_0_IO_= REMAPPING_ID_TABLE)));
 }
 
 /** Returns the total size required for the PMCG nodes and
@@ -525,7 +525,7 @@ GetPmcgNodeSize (
     @retval Total size of the PMCG nodes.
 **/
 STATIC
-UINT32
+UINT64
 GetSizeofPmcgNodes (
   IN      CONST UINT32   = ;            &n= bsp;     NodeStartOffset,
   IN      CONST CM_ARM_PMCG_NODE &= nbsp; *       NodeList,
@@ -533,7 +533,7 @@ GetSizeofPmcgNodes (
   IN OUT        IORT_NODE_IND= EXER ** CONST NodeIndexer
   )
 {
-  UINT32  Size;
+  UINT64  Size;
 
   ASSERT (NodeList !=3D NULL);
 
@@ -541,7 +541,7 @@ GetSizeofPmcgNodes (
   while (NodeCount-- !=3D 0) {
     (*NodeIndexer)->Token =3D NodeList->Token;      (*NodeIndexer)->Object =3D (VOID*)NodeList;
-    (*NodeIndexer)->Offset =3D Size + NodeStartOffse= t;
+    (*NodeIndexer)->Offset =3D (UINT32)(Size + N= odeStartOffset);
     DEBUG ((
       DEBUG_INFO,
       "IORT: Node Indexer =3D %p, Token= =3D %p, Object =3D %p, Offset =3D 0x%x\n",
@@ -735,6 +735,7 @@ AddItsGroupNodes (
   CM_ARM_ITS_IDENTIFIER       = ;        * ItsIdentifier;
   UINT32         &n= bsp;            = ;          ItsIdentifierCount;=
   UINT32         &n= bsp;            = ;          IdIndex;
+  UINT64         &nb= sp;            =           NodeLength;
 
   ASSERT (Iort !=3D NULL);
 
@@ -742,9 +743,22 @@ AddItsGroupNodes (
            &nb= sp;      NodesStartOffset);
 
   while (NodeCount-- !=3D 0) {
+    NodeLength =3D GetItsGroupNodeSize (NodeList);
+    if (NodeLength > MAX_UINT16) {
+      Status =3D EFI_INVALID_PARAMETER;
+      DEBUG ((
+        DEBUG_ERROR,
+        "ERROR: IORT: ITS Id A= rray Node length 0x%lx > MAX_UINT16."
+        " Status =3D %r\n"= ;,
+        NodeLength,
+        Status
+        ));
+      return Status;
+    }
+
     // Populate the node header
     ItsGroupNode->Node.Type =3D EFI_ACPI_IORT_TYPE_= ITS_GROUP;
-    ItsGroupNode->Node.Length =3D GetItsGroupNodeSize (N= odeList);
+    ItsGroupNode->Node.Length =3D (UINT16)NodeLength= ;
     ItsGroupNode->Node.Revision =3D 0;
     ItsGroupNode->Node.Reserved =3D EFI_ACPI_RESERV= ED_DWORD;
     ItsGroupNode->Node.NumIdMappings =3D 0;
@@ -825,8 +839,9 @@ AddNamedComponentNodes (
   EFI_STATUS        &nbs= p;            &= nbsp;           &nbs= p; Status;
   EFI_ACPI_6_0_IO_REMAPPING_NAMED_COMP_NODE  * NcNode;
   EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE    &nbs= p;    * IdMapArray;
-  UINT32          &= nbsp;           &nbs= p;            &= nbsp;   ObjectNameLenght;
   CHAR8         &nb= sp;            =             &nb= sp;   * ObjectName;
+  UINTN         &nbs= p;            &= nbsp;           &nbs= p;     ObjectNameLength;
+  UINT64         &nb= sp;            =             &nb= sp;    NodeLength;
 
   ASSERT (Iort !=3D NULL);
 
@@ -834,18 +849,30 @@ AddNamedComponentNodes (
             No= desStartOffset);
 
   while (NodeCount-- !=3D 0) {
+    NodeLength =3D GetNamedComponentNodeSize (NodeList)= ;
+    if (NodeLength > MAX_UINT16) {
+      Status =3D EFI_INVALID_PARAMETER;
+      DEBUG ((
+        DEBUG_ERROR,
+        "ERROR: IORT: Named Co= mponent Node length 0x%lx > MAX_UINT16."
+        " Status =3D %r\n"= ;,
+        NodeLength,
+        Status
+        ));
+      return Status;
+    }
+
     // Populate the node header
     NcNode->Node.Type =3D EFI_ACPI_IORT_TYPE_NAMED_= COMP;
-    NcNode->Node.Length =3D
-      GetNamedComponentNodeSize (NodeList);
+    NcNode->Node.Length =3D (UINT16)NodeLength;
     NcNode->Node.Revision =3D 2;
     NcNode->Node.Reserved =3D EFI_ACPI_RESERVED_DWO= RD;
     NcNode->Node.NumIdMappings =3D NodeList->IdM= appingCount;
 
-    ObjectNameLenght =3D AsciiStrLen (NodeList->ObjectNa= me) + 1;
+    ObjectNameLength =3D AsciiStrLen (NodeList->Obje= ctName) + 1;
     NcNode->Node.IdReference =3D
-      sizeof (EFI_ACPI_6_0_IO_REMAPPING_NAMED_COM= P_NODE) +
-      (ALIGN_VALUE (ObjectNameLenght, 4));
+      (UINT32)(sizeof (EFI_ACPI_6_0_IO_REMAPP= ING_NAMED_COMP_NODE) +
+        (ALIGN_VALUE (ObjectNameLen= gth, 4)));
 
     // Named Component specific data
     NcNode->Flags =3D NodeList->Flags;
@@ -860,7 +887,7 @@ AddNamedComponentNodes (
       sizeof (EFI_ACPI_6_0_IO_REMAPPING_NAME= D_COMP_NODE));
     Status =3D AsciiStrCpyS (
            &nb= sp;   ObjectName,
-            &n= bsp;  ObjectNameLenght,
+           &nbs= p;   ObjectNameLength,
            &nb= sp;   NodeList->ObjectName
            &nb= sp;   );
     if (EFI_ERROR (Status)) {
@@ -936,6 +963,7 @@ AddRootComplexNodes (
   EFI_STATUS        &nbs= p;            &= nbsp;     Status;
   EFI_ACPI_6_0_IO_REMAPPING_RC_NODE  * RcNode;
   EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE * IdMapArray;
+  UINT64         &nb= sp;            =          NodeLength;
 
   ASSERT (Iort !=3D NULL);
 
@@ -943,9 +971,22 @@ AddRootComplexNodes (
             No= desStartOffset);
 
   while (NodeCount-- !=3D 0) {
+    NodeLength =3D GetRootComplexNodeSize (NodeList); +    if (NodeLength > MAX_UINT16) {
+      Status =3D EFI_INVALID_PARAMETER;
+      DEBUG ((
+        DEBUG_ERROR,
+        "ERROR: IORT: Root Com= plex Node length 0x%lx > MAX_UINT16."
+        " Status =3D %r\n"= ;,
+        NodeLength,
+        Status
+        ));
+      return Status;
+    }
+
     // Populate the node header
     RcNode->Node.Type =3D EFI_ACPI_IORT_TYPE_ROOT_C= OMPLEX;
-    RcNode->Node.Length =3D GetRootComplexNodeSize (Node= List);
+    RcNode->Node.Length =3D (UINT16)NodeLength;
     RcNode->Node.Revision =3D 1;
     RcNode->Node.Reserved =3D EFI_ACPI_RESERVED_DWO= RD;
     RcNode->Node.NumIdMappings =3D NodeList->IdM= appingCount;
@@ -1093,6 +1134,7 @@ AddSmmuV1V2Nodes (
 
   EFI_ACPI_6_0_IO_REMAPPING_SMMU_INT  * ContextInterruptArr= ay;
   EFI_ACPI_6_0_IO_REMAPPING_SMMU_INT  * PmuInterruptArray;<= br> +  UINT64         &nb= sp;            =           NodeLength;
 
   ASSERT (Iort !=3D NULL);
 
@@ -1100,9 +1142,21 @@ AddSmmuV1V2Nodes (
            &nb= sp;  NodesStartOffset);
 
   while (NodeCount-- !=3D 0) {
+    NodeLength =3D GetSmmuV1V2NodeSize (NodeList);
+    if (NodeLength > MAX_UINT16) {
+      Status =3D EFI_INVALID_PARAMETER;
+      DEBUG ((
+        DEBUG_ERROR,
+        "ERROR: IORT: SMMU V1/= V2 Node length 0x%lx > MAX_UINT16. Status =3D %r\n",
+        NodeLength,
+        Status
+        ));
+      return Status;
+    }
+
     // Populate the node header
     SmmuNode->Node.Type =3D EFI_ACPI_IORT_TYPE_SMMU= v1v2;
-    SmmuNode->Node.Length =3D GetSmmuV1V2NodeSize (NodeL= ist);
+    SmmuNode->Node.Length =3D (UINT16)NodeLength;      SmmuNode->Node.Revision =3D 0;
     SmmuNode->Node.Reserved =3D EFI_ACPI_RESERVED_D= WORD;
     SmmuNode->Node.NumIdMappings =3D NodeList->I= dMappingCount;
@@ -1239,6 +1293,7 @@ AddSmmuV3Nodes (
   EFI_STATUS        &nbs= p;            &= nbsp;       Status;
   EFI_ACPI_6_0_IO_REMAPPING_SMMU3_NODE * SmmuV3Node;
   EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE   * IdMapArray; +  UINT64         &nb= sp;            =            NodeLength;  
   ASSERT (Iort !=3D NULL);
 
@@ -1246,9 +1301,21 @@ AddSmmuV3Nodes (
            &nb= sp;    NodesStartOffset);
 
   while (NodeCount-- !=3D 0) {
+    NodeLength =3D GetSmmuV3NodeSize (NodeList);
+    if (NodeLength > MAX_UINT16) {
+      Status =3D EFI_INVALID_PARAMETER;
+      DEBUG ((
+        DEBUG_ERROR,
+        "ERROR: IORT: SMMU V3 = Node length 0x%lx > MAX_UINT16. Status =3D %r\n",
+        NodeLength,
+        Status
+        ));
+      return Status;
+    }
+
     // Populate the node header
     SmmuV3Node->Node.Type =3D EFI_ACPI_IORT_TYPE_SM= MUv3;
-    SmmuV3Node->Node.Length =3D GetSmmuV3NodeSize (NodeL= ist);
+    SmmuV3Node->Node.Length =3D (UINT16)NodeLength;<= br>      SmmuV3Node->Node.Revision =3D 2;
     SmmuV3Node->Node.Reserved =3D EFI_ACPI_RESERVED= _DWORD;
     SmmuV3Node->Node.NumIdMappings =3D NodeList->= ;IdMappingCount;
@@ -1344,6 +1411,7 @@ AddPmcgNodes (
   EFI_ACPI_6_0_IO_REMAPPING_PMCG_NODE  * PmcgNode;
   EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE   * IdMapArray;    ACPI_IORT_GENERATOR       &= nbsp;          * Generator; +  UINT64         &nb= sp;            =            NodeLength;  
   ASSERT (Iort !=3D NULL);
 
@@ -1352,9 +1420,21 @@ AddPmcgNodes (
            &nb= sp;  NodesStartOffset);
 
   while (NodeCount-- !=3D 0) {
+    NodeLength =3D GetPmcgNodeSize (NodeList);
+    if (NodeLength > MAX_UINT16) {
+      Status =3D EFI_INVALID_PARAMETER;
+      DEBUG ((
+        DEBUG_ERROR,
+        "ERROR: IORT: PMCG Nod= e length 0x%lx > MAX_UINT16. Status =3D %r\n",
+        NodeLength,
+        Status
+        ));
+      return Status;
+    }
+
     // Populate the node header
     PmcgNode->Node.Type =3D EFI_ACPI_IORT_TYPE_PMCG= ;
-    PmcgNode->Node.Length =3D GetPmcgNodeSize (NodeList)= ;
+    PmcgNode->Node.Length =3D (UINT16)NodeLength;      PmcgNode->Node.Revision =3D 1;
     PmcgNode->Node.Reserved =3D EFI_ACPI_RESERVED_D= WORD;
     PmcgNode->Node.NumIdMappings =3D NodeList->I= dMappingCount;
@@ -1448,9 +1528,11 @@ BuildIortTable (
   )
 {
   EFI_STATUS        &nbs= p;            &= nbsp;       Status;
-  UINT32          &= nbsp;           &nbs= p;          TableSize;
+
+  UINT64         &nb= sp;            =            TableSize;
+  UINT64         &nb= sp;            =            NodeSize;
+
   UINT32         &n= bsp;            = ;           IortNodeCount= ;
-
   UINT32         &n= bsp;            = ;           ItsGroupNodeC= ount;
   UINT32         &n= bsp;            = ;           NamedComponen= tNodeCount;
   UINT32         &n= bsp;            = ;           RootComplexNo= deCount;
@@ -1638,81 +1720,141 @@ BuildIortTable (
 
   // ITS Group Nodes
   if (ItsGroupNodeCount > 0) {
-    ItsGroupOffset =3D TableSize;
+    ItsGroupOffset =3D (UINT32)TableSize;
     // Size of ITS Group node list.
-    TableSize +=3D GetSizeofItsGroupNodes (
-            &n= bsp;      ItsGroupOffset,
-            &n= bsp;      ItsGroupNodeList,
-            &n= bsp;      ItsGroupNodeCount,
-            &n= bsp;      &NodeIndexer
-            &n= bsp;      );
+    NodeSize =3D GetSizeofItsGroupNodes (
+           &nbs= p;     ItsGroupOffset,
+           &nbs= p;     ItsGroupNodeList,
+           &nbs= p;     ItsGroupNodeCount,
+           &nbs= p;     &NodeIndexer
+           &nbs= p;     );
+    if (NodeSize > MAX_UINT32) {
+      Status =3D EFI_INVALID_PARAMETER;
+      DEBUG ((
+        DEBUG_ERROR,
+        "ERROR: IORT: Invalid = Size of Group Nodes. Status =3D %r\n",
+        Status
+        ));
+      goto error_handler;
+    }
+    TableSize +=3D NodeSize;
   }
 
   // Named Component Nodes
   if (NamedComponentNodeCount > 0) {
-    NamedComponentOffset =3D TableSize;
+    NamedComponentOffset =3D (UINT32)TableSize;
     // Size of Named Component node list.
-    TableSize +=3D GetSizeofNamedComponentNodes (
-            &n= bsp;      NamedComponentOffset,
-            &n= bsp;      NamedComponentNodeList,
-            &n= bsp;      NamedComponentNodeCount,
-            &n= bsp;      &NodeIndexer
-            &n= bsp;      );
+    NodeSize =3D GetSizeofNamedComponentNodes (
+           &nbs= p;     NamedComponentOffset,
+           &nbs= p;     NamedComponentNodeList,
+           &nbs= p;     NamedComponentNodeCount,
+           &nbs= p;     &NodeIndexer
+           &nbs= p;     );
+    if (NodeSize > MAX_UINT32) {
+      Status =3D EFI_INVALID_PARAMETER;
+      DEBUG ((
+        DEBUG_ERROR,
+        "ERROR: IORT: Invalid = Size of Named Component Nodes. Status =3D %r\n",
+        Status
+        ));
+      goto error_handler;
+    }
+    TableSize +=3D NodeSize;
   }
 
   // Root Complex Nodes
   if (RootComplexNodeCount > 0) {
-    RootComplexOffset =3D TableSize;
+    RootComplexOffset =3D (UINT32)TableSize;
     // Size of Root Complex node list.
-    TableSize +=3D GetSizeofRootComplexNodes (
-            &n= bsp;      RootComplexOffset,
-            &n= bsp;      RootComplexNodeList,
-            &n= bsp;      RootComplexNodeCount,
-            &n= bsp;      &NodeIndexer
-            &n= bsp;      );
+    NodeSize =3D GetSizeofRootComplexNodes (
+           &nbs= p;     RootComplexOffset,
+           &nbs= p;     RootComplexNodeList,
+           &nbs= p;     RootComplexNodeCount,
+           &nbs= p;     &NodeIndexer
+           &nbs= p;     );
+    if (NodeSize > MAX_UINT32) {
+      Status =3D EFI_INVALID_PARAMETER;
+      DEBUG ((
+        DEBUG_ERROR,
+        "ERROR: IORT: Invalid = Size of Root Complex Nodes. Status =3D %r\n",
+        Status
+        ));
+      goto error_handler;
+    }
+    TableSize +=3D NodeSize;
   }
 
   // SMMUv1/SMMUv2 Nodes
   if (SmmuV1V2NodeCount > 0) {
-    SmmuV1V2Offset =3D TableSize;
+    SmmuV1V2Offset =3D (UINT32)TableSize;
     // Size of SMMUv1/SMMUv2 node list.
-    TableSize +=3D GetSizeofSmmuV1V2Nodes (
-            &n= bsp;      SmmuV1V2Offset,
-            &n= bsp;      SmmuV1V2NodeList,
-            &n= bsp;      SmmuV1V2NodeCount,
-            &n= bsp;      &NodeIndexer
-            &n= bsp;      );
+    NodeSize =3D GetSizeofSmmuV1V2Nodes (
+           &nbs= p;     SmmuV1V2Offset,
+           &nbs= p;     SmmuV1V2NodeList,
+           &nbs= p;     SmmuV1V2NodeCount,
+           &nbs= p;     &NodeIndexer
+           &nbs= p;     );
+    if (NodeSize > MAX_UINT32) {
+      Status =3D EFI_INVALID_PARAMETER;
+      DEBUG ((
+        DEBUG_ERROR,
+        "ERROR: IORT: Invalid = Size of SMMUv1/v2 Nodes. Status =3D %r\n",
+        Status
+        ));
+      goto error_handler;
+    }
+    TableSize +=3D NodeSize;
   }
 
   // SMMUv3 Nodes
   if (SmmuV3NodeCount > 0) {
-    SmmuV3Offset =3D TableSize;
+    SmmuV3Offset =3D (UINT32)TableSize;
     // Size of SMMUv3 node list.
-    TableSize +=3D GetSizeofSmmuV3Nodes (
-            &n= bsp;      SmmuV3Offset,
-            &n= bsp;      SmmuV3NodeList,
-            &n= bsp;      SmmuV3NodeCount,
-            &n= bsp;      &NodeIndexer
-            &n= bsp;      );
+    NodeSize =3D GetSizeofSmmuV3Nodes (
+           &nbs= p;     SmmuV3Offset,
+           &nbs= p;     SmmuV3NodeList,
+           &nbs= p;     SmmuV3NodeCount,
+           &nbs= p;     &NodeIndexer
+           &nbs= p;     );
+    if (NodeSize > MAX_UINT32) {
+      Status =3D EFI_INVALID_PARAMETER;
+      DEBUG ((
+        DEBUG_ERROR,
+        "ERROR: IORT: Invalid = Size of SMMUv3 Nodes. Status =3D %r\n",
+        Status
+        ));
+      goto error_handler;
+    }
+    TableSize +=3D NodeSize;
   }
 
   // PMCG Nodes
   if (PmcgNodeCount > 0) {
-    PmcgOffset =3D TableSize;
+    PmcgOffset =3D (UINT32)TableSize;
     // Size of PMCG node list.
-    TableSize +=3D GetSizeofPmcgNodes (
-            &n= bsp;      PmcgOffset,
-            &n= bsp;      PmcgNodeList,
-            &n= bsp;      PmcgNodeCount,
-            &n= bsp;      &NodeIndexer
-            &n= bsp;      );
+    NodeSize =3D GetSizeofPmcgNodes (
+           &nbs= p;     PmcgOffset,
+           &nbs= p;     PmcgNodeList,
+           &nbs= p;     PmcgNodeCount,
+           &nbs= p;     &NodeIndexer
+           &nbs= p;     );
+    if (NodeSize > MAX_UINT32) {
+      Status =3D EFI_INVALID_PARAMETER;
+      DEBUG ((
+        DEBUG_ERROR,
+        "ERROR: IORT: Invalid = Size of PMCG Nodes. Status =3D %r\n",
+        Status
+        ));
+      goto error_handler;
+    }
+    TableSize +=3D NodeSize;
   }
 
   DEBUG ((
     DEBUG_INFO,
     "INFO: IORT:\n" \
     " IortNodeCount =3D %d\n" \
-    " TableSize =3D %d\n",
+    " TableSize =3D 0x%lx\n",
     IortNodeCount,
     TableSize
     ));
@@ -1765,6 +1907,18 @@ BuildIortTable (
     PmcgOffset
     ));
 
+  if (TableSize > MAX_UINT32) {
+    Status =3D EFI_INVALID_PARAMETER;
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: IORT: IORT Table Size 0x%l= x > MAX_UINT32," \
+      " Status =3D %r\n",
+      TableSize,
+      Status
+      ));
+    goto error_handler;
+  }
+
   // Allocate the Buffer for IORT table
   *Table =3D (EFI_ACPI_DESCRIPTION_HEADER*)AllocateZeroPool (Tab= leSize);
   if (*Table =3D=3D NULL) {
@@ -1783,7 +1937,7 @@ BuildIortTable (
 
   DEBUG ((
     DEBUG_INFO,
-    "IORT: Iort =3D 0x%p TableSize =3D 0x%x\n", +    "IORT: Iort =3D 0x%p TableSize =3D 0x%lx\n&quo= t;,
     Iort,
     TableSize
     ));
@@ -1793,7 +1947,7 @@ BuildIortTable (
            &nb= sp; This,
            &nb= sp; &Iort->Header,
            &nb= sp; AcpiTableInfo,
-             T= ableSize
+           &nbs= p; (UINT32)TableSize
            &nb= sp; );
   if (EFI_ERROR (Status)) {
     DEBUG ((
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'


IMPORTANT NOTICE: The contents of this email and any attachments are confid= ential and may also be privileged. If you are not the intended recipient, p= lease notify the sender immediately and do not disclose the contents to any= other person, use it for any purpose, or store or copy the information in any medium. Thank you. --_000_AM5PR0801MB17325DECC1C13DD30E8CE1819AA40AM5PR0801MB1732_--