From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (EUR05-VI1-obe.outbound.protection.outlook.com [40.107.21.51]) by mx.groups.io with SMTP id smtpd.web10.7980.1617969671733773705 for ; Fri, 09 Apr 2021 05:01:12 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=ubtPM/He; spf=pass (domain: arm.com, ip: 40.107.21.51, mailfrom: joey.gouly@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=Ch3fULiG588WjCNunA7chUflJJlorndik+kevZFDjmY=; b=ubtPM/HekkONcf8LY2BN/nSJYDW42wHQGeLGadlN0X3g092W7x2H8RR9kMMxaedbimJS7eenVMY1wAGZJdf2HWni93n5i4WheVl5Jr7O8Hbdz7s6a7+wu3779oWdEcCbusYYWN75fjeyoKgQ0qhKg1UXZyfXAOLvo7Usx+3bGAU= Received: from AS8PR04CA0063.eurprd04.prod.outlook.com (2603:10a6:20b:313::8) by AM9PR08MB6050.eurprd08.prod.outlook.com (2603:10a6:20b:285::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.18; Fri, 9 Apr 2021 12:01:09 +0000 Received: from VE1EUR03FT031.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:313:cafe::f2) by AS8PR04CA0063.outlook.office365.com (2603:10a6:20b:313::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Fri, 9 Apr 2021 12:01:09 +0000 X-MS-Exchange-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=pass 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 VE1EUR03FT031.mail.protection.outlook.com (10.152.18.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Fri, 9 Apr 2021 12:01:08 +0000 Received: ("Tessian outbound 81a4524e9a48:v90"); Fri, 09 Apr 2021 12:01:08 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: fb5ab46ed438510d X-CR-MTA-TID: 64aa7808 Received: from c5bd8c1ca3e5.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id EA1F15B2-1948-4550-823A-BCC2507E9667.1; Fri, 09 Apr 2021 12:01:00 +0000 Received: from EUR03-DB5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id c5bd8c1ca3e5.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 09 Apr 2021 12:01:00 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S7XrBIGMsiPcu8TGc76BjgLJ0Qp4WTJX+HG6//eDNpoH6c+bS41BmXoJoLFDBn9ejsKUxg8JPAMHUDAr6LkayUD/7JlYrlwAahFzYFjx3GvM6UUqZq3JtGgRLXE/91WpUl7GPtqjddod/eeHvbsUvIetoPIkrV4KrmU50UUe2uslJGe+ObOwVjxZMYYWihcfF+LzLd5QXX6uDbYLZxK3nA6XVolGDG5o4JobPHQLtOp29MM/8yEdVaiTpwTcySbLrMFKD2XlzuxvrrvYIB+XrqQQurTdvqMHh5+gQwP7o4oG+i103jljnFB0wsUlyFer/JzaqfjYPfXIjMIuBTcaJQ== 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=Ch3fULiG588WjCNunA7chUflJJlorndik+kevZFDjmY=; b=Ako2EMbLthIoKBoV3/umIjp4+5txtJ4bo2T7U49bn+viHUVbF8uHjIO1IqQgoSr0Tmf2Q8He2ggL9rRjBT4O6Pe6KIT20wuAq060Rryur+ATvhyY/c/3FsHZ4a2Da8kyBjeRXAqcmMBknxzWAlvtfqwSuKlI7UqeCVmK1N/4QR5QnZiVn+9Z5QcDRJPT7JSjW1MOELI51HjFqz7Sa1C0jli7dL6a7ihjX70Td6vToclXMFfw98dFdIPPkikJGCM0hhqw7/i8fGpii6hTNTe9zH3+a9Smec6nGaRXgl8fSaPp1dJBev13Nb6MYFISjpXNfgqWTVPYg1AJQKIEaFPuxQ== 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=pass (p=none sp=none pct=100) 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=Ch3fULiG588WjCNunA7chUflJJlorndik+kevZFDjmY=; b=ubtPM/HekkONcf8LY2BN/nSJYDW42wHQGeLGadlN0X3g092W7x2H8RR9kMMxaedbimJS7eenVMY1wAGZJdf2HWni93n5i4WheVl5Jr7O8Hbdz7s6a7+wu3779oWdEcCbusYYWN75fjeyoKgQ0qhKg1UXZyfXAOLvo7Usx+3bGAU= Received: from MR2P264CA0074.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:32::14) by AS8PR08MB6568.eurprd08.prod.outlook.com (2603:10a6:20b:338::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.18; Fri, 9 Apr 2021 12:01:00 +0000 Received: from VE1EUR03FT011.eop-EUR03.prod.protection.outlook.com (2603:10a6:500:32:cafe::f0) by MR2P264CA0074.outlook.office365.com (2603:10a6:500:32::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Fri, 9 Apr 2021 12:01:00 +0000 X-MS-Exchange-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=pass 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 VE1EUR03FT011.mail.protection.outlook.com (10.152.18.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4020.17 via Frontend Transport; Fri, 9 Apr 2021 12:00:59 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) 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.2176.2; Fri, 9 Apr 2021 12:00:58 +0000 Received: from e124191.cambridge.arm.com (10.11.7.12) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2176.2 via Frontend Transport; Fri, 9 Apr 2021 12:00:58 +0000 From: "Joey Gouly" To: CC: , , , , Subject: [PATCH] DynamicTablesPkg: add validation for PcdNonBsaCompliant16550SerialHid Date: Fri, 9 Apr 2021 13:00:58 +0100 Message-ID: <20210409120058.13313-1-joey.gouly@arm.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2f8e2453-7cb0-4477-1435-08d8fb4f2980 X-MS-TrafficTypeDiagnostic: AS8PR08MB6568:|AM9PR08MB6050: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:9508;OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: ROBYQzK9gto7T3fWAIQHvt7BxRDKe2q73lAqZUo6U/kK/Bwjfwz4rQG1ny0FeP9EqY/S+ckDgkVx8HDLlJht0VfnNzhIlo9jK54rX23pJ1MY5wBw3oWh13MDdZqoNcpsxoF755L2vTcKFazpq4JyGEOsbXzbanxKug5zqxI/mbRE+IsHjg7wOv0MnmrHT7Xdxrwmx6FCO0I+IkLfKTWQzHHgkb9K5PYd1OYtLgkn2250vyUGBYr/OZkmfASvrqiDrdsNB2eHwWdOEk8B4NNK/Lx2K0BeRQt9nqNo3iEjkUKbWHPMgb61dBTMmF6QgDkHPhiyx/mnKympfNIyJdr5uaCF/4TwfbD3orl2vHk6SYMaeNV0+bSNBo4Hp+GQ6C1mKsOshJczBBbtypsDYqz2o5BJRe+PaMKMJCZNOKsfPcEW7F5zC4V8HvvWZt7LIneQGGlVRMFDHExxzbgj9UgTnqaVS/pEKIJdvZukYPZZw9dSi77rIHnD3Lm7dDW3S8QBJUSH6O55Rx9n26NTcSDgaV2wsbvqHe6zLMH1/C31Gc/TCWqHuZtSn1c8hp9NIlo9PTWE2N8GPUCD3nL25qBoivpngl6V1vHH1z998i5YAIJbzj1i7C0pwjGjiH/FDi/fDy6lfAJ+DFQqlbM8eZ/DuOKz7Nf3J3SfCsKw/+PdUz2Qx7nmAiak9XHGyh8ZVKk7Ievsy9TikhvV8N/5LS+FBwD2rcg4jJBH9V6J/U0Lt0SjiyahuCCSld7b3wwJJPgfE9z6Gqdw50wt6//tH+e/2w== X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:nebula.arm.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(346002)(376002)(136003)(39860400002)(396003)(46966006)(36840700001)(70206006)(70586007)(81166007)(356005)(83380400001)(4326008)(82740400003)(36860700001)(478600001)(36756003)(44832011)(86362001)(47076005)(82310400003)(2616005)(54906003)(336012)(426003)(2906002)(8676002)(186003)(5660300002)(7696005)(966005)(6916009)(8936002)(316002)(1076003)(26005)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6568 Return-Path: Joey.Gouly@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT031.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: de45614b-2f89-4e6d-17b5-08d8fb4f23fc X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yJpIwKE+Z1aOx5AS1eQm60LsmR6Z33gy0IcSdND0UtjHk1S4EurvZNXMonZjVkPmhaI0olQjzj3XcfYDrWg4GC7fH4+99cxxb0uBy6lz4nlOYx8111ZZIBDm4Kf2p6bFv8/3gH+9oFIfr8QPUtMXEmODuX9uauin4/f7N1kaVvTbYv3nDZR60jkiTP6EOAbtl38OFghEjDcK+HRa5iwvEgHEYD7+0TB+veUiCFYBpYH9e4erF3i2XWJxIYZhCz0kFi04cfS5JSVbqDspZilwtWl+9P/jtb4htaoJq97GIq1KqAeDQTRFWVD38kXDx9zxs+yDhIdrbdERvhGux1pDxof8/1aQpzmwuDvnFZxm1aznmNwL5rW9IQ4y0oevLd9nrIKsHWU4yUtBblSIl1nuvSmjPlf2wvYPKB6cVVeIa2cBimjcePfkdxLhrYeXz6QnsF0CFlB5cv27Yps7Oggmgr1jUjfUUl9ZNwbOxn4sm2xgxisMCr6tXdXfta6Hsa56QRvoGarboAqDOIP5EY3V7owwMA0g68/MfkakKRm0mzqjaLBWstDUc52dADkdSU0vewwJ6dnrQvW/GU7gAs51TeyxcGzxCmZeqGdjyRyyn98P73MiuZ9yEy0nSXTiGY2bF0ZOGVAXnusbfwMcEJyNZwf3aiyjsxvRIaro5/j6sXqUYAVk1kLsFqZxnWdZQTJVY1g7la2H60dx9NabqFHD3c5/oiE6a6XdkYaS6HIJLlE= X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(4636009)(346002)(136003)(39860400002)(376002)(396003)(36840700001)(46966006)(6916009)(5660300002)(36756003)(316002)(426003)(336012)(8676002)(1076003)(7696005)(2906002)(82310400003)(54906003)(2616005)(44832011)(36860700001)(70586007)(83380400001)(47076005)(966005)(478600001)(70206006)(4326008)(81166007)(186003)(26005)(8936002)(86362001)(82740400003);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Apr 2021 12:01:08.8883 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2f8e2453-7cb0-4477-1435-08d8fb4f2980 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-AuthSource: VE1EUR03FT031.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR08MB6050 Content-Type: text/plain According to ACPI 6.4, 6.1.5 _HID states: - A valid PNP ID must be of the form "AAA####" where A is an uppercase letter and # is a hex digit. - A valid ACPI ID must be of the form "NNNN####" where N is an uppercase letter or a digit ('0'-'9') and # is a hex digit. Signed-off-by: Joey Gouly --- The changes can be seen at https://github.com/jgouly/edk2/tree/1645_non_sba_compliant_validation_v1 DynamicTablesPkg/Include/Library/TableHelperLib.h | 38 +++++++++- DynamicTablesPkg/Library/Common/SsdtSerialPortFixupLib/SsdtSerialPortFixupLib.c | 4 ++ DynamicTablesPkg/Library/Common/TableHelperLib/TableHelper.c | 73 +++++++++++++++++++- 3 files changed, 113 insertions(+), 2 deletions(-) diff --git a/DynamicTablesPkg/Include/Library/TableHelperLib.h b/DynamicTablesPkg/Include/Library/TableHelperLib.h index 099a0a4544e3d1f746d4be8533cb006786f11611..0f93cdbf08953af2377952ef616f760a51706170 100644 --- a/DynamicTablesPkg/Include/Library/TableHelperLib.h +++ b/DynamicTablesPkg/Include/Library/TableHelperLib.h @@ -1,6 +1,6 @@ /** @file - Copyright (c) 2017 - 2020, Arm Limited. All rights reserved.
+ Copyright (c) 2017 - 2021, Arm Limited. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent @@ -12,6 +12,18 @@ #ifndef TABLE_HELPER_LIB_H_ #define TABLE_HELPER_LIB_H_ +/** Is a character upper case +*/ +#define IS_UPPER_CHAR(x) ((x >= 'A') && (x <= 'Z')) + +/** Is a character a decimal digit +*/ +#define IS_DIGIT(x) ((x >= '0') && (x <= '9')) + +/** Is a character an upper case hexadecimal digit +*/ +#define IS_UPPER_HEX(x) (((x >= 'A') && (x <= 'F')) || IS_DIGIT (x)) + /** The GetCgfMgrInfo function gets the CM_STD_OBJ_CONFIGURATION_MANAGER_INFO object from the Configuration Manager. @@ -120,4 +132,28 @@ AsciiFromHex ( IN UINT8 x ); +/** Check if a HID is a valid PNP ID. + + @param [in] Hid The Hid to validate. + + @retval TRUE The Hid is a valid PNP ID. + @retval FALSE The Hid is not a valid PNP ID. +**/ +BOOLEAN +IsValidPnpId ( + IN CONST CHAR8 * Hid + ); + +/** Check if a HID is a valid ACPI ID. + + @param [in] Hid The Hid to validate. + + @retval TRUE The Hid is a valid ACPI ID. + @retval FALSE The Hid is not a valid ACPI ID. +**/ +BOOLEAN +IsValidAcpiId ( + IN CONST CHAR8 * Hid + ); + #endif // TABLE_HELPER_LIB_H_ diff --git a/DynamicTablesPkg/Library/Common/SsdtSerialPortFixupLib/SsdtSerialPortFixupLib.c b/DynamicTablesPkg/Library/Common/SsdtSerialPortFixupLib/SsdtSerialPortFixupLib.c index 3c4356097c3bf25e8d1432b45ba8ca59d33e8d09..f2b4831ad596284476fb342148d9c1f62bc7f98b 100644 --- a/DynamicTablesPkg/Library/Common/SsdtSerialPortFixupLib/SsdtSerialPortFixupLib.c +++ b/DynamicTablesPkg/Library/Common/SsdtSerialPortFixupLib/SsdtSerialPortFixupLib.c @@ -148,6 +148,10 @@ FixupIds ( // If there is a non-BSA compliant HID, use that. NonBsaHid = (CONST CHAR8*)PcdGetPtr (PcdNonBsaCompliant16550SerialHid); if ((NonBsaHid != NULL) && (AsciiStrLen (NonBsaHid) != 0)) { + if (!(IsValidPnpId (NonBsaHid) || IsValidAcpiId (NonBsaHid))) { + return EFI_INVALID_PARAMETER; + } + HidString = NonBsaHid; CidString = ""; } else { diff --git a/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelper.c b/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelper.c index 0d9daad3b05b6e82089f92afb6de4eeee5af9a28..9830ce62b3cb94be6d861a09d8d8356d60fdfbba 100644 --- a/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelper.c +++ b/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelper.c @@ -1,7 +1,7 @@ /** @file Table Helper - Copyright (c) 2017 - 2020, Arm Limited. All rights reserved.
+ Copyright (c) 2017 - 2021, Arm Limited. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -270,3 +270,74 @@ AsciiFromHex ( ASSERT (FALSE); return (UINT8)0; } + +/** Check if a HID is a valid PNP ID. + + @param [in] Hid The Hid to validate. + + @retval TRUE The Hid is a valid PNP ID. + @retval FALSE The Hid is not a valid PNP ID. +**/ +BOOLEAN +IsValidPnpId ( + IN CONST CHAR8 * Hid + ) +{ + UINTN Index; + + if (AsciiStrLen (Hid) != 7) { + return FALSE; + } + + // A valid PNP ID must be of the form "AAA####" + // where A is an uppercase letter and # is a hex digit. + for (Index = 0; Index < 3; Index++) { + if (!IS_UPPER_CHAR (Hid[Index])) { + return FALSE; + } + } + + for (Index = 3; Index < 7; Index++) { + if (!IS_UPPER_HEX (Hid[Index])) { + return FALSE; + } + } + + return TRUE; +} + +/** Check if a HID is a valid ACPI ID. + + @param [in] Hid The Hid to validate. + + @retval TRUE The Hid is a valid ACPI ID. + @retval FALSE The Hid is not a valid ACPI ID. +**/ +BOOLEAN +IsValidAcpiId ( + IN CONST CHAR8 * Hid + ) +{ + UINTN Index; + + if (AsciiStrLen (Hid) != 8) { + return FALSE; + } + + // A valid ACPI ID must be of the form "NNNN####" + // where N is an uppercase letter or a digit ('0'-'9') + // and # is a hex digit. + for (Index = 0; Index < 4; Index++) { + if (!(IS_UPPER_CHAR (Hid[Index]) || IS_DIGIT (Hid[Index]))) { + return FALSE; + } + } + + for (Index = 4; Index < 8; Index++) { + if (!IS_UPPER_HEX (Hid[Index])) { + return FALSE; + } + } + + return TRUE; +} -- Guid("CE165669-3EF3-493F-B85D-6190EE5B9759")