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=Kx1JsiZv; spf=pass (domain: arm.com, ip: 40.107.5.74, mailfrom: sami.mujawar@arm.com) Received: from EUR03-VE1-obe.outbound.protection.outlook.com (EUR03-VE1-obe.outbound.protection.outlook.com [40.107.5.74]) by groups.io with SMTP; Fri, 23 Aug 2019 03:57:46 -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=eiPiFx2wqG2+xd+2ekwFjIFyo6E4OWIRrVgXaU7B3o0=; b=Kx1JsiZv2QpYE8kI0WRcGwCMdi7oVXekfzH1O9dNRSxGKwL2svVR1MTAKlobF/Hj1ttvKVYDK4wAULTqJ8t/fPjs3q/9/T3HvL3nDa3GQd2o+mbndQfh83a9VGX86bwjl10ZVltWLbg6qXqQEIpNmgmSaOQA7b971wCgYn6YQ8A= Received: from VI1PR08CA0178.eurprd08.prod.outlook.com (2603:10a6:800:d1::32) by VE1PR08MB4959.eurprd08.prod.outlook.com (2603:10a6:803:110::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2178.16; Fri, 23 Aug 2019 10:57:40 +0000 Received: from VE1EUR03FT064.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e09::209) by VI1PR08CA0178.outlook.office365.com (2603:10a6:800:d1::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.17 via Frontend Transport; Fri, 23 Aug 2019 10:57:40 +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 VE1EUR03FT064.mail.protection.outlook.com (10.152.19.210) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.13 via Frontend Transport; Fri, 23 Aug 2019 10:57:38 +0000 Received: ("Tessian outbound 0c23f37acac0:v27"); Fri, 23 Aug 2019 10:57:38 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 2b48922cfb706f02 X-CR-MTA-TID: 64aa7808 Received: from 7bc86ae40e87.1 (ip-172-16-0-2.eu-west-1.compute.internal [104.47.13.51]) by 64aa7808-outbound-1.mta.getcheckrecipient.com id EB1507DB-8DEE-454F-B98D-DB76EF7707DC.1; Fri, 23 Aug 2019 10:57:38 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04lp2051.outbound.protection.outlook.com [104.47.13.51]) by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 7bc86ae40e87.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 23 Aug 2019 10:57:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gVJuZCrXZJWmuKcMxsbKY9rS2KoXlM1b6AB8bxgruFEPAhW02IZbDiu+TyOTyaJOp4I0+qZHtwhzU87caP53gJf1+DHSafIRvBI6k1Tflyoa4Og9o0GfSHO+LHD/laJ+T5/isBuN4GYX+fsVH6lEjU5MOV1BpnWYweU/QxVXsV4tUapFDdCDcS3Df9MoedgqYu1fyfAAuyA85l8jxwkT1JzrxrFukY3bEH53VcaRxzu1dD+wSUhrtuWmTOuR8rLrRmc6X8WZKioC0oZKSl7UDmq1307YeEjPxyHeDrzvt5ibG2UTrVOYzeSl/wlEeRSIj5XL2PDUhjPVovxoCzFAeg== 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=eiPiFx2wqG2+xd+2ekwFjIFyo6E4OWIRrVgXaU7B3o0=; b=j16oexKt3Cv0mPtcnrl2w0mQPknrfkIEqAxWg8ufdFfEgb49o/b929mramB5FtkpDF4i9ITAxCMjECQL1ddoLOvSIqw+J1JefMvgtTnqTPujCy4G+mNLwP4t4djps1HBSv/T6CxLI5W8EYdtDHSIGkqerJJUGHE25JLrmEWkwm2NrthblvNjIXJc6S28MIbu3gVJgwvo+CLk2wxlycn2lrP45Ve56nQrPQ7/e1aXd/68lsTGsSxwaqo3F8vJPGGvaRHEDSkHnRU9vVz8R0HGWpR3ms/oM/OlhI8i09So5EuH0q1LHdvjzqivGnJ4KLhqhXpb6O+mhWLILS+s5qZvzA== 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=eiPiFx2wqG2+xd+2ekwFjIFyo6E4OWIRrVgXaU7B3o0=; b=Kx1JsiZv2QpYE8kI0WRcGwCMdi7oVXekfzH1O9dNRSxGKwL2svVR1MTAKlobF/Hj1ttvKVYDK4wAULTqJ8t/fPjs3q/9/T3HvL3nDa3GQd2o+mbndQfh83a9VGX86bwjl10ZVltWLbg6qXqQEIpNmgmSaOQA7b971wCgYn6YQ8A= Received: from VI1PR08CA0142.eurprd08.prod.outlook.com (2603:10a6:800:d5::20) by AM5PR0802MB2596.eurprd08.prod.outlook.com (2603:10a6:203:98::8) 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 10:57:35 +0000 Received: from AM5EUR03FT017.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e08::209) by VI1PR08CA0142.outlook.office365.com (2603:10a6:800:d5::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.14 via Frontend Transport; Fri, 23 Aug 2019 10:57:35 +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 AM5EUR03FT017.mail.protection.outlook.com (10.152.16.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.2199.13 via Frontend Transport; Fri, 23 Aug 2019 10:57:33 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1415.2; Fri, 23 Aug 2019 10:56:24 +0000 Received: from E107187.Arm.com (10.1.195.55) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.1415.2 via Frontend Transport; Fri, 23 Aug 2019 10:56:24 +0000 From: "Sami Mujawar" To: CC: Sami Mujawar , , , , Subject: [PATCH v1 12/19] DynamicTablesPkg: Fix IORT node length assignment Date: Fri, 23 Aug 2019 11:55:32 +0100 Message-ID: <20190823105539.13260-13-sami.mujawar@arm.com> X-Mailer: git-send-email 2.11.0.windows.3 In-Reply-To: <20190823105539.13260-1-sami.mujawar@arm.com> References: <20190823105539.13260-1-sami.mujawar@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)(39860400002)(346002)(396003)(376002)(2980300002)(199004)(189003)(53416004)(50226002)(4326008)(19627235002)(478600001)(36756003)(356004)(6666004)(30864003)(53936002)(2351001)(5660300002)(6916009)(14444005)(16586007)(76176011)(51416003)(8676002)(7696005)(50466002)(126002)(26005)(426003)(476003)(81166006)(81156014)(48376002)(305945005)(47776003)(70206006)(2906002)(486006)(70586007)(44832011)(336012)(86362001)(63370400001)(63350400001)(54906003)(186003)(1076003)(8936002)(316002)(446003)(2616005)(11346002);DIR:OUT;SFP:1101;SCL:1;SRVR:AM5PR0802MB2596;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: 9962a960-3b08-40bc-ca3e-08d727b8b683 X-Microsoft-Antispam-Untrusted: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(2017052603328);SRVR:AM5PR0802MB2596; X-MS-TrafficTypeDiagnostic: AM5PR0802MB2596:|VE1PR08MB4959: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true X-MS-Oob-TLC-OOBClassifiers: OLM:9508;OLM:9508; X-Forefront-PRVS: 0138CD935C X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info-Original: Lnidv40KvUPc3a/adWYJwcPNLSHPkzerNrgIYUz/UxqAu58E5A2di0vAFy2J6ot4oHo9AJGJkDf7BJQe38AIjx5yi0DNkFJZYgoeC8eGvRAhT4K+7ZTy2ypnqKE9xiTX8EuY5Y9ZnNHn9R1ebxd9DxPYtIMEYA7D8z9yeIe5Wup3RE4uIiKnksvmvGEgBWTtaTWEi/SQCKZgfU5F6rY4WkC+RczNFsjt2sl/cZ321i/FGHArEjUU0M+4l7Tql046irKzRWL+qdNcziSrD9iN4B9cmRW1YiQ2MFiQKOzBBRwA6onsc0u5h0zY/zSon0lvj357c8EVvGm9k/yPS+1Fmgmkr4bYpn0IuM8kbRPVwcvdWi3D1gdtyRCK1PNf7j/SCNck/pmtHYC0+Cv6wAQ1LlIhpDsz151YAHWkdRR0Dx4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0802MB2596 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: Sami.Mujawar@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT064.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)(39860400002)(376002)(346002)(396003)(136003)(2980300002)(189003)(199004)(5660300002)(336012)(316002)(63350400001)(16586007)(44832011)(8676002)(14444005)(426003)(22756006)(63370400001)(86362001)(19627235002)(1076003)(36756003)(81156014)(81166006)(76130400001)(186003)(26005)(50226002)(70586007)(2906002)(70206006)(36906005)(305945005)(8936002)(4326008)(54906003)(47776003)(7696005)(30864003)(76176011)(50466002)(2351001)(6916009)(53416004)(51416003)(26826003)(48376002)(486006)(478600001)(2616005)(446003)(126002)(11346002)(476003)(6666004);DIR:OUT;SFP:1101;SCL:1;SRVR:VE1PR08MB4959;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: 80a1fa9d-cc98-42d3-25ad-08d727b8b389 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(710020)(711020)(4605104)(1401327)(2017052603328);SRVR:VE1PR08MB4959; NoDisclaimer: True X-Forefront-PRVS: 0138CD935C X-Microsoft-Antispam-Message-Info: CPOefFxfzfmEJU5NrP88VFW631gq+XRqcKWL6PbcXzI+N4tE5FyM8cA7p1ha99NnmNvvbLfJQ8m7gq2K9M+noG2Sj5lcH1fb/WwPHyH9sbQ/pRAK15XB0xwIboXHIdLWv25q38oCVQbW5I61duW+IKK8nYhrCHmubPRDO1P9zK2LDyPhQqVbnCMsG1xkWE/ePkaJCJ98zRcJ60Lx4rtGd/Ds0kSy5DnNCVQrAI4xkVJTpL1wg4pp9x34VsXMZ+HYEN+4SUDU5f2yR5ymbde2ShWblFZL2u7W85hJAznTxaMm9k6Sh4Wicus9FBCNLSoY6GGJ5GrwPgcH8hDOieFhiPV0SYG0ZNbe9e3S9CfenJDC1tghsQrwF5UCmHGfbLvGJxCdHOqp6DCxm+fS3XtFbI/8myk4BYyfD38xfs9scIo= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2019 10:57:38.4159 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9962a960-3b08-40bc-ca3e-08d727b8b683 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: VE1PR08MB4959 Content-Type: text/plain 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..bd71220ca19679792de2bb6d88eed8d1913a7600 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 != NULL); @@ -176,7 +176,7 @@ GetSizeofItsGroupNodes ( while (NodeCount-- != 0) { (*NodeIndexer)->Token = NodeList->Token; (*NodeIndexer)->Object = (VOID*)NodeList; - (*NodeIndexer)->Offset = Size + NodeStartOffset; + (*NodeIndexer)->Offset = (UINT32)(Size + NodeStartOffset); DEBUG (( DEBUG_INFO, "IORT: Node Indexer = %p, Token = %p, Object = %p, Offset = 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 != NULL); @@ -249,7 +249,7 @@ GetSizeofNamedComponentNodes ( while (NodeCount-- != 0) { (*NodeIndexer)->Token = NodeList->Token; (*NodeIndexer)->Object = (VOID*)NodeList; - (*NodeIndexer)->Offset = Size + NodeStartOffset; + (*NodeIndexer)->Offset = (UINT32)(Size + NodeStartOffset); DEBUG (( DEBUG_INFO, "IORT: Node Indexer = %p, Token = %p, Object = %p, Offset = 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 != NULL); @@ -321,7 +321,7 @@ GetSizeofRootComplexNodes ( while (NodeCount-- != 0) { (*NodeIndexer)->Token = NodeList->Token; (*NodeIndexer)->Object = (VOID*)NodeList; - (*NodeIndexer)->Offset = Size + NodeStartOffset; + (*NodeIndexer)->Offset = (UINT32)(Size + NodeStartOffset); DEBUG (( DEBUG_INFO, "IORT: Node Indexer = %p, Token = %p, Object = %p, Offset = 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 != NULL); @@ -399,7 +399,7 @@ GetSizeofSmmuV1V2Nodes ( while (NodeCount-- != 0) { (*NodeIndexer)->Token = NodeList->Token; (*NodeIndexer)->Object = (VOID*)NodeList; - (*NodeIndexer)->Offset = Size + NodeStartOffset; + (*NodeIndexer)->Offset = (UINT32)(Size + NodeStartOffset); DEBUG (( DEBUG_INFO, "IORT: Node Indexer = %p, Token = %p, Object = %p, Offset = 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 != NULL); @@ -470,7 +470,7 @@ GetSizeofSmmuV3Nodes ( while (NodeCount-- != 0) { (*NodeIndexer)->Token = NodeList->Token; (*NodeIndexer)->Object = (VOID*)NodeList; - (*NodeIndexer)->Offset = Size + NodeStartOffset; + (*NodeIndexer)->Offset = (UINT32)(Size + NodeStartOffset); DEBUG (( DEBUG_INFO, "IORT: Node Indexer = %p, Token = %p, Object = %p, Offset = 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 != NULL); @@ -541,7 +541,7 @@ GetSizeofPmcgNodes ( while (NodeCount-- != 0) { (*NodeIndexer)->Token = NodeList->Token; (*NodeIndexer)->Object = (VOID*)NodeList; - (*NodeIndexer)->Offset = Size + NodeStartOffset; + (*NodeIndexer)->Offset = (UINT32)(Size + NodeStartOffset); DEBUG (( DEBUG_INFO, "IORT: Node Indexer = %p, Token = %p, Object = %p, Offset = 0x%x\n", @@ -735,6 +735,7 @@ AddItsGroupNodes ( CM_ARM_ITS_IDENTIFIER * ItsIdentifier; UINT32 ItsIdentifierCount; UINT32 IdIndex; + UINT64 NodeLength; ASSERT (Iort != NULL); @@ -742,9 +743,22 @@ AddItsGroupNodes ( NodesStartOffset); while (NodeCount-- != 0) { + NodeLength = GetItsGroupNodeSize (NodeList); + if (NodeLength > MAX_UINT16) { + Status = EFI_INVALID_PARAMETER; + DEBUG (( + DEBUG_ERROR, + "ERROR: IORT: ITS Id Array Node length 0x%lx > MAX_UINT16." + " Status = %r\n", + NodeLength, + Status + )); + return Status; + } + // Populate the node header ItsGroupNode->Node.Type = EFI_ACPI_IORT_TYPE_ITS_GROUP; - ItsGroupNode->Node.Length = GetItsGroupNodeSize (NodeList); + ItsGroupNode->Node.Length = (UINT16)NodeLength; ItsGroupNode->Node.Revision = 0; ItsGroupNode->Node.Reserved = EFI_ACPI_RESERVED_DWORD; ItsGroupNode->Node.NumIdMappings = 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 != NULL); @@ -834,18 +849,30 @@ AddNamedComponentNodes ( NodesStartOffset); while (NodeCount-- != 0) { + NodeLength = GetNamedComponentNodeSize (NodeList); + if (NodeLength > MAX_UINT16) { + Status = EFI_INVALID_PARAMETER; + DEBUG (( + DEBUG_ERROR, + "ERROR: IORT: Named Component Node length 0x%lx > MAX_UINT16." + " Status = %r\n", + NodeLength, + Status + )); + return Status; + } + // Populate the node header NcNode->Node.Type = EFI_ACPI_IORT_TYPE_NAMED_COMP; - NcNode->Node.Length = - GetNamedComponentNodeSize (NodeList); + NcNode->Node.Length = (UINT16)NodeLength; NcNode->Node.Revision = 2; NcNode->Node.Reserved = EFI_ACPI_RESERVED_DWORD; NcNode->Node.NumIdMappings = NodeList->IdMappingCount; - ObjectNameLenght = AsciiStrLen (NodeList->ObjectName) + 1; + ObjectNameLength = AsciiStrLen (NodeList->ObjectName) + 1; NcNode->Node.IdReference = - 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 = NodeList->Flags; @@ -860,7 +887,7 @@ AddNamedComponentNodes ( sizeof (EFI_ACPI_6_0_IO_REMAPPING_NAMED_COMP_NODE)); Status = 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 != NULL); @@ -943,9 +971,22 @@ AddRootComplexNodes ( NodesStartOffset); while (NodeCount-- != 0) { + NodeLength = GetRootComplexNodeSize (NodeList); + if (NodeLength > MAX_UINT16) { + Status = EFI_INVALID_PARAMETER; + DEBUG (( + DEBUG_ERROR, + "ERROR: IORT: Root Complex Node length 0x%lx > MAX_UINT16." + " Status = %r\n", + NodeLength, + Status + )); + return Status; + } + // Populate the node header RcNode->Node.Type = EFI_ACPI_IORT_TYPE_ROOT_COMPLEX; - RcNode->Node.Length = GetRootComplexNodeSize (NodeList); + RcNode->Node.Length = (UINT16)NodeLength; RcNode->Node.Revision = 1; RcNode->Node.Reserved = EFI_ACPI_RESERVED_DWORD; RcNode->Node.NumIdMappings = 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 != NULL); @@ -1100,9 +1142,21 @@ AddSmmuV1V2Nodes ( NodesStartOffset); while (NodeCount-- != 0) { + NodeLength = GetSmmuV1V2NodeSize (NodeList); + if (NodeLength > MAX_UINT16) { + Status = EFI_INVALID_PARAMETER; + DEBUG (( + DEBUG_ERROR, + "ERROR: IORT: SMMU V1/V2 Node length 0x%lx > MAX_UINT16. Status = %r\n", + NodeLength, + Status + )); + return Status; + } + // Populate the node header SmmuNode->Node.Type = EFI_ACPI_IORT_TYPE_SMMUv1v2; - SmmuNode->Node.Length = GetSmmuV1V2NodeSize (NodeList); + SmmuNode->Node.Length = (UINT16)NodeLength; SmmuNode->Node.Revision = 0; SmmuNode->Node.Reserved = EFI_ACPI_RESERVED_DWORD; SmmuNode->Node.NumIdMappings = 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 != NULL); @@ -1246,9 +1301,21 @@ AddSmmuV3Nodes ( NodesStartOffset); while (NodeCount-- != 0) { + NodeLength = GetSmmuV3NodeSize (NodeList); + if (NodeLength > MAX_UINT16) { + Status = EFI_INVALID_PARAMETER; + DEBUG (( + DEBUG_ERROR, + "ERROR: IORT: SMMU V3 Node length 0x%lx > MAX_UINT16. Status = %r\n", + NodeLength, + Status + )); + return Status; + } + // Populate the node header SmmuV3Node->Node.Type = EFI_ACPI_IORT_TYPE_SMMUv3; - SmmuV3Node->Node.Length = GetSmmuV3NodeSize (NodeList); + SmmuV3Node->Node.Length = (UINT16)NodeLength; SmmuV3Node->Node.Revision = 2; SmmuV3Node->Node.Reserved = EFI_ACPI_RESERVED_DWORD; SmmuV3Node->Node.NumIdMappings = 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 != NULL); @@ -1352,9 +1420,21 @@ AddPmcgNodes ( NodesStartOffset); while (NodeCount-- != 0) { + NodeLength = GetPmcgNodeSize (NodeList); + if (NodeLength > MAX_UINT16) { + Status = EFI_INVALID_PARAMETER; + DEBUG (( + DEBUG_ERROR, + "ERROR: IORT: PMCG Node length 0x%lx > MAX_UINT16. Status = %r\n", + NodeLength, + Status + )); + return Status; + } + // Populate the node header PmcgNode->Node.Type = EFI_ACPI_IORT_TYPE_PMCG; - PmcgNode->Node.Length = GetPmcgNodeSize (NodeList); + PmcgNode->Node.Length = (UINT16)NodeLength; PmcgNode->Node.Revision = 1; PmcgNode->Node.Reserved = EFI_ACPI_RESERVED_DWORD; PmcgNode->Node.NumIdMappings = 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 = TableSize; + ItsGroupOffset = (UINT32)TableSize; // Size of ITS Group node list. - TableSize += GetSizeofItsGroupNodes ( - ItsGroupOffset, - ItsGroupNodeList, - ItsGroupNodeCount, - &NodeIndexer - ); + NodeSize = GetSizeofItsGroupNodes ( + ItsGroupOffset, + ItsGroupNodeList, + ItsGroupNodeCount, + &NodeIndexer + ); + if (NodeSize > MAX_UINT32) { + Status = EFI_INVALID_PARAMETER; + DEBUG (( + DEBUG_ERROR, + "ERROR: IORT: Invalid Size of Group Nodes. Status = %r\n", + Status + )); + goto error_handler; + } + TableSize += NodeSize; } // Named Component Nodes if (NamedComponentNodeCount > 0) { - NamedComponentOffset = TableSize; + NamedComponentOffset = (UINT32)TableSize; // Size of Named Component node list. - TableSize += GetSizeofNamedComponentNodes ( - NamedComponentOffset, - NamedComponentNodeList, - NamedComponentNodeCount, - &NodeIndexer - ); + NodeSize = GetSizeofNamedComponentNodes ( + NamedComponentOffset, + NamedComponentNodeList, + NamedComponentNodeCount, + &NodeIndexer + ); + if (NodeSize > MAX_UINT32) { + Status = EFI_INVALID_PARAMETER; + DEBUG (( + DEBUG_ERROR, + "ERROR: IORT: Invalid Size of Named Component Nodes. Status = %r\n", + Status + )); + goto error_handler; + } + TableSize += NodeSize; } // Root Complex Nodes if (RootComplexNodeCount > 0) { - RootComplexOffset = TableSize; + RootComplexOffset = (UINT32)TableSize; // Size of Root Complex node list. - TableSize += GetSizeofRootComplexNodes ( - RootComplexOffset, - RootComplexNodeList, - RootComplexNodeCount, - &NodeIndexer - ); + NodeSize = GetSizeofRootComplexNodes ( + RootComplexOffset, + RootComplexNodeList, + RootComplexNodeCount, + &NodeIndexer + ); + if (NodeSize > MAX_UINT32) { + Status = EFI_INVALID_PARAMETER; + DEBUG (( + DEBUG_ERROR, + "ERROR: IORT: Invalid Size of Root Complex Nodes. Status = %r\n", + Status + )); + goto error_handler; + } + TableSize += NodeSize; } // SMMUv1/SMMUv2 Nodes if (SmmuV1V2NodeCount > 0) { - SmmuV1V2Offset = TableSize; + SmmuV1V2Offset = (UINT32)TableSize; // Size of SMMUv1/SMMUv2 node list. - TableSize += GetSizeofSmmuV1V2Nodes ( - SmmuV1V2Offset, - SmmuV1V2NodeList, - SmmuV1V2NodeCount, - &NodeIndexer - ); + NodeSize = GetSizeofSmmuV1V2Nodes ( + SmmuV1V2Offset, + SmmuV1V2NodeList, + SmmuV1V2NodeCount, + &NodeIndexer + ); + if (NodeSize > MAX_UINT32) { + Status = EFI_INVALID_PARAMETER; + DEBUG (( + DEBUG_ERROR, + "ERROR: IORT: Invalid Size of SMMUv1/v2 Nodes. Status = %r\n", + Status + )); + goto error_handler; + } + TableSize += NodeSize; } // SMMUv3 Nodes if (SmmuV3NodeCount > 0) { - SmmuV3Offset = TableSize; + SmmuV3Offset = (UINT32)TableSize; // Size of SMMUv3 node list. - TableSize += GetSizeofSmmuV3Nodes ( - SmmuV3Offset, - SmmuV3NodeList, - SmmuV3NodeCount, - &NodeIndexer - ); + NodeSize = GetSizeofSmmuV3Nodes ( + SmmuV3Offset, + SmmuV3NodeList, + SmmuV3NodeCount, + &NodeIndexer + ); + if (NodeSize > MAX_UINT32) { + Status = EFI_INVALID_PARAMETER; + DEBUG (( + DEBUG_ERROR, + "ERROR: IORT: Invalid Size of SMMUv3 Nodes. Status = %r\n", + Status + )); + goto error_handler; + } + TableSize += NodeSize; } // PMCG Nodes if (PmcgNodeCount > 0) { - PmcgOffset = TableSize; + PmcgOffset = (UINT32)TableSize; // Size of PMCG node list. - TableSize += GetSizeofPmcgNodes ( - PmcgOffset, - PmcgNodeList, - PmcgNodeCount, - &NodeIndexer - ); + NodeSize = GetSizeofPmcgNodes ( + PmcgOffset, + PmcgNodeList, + PmcgNodeCount, + &NodeIndexer + ); + if (NodeSize > MAX_UINT32) { + Status = EFI_INVALID_PARAMETER; + DEBUG (( + DEBUG_ERROR, + "ERROR: IORT: Invalid Size of PMCG Nodes. Status = %r\n", + Status + )); + goto error_handler; + } + TableSize += NodeSize; } DEBUG (( DEBUG_INFO, "INFO: IORT:\n" \ " IortNodeCount = %d\n" \ - " TableSize = %d\n", + " TableSize = 0x%lx\n", IortNodeCount, TableSize )); @@ -1765,6 +1907,18 @@ BuildIortTable ( PmcgOffset )); + if (TableSize > MAX_UINT32) { + Status = EFI_INVALID_PARAMETER; + DEBUG (( + DEBUG_ERROR, + "ERROR: IORT: IORT Table Size 0x%lx > MAX_UINT32," \ + " Status = %r\n", + TableSize, + Status + )); + goto error_handler; + } + // Allocate the Buffer for IORT table *Table = (EFI_ACPI_DESCRIPTION_HEADER*)AllocateZeroPool (TableSize); if (*Table == NULL) { @@ -1783,7 +1937,7 @@ BuildIortTable ( DEBUG (( DEBUG_INFO, - "IORT: Iort = 0x%p TableSize = 0x%x\n", + "IORT: Iort = 0x%p TableSize = 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)'