]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add check to make sure the data be valid.
authorGao, Liming <liming.gao@intel.com>
Wed, 26 Mar 2014 09:27:01 +0000 (09:27 +0000)
committerlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 26 Mar 2014 09:27:01 +0000 (09:27 +0000)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Gao, Liming <liming.gao@intel.com>
Reviewed-by: Zeng, Star <star.zeng@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15393 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideDxe.c
MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideLib.c

index ab254a0b450e1eb4d558c427ff7a0bafdf4fcdba..3c55a785fca4827c16e5b8abe9adb955fb5b4501 100644 (file)
@@ -13,7 +13,7 @@
   4. It save all the mapping info in NV variables which will be consumed\r
      by platform override protocol driver to publish the platform override protocol.\r
 \r
-Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -1240,6 +1240,7 @@ PlatOverMngrRouteConfig (
   EFI_CALLBACK_INFO                         *Private;\r
   UINT16                                    KeyValue;\r
   PLAT_OVER_MNGR_DATA                       *FakeNvData;\r
+  EFI_STATUS                                Status;\r
 \r
   if (Configuration == NULL || Progress == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -1260,11 +1261,12 @@ PlatOverMngrRouteConfig (
     return EFI_SUCCESS;\r
   }\r
 \r
+  Status = EFI_SUCCESS;\r
   if (mCurrentPage == FORM_ID_DRIVER) {\r
     KeyValue = KEY_VALUE_DRIVER_GOTO_ORDER;\r
     UpdatePrioritySelectPage (Private, KeyValue, FakeNvData);\r
     KeyValue = KEY_VALUE_ORDER_SAVE_AND_EXIT;\r
-    CommintChanges (Private, KeyValue, FakeNvData);\r
+    Status = CommintChanges (Private, KeyValue, FakeNvData);\r
     //\r
     // Since UpdatePrioritySelectPage will change mCurrentPage,\r
     // should ensure the mCurrentPage still indicate the second page here\r
@@ -1274,10 +1276,10 @@ PlatOverMngrRouteConfig (
 \r
   if (mCurrentPage == FORM_ID_ORDER) {\r
     KeyValue = KEY_VALUE_ORDER_SAVE_AND_EXIT;\r
-    CommintChanges (Private, KeyValue, FakeNvData);\r
+    Status = CommintChanges (Private, KeyValue, FakeNvData);\r
   }\r
 \r
-  return EFI_SUCCESS;\r
+  return Status;\r
 }\r
 \r
 /**\r
index 2391ade211d242a0cb5cb54aa2b0af561fea9b96..d07f62ab4ac0914a84ec0c3dfdc5b425eb794b4c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Implementation of the shared functions to do the platform driver vverride mapping.\r
 \r
-  Copyright (c) 2007 - 2009, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -691,12 +691,17 @@ InitOverridesMapping (
   //\r
   VariableNum = 1;\r
   Corrupted = FALSE;\r
+  NotEnd = 0;\r
   do {\r
     VariableIndex = VariableBuffer;\r
-    //\r
-    // End flag\r
-    //\r
-    NotEnd = *(UINT32*) VariableIndex;\r
+    if (VariableIndex + sizeof (UINT32) > (UINT8 *) VariableBuffer + BufferSize) {\r
+      Corrupted = TRUE;\r
+    } else {\r
+      //\r
+      // End flag\r
+      //\r
+      NotEnd = *(UINT32*) VariableIndex;\r
+    }\r
     //\r
     // Traverse the entries containing the mapping that Controller Device Path\r
     // to a set of Driver Device Paths within this variable.\r
@@ -706,6 +711,10 @@ InitOverridesMapping (
       //\r
       // Check signature of this entry\r
       //\r
+      if (VariableIndex + sizeof (UINT32) > (UINT8 *) VariableBuffer + BufferSize) {\r
+        Corrupted = TRUE;\r
+        break;\r
+      }\r
       Signature = *(UINT32 *) VariableIndex;\r
       if (Signature != PLATFORM_OVERRIDE_ITEM_SIGNATURE) {\r
         Corrupted = TRUE;\r
@@ -722,6 +731,10 @@ InitOverridesMapping (
       //\r
       // Get DriverNum\r
       //\r
+      if (VariableIndex + sizeof (UINT32) >= (UINT8 *) VariableBuffer + BufferSize) {\r
+        Corrupted = TRUE;\r
+        break;\r
+      }\r
       DriverNumber = *(UINT32*) VariableIndex;\r
       OverrideItem->DriverInfoNum = DriverNumber;\r
       VariableIndex = VariableIndex + sizeof (UINT32);\r
@@ -735,6 +748,14 @@ InitOverridesMapping (
       // Align the VariableIndex since the controller device path may not be aligned, refer to the SaveOverridesMapping()\r
       //\r
       VariableIndex += ((sizeof(UINT32) - ((UINTN) (VariableIndex))) & (sizeof(UINT32) - 1));\r
+      //\r
+      // Check buffer overflow.\r
+      //\r
+      if ((OverrideItem->ControllerDevicePath == NULL) || (VariableIndex < (UINT8 *) ControllerDevicePath) || \r
+          (VariableIndex > (UINT8 *) VariableBuffer + BufferSize)) {\r
+        Corrupted = TRUE;\r
+        break;\r
+      }\r
 \r
       //\r
       // Get all DriverImageDevicePath[]\r
@@ -756,8 +777,20 @@ InitOverridesMapping (
         VariableIndex += ((sizeof(UINT32) - ((UINTN) (VariableIndex))) & (sizeof(UINT32) - 1));\r
 \r
         InsertTailList (&OverrideItem->DriverInfoList, &DriverImageInfo->Link);\r
+\r
+        //\r
+        // Check buffer overflow\r
+        //\r
+        if ((DriverImageInfo->DriverImagePath == NULL) || (VariableIndex < (UINT8 *) DriverDevicePath) || \r
+            (VariableIndex < (UINT8 *) VariableBuffer + BufferSize)) {\r
+          Corrupted = TRUE;\r
+          break;\r
+        }\r
       }\r
       InsertTailList (MappingDataBase, &OverrideItem->Link);\r
+      if (Corrupted) {\r
+        break;\r
+      }\r
     }\r
 \r
     FreePool (VariableBuffer);\r
@@ -866,11 +899,11 @@ DeleteOverridesVariables (
   //\r
   // Check NotEnd to get all PlatDriOverX variable(s)\r
   //\r
-  while ((*(UINT32*)VariableBuffer) != 0) {\r
+  while ((VariableBuffer != NULL) && ((*(UINT32*)VariableBuffer) != 0)) {\r
+    FreePool (VariableBuffer);\r
     UnicodeSPrint (OverrideVariableName, sizeof (OverrideVariableName), L"PlatDriOver%d", VariableNum);\r
     VariableBuffer = GetVariableAndSize (OverrideVariableName, &gEfiCallerIdGuid, &BufferSize);\r
     VariableNum++;\r
-    ASSERT (VariableBuffer != NULL);\r
   }\r
 \r
   //\r
@@ -1057,10 +1090,19 @@ SaveOverridesMapping (
                     VariableNeededSize,\r
                     VariableBuffer\r
                     );\r
-    ASSERT (!EFI_ERROR(Status));\r
+    FreePool (VariableBuffer);\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      if (NumIndex > 0) {\r
+        //\r
+        // Delete all PlatDriOver variables when full mapping can't be set.  \r
+        //\r
+        DeleteOverridesVariables ();\r
+      }\r
+      return Status;\r
+    }\r
 \r
     NumIndex ++;\r
-    FreePool (VariableBuffer);\r
   }\r
 \r
   return EFI_SUCCESS;\r