From nobody Fri May 3 04:17:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+46766+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+46766+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1567585569; cv=none; d=zoho.com; s=zohoarc; b=nCdBkFU9A1wkkOJyDpUGEr6wtDb2iSeZuVOA6WDNNrWUBdXZEUUy+gTe3DWF3qbFV3I41j7snWWz9RbbJ0ZjzyI8NAr3y+a6I6JdiMyp7z05rdSga99LsbfXIXqeLLduK2GBAkIwDQj4ItM1vrZMCrihs2GuaCtCTBNCj2lxMsc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567585569; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To:ARC-Authentication-Results; bh=6mnslXxWIlzVJq0n1M92p9L7sBwthUne6U3jVNUbm+Q=; b=CK949hTInIsajw+a0IUxmv6cM83ZEa8ALOgJkY2PaqTCxQzBsbAcDKhDjCtiEwtJ1X+vZemDx/PIWxh7zVr9rbWFJSjGKZ7n839hSUzkSHeEw44ktekYLi9Sho4f9mFvCF/SmRFSWJm+Oc3wqyuMJpBt5OCCshROQI3yhPKw4eM= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+46766+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1567585569798542.6915035316409; Wed, 4 Sep 2019 01:26:09 -0700 (PDT) Return-Path: X-Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by groups.io with SMTP; Wed, 04 Sep 2019 01:26:09 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Sep 2019 01:26:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,465,1559545200"; d="scan'208";a="187549163" X-Received: from shwdeopenpsi114.ccr.corp.intel.com ([10.239.157.147]) by orsmga006.jf.intel.com with ESMTP; 04 Sep 2019 01:26:06 -0700 From: "Dandan Bi" To: devel@edk2.groups.io Cc: Leif Lindholm , Ard Biesheuvel , Laszlo Ersek Subject: [edk2-devel] [patch 1/3] EmbeddedPkg: Unload image on EFI_SECURITY_VIOLATION Date: Wed, 4 Sep 2019 16:25:53 +0800 Message-Id: <20190904082555.35424-2-dandan.bi@intel.com> In-Reply-To: <20190904082555.35424-1-dandan.bi@intel.com> References: <20190904082555.35424-1-dandan.bi@intel.com> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,dandan.bi@intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1567585569; bh=fXdHuJtQveNuPD6jyBX03jvvSSrybAoda7TIWZuuaUY=; h=Cc:Date:From:Reply-To:Subject:To; b=RPGs4WHGUEi3GCTHk/ut6wU3aHmIu8R+jUiC1oig4zqPBxDTCoJZ0ePCdSHHgQAucmZ hHKSIASy+okR+eRGajRXEN6hgNgGxE8cQw8kN0SaVRaNQoAy+Ht6iG7rlCNOq5k51AEXf gjiAUczygN0bAFmC2A4JPBqNphkDwHchGDw= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 EmbeddedPkg which don't have the policy to defer the execution of the image. Cc: Leif Lindholm Cc: Ard Biesheuvel Cc: Laszlo Ersek REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1992 Signed-off-by: Dandan Bi Acked-by: Ard Biesheuvel Acked-by: Laszlo Ersek --- .../AndroidFastboot/Arm/BootAndroidBootImg.c | 9 +++++++++ .../Library/AndroidBootImgLib/AndroidBootImgLib.c | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/EmbeddedPkg/Application/AndroidFastboot/Arm/BootAndroidBootImg= .c b/EmbeddedPkg/Application/AndroidFastboot/Arm/BootAndroidBootImg.c index 591afbe7cc..9fa28e3390 100644 --- a/EmbeddedPkg/Application/AndroidFastboot/Arm/BootAndroidBootImg.c +++ b/EmbeddedPkg/Application/AndroidFastboot/Arm/BootAndroidBootImg.c @@ -71,10 +71,19 @@ StartEfiApplication ( =20 // Load the image from the device path with Boot Services function Status =3D gBS->LoadImage (TRUE, ParentImageHandle, DevicePath, NULL, 0, &ImageHandle); if (EFI_ERROR (Status)) { + // + // With EFI_SECURITY_VIOLATION retval, the Image was loaded and an Ima= geHandle was created + // with a valid EFI_LOADED_IMAGE_PROTOCOL, but the image can not be st= arted right now. + // If the caller doesn't have the option to defer the execution of an = image, we should + // unload image for the EFI_SECURITY_VIOLATION to avoid resource leak. + // + if (Status =3D=3D EFI_SECURITY_VIOLATION) { + gBS->UnloadImage (ImageHandle); + } return Status; } =20 // Passed LoadOptions to the EFI Application if (LoadOptionsSize !=3D 0) { diff --git a/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c b/Em= beddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c index d9e7aa7d2b..2e9e74db1d 100644 --- a/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c +++ b/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c @@ -439,10 +439,22 @@ AndroidBootImgBoot ( + KernelSize; =20 Status =3D gBS->LoadImage (TRUE, gImageHandle, (EFI_DEVICE_PATH *)&KernelDevicePath, (VOID*)(UINTN)Kernel, KernelSize, &ImageHandle); + if (EFI_ERROR (Status)) { + // + // With EFI_SECURITY_VIOLATION retval, the Image was loaded and an Ima= geHandle was created + // with a valid EFI_LOADED_IMAGE_PROTOCOL, but the image can not be st= arted right now. + // If the caller doesn't have the option to defer the execution of an = image, we should + // unload image for the EFI_SECURITY_VIOLATION to avoid resource leak. + // + if (Status =3D=3D EFI_SECURITY_VIOLATION) { + gBS->UnloadImage (ImageHandle); + } + return Status; + } =20 // Set kernel arguments Status =3D gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGui= d, (VOID **) &ImageInfo); ImageInfo->LoadOptions =3D NewKernelArg; --=20 2.18.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#46766): https://edk2.groups.io/g/devel/message/46766 Mute This Topic: https://groups.io/mt/33136045/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 3 04:17:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+46767+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+46767+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1567585574; cv=none; d=zoho.com; s=zohoarc; b=Ldy6AI9kYFpme/Ma252tN03/jcayd/A/DLKNCbUCX6zc1++Ac/jwVlsm1L4h1olsRsUEZ8GOREW915oO1G2Aq2YCkg7f1+cuNP57ut+CRJuQ7pIstTy9dN4Mt0+9yEWgaWAuf+GAVPsVGeDYdeL6GiAkcXQEtati3RDQiroo1FA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567585574; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To:ARC-Authentication-Results; bh=AJhzKsJPhAJxPzvhmr0YKH7cJRNIIdv+Mj+9Bc2aiAQ=; b=WGjhw4Byl1Dfjqj0kuGpSHctsV1k5ghqFI7P5YD/fOgCSJ8oJF+beTRGDTy+j3R7D0MezpQVR02gjop1hOaQCQMpML9Th1N0uGRYu5mlVoQ6+5gEPo6xsD81rPMLM7jzobkl39z+MgsNK7pCVaSGDRF0Yiv0R/RKSdtnwqBCSRw= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+46767+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 15675855743621012.9545476389845; Wed, 4 Sep 2019 01:26:14 -0700 (PDT) Return-Path: X-Received: from mga02.intel.com (mga02.intel.com []) by groups.io with SMTP; Wed, 04 Sep 2019 01:26:13 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Sep 2019 01:26:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,465,1559545200"; d="scan'208";a="187549186" X-Received: from shwdeopenpsi114.ccr.corp.intel.com ([10.239.157.147]) by orsmga006.jf.intel.com with ESMTP; 04 Sep 2019 01:26:11 -0700 From: "Dandan Bi" To: devel@edk2.groups.io Cc: Jian J Wang , Hao A Wu , Ray Ni , Liming Gao , Laszlo Ersek Subject: [edk2-devel] [patch 2/3] MdeModulePkg: Unload image on EFI_SECURITY_VIOLATION Date: Wed, 4 Sep 2019 16:25:54 +0800 Message-Id: <20190904082555.35424-3-dandan.bi@intel.com> In-Reply-To: <20190904082555.35424-1-dandan.bi@intel.com> References: <20190904082555.35424-1-dandan.bi@intel.com> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,dandan.bi@intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1567585574; bh=Zqgh8hks6W4zthvs4temYyjeme8lbAfeF8kPWt/TkSc=; h=Cc:Date:From:Reply-To:Subject:To; b=uaPXzZpb3P9dOCuy4d/vN8XroVMgRPWCLrRKbjyxQhvlG2f6MLa2HcFn5ogHoPQEZZn UOk4JN4ksbE98QR/tHRBX+etc0D1WGEMImG1J4s42iFSNjqPKd469hTB5d1PKI2kfPLgl pWf8cnQ4nalHOciPMNLcp1PNWlRgpVtWw1E= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 MdeModulePkg which don't have the policy to defer the execution of the image. Cc: Jian J Wang Cc: Hao A Wu Cc: Ray Ni Cc: Liming Gao Cc: Laszlo Ersek REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1992 Signed-off-by: Dandan Bi --- MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c | 9 +++++++++ MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c | 9 +++++++++ MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c | 9 +++++++++ .../Library/UefiBootManagerLib/BmLoadOption.c | 11 ++++++++++- MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c | 11 ++++++++++- .../PlatformDriOverrideDxe/PlatDriOverrideLib.c | 11 ++++++++++- 6 files changed, 57 insertions(+), 3 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c b/MdeModu= lePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c index c994ed5fe3..1a8d9811b0 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c @@ -726,10 +726,19 @@ ProcessOpRomImage ( Buffer, BufferSize, &ImageHandle ); if (EFI_ERROR (Status)) { + // + // With EFI_SECURITY_VIOLATION retval, the Image was loaded and an I= mageHandle was created + // with a valid EFI_LOADED_IMAGE_PROTOCOL, but the image can not be = started right now. + // If the caller doesn't have the option to defer the execution of a= n image, we should + // unload image for the EFI_SECURITY_VIOLATION to avoid resource lea= k. + // + if (Status =3D=3D EFI_SECURITY_VIOLATION) { + gBS->UnloadImage (ImageHandle); + } // // Record the Option ROM Image device path when LoadImage fails. // PciOverride.GetDriver() will try to look for the Image Handle usi= ng the device path later. // AddDriver (PciDevice, NULL, PciOptionRomImageDevicePath); diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c b/MdeMod= ulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c index 95aa9de087..74c00ecf9e 100644 --- a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c +++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c @@ -1028,10 +1028,19 @@ StartFmpImage ( ImageSize, &ImageHandle ); DEBUG((DEBUG_INFO, "FmpCapsule: LoadImage - %r\n", Status)); if (EFI_ERROR(Status)) { + // + // With EFI_SECURITY_VIOLATION retval, the Image was loaded and an Ima= geHandle was created + // with a valid EFI_LOADED_IMAGE_PROTOCOL, but the image can not be st= arted right now. + // If the caller doesn't have the option to defer the execution of an = image, we should + // unload image for the EFI_SECURITY_VIOLATION to avoid resource leak. + // + if (Status =3D=3D EFI_SECURITY_VIOLATION) { + gBS->UnloadImage (ImageHandle); + } FreePool(DriverDevicePath); return Status; } =20 DEBUG((DEBUG_INFO, "FmpCapsule: StartImage ...\n")); diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c b/MdeModulePk= g/Library/UefiBootManagerLib/BmBoot.c index 952033fc82..c8de7eec03 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c @@ -1859,10 +1859,19 @@ EfiBootManagerBoot ( if (FilePath !=3D NULL) { FreePool (FilePath); } =20 if (EFI_ERROR (Status)) { + // + // With EFI_SECURITY_VIOLATION retval, the Image was loaded and an I= mageHandle was created + // with a valid EFI_LOADED_IMAGE_PROTOCOL, but the image can not be = started right now. + // If the caller doesn't have the option to defer the execution of a= n image, we should + // unload image for the EFI_SECURITY_VIOLATION to avoid resource lea= k. + // + if (Status =3D=3D EFI_SECURITY_VIOLATION) { + gBS->UnloadImage (ImageHandle); + } // // Report Status Code with the failure status to indicate that the f= ailure to load boot option // BmReportLoadFailure (EFI_SW_DXE_BS_EC_BOOT_OPTION_LOAD_ERROR, Status= ); BootOption->Status =3D Status; diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c b/MdeMo= dulePkg/Library/UefiBootManagerLib/BmLoadOption.c index 07592f8ebd..233fb43c27 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c @@ -1,9 +1,9 @@ /** @file Load option library functions which relate with creating and processing = load options. =20 -Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) 2011 - 2019, Intel Corporation. All rights reserved.
(C) Copyright 2015-2018 Hewlett Packard Enterprise Development LP
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ =20 @@ -1409,10 +1409,19 @@ EfiBootManagerProcessLoadOption ( FileSize, &ImageHandle ); FreePool (FileBuffer); =20 + // + // With EFI_SECURITY_VIOLATION retval, the Image was loaded and an Ima= geHandle was created + // with a valid EFI_LOADED_IMAGE_PROTOCOL, but the image can not be st= arted right now. + // If the caller doesn't have the option to defer the execution of an = image, we should + // unload image for the EFI_SECURITY_VIOLATION to avoid resource leak. + // + if (Status =3D=3D EFI_SECURITY_VIOLATION) { + gBS->UnloadImage (ImageHandle); + } if (!EFI_ERROR (Status)) { Status =3D gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtoco= lGuid, (VOID **)&ImageInfo); ASSERT_EFI_ERROR (Status); =20 ImageInfo->LoadOptionsSize =3D LoadOption->OptionalDataSize; diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c b/MdeModulePk= g/Library/UefiBootManagerLib/BmMisc.c index 6b8fb4d924..cdfc57741b 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c @@ -1,9 +1,9 @@ /** @file Misc library functions. =20 -Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) 2011 - 2019, Intel Corporation. All rights reserved.
(C) Copyright 2016 Hewlett Packard Enterprise Development LP
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ =20 @@ -491,10 +491,19 @@ EfiBootManagerDispatchDeferredImages ( ImageDevicePath, NULL, 0, &ImageHandle ); + // + // With EFI_SECURITY_VIOLATION retval, the Image was loaded and an I= mageHandle was created + // with a valid EFI_LOADED_IMAGE_PROTOCOL, but the image can not be = started right now. + // If the caller doesn't have the option to defer the execution of a= n image, we should + // unload image for the EFI_SECURITY_VIOLATION to avoid resource lea= k. + // + if (Status =3D=3D EFI_SECURITY_VIOLATION) { + gBS->UnloadImage (ImageHandle); + } if (!EFI_ERROR (Status)) { LoadCount++; // // Before calling the image, enable the Watchdog Timer for // a 5 Minute period diff --git a/MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideL= ib.c b/MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideLib.c index 2d3736b468..e4b6b26330 100644 --- a/MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideLib.c +++ b/MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideLib.c @@ -1,9 +1,9 @@ /** @file Implementation of the shared functions to do the platform driver vverrid= e mapping. =20 - Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
+ Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ =20 #include "InternalPlatDriOverrideDxe.h" @@ -1484,10 +1484,19 @@ GetDriverFromMapping ( ); ASSERT (DriverBinding !=3D NULL); DriverImageInfo->ImageHandle =3D ImageHandle; } } else { + // + // 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. + // If the caller doesn't have the option to defer the execut= ion of an image, we should + // unload image for the EFI_SECURITY_VIOLATION to avoid reso= urce leak. + // + if (Status =3D=3D EFI_SECURITY_VIOLATION) { + gBS->UnloadImage (ImageHandle); + } DriverImageInfo->UnLoadable =3D TRUE; DriverImageInfo->ImageHandle =3D NULL; } } } --=20 2.18.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#46767): https://edk2.groups.io/g/devel/message/46767 Mute This Topic: https://groups.io/mt/33136046/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 3 04:17:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+46768+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+46768+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1567585582; cv=none; d=zoho.com; s=zohoarc; b=OS0GFXtatfeAxBaTCAu+FYUNHqS80X499n15hKld8rr7GeNgKf28thboB8Wx07MaS9q7s1yoisxgz3FqfcBugD49h4XAQ7G4aALYOm0EfLjtP8xTI9pfjCEEk0tLTEMZbQj3ZUCTioyasgarKiCvmuwYbiFpWECdS0g5Dl62T2U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567585582; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To:ARC-Authentication-Results; bh=ooJuwTkRaucc4w57KMmBntFvkGB5dLO8zy4CX7FDyU8=; b=Z47gSUB81wTXBWZrhDc0chmnVe0xZKFhKMPcuRCfTOcvdFVxNMlllKyh0VcVPZKvKXFT+/RZLvwSASWWlHctQVPVuu9onbJ5ZFFx/tPceN0wUDwGotCwR2iRtVTsGfNOioVSd0vv7nkI22zgGBsCVmUeFbpuMvuYXcUd6BOPUbM= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+46768+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1567585582640454.4807145365486; Wed, 4 Sep 2019 01:26:22 -0700 (PDT) Return-Path: X-Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by groups.io with SMTP; Wed, 04 Sep 2019 01:26:22 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Sep 2019 01:26:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,465,1559545200"; d="scan'208";a="187549203" X-Received: from shwdeopenpsi114.ccr.corp.intel.com ([10.239.157.147]) by orsmga006.jf.intel.com with ESMTP; 04 Sep 2019 01:26:19 -0700 From: "Dandan Bi" To: devel@edk2.groups.io Cc: Ray Ni , Zhichao Gao , Laszlo Ersek Subject: [edk2-devel] [patch 3/3] ShellPkg: Unload image on EFI_SECURITY_VIOLATION Date: Wed, 4 Sep 2019 16:25:55 +0800 Message-Id: <20190904082555.35424-4-dandan.bi@intel.com> In-Reply-To: <20190904082555.35424-1-dandan.bi@intel.com> References: <20190904082555.35424-1-dandan.bi@intel.com> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,dandan.bi@intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1567585582; bh=DfSUp8ZVztixzDtW4kt/NbGcxPhSShJa7MrYYpt8YY4=; h=Cc:Date:From:Reply-To:Subject:To; b=G4sdl+aCDfzkg+grD+THM7RatLxvjWsOqYhNBGohu9qr4ThDDvMtYshRXMJ6pkmQrA7 iBHVir5sPhdGBlIjdRjL6Voy621ekz9u3k36Y3Etr8fN4Ijjne1nJhWG+K793mSoZZQGR PFTReCw4wdQLBFJlLjvPn50OjP3Kkflhgmw= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 ShellPkg which don't have the policy to defer the execution of the image. Cc: Ray Ni Cc: Zhichao Gao Cc: Laszlo Ersek REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1992 Signed-off-by: Dandan Bi Reviewed-by: Zhichao Gao --- ShellPkg/Application/Shell/ShellManParser.c | 9 +++++++++ .../Library/UefiShellDebug1CommandsLib/LoadPciRom.c | 11 ++++++++++- ShellPkg/Library/UefiShellLevel2CommandsLib/Load.c | 11 ++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/ShellPkg/Application/Shell/ShellManParser.c b/ShellPkg/Applica= tion/Shell/ShellManParser.c index 6909f29441..e5f97bbb11 100644 --- a/ShellPkg/Application/Shell/ShellManParser.c +++ b/ShellPkg/Application/Shell/ShellManParser.c @@ -643,10 +643,19 @@ ProcessManFile( goto Done; } DevPath =3D ShellInfoObject.NewEfiShellProtocol->GetDevicePathFromFile= Path(CmdFilePathName); Status =3D gBS->LoadImage(FALSE, gImageHandle, DevPath, NULL, 0, = &CmdFileImgHandle); if(EFI_ERROR(Status)) { + // + // With EFI_SECURITY_VIOLATION retval, the Image was loaded and an I= mageHandle was created + // with a valid EFI_LOADED_IMAGE_PROTOCOL, but the image can not be = started right now. + // If the caller doesn't have the option to defer the execution of a= n image, we should + // unload image for the EFI_SECURITY_VIOLATION to avoid the resource= leak. + // + if (Status =3D=3D EFI_SECURITY_VIOLATION) { + gBS->UnloadImage (CmdFileImgHandle); + } *HelpText =3D NULL; goto Done; } Status =3D gBS->OpenProtocol( CmdFileImgHandle, diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c b/She= llPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c index 1b169d0d3c..f91e3eb6e7 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c @@ -1,10 +1,10 @@ /** @file Main file for LoadPciRom shell Debug1 function. =20 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.
- Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.
+ Copyright (c) 2005 - 2019, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ =20 #include "UefiShellDebug1CommandsLib.h" @@ -332,10 +332,19 @@ LoadEfiDriversFromRomImage ( ImageBuffer, ImageLength, &ImageHandle ); if (EFI_ERROR (Status)) { + // + // With EFI_SECURITY_VIOLATION retval, the Image was loaded an= d an ImageHandle was created + // with a valid EFI_LOADED_IMAGE_PROTOCOL, but the image can n= ot be started right now. + // If the caller doesn't have the option to defer the executio= n of an image, we should + // unload image for the EFI_SECURITY_VIOLATION to avoid resour= ce leak. + // + if (Status =3D=3D EFI_SECURITY_VIOLATION) { + gBS->UnloadImage (ImageHandle); + } ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LOADPCIROM_LOA= D_FAIL), gShellDebug1HiiHandle, L"loadpcirom", FileName, ImageIndex); // PrintToken (STRING_TOKEN (STR_LOADPCIROM_LOAD_IMAGE_ERROR), = HiiHandle, ImageIndex, Status); } else { Status =3D gBS->StartImage (ImageHandle, NULL, NULL); if (EFI_ERROR (Status)) { diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Load.c b/ShellPkg/= Library/UefiShellLevel2CommandsLib/Load.c index 6a94b48c86..a13e1bda2d 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Load.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Load.c @@ -1,10 +1,10 @@ /** @file Main file for attrib shell level 2 function. =20 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.
- Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2019, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ =20 #include "UefiShellLevel2CommandsLib.h" @@ -110,10 +110,19 @@ LoadDriver( NULL, 0, &LoadedDriverHandle); =20 if (EFI_ERROR(Status)) { + // + // With EFI_SECURITY_VIOLATION retval, the Image was loaded and an Ima= geHandle was created + // with a valid EFI_LOADED_IMAGE_PROTOCOL, but the image can not be st= arted right now. + // If the caller doesn't have the option to defer the execution of an = image, we should + // unload image for the EFI_SECURITY_VIOLATION to avoid resource leak. + // + if (Status =3D=3D EFI_SECURITY_VIOLATION) { + gBS->UnloadImage (LoadedDriverHandle); + } ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LOAD_NOT_IMAGE), gShel= lLevel2HiiHandle, FileName, Status); } else { // // Make sure it is a driver image // --=20 2.18.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#46768): https://edk2.groups.io/g/devel/message/46768 Mute This Topic: https://groups.io/mt/33136047/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-