From nobody Mon Feb 9 06:00:16 2026 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+47946+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+47946+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1569331193; cv=none; d=zoho.com; s=zohoarc; b=oiNQ1mntbZuZEhE7vsN/F2W7lR0DbSk/E1/ucKMsiWjAGT5cNIOf/e+nfdQkBrAL+Mn4FlPp/YSY77njWrkSVUgW6M7hwk1rAVP2eNhkslmlEIPZ0mB+0WxLOuyKkjXCZvbCGl8rykSkojRvr9xI/0zP87Mm/yeGbnHgYUSYoDE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569331193; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To:ARC-Authentication-Results; bh=9/q47C+4mH01OTBRwHFS4fz5tSTX+JWDGo7CuihGAKQ=; b=imcwKxA86qq4wya2GKFzB/qkVmHsEf5FYXfT+v4hfKV/iijiO3Dm+0hnVqy5pGuLDFpCHZEubPCUhQG76Aw/dRDgtRMeyIlPMtjrEKVsUSkuidCoeAka2lzITWEVStHpBhH4g4C/jUa1PNH0TpZu7WhPTipcEJ/DFENx95bTQZI= 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+47946+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 1569331193460272.45889958182306; Tue, 24 Sep 2019 06:19:53 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id sqQLYY1788612xSsclKfQeHf; Tue, 24 Sep 2019 06:19:52 -0700 X-Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by groups.io with SMTP; Tue, 24 Sep 2019 06:19:52 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Sep 2019 06:19:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,544,1559545200"; d="scan'208";a="189365338" X-Received: from dandanbi-mobl2.ccr.corp.intel.com ([10.249.168.26]) by fmsmga007.fm.intel.com with ESMTP; 24 Sep 2019 06:19:49 -0700 From: "Dandan Bi" To: devel@edk2.groups.io Cc: Jian J Wang , Hao A Wu , Ray Ni , Zhichao Gao , Liming Gao , Laszlo Ersek , Philippe Mathieu-Daude Subject: [edk2-devel] [patch v3 3/5] MdeModulePkg/UefiBootManager: Unload image on EFI_SECURITY_VIOLATION Date: Tue, 24 Sep 2019 21:16:42 +0800 Message-Id: <20190924131644.10412-4-dandan.bi@intel.com> In-Reply-To: <20190924131644.10412-1-dandan.bi@intel.com> References: <20190924131644.10412-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 X-Gm-Message-State: kmSXQ5SfuIeltRDUmtC1BGmpx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1569331192; bh=tAe4zeHW0t06EMUIpbdO8lHmfsLO6INn3pv2E8pwRlE=; h=Cc:Date:From:Reply-To:Subject:To; b=gG3cdjeVX9WZ9rfG7d8fa00AyERvwxeMnjhQs/ooAAVcaa61AuShcKdOjIEhS8Fy4ze l6wdmFStOwiRpZAoRN+1r/pieimD4O+GG5rTCJOCljyT1kOillVmciOOZ7+q360yi2XN8 zGjuBOdzk2mPm/tn34J/JTtmValNlzmh3Bk= 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 UefiBootManagerLib 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: Zhichao Gao Cc: Liming Gao Cc: Laszlo Ersek Cc: Philippe Mathieu-Daude REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1992 Signed-off-by: Dandan Bi Reviewed-by: Philippe Mathieu-Daude Reviewed-by: Zhichao Gao --- V3: Enahnce the error handling logic in BmLoadOption.c and BmMisc.c. MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c | 9 +++++++++ .../Library/UefiBootManagerLib/BmLoadOption.c | 14 ++++++++++++-- MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c | 14 ++++++++++++-- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c b/MdeModulePk= g/Library/UefiBootManagerLib/BmBoot.c index 952033fc82..760d7647b8 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..89372b3b97 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,11 +1409,21 @@ EfiBootManagerProcessLoadOption ( FileSize, &ImageHandle ); FreePool (FileBuffer); =20 - if (!EFI_ERROR (Status)) { + 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); + } + } else { Status =3D gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtoco= lGuid, (VOID **)&ImageInfo); ASSERT_EFI_ERROR (Status); =20 ImageInfo->LoadOptionsSize =3D LoadOption->OptionalDataSize; ImageInfo->LoadOptions =3D LoadOption->OptionalData; diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c b/MdeModulePk= g/Library/UefiBootManagerLib/BmMisc.c index 6b8fb4d924..89595747af 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,11 +491,21 @@ EfiBootManagerDispatchDeferredImages ( ImageDevicePath, NULL, 0, &ImageHandle ); - if (!EFI_ERROR (Status)) { + if (EFI_ERROR (Status)) { + // + // 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 b= e started 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 l= eak. + // + if (Status =3D=3D EFI_SECURITY_VIOLATION) { + gBS->UnloadImage (ImageHandle); + } + } else { LoadCount++; // // Before calling the image, enable the Watchdog Timer for // a 5 Minute period // --=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 (#47946): https://edk2.groups.io/g/devel/message/47946 Mute This Topic: https://groups.io/mt/34275944/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-