From nobody Fri Apr 26 05:08:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+73900+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=fail(p=none dis=none) header.from=arm.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1617969680679184.8428257741524; Fri, 9 Apr 2021 05:01:20 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 46RNYY1788612xBTNyKHXERP; Fri, 09 Apr 2021 05:01:19 -0700 X-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 X-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 X-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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+73900+1787277+3901457@groups.io; helo=mail02.groups.io; 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; X-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 X-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 X-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 X-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 X-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 X-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; X-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 X-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 X-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: [edk2-devel] [PATCH] DynamicTablesPkg: add validation for PcdNonBsaCompliant16550SerialHid Date: Fri, 9 Apr 2021 13:00:58 +0100 Message-ID: <20210409120058.13313-1-joey.gouly@arm.com> 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 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-Message-Info: yJpIwKE+Z1aOx5AS1eQm60LsmR6Z33gy0IcSdND0UtjHk1S4EurvZNXMonZjVkPmhaI0olQjzj3XcfYDrWg4GC7fH4+99cxxb0uBy6lz4nlOYx8111ZZIBDm4Kf2p6bFv8/3gH+9oFIfr8QPUtMXEmODuX9uauin4/f7N1kaVvTbYv3nDZR60jkiTP6EOAbtl38OFghEjDcK+HRa5iwvEgHEYD7+0TB+veUiCFYBpYH9e4erF3i2XWJxIYZhCz0kFi04cfS5JSVbqDspZilwtWl+9P/jtb4htaoJq97GIq1KqAeDQTRFWVD38kXDx9zxs+yDhIdrbdERvhGux1pDxof8/1aQpzmwuDvnFZxm1aznmNwL5rW9IQ4y0oevLd9nrIKsHWU4yUtBblSIl1nuvSmjPlf2wvYPKB6cVVeIa2cBimjcePfkdxLhrYeXz6QnsF0CFlB5cv27Yps7Oggmgr1jUjfUUl9ZNwbOxn4sm2xgxisMCr6tXdXfta6Hsa56QRvoGarboAqDOIP5EY3V7owwMA0g68/MfkakKRm0mzqjaLBWstDUc52dADkdSU0vewwJ6dnrQvW/GU7gAs51TeyxcGzxCmZeqGdjyRyyn98P73MiuZ9yEy0nSXTiGY2bF0ZOGVAXnusbfwMcEJyNZwf3aiyjsxvRIaro5/j6sXqUYAVk1kLsFqZxnWdZQTJVY1g7la2H60dx9NabqFHD3c5/oiE6a6XdkYaS6HIJLlE= 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 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,joey.gouly@arm.com X-Gm-Message-State: aZRreCBFyK8bhKEinaCppRNAx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1617969679; bh=SlVPO8QUEsVDC28t16YCHHmRRfmWUgjMjttt7kuqxAE=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=tzu9NxV1Czw1/ZvDXaLuE3VbM4c6HdO66M+eB2CCxzBeaGvhcUSmoX5aJbTG4nGWH0l 8U6L9UXUy+3nmVT9gZs6uofFJ3jq9MmYMXvuCwB9W7FmkPUIXR4oGmF+YXA1lTYJPI5HT xNSlFaoIXkQLpHZX17geZHXajrarn7TfUbI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Sami Mujawar --- 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/SsdtSerialPortFixup= Lib.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/DynamicTab= lesPkg/Include/Library/TableHelperLib.h index 099a0a4544e3d1f746d4be8533cb006786f11611..0f93cdbf08953af2377952ef616= f760a51706170 100644 --- a/DynamicTablesPkg/Include/Library/TableHelperLib.h +++ b/DynamicTablesPkg/Include/Library/TableHelperLib.h @@ -1,6 +1,6 @@ /** @file =20 - Copyright (c) 2017 - 2020, Arm Limited. All rights reserved.
+ Copyright (c) 2017 - 2021, Arm Limited. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -12,6 +12,18 @@ #ifndef TABLE_HELPER_LIB_H_ #define TABLE_HELPER_LIB_H_ =20 +/** Is a character upper case +*/ +#define IS_UPPER_CHAR(x) ((x >=3D 'A') && (x <=3D 'Z')) + +/** Is a character a decimal digit +*/ +#define IS_DIGIT(x) ((x >=3D '0') && (x <=3D '9')) + +/** Is a character an upper case hexadecimal digit +*/ +#define IS_UPPER_HEX(x) (((x >=3D 'A') && (x <=3D 'F')) || IS_DIGIT (x)) + /** The GetCgfMgrInfo function gets the CM_STD_OBJ_CONFIGURATION_MANAGER_I= NFO object from the Configuration Manager. =20 @@ -120,4 +132,28 @@ AsciiFromHex ( IN UINT8 x ); =20 +/** 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/SsdtSer= ialPortFixupLib.c b/DynamicTablesPkg/Library/Common/SsdtSerialPortFixupLib/= SsdtSerialPortFixupLib.c index 3c4356097c3bf25e8d1432b45ba8ca59d33e8d09..f2b4831ad596284476fb342148d= 9c1f62bc7f98b 100644 --- a/DynamicTablesPkg/Library/Common/SsdtSerialPortFixupLib/SsdtSerialPort= FixupLib.c +++ b/DynamicTablesPkg/Library/Common/SsdtSerialPortFixupLib/SsdtSerialPort= FixupLib.c @@ -148,6 +148,10 @@ FixupIds ( // If there is a non-BSA compliant HID, use that. NonBsaHid =3D (CONST CHAR8*)PcdGetPtr (PcdNonBsaCompliant16550Serial= Hid); if ((NonBsaHid !=3D NULL) && (AsciiStrLen (NonBsaHid) !=3D 0)) { + if (!(IsValidPnpId (NonBsaHid) || IsValidAcpiId (NonBsaHid))) { + return EFI_INVALID_PARAMETER; + } + HidString =3D NonBsaHid; CidString =3D ""; } else { diff --git a/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelper.c b= /DynamicTablesPkg/Library/Common/TableHelperLib/TableHelper.c index 0d9daad3b05b6e82089f92afb6de4eeee5af9a28..9830ce62b3cb94be6d861a09d8d= 8356d60fdfbba 100644 --- a/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelper.c +++ b/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelper.c @@ -1,7 +1,7 @@ /** @file Table Helper =20 - Copyright (c) 2017 - 2020, Arm Limited. All rights reserved.
+ Copyright (c) 2017 - 2021, Arm Limited. All rights reserved.
=20 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) !=3D 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 =3D 0; Index < 3; Index++) { + if (!IS_UPPER_CHAR (Hid[Index])) { + return FALSE; + } + } + + for (Index =3D 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) !=3D 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 =3D 0; Index < 4; Index++) { + if (!(IS_UPPER_CHAR (Hid[Index]) || IS_DIGIT (Hid[Index]))) { + return FALSE; + } + } + + for (Index =3D 4; Index < 8; Index++) { + if (!IS_UPPER_HEX (Hid[Index])) { + return FALSE; + } + } + + return TRUE; +} --=20 Guid("CE165669-3EF3-493F-B85D-6190EE5B9759") -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#73900): https://edk2.groups.io/g/devel/message/73900 Mute This Topic: https://groups.io/mt/81966375/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-