From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.100; helo=mga07.intel.com; envelope-from=jian.j.wang@intel.com; receiver=edk2-devel@lists.01.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C4C86211799F1 for ; Fri, 2 Nov 2018 23:42:26 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Nov 2018 23:42:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,458,1534834800"; d="scan'208";a="105587978" Received: from shwdeopenpsi777.ccr.corp.intel.com ([10.239.158.27]) by orsmga002.jf.intel.com with ESMTP; 02 Nov 2018 23:42:25 -0700 From: Jian J Wang To: edk2-devel@lists.01.org Cc: Star Zeng , Jiewen Yao , Ruiyu Ni Date: Sat, 3 Nov 2018 14:42:20 +0800 Message-Id: <20181103064221.4764-2-jian.j.wang@intel.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: <20181103064221.4764-1-jian.j.wang@intel.com> References: <20181103064221.4764-1-jian.j.wang@intel.com> Subject: [PATCH 1/2] MdeModulePkg/Core: fill logic hole in MemoryProtectionCpuArchProtocolNotify X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 03 Nov 2018 06:42:26 -0000 At the end of of MemoryProtectionCpuArchProtocolNotify there's cleanup code to free resource. But at line 978, 994, 1005 the function returns directly. This patch use "goto" to replace "return" to make sure the resource is freed before exit. 1029: CoreCloseEvent (Event); 1030: return; Cc: Star Zeng Cc: Jiewen Yao Cc: Ruiyu Ni Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang --- MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c | 42 +++++++++++++-------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c index 6298b67db1..30e5c5153c 100644 --- a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c @@ -975,7 +975,7 @@ MemoryProtectionCpuArchProtocolNotify ( DEBUG ((DEBUG_INFO, "MemoryProtectionCpuArchProtocolNotify:\n")); Status = CoreLocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&gCpu); if (EFI_ERROR (Status)) { - return; + goto Done; } // @@ -991,7 +991,7 @@ MemoryProtectionCpuArchProtocolNotify ( HeapGuardCpuArchProtocolNotify (); if (mImageProtectionPolicy == 0) { - return; + goto Done; } Status = gBS->LocateHandleBuffer ( @@ -1002,7 +1002,7 @@ MemoryProtectionCpuArchProtocolNotify ( &HandleBuffer ); if (EFI_ERROR (Status) && (NoHandles == 0)) { - return ; + goto Done; } for (Index = 0; Index < NoHandles; Index++) { @@ -1026,8 +1026,8 @@ MemoryProtectionCpuArchProtocolNotify ( ProtectUefiImage (LoadedImage, LoadedImageDevicePath); } +Done: CoreCloseEvent (Event); - return; } /** @@ -1136,24 +1136,24 @@ CoreInitializeMemoryProtection ( GetPermissionAttributeForMemoryType (EfiConventionalMemory)); if (mImageProtectionPolicy != 0 || PcdGet64 (PcdDxeNxMemoryProtectionPolicy) != 0) { - Status = CoreCreateEvent ( - EVT_NOTIFY_SIGNAL, - TPL_CALLBACK, - MemoryProtectionCpuArchProtocolNotify, - NULL, - &Event - ); - ASSERT_EFI_ERROR(Status); + Status = CoreCreateEvent ( + EVT_NOTIFY_SIGNAL, + TPL_CALLBACK, + MemoryProtectionCpuArchProtocolNotify, + NULL, + &Event + ); + ASSERT_EFI_ERROR(Status); - // - // Register for protocol notifactions on this event - // - Status = CoreRegisterProtocolNotify ( - &gEfiCpuArchProtocolGuid, - Event, - &Registration - ); - ASSERT_EFI_ERROR(Status); + // + // Register for protocol notifactions on this event + // + Status = CoreRegisterProtocolNotify ( + &gEfiCpuArchProtocolGuid, + Event, + &Registration + ); + ASSERT_EFI_ERROR(Status); } // -- 2.16.2.windows.1