]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg: Check invalid RegisterCpuFeature parameter
authorSong, BinX <binx.song@intel.com>
Wed, 13 Dec 2017 02:35:15 +0000 (10:35 +0800)
committerEric Dong <eric.dong@intel.com>
Wed, 13 Dec 2017 08:40:25 +0000 (16:40 +0800)
V2:
Update function name, add more detail description.
V1:
Check and assert invalid RegisterCpuFeature function parameter

Cc: Eric Dong <eric.dong@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Bell Song <binx.song@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
UefiCpuPkg/Include/Library/RegisterCpuFeaturesLib.h
UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c

index 9331e49d13ed7f77c61f1e87b90fb74f3570c585..fc3ccda1ba7893eda1718135dfe4083e7532e273 100644 (file)
 #define CPU_FEATURE_APIC_TPR_UPDATE_MESSAGE         (32+9)\r
 #define CPU_FEATURE_ENERGY_PERFORMANCE_BIAS         (32+10)\r
 #define CPU_FEATURE_PPIN                            (32+11)\r
+//\r
+// Currently, CPU_FEATURE_PROC_TRACE is the MAX feature we support.\r
+// If you define a feature bigger than it, please also replace it\r
+// in RegisterCpuFeatureLibIsFeatureValid function.\r
+//\r
 #define CPU_FEATURE_PROC_TRACE                      (32+12)\r
 \r
 #define CPU_FEATURE_BEFORE_ALL                      BIT27\r
index dd6a82be7a5a1c2a2cf1c2e1b0475c496adcc8e6..6ec26e1e92a1de0c220add8fcd627ede4e4bb5f9 100644 (file)
@@ -80,6 +80,34 @@ DumpCpuFeature (
   }\r
 }\r
 \r
+/**\r
+  Determines if the CPU feature is valid.\r
+\r
+  @param[in]  Feature        Pointer to CPU feature\r
+\r
+  @retval TRUE  The CPU feature is valid.\r
+  @retval FALSE The CPU feature is invalid.\r
+**/\r
+BOOLEAN\r
+RegisterCpuFeatureLibIsFeatureValid (\r
+  IN UINT32        Feature\r
+  )\r
+{\r
+  UINT32      Data;\r
+\r
+  Data = Feature;\r
+  Data &= ~(CPU_FEATURE_BEFORE | CPU_FEATURE_AFTER | CPU_FEATURE_BEFORE_ALL | CPU_FEATURE_AFTER_ALL);\r
+  //\r
+  // Currently, CPU_FEATURE_PROC_TRACE is the MAX feature we support.\r
+  // If you define a feature bigger than it, please replace it at below.\r
+  //\r
+  if (Data > CPU_FEATURE_PROC_TRACE) {\r
+    DEBUG ((DEBUG_ERROR, "Invalid CPU feature: 0x%x ", Feature));\r
+    return FALSE;\r
+  }\r
+  return TRUE;\r
+}\r
+\r
 /**\r
   Determines if the feature bit mask is in dependent CPU feature bit mask buffer.\r
 \r
@@ -444,6 +472,7 @@ RegisterCpuFeature (
 \r
   VA_START (Marker, InitializeFunc);\r
   Feature = VA_ARG (Marker, UINT32);\r
+  ASSERT (RegisterCpuFeatureLibIsFeatureValid(Feature));\r
   while (Feature != CPU_FEATURE_END) {\r
     ASSERT ((Feature & (CPU_FEATURE_BEFORE | CPU_FEATURE_AFTER))\r
                     != (CPU_FEATURE_BEFORE | CPU_FEATURE_AFTER));\r