summaryrefslogtreecommitdiff
path: root/IntelFrameworkModulePkg/Universal/BdsDxe
diff options
context:
space:
mode:
authorydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>2012-05-18 02:13:29 +0000
committerydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>2012-05-18 02:13:29 +0000
commit7ea22852094257713c3d7f31f1c02b0433c2729f (patch)
treea28b68ac4f3c816ff118118c919afcf45c3a8e82 /IntelFrameworkModulePkg/Universal/BdsDxe
parent17aa79bfa7e28a550ea89c96c9caf66394e500e7 (diff)
downloadedk2-platforms-7ea22852094257713c3d7f31f1c02b0433c2729f.tar.xz
Add logic to validate console variables when enter BDS.
Signed-off-by: Eric Dong <eric.dong@intel.com> Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com> git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13322 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'IntelFrameworkModulePkg/Universal/BdsDxe')
-rw-r--r--IntelFrameworkModulePkg/Universal/BdsDxe/BdsEntry.c111
1 files changed, 111 insertions, 0 deletions
diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/BdsEntry.c b/IntelFrameworkModulePkg/Universal/BdsDxe/BdsEntry.c
index 6561efe5a7..e0862aed5e 100644
--- a/IntelFrameworkModulePkg/Universal/BdsDxe/BdsEntry.c
+++ b/IntelFrameworkModulePkg/Universal/BdsDxe/BdsEntry.c
@@ -275,6 +275,112 @@ BdsBootDeviceSelect (
}
/**
+ Validate the device path instance.
+
+ Only base on the length filed in the device path node to validate the device path.
+
+ @param DevicePath A pointer to a device path data structure.
+ @param MaxSize Max valid device path size. If big than this size,
+ return error.
+
+ @retval TRUE An valid device path.
+ @retval FALSE An invalid device path.
+
+**/
+BOOLEAN
+IsValidDevicePath (
+ IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
+ IN UINTN MaxSize
+ )
+{
+ UINTN Size;
+ UINTN NodeSize;
+
+ if (DevicePath == NULL) {
+ return TRUE;
+ }
+
+ Size = 0;
+
+ while (!IsDevicePathEnd (DevicePath)) {
+ NodeSize = DevicePathNodeLength (DevicePath);
+ if (NodeSize < END_DEVICE_PATH_LENGTH) {
+ return FALSE;
+ }
+
+ Size += NodeSize;
+ if (Size > MaxSize) {
+ return FALSE;
+ }
+
+ DevicePath = NextDevicePathNode (DevicePath);
+ }
+
+ Size += DevicePathNodeLength (DevicePath);
+ if (Size > MaxSize) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/**
+
+ Validate input console variable data.
+
+ If found the device path is not a valid device path, remove the variable.
+
+ @param VariableName Input console variable name.
+
+**/
+
+VOID
+BdsFormalizeConsoleVariable (
+ IN CHAR16 *VariableName
+ )
+{
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+ UINTN VariableSize;
+ EFI_STATUS Status;
+
+ DevicePath = BdsLibGetVariableAndSize (
+ VariableName,
+ &gEfiGlobalVariableGuid,
+ &VariableSize
+ );
+ if (!IsValidDevicePath (DevicePath, VariableSize)) {
+ Status = gRT->SetVariable (
+ VariableName,
+ &gEfiGlobalVariableGuid,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+ 0,
+ NULL
+ );
+ ASSERT_EFI_ERROR (Status);
+ }
+}
+
+/**
+
+ Validate variables.
+
+ If found the device path is not a valid device path, remove the variable.
+
+**/
+VOID
+BdsFormalizeEfiGlobalVariable (
+ VOID
+ )
+{
+ //
+ // Validate Console variable.
+ //
+ BdsFormalizeConsoleVariable (L"ConIn");
+ BdsFormalizeConsoleVariable (L"ConOut");
+ BdsFormalizeConsoleVariable (L"ErrOut");
+}
+
+/**
Service routine for BdsInstance->Entry(). Devices are connected, the
consoles are initialized, and the boot options are tried.
@@ -324,6 +430,11 @@ BdsEntry (
gBS->CalculateCrc32 ((VOID *)gST, sizeof(EFI_SYSTEM_TABLE), &gST->Hdr.CRC32);
//
+ // Validate Variable.
+ //
+ BdsFormalizeEfiGlobalVariable();
+
+ //
// Do the platform init, can be customized by OEM/IBV
//
PERF_START (NULL, "PlatformBds", "BDS", 0);