* [PATCH] DynamicTablesPkg: add validation for PcdNonBsaCompliant16550SerialHid
@ 2021-04-09 12:00 Joey Gouly
2021-04-12 10:01 ` [edk2-devel] " Sami Mujawar
0 siblings, 1 reply; 4+ messages in thread
From: Joey Gouly @ 2021-04-09 12:00 UTC (permalink / raw)
To: devel; +Cc: joey.gouly, alexei.fedorov, sami.mujawar, samer.el-haj-mahmoud,
nd
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 <joey.goulyd@arm.com>
---
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.<BR>
+ Copyright (c) 2017 - 2021, Arm Limited. All rights reserved.<BR>
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.<BR>
+ Copyright (c) 2017 - 2021, Arm Limited. All rights reserved.<BR>
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")
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [edk2-devel] [PATCH] DynamicTablesPkg: add validation for PcdNonBsaCompliant16550SerialHid
2021-04-09 12:00 [PATCH] DynamicTablesPkg: add validation for PcdNonBsaCompliant16550SerialHid Joey Gouly
@ 2021-04-12 10:01 ` Sami Mujawar
2021-04-13 9:28 ` Joey Gouly
0 siblings, 1 reply; 4+ messages in thread
From: Sami Mujawar @ 2021-04-12 10:01 UTC (permalink / raw)
To: Joey Gouly, devel
[-- Attachment #1: Type: text/plain, Size: 191 bytes --]
Hi Joey,
Can you confirm that your sign-off ID is correct, please?
Otherwise this patch looks good to me.
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
Regards,
Sami Mujawar
[-- Attachment #2: Type: text/html, Size: 233 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [edk2-devel] [PATCH] DynamicTablesPkg: add validation for PcdNonBsaCompliant16550SerialHid
2021-04-12 10:01 ` [edk2-devel] " Sami Mujawar
@ 2021-04-13 9:28 ` Joey Gouly
2021-04-13 10:39 ` Sami Mujawar
0 siblings, 1 reply; 4+ messages in thread
From: Joey Gouly @ 2021-04-13 9:28 UTC (permalink / raw)
To: devel@edk2.groups.io, Sami Mujawar; +Cc: nd
> Hi Joey,
>
> Can you confirm that your sign-off ID is correct, please?
> Otherwise this patch looks good to me.
That was silly to typo my own name!
Signed-off-by: Joey Gouly <joey.gouly@arm.com>
Thanks for the review!
Joey
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [edk2-devel] [PATCH] DynamicTablesPkg: add validation for PcdNonBsaCompliant16550SerialHid
2021-04-13 9:28 ` Joey Gouly
@ 2021-04-13 10:39 ` Sami Mujawar
0 siblings, 0 replies; 4+ messages in thread
From: Sami Mujawar @ 2021-04-13 10:39 UTC (permalink / raw)
To: Joey Gouly, devel@edk2.groups.io; +Cc: nd
Pushed as 54211ab10fcd..16136f218d54
Thanks.
Regards,
Sami Mujawar
On 13/04/2021, 10:28, "Joey Gouly" <Joey.Gouly@arm.com> wrote:
> Hi Joey,
>
> Can you confirm that your sign-off ID is correct, please?
> Otherwise this patch looks good to me.
That was silly to typo my own name!
Signed-off-by: Joey Gouly <joey.gouly@arm.com>
Thanks for the review!
Joey
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-04-13 10:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-09 12:00 [PATCH] DynamicTablesPkg: add validation for PcdNonBsaCompliant16550SerialHid Joey Gouly
2021-04-12 10:01 ` [edk2-devel] " Sami Mujawar
2021-04-13 9:28 ` Joey Gouly
2021-04-13 10:39 ` Sami Mujawar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox