]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.c
MdeModulePkg: SecurityManagementLib to handle LoadFile DevicePath
[mirror_edk2.git] / MdeModulePkg / Library / DxeSecurityManagementLib / DxeSecurityManagementLib.c
index 6a50937adea560edbf999922408537e5b6e86fd9..b96d78664d772af269a2e00d4044009a9ab3cde1 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Provides generic security measurement functions for DXE module.\r
 \r
-Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 2015, 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
@@ -13,10 +13,13 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/\r
 \r
 #include <PiDxe.h>\r
+#include <Protocol/LoadFile.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/DxeServicesLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/SecurityManagementLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
 \r
 #define SECURITY_HANDLER_TABLE_SIZE   0x10\r
 \r
@@ -219,6 +222,9 @@ ExecuteSecurityHandlers (
   UINT32        HandlerAuthenticationStatus;\r
   VOID          *FileBuffer;\r
   UINTN         FileSize;\r
+  EFI_HANDLE    Handle;\r
+  EFI_DEVICE_PATH_PROTOCOL        *Node;\r
+  EFI_DEVICE_PATH_PROTOCOL        *FilePathToVerfiy;\r
   \r
   if (FilePath == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -235,6 +241,7 @@ ExecuteSecurityHandlers (
   FileBuffer                  = NULL;\r
   FileSize                    = 0;\r
   HandlerAuthenticationStatus = AuthenticationStatus;\r
+  FilePathToVerfiy            = (EFI_DEVICE_PATH_PROTOCOL *) FilePath;\r
   //\r
   // Run security handler in same order to their registered list\r
   //\r
@@ -244,6 +251,8 @@ ExecuteSecurityHandlers (
       // Try get file buffer when the handler requires image buffer.\r
       //\r
       if (FileBuffer == NULL) {\r
+        Node   = FilePathToVerfiy;\r
+        Status = gBS->LocateDevicePath (&gEfiLoadFileProtocolGuid, &Node, &Handle);\r
         //\r
         // Try to get image by FALSE boot policy for the exact boot file path.\r
         //\r
@@ -254,11 +263,17 @@ ExecuteSecurityHandlers (
           //\r
           FileBuffer = GetFileBufferByFilePath (TRUE, FilePath, &FileSize, &AuthenticationStatus);\r
         }\r
+        if ((FileBuffer != NULL) && (!EFI_ERROR (Status))) {\r
+          //\r
+          // LoadFile () may cause the device path of the Handle be updated.\r
+          //\r
+          FilePathToVerfiy = AppendDevicePath (DevicePathFromHandle (Handle), Node);\r
+        }\r
       }\r
     }\r
     Status = mSecurityTable[Index].SecurityHandler (\r
                HandlerAuthenticationStatus,\r
-               FilePath,\r
+               FilePathToVerfiy,\r
                FileBuffer,\r
                FileSize\r
                );\r
@@ -270,6 +285,9 @@ ExecuteSecurityHandlers (
   if (FileBuffer != NULL) {\r
     FreePool (FileBuffer);\r
   }\r
+  if (FilePathToVerfiy != FilePath) {\r
+    FreePool (FilePathToVerfiy);\r
+  }\r
 \r
   return Status;\r
 }\r