public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v3 0/3] CryptoPkg bug fixes
@ 2022-07-14 22:04 Judah Vang
  2022-07-14 22:04 ` [PATCH v3 1/3] CryptoPkg: Fix memoryleak in BaseMemAllocation Judah Vang
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Judah Vang @ 2022-07-14 22:04 UTC (permalink / raw)
  To: devel

https://bugzilla.tianocore.org/show_bug.cgi?id=3990
https://bugzilla.tianocore.org/show_bug.cgi?id=3991
https://bugzilla.tianocore.org/show_bug.cgi?id=3992

There is a memory leak issue with BaseMemAllocation.
It calls AllocatePool() and FreePool() but FreePool()
is not supported in PEI phase so this can cause a memory leak.

There is a #define to deprecate Sha1 functions but not
all the Sha1 function are wrapped around this #define causing
a build error. The fix is to wrap all Sha1 functions with
the #define.

Need crypto AES to be supported for PEI phase and need
crypto KDF to be supported for SMM phase.

Judah Vang (3):
  CryptoPkg: Fix memoryleak in BaseMemAllocation
  CryptoPkg: Sha1 functions causing build errors
  CryptoPkg: Need to enable crypto functions

 CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf             |  2 +-
 CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf             |  2 +-
 CryptoPkg/Library/BaseCryptLib/SysCall/BaseMemAllocation.c | 11 ++++++-----
 CryptoPkg/Library/BaseHashApiLib/BaseHashApiLib.c          | 14 +++++++++++++-
 4 files changed, 21 insertions(+), 8 deletions(-)

--
2.35.1.windows.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v3 1/3] CryptoPkg: Fix memoryleak in BaseMemAllocation
  2022-07-14 22:04 [PATCH v3 0/3] CryptoPkg bug fixes Judah Vang
@ 2022-07-14 22:04 ` Judah Vang
  2022-07-14 22:04 ` [PATCH v3 2/3] CryptoPkg: Sha1 functions causing build errors Judah Vang
  2022-07-14 22:04 ` [PATCH v3 3/3] CryptoPkg: Need to enable crypto functions Judah Vang
  2 siblings, 0 replies; 4+ messages in thread
From: Judah Vang @ 2022-07-14 22:04 UTC (permalink / raw)
  To: devel; +Cc: Jiewen Yao, Jian J Wang, Xiaoyu Lu, Guomin Jiang,
	Nishant C Mistry

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 <jiewen.yao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Xiaoyu Lu <xiaoyux.lu@intel.com>
Cc: Guomin Jiang <guomin.jiang@intel.com>
Cc: Nishant C Mistry <nishant.c.mistry@intel.com>
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Signed-off-by: Nishant C Mistry <nishant.c.mistry@intel.com>
Signed-off-by: Judah Vang <judah.vang@intel.com>
---
 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.<BR>
+Copyright (c) 2009 - 2022, Intel Corporation. All rights reserved.<BR>
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
 
 #include <CrtLibSupport.h>
 #include <Library/MemoryAllocationLib.h>
