]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/UefiBootManager: Unload image on EFI_SECURITY_VIOLATION
authorDandan Bi <dandan.bi@intel.com>
Thu, 5 Sep 2019 07:06:13 +0000 (15:06 +0800)
committerHao A Wu <hao.a.wu@intel.com>
Wed, 25 Sep 2019 02:03:57 +0000 (10:03 +0800)
For the LoadImage() boot service, with EFI_SECURITY_VIOLATION retval,
the Image was loaded and an ImageHandle was created with a valid
EFI_LOADED_IMAGE_PROTOCOL, but the image can not be started right now.
This follows UEFI Spec.

But if the caller of LoadImage() doesn't have the option to defer
the execution of an image, we can not treat EFI_SECURITY_VIOLATION
like any other LoadImage() error, we should unload image for the
EFI_SECURITY_VIOLATION to avoid resource leak.

This patch is to do error handling for EFI_SECURITY_VIOLATION explicitly
for the callers in UefiBootManagerLib which don't have the policy to defer
the execution of the image.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Zhichao Gao <zhichao.gao@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Philippe Mathieu-Daude <philmd@redhat.com>
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1992
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
Reviewed-by: Zhichao Gao <zhichao.gao@intel.com>
Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>
MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c
MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c

index 952033fc825bb72891918bff59eb0695182efffe..760d7647b8b3ad392edb2da5bef3c3b3ea5e2607 100644 (file)
@@ -1861,6 +1861,15 @@ EfiBootManagerBoot (
     }\r
 \r
     if (EFI_ERROR (Status)) {\r
+      //\r
+      // With EFI_SECURITY_VIOLATION retval, the Image was loaded and an ImageHandle was created\r
+      // with a valid EFI_LOADED_IMAGE_PROTOCOL, but the image can not be started right now.\r
+      // If the caller doesn't have the option to defer the execution of an image, we should\r
+      // unload image for the EFI_SECURITY_VIOLATION to avoid resource leak.\r
+      //\r
+      if (Status == EFI_SECURITY_VIOLATION) {\r
+        gBS->UnloadImage (ImageHandle);\r
+      }\r
       //\r
       // Report Status Code with the failure status to indicate that the failure to load boot option\r
       //\r
index 07592f8ebd73afe1f3a146c5257711533ecfcc9a..89372b3b97b8f2835e927843889ba86fb38a8879 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Load option library functions which relate with creating and processing load options.\r
 \r
-Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2011 - 2019, Intel Corporation. All rights reserved.<BR>\r
 (C) Copyright 2015-2018 Hewlett Packard Enterprise Development LP<BR>\r
 SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
@@ -1411,7 +1411,17 @@ EfiBootManagerProcessLoadOption (
                     );\r
     FreePool (FileBuffer);\r
 \r
-    if (!EFI_ERROR (Status)) {\r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // With EFI_SECURITY_VIOLATION retval, the Image was loaded and an ImageHandle was created\r
+      // with a valid EFI_LOADED_IMAGE_PROTOCOL, but the image can not be started right now.\r
+      // If the caller doesn't have the option to defer the execution of an image, we should\r
+      // unload image for the EFI_SECURITY_VIOLATION to avoid resource leak.\r
+      //\r
+      if (Status == EFI_SECURITY_VIOLATION) {\r
+        gBS->UnloadImage (ImageHandle);\r
+      }\r
+    } else {\r
       Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **)&ImageInfo);\r
       ASSERT_EFI_ERROR (Status);\r
 \r
index 6b8fb4d92461c4419937d8f1b78a50abf32c5696..89595747af3d87f4ed8dfdb7a94bb71010d58154 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Misc library functions.\r
 \r
-Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2011 - 2019, Intel Corporation. All rights reserved.<BR>\r
 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
 SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
@@ -493,7 +493,17 @@ EfiBootManagerDispatchDeferredImages (
         0,\r
         &ImageHandle\r
       );\r
-      if (!EFI_ERROR (Status)) {\r
+      if (EFI_ERROR (Status)) {\r
+        //\r
+        // With EFI_SECURITY_VIOLATION retval, the Image was loaded and an ImageHandle was created\r
+        // with a valid EFI_LOADED_IMAGE_PROTOCOL, but the image can not be started right now.\r
+        // If the caller doesn't have the option to defer the execution of an image, we should\r
+        // unload image for the EFI_SECURITY_VIOLATION to avoid resource leak.\r
+        //\r
+        if (Status == EFI_SECURITY_VIOLATION) {\r
+          gBS->UnloadImage (ImageHandle);\r
+        }\r
+      } else {\r
         LoadCount++;\r
         //\r
         // Before calling the image, enable the Watchdog Timer for\r