From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web12.2325.1657836288174243203 for ; Thu, 14 Jul 2022 15:04:48 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=jJnsJAr/; spf=pass (domain: intel.com, ip: 192.55.52.115, mailfrom: judah.vang@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657836288; x=1689372288; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MOH2onNYmItrS1IrqEKPOeaAGZ4erWmLlt/HLn2nTUU=; b=jJnsJAr/ulw+KxPAFYHfuasBGL6H4QIbAUxVsrfQPBIJ6yEPC7G1M+Id 0h9ASejHBOiYUSTjf6I9JhRSR7kE4uxdBaN1bHRLJob7w0kNGu4hRUhNo fg4VH445s1RldepLjNV4sqkJdQaugDIjTJGvRXBrDiSezExEnKDa8D79x RHPPmb2s6inAKpmgTU5u6xzeoFoLCmW6mOlfo0jvlQRPC6XxecHWMdtGQ 3tpEuA+ea9qLLN+D44qYTlBuvaEIujNa03RqGcqe4IkovrcjXOeX6Dh4f B9Vo2awhSidgvG6p1hZdTxwJNxyGZsSjtWErYuiyAdzWTl59x72q78guM g==; X-IronPort-AV: E=McAfee;i="6400,9594,10408"; a="285661706" X-IronPort-AV: E=Sophos;i="5.92,272,1650956400"; d="scan'208";a="285661706" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jul 2022 15:04:43 -0700 X-IronPort-AV: E=Sophos;i="5.92,272,1650956400"; d="scan'208";a="623600221" Received: from jvang-mobl.amr.corp.intel.com ([10.209.53.127]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jul 2022 15:04:42 -0700 From: "Judah Vang" To: devel@edk2.groups.io Cc: Jiewen Yao , Jian J Wang , Xiaoyu Lu , Guomin Jiang , Nishant C Mistry Subject: [PATCH v3 1/3] CryptoPkg: Fix memoryleak in BaseMemAllocation Date: Thu, 14 Jul 2022 15:04:14 -0700 Message-Id: <20220714220416.1660-2-judah.vang@intel.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220714220416.1660-1-judah.vang@intel.com> References: <20220714220416.1660-1-judah.vang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3990 Replace AllocatePool() with AllocatePages() and FreePool() with FreePages() because FreePool() is not supported in PEI phase. FreePool() does not free the allocated pool in PEI phase causing a memory leak. Cc: Jiewen Yao Cc: Jian J Wang Cc: Xiaoyu Lu Cc: Guomin Jiang Cc: Nishant C Mistry Signed-off-by: Jian J Wang Signed-off-by: Nishant C Mistry Signed-off-by: Judah Vang --- CryptoPkg/Library/BaseCryptLib/SysCall/BaseMemAllocation.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/CryptoPkg/Library/BaseCryptLib/SysCall/BaseMemAllocation.c b/CryptoPkg/Library/BaseCryptLib/SysCall/BaseMemAllocation.c index b7bed15c18df..d77e1f7de5e3 100644 --- a/CryptoPkg/Library/BaseCryptLib/SysCall/BaseMemAllocation.c +++ b/CryptoPkg/Library/BaseCryptLib/SysCall/BaseMemAllocation.c @@ -2,13 +2,14 @@ Base Memory Allocation Routines Wrapper for Crypto library over OpenSSL during PEI & DXE phases. -Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.
+Copyright (c) 2009 - 2022, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include #include +#include // // Extra header to record the memory buffer size from malloc routine. @@ -41,7 +42,7 @@ malloc ( // NewSize = (UINTN)(size) + CRYPTMEM_OVERHEAD; - Data = AllocatePool (NewSize); + Data = AllocatePages (EFI_SIZE_TO_PAGES (NewSize)); if (Data != NULL) { PoolHdr = (CRYPTMEM_HEAD *)Data; // @@ -73,7 +74,7 @@ realloc ( VOID *Data; NewSize = (UINTN)size + CRYPTMEM_OVERHEAD; - Data = AllocatePool (NewSize); + Data = AllocatePages (EFI_SIZE_TO_PAGES (NewSize)); if (Data != NULL) { NewPoolHdr = (CRYPTMEM_HEAD *)Data; NewPoolHdr->Signature = CRYPTMEM_HEAD_SIGNATURE; @@ -90,7 +91,7 @@ realloc ( // Duplicate the buffer content. // CopyMem ((VOID *)(NewPoolHdr + 1), ptr, MIN (OldSize, size)); - FreePool ((VOID *)OldPoolHdr); + FreePages (((VOID *)OldPoolHdr), EFI_SIZE_TO_PAGES (OldSize)); } return (VOID *)(NewPoolHdr + 1); @@ -117,6 +118,6 @@ free ( if (ptr != NULL) { PoolHdr = (CRYPTMEM_HEAD *)ptr - 1; ASSERT (PoolHdr->Signature == CRYPTMEM_HEAD_SIGNATURE); - FreePool (PoolHdr); + FreePages (((VOID *)PoolHdr), EFI_SIZE_TO_PAGES (PoolHdr->Size)); } } -- 2.35.1.windows.2