]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/Hand/DriverSupport.c
Check the parameter before use it.
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Hand / DriverSupport.c
index 74cc5dfca7a9ba6678212e56358f155140156dc2..92218ee7aaf39ca994616368ef5dd185b30a6357 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   Support functions to connect/disconnect UEFI Driver model Protocol\r
 \r
-Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2006 - 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
 http://opensource.org/licenses/bsd-license.php\r
@@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/\r
 \r
 #include "DxeMain.h"\r
+#include "Handle.h"\r
 \r
 \r
 //\r
@@ -21,19 +22,27 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 /**\r
   Connects one or more drivers to a controller.\r
 \r
-  @param  ControllerHandle                      Handle of the controller to be\r
-                                                connected.\r
-  @param  DriverImageHandle                     DriverImageHandle A pointer to an\r
-                                                ordered list of driver image\r
-                                                handles.\r
-  @param  RemainingDevicePath                   RemainingDevicePath A pointer to\r
-                                                the device path that specifies a\r
-                                                child of the controller specified\r
-                                                by ControllerHandle.\r
-  @param  Recursive                             Whether the function would be\r
-                                                called recursively or not.\r
-\r
-  @return Status code.\r
+  @param  ControllerHandle      The handle of the controller to which driver(s) are to be connected.\r
+  @param  DriverImageHandle     A pointer to an ordered list handles that support the\r
+                                EFI_DRIVER_BINDING_PROTOCOL.\r
+  @param  RemainingDevicePath   A pointer to the device path that specifies a child of the\r
+                                controller specified by ControllerHandle.\r
+  @param  Recursive             If TRUE, then ConnectController() is called recursively\r
+                                until the entire tree of controllers below the controller specified\r
+                                by ControllerHandle have been created. If FALSE, then\r
+                                the tree of controllers is only expanded one level.\r
+\r
+  @retval EFI_SUCCESS           1) One or more drivers were connected to ControllerHandle.\r
+                                2) No drivers were connected to ControllerHandle, but\r
+                                RemainingDevicePath is not NULL, and it is an End Device\r
+                                Path Node.\r
+  @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
+  @retval EFI_NOT_FOUND         1) There are no EFI_DRIVER_BINDING_PROTOCOL instances\r
+                                present in the system.\r
+                                2) No drivers were connected to ControllerHandle.\r
+  @retval EFI_SECURITY_VIOLATION \r
+                                The user has no permission to start UEFI device drivers on the device path \r
+                                associated with the ControllerHandle or specified by the RemainingDevicePath.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -56,6 +65,11 @@ CoreConnectController (
   EFI_HANDLE                           *ChildHandleBuffer;\r
   UINTN                                ChildHandleCount;\r
   UINTN                                Index;\r
+  UINTN                                HandleFilePathSize;\r
+  UINTN                                RemainingDevicePathSize;\r
+  EFI_DEVICE_PATH_PROTOCOL             *HandleFilePath;\r
+  EFI_DEVICE_PATH_PROTOCOL             *FilePath;\r
+  EFI_DEVICE_PATH_PROTOCOL             *TempFilePath;\r
 \r
   //\r
   // Make sure ControllerHandle is valid\r
@@ -65,6 +79,40 @@ CoreConnectController (
     return Status;\r
   }\r
 \r
+  if (gSecurity2 != NULL) {\r
+    //\r
+    // Check whether the user has permission to start UEFI device drivers.\r
+    //\r
+    Status = CoreHandleProtocol (ControllerHandle, &gEfiDevicePathProtocolGuid, (VOID **)&HandleFilePath);\r
+    if (!EFI_ERROR (Status)) {\r
+      ASSERT (HandleFilePath != NULL);\r
+      FilePath     = HandleFilePath;\r
+      TempFilePath = NULL;\r
+      if (RemainingDevicePath != NULL && !Recursive) {\r
+        HandleFilePathSize      = GetDevicePathSize (HandleFilePath) - sizeof (EFI_DEVICE_PATH_PROTOCOL);\r
+        RemainingDevicePathSize = GetDevicePathSize (RemainingDevicePath);\r
+        TempFilePath = AllocateZeroPool (HandleFilePathSize + RemainingDevicePathSize);\r
+        ASSERT (TempFilePath != NULL);\r
+        CopyMem (TempFilePath, HandleFilePath, HandleFilePathSize);\r
+        CopyMem ((UINT8 *) TempFilePath + HandleFilePathSize, RemainingDevicePath, RemainingDevicePathSize);\r
+        FilePath = TempFilePath;\r
+      }\r
+      Status = gSecurity2->FileAuthentication (\r
+                            gSecurity2,\r
+                            FilePath,\r
+                            NULL,\r
+                            0,\r
+                            FALSE\r
+                            );\r
+      if (TempFilePath != NULL) {\r
+        FreePool (TempFilePath);\r
+      }\r
+      if (EFI_ERROR (Status)) {\r
+        return Status;\r
+      }\r
+    }\r
+  }\r
+  \r
   Handle = ControllerHandle;\r
 \r
   //\r
@@ -351,8 +399,10 @@ CoreConnectSingleController (
   UINTN                                      NewDriverBindingHandleCount;\r
   EFI_HANDLE                                 *NewDriverBindingHandleBuffer;\r
   EFI_DRIVER_BINDING_PROTOCOL                *DriverBinding;\r
+  EFI_DRIVER_FAMILY_OVERRIDE_PROTOCOL        *DriverFamilyOverride;\r
   UINTN                                      NumberOfSortedDriverBindingProtocols;\r
   EFI_DRIVER_BINDING_PROTOCOL                **SortedDriverBindingProtocols;\r
+  UINT32                                     DriverFamilyOverrideVersion;\r
   UINT32                                     HighestVersion;\r
   UINTN                                      HighestIndex;\r
   UINTN                                      SortIndex;\r
@@ -435,6 +485,41 @@ CoreConnectSingleController (
     } while (!EFI_ERROR (Status));\r
   }\r
 \r
+  //\r
+  // Add the Driver Family Override Protocol drivers for ControllerHandle\r
+  //\r
+  while (TRUE) {\r
+    HighestIndex   = DriverBindingHandleCount;\r
+    HighestVersion = 0;\r
+    for (Index = 0; Index < DriverBindingHandleCount; Index++) {\r
+      Status = CoreHandleProtocol (\r
+                 DriverBindingHandleBuffer[Index],\r
+                 &gEfiDriverFamilyOverrideProtocolGuid,\r
+                 (VOID **) &DriverFamilyOverride\r
+                 );\r
+      if (!EFI_ERROR (Status) && (DriverFamilyOverride != NULL)) {\r
+        DriverFamilyOverrideVersion = DriverFamilyOverride->GetVersion (DriverFamilyOverride);\r
+        if ((HighestIndex == DriverBindingHandleCount) || (DriverFamilyOverrideVersion > HighestVersion)) {\r
+          HighestVersion = DriverFamilyOverrideVersion;\r
+          HighestIndex   = Index;\r
+        }\r
+      }\r
+    }\r
+\r
+    if (HighestIndex == DriverBindingHandleCount) {\r
+      break;\r
+    }\r
+\r
+    AddSortedDriverBindingProtocol (\r
+      DriverBindingHandleBuffer[HighestIndex],\r
+      &NumberOfSortedDriverBindingProtocols,\r
+      SortedDriverBindingProtocols,\r
+      DriverBindingHandleCount,\r
+      DriverBindingHandleBuffer,\r
+      FALSE\r
+      );\r
+  }\r
+\r
   //\r
   // Get the Bus Specific Driver Override Protocol instance on the Controller Handle\r
   //\r
@@ -540,11 +625,13 @@ CoreConnectSingleController (
     for (Index = 0; (Index < NumberOfSortedDriverBindingProtocols) && !DriverFound; Index++) {\r
       if (SortedDriverBindingProtocols[Index] != NULL) {\r
         DriverBinding = SortedDriverBindingProtocols[Index];\r
+        PERF_START (DriverBinding->DriverBindingHandle, "DB:Support:", NULL, 0);\r
         Status = DriverBinding->Supported(\r
                                   DriverBinding,\r
                                   ControllerHandle,\r
                                   RemainingDevicePath\r
                                   );\r
+        PERF_END (DriverBinding->DriverBindingHandle, "DB:Support:", NULL, 0);\r
         if (!EFI_ERROR (Status)) {\r
           SortedDriverBindingProtocols[Index] = NULL;\r
           DriverFound = TRUE;\r
@@ -553,13 +640,13 @@ CoreConnectSingleController (
           // A driver was found that supports ControllerHandle, so attempt to start the driver\r
           // on ControllerHandle.\r
           //\r
-          PERF_START (DriverBinding->DriverBindingHandle, DRIVERBINDING_START_TOK, NULL, 0);\r
+          PERF_START (DriverBinding->DriverBindingHandle, "DB:Start:", NULL, 0);\r
           Status = DriverBinding->Start (\r
                                     DriverBinding,\r
                                     ControllerHandle,\r
                                     RemainingDevicePath\r
                                     );\r
-          PERF_END (DriverBinding->DriverBindingHandle, DRIVERBINDING_START_TOK, NULL, 0);\r
+          PERF_END (DriverBinding->DriverBindingHandle, "DB:Start:", NULL, 0);\r
 \r
           if (!EFI_ERROR (Status)) {\r
             //\r
@@ -620,8 +707,7 @@ CoreConnectSingleController (
   @retval EFI_SUCCESS                           DriverImageHandle is not NULL,\r
                                                 and on entry DriverImageHandle is\r
                                                 not managing ControllerHandle.\r
-  @retval EFI_INVALID_PARAMETER                 ControllerHandle is not a valid\r
-                                                EFI_HANDLE.\r
+  @retval EFI_INVALID_PARAMETER                 ControllerHandle is NULL.\r
   @retval EFI_INVALID_PARAMETER                 DriverImageHandle is not NULL,\r
                                                 and it is not a valid EFI_HANDLE.\r
   @retval EFI_INVALID_PARAMETER                 ChildHandle is not NULL, and it\r
@@ -763,7 +849,7 @@ CoreDisconnectController (
                &gEfiDriverBindingProtocolGuid,\r
                (VOID **)&DriverBinding\r
                );\r
-    if (EFI_ERROR (Status)) {\r
+    if (EFI_ERROR (Status) || DriverBinding == NULL) {\r
       Status = EFI_INVALID_PARAMETER;\r
       goto Done;\r
     }\r