+#include <Library/BaseCryptLib.h>
 
 //
 // 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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v3 2/3] CryptoPkg: Sha1 functions causing build errors
  2022-07-14 22:04 [PATCH v3 0/3] CryptoPkg bug fixes Judah Vang
  2022-07-14 22:04 ` [PATCH v3 1/3] CryptoPkg: Fix memoryleak in BaseMemAllocation Judah Vang
@ 2022-07-14 22:04 ` Judah Vang
  2022-07-14 22:04 ` [PATCH v3 3/3] CryptoPkg: Need to enable crypto functions Judah Vang
  2 siblings, 0 replies; 4+ messages in thread
From: Judah Vang @ 2022-07-14 22:04 UTC (permalink / raw)
  To: devel; +Cc: Jiewen Yao, Jian J Wang, Xiaoyu Lu, Guomin Jiang,
	Nishant C Mistry

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3991

Fix build issue when DiSABLE_SHA1_DEPRECATED_INTERFACES
is defined. Percolate the #ifndef DiSABLE_SHA1_DEPRECATED_INTERFACES
to all the Sha1 functions.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Xiaoyu Lu <xiaoyux.lu@intel.com>
Cc: Guomin Jiang <guomin.jiang@intel.com>
Cc: Nishant C Mistry <nishant.c.mistry@intel.com>
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Signed-off-by: Nishant C Mistry <nishant.c.mistry@intel.com>
Signed-off-by: Judah Vang <judah.vang@intel.com>
---
 CryptoPkg/Library/BaseHashApiLib/BaseHashApiLib.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/CryptoPkg/Library/BaseHashApiLib/BaseHashApiLib.c b/CryptoPkg/Library/BaseHashApiLib/BaseHashApiLib.c
index f9796b215865..ede9fa8c09ec 100644
--- a/CryptoPkg/Library/BaseHashApiLib/BaseHashApiLib.c
+++ b/CryptoPkg/Library/BaseHashApiLib/BaseHashApiLib.c
@@ -6,7 +6,7 @@
   This API, when called, will calculate the Hash using the
   hashing algorithm specified by PcdHashApiLibPolicy.
 
-  Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2020-2022, Intel Corporation. All rights reserved.<BR>
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -33,9 +33,11 @@ HashApiGetContextSize (
   )
 {
   switch (PcdGet32 (PcdHashApiLibPolicy)) {
+ #ifndef DISABLE_SHA1_DEPRECATED_INTERFACES
     case HASH_ALG_SHA1:
       return Sha1GetContextSize ();
       break;
+ #endif
 
     case HASH_ALG_SHA256:
       return Sha256GetContextSize ();
@@ -75,9 +77,11 @@ HashApiInit (
   )
 {
   switch (PcdGet32 (PcdHashApiLibPolicy)) {
+ #ifndef DISABLE_SHA1_DEPRECATED_INTERFACES
     case HASH_ALG_SHA1:
       return Sha1Init (HashContext);
       break;
+ #endif
 
     case HASH_ALG_SHA256:
       return Sha256Init (HashContext);
@@ -119,9 +123,11 @@ HashApiDuplicate (
   )
 {
   switch (PcdGet32 (PcdHashApiLibPolicy)) {
+ #ifndef DISABLE_SHA1_DEPRECATED_INTERFACES
     case HASH_ALG_SHA1:
       return Sha1Duplicate (HashContext, NewHashContext);
       break;
+ #endif
 
     case HASH_ALG_SHA256:
       return Sha256Duplicate (HashContext, NewHashContext);
@@ -165,9 +171,11 @@ HashApiUpdate (
   )
 {
   switch (PcdGet32 (PcdHashApiLibPolicy)) {
+ #ifndef DISABLE_SHA1_DEPRECATED_INTERFACES
     case HASH_ALG_SHA1:
       return Sha1Update (HashContext, DataToHash, DataToHashLen);
       break;
+ #endif
 
     case HASH_ALG_SHA256:
       return Sha256Update (HashContext, DataToHash, DataToHashLen);
@@ -209,9 +217,11 @@ HashApiFinal (
   )
 {
   switch (PcdGet32 (PcdHashApiLibPolicy)) {
+ #ifndef DISABLE_SHA1_DEPRECATED_INTERFACES
     case HASH_ALG_SHA1:
       return Sha1Final (HashContext, Digest);
       break;
+ #endif
 
     case HASH_ALG_SHA256:
       return Sha256Final (HashContext, Digest);
@@ -255,9 +265,11 @@ HashApiHashAll (
   )
 {
   switch (PcdGet32 (PcdHashApiLibPolicy)) {
+ #ifndef DISABLE_SHA1_DEPRECATED_INTERFACES
     case HASH_ALG_SHA1:
       return Sha1HashAll (DataToHash, DataToHashLen, Digest);
       break;
+ #endif
 
     case HASH_ALG_SHA256:
       return Sha256HashAll (DataToHash, DataToHashLen, Digest);
-- 
2.35.1.windows.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v3 3/3] CryptoPkg: Need to enable crypto functions
  2022-07-14 22:04 [PATCH v3 0/3] CryptoPkg bug fixes Judah Vang
  2022-07-14 22:04 ` [PATCH v3 1/3] CryptoPkg: Fix memoryleak in BaseMemAllocation Judah Vang
  2022-07-14 22:04 ` [PATCH v3 2/3] CryptoPkg: Sha1 functions causing build errors Judah Vang
@ 2022-07-14 22:04 ` Judah Vang
  2 siblings, 0 replies; 4+ messages in thread
From: Judah Vang @ 2022-07-14 22:04 UTC (permalink / raw)
  To: devel; +Cc: Jiewen Yao, Jian J Wang, Xiaoyu Lu, Guomin Jiang,
	Nishant C Mistry

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3992

Enable CryptAes for PEI phase.
Enable CryptHkdf for SMM phase.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Xiaoyu Lu <xiaoyux.lu@intel.com>
Cc: Guomin Jiang <guomin.jiang@intel.com>
Cc: Nishant C Mistry <nishant.c.mistry@intel.com>
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Signed-off-by: Nishant C Mistry <nishant.c.mistry@intel.com>
Signed-off-by: Judah Vang <judah.vang@intel.com>
---
 CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf | 2 +-
 CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf b/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
index 01de27e03747..40728af37822 100644
--- a/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
+++ b/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
@@ -43,7 +43,7 @@ [Sources]
   Hash/CryptParallelHashNull.c
   Hmac/CryptHmacSha256.c
   Kdf/CryptHkdf.c
-  Cipher/CryptAesNull.c
+  Cipher/CryptAes.c
   Pk/CryptRsaBasic.c
   Pk/CryptRsaExtNull.c
   Pk/CryptPkcs1OaepNull.c
diff --git a/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf b/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf
index 91a171509540..706b527338f0 100644
--- a/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf
+++ b/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf
@@ -43,7 +43,7 @@ [Sources]
   Hash/CryptCShake256.c
   Hash/CryptParallelHash.c
   Hmac/CryptHmacSha256.c
-  Kdf/CryptHkdfNull.c
+  Kdf/CryptHkdf.c
   Cipher/CryptAes.c
   Pk/CryptRsaBasic.c
   Pk/CryptRsaExtNull.c
-- 
2.35.1.windows.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-07-14 22:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-14 22:04 [PATCH v3 0/3] CryptoPkg bug fixes Judah Vang
2022-07-14 22:04 ` [PATCH v3 1/3] CryptoPkg: Fix memoryleak in BaseMemAllocation Judah Vang
2022-07-14 22:04 ` [PATCH v3 2/3] CryptoPkg: Sha1 functions causing build errors Judah Vang
2022-07-14 22:04 ` [PATCH v3 3/3] CryptoPkg: Need to enable crypto functions Judah Vang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox