]> git.proxmox.com Git - mirror_edk2.git/commitdiff
SecurityPkg/TPM: Fix bugs in imported PeiDxeTpmPlatformHierarchyLib
authorStefan Berger <stefanb@linux.vnet.ibm.com>
Mon, 13 Sep 2021 14:20:58 +0000 (22:20 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Mon, 13 Sep 2021 16:53:14 +0000 (16:53 +0000)
Fix some bugs in the original PeiDxeTpmPlatformHierarchyLib.c.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
SecurityPkg/Library/PeiDxeTpmPlatformHierarchyLib/PeiDxeTpmPlatformHierarchyLib.c
SecurityPkg/Library/PeiDxeTpmPlatformHierarchyLib/PeiDxeTpmPlatformHierarchyLib.inf

index 9812ab99abf5c202890941b6adca69881bc9bad2..d82a0ae1bd5f5f0ea569322cb65d3f96ec96aa12 100644 (file)
@@ -18,7 +18,6 @@
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
-#include <Library/PcdLib.h>\r
 #include <Library/RngLib.h>\r
 #include <Library/Tpm2CommandLib.h>\r
 #include <Library/Tpm2DeviceLib.h>\r
@@ -27,7 +26,6 @@
 // The authorization value may be no larger than the digest produced by the hash\r
 //   algorithm used for context integrity.\r
 //\r
-#define      MAX_NEW_AUTHORIZATION_SIZE SHA512_DIGEST_SIZE\r
 \r
 UINT16       mAuthSize;\r
 \r
@@ -54,7 +52,7 @@ RdRandGenerateEntropy (
   UINT8       *Ptr;\r
 \r
   Status = EFI_NOT_READY;\r
-  BlockCount = Length / 64;\r
+  BlockCount = Length / sizeof(Seed);\r
   Ptr = (UINT8 *)Entropy;\r
 \r
   //\r
@@ -65,10 +63,10 @@ RdRandGenerateEntropy (
     if (EFI_ERROR (Status)) {\r
       return Status;\r
     }\r
-    CopyMem (Ptr, Seed, 64);\r
+    CopyMem (Ptr, Seed, sizeof(Seed));\r
 \r
     BlockCount--;\r
-    Ptr = Ptr + 64;\r
+    Ptr = Ptr + sizeof(Seed);\r
   }\r
 \r
   //\r
@@ -78,7 +76,7 @@ RdRandGenerateEntropy (
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
-  CopyMem (Ptr, Seed, (Length % 64));\r
+  CopyMem (Ptr, Seed, (Length % sizeof(Seed)));\r
 \r
   return Status;\r
 }\r
@@ -164,8 +162,6 @@ RandomizePlatformAuth (
 {\r
   EFI_STATUS                        Status;\r
   UINT16                            AuthSize;\r
-  UINT8                             *Rand;\r
-  UINTN                             RandSize;\r
   TPM2B_AUTH                        NewPlatformAuth;\r
 \r
   //\r
@@ -174,19 +170,13 @@ RandomizePlatformAuth (
 \r
   GetAuthSize (&AuthSize);\r
 \r
-  ZeroMem (NewPlatformAuth.buffer, AuthSize);\r
   NewPlatformAuth.size = AuthSize;\r
 \r
   //\r
-  // Allocate one buffer to store random data.\r
+  // Create the random bytes in the destination buffer\r
   //\r
-  RandSize = MAX_NEW_AUTHORIZATION_SIZE;\r
-  Rand = AllocatePool (RandSize);\r
-\r
-  RdRandGenerateEntropy (RandSize, Rand);\r
-  CopyMem (NewPlatformAuth.buffer, Rand, AuthSize);\r
 \r
-  FreePool (Rand);\r
+  RdRandGenerateEntropy (NewPlatformAuth.size, NewPlatformAuth.buffer);\r
 \r
   //\r
   // Send Tpm2HierarchyChangeAuth command with the new Auth value\r
@@ -194,7 +184,6 @@ RandomizePlatformAuth (
   Status = Tpm2HierarchyChangeAuth (TPM_RH_PLATFORM, NULL, &NewPlatformAuth);\r
   DEBUG ((DEBUG_INFO, "Tpm2HierarchyChangeAuth Result: - %r\n", Status));\r
   ZeroMem (NewPlatformAuth.buffer, AuthSize);\r
-  ZeroMem (Rand, RandSize);\r
 }\r
 \r
 /**\r
index b7a7fb0a088d8bd797f5a2638f4537b3c70e00a4..7bf666794f18e6af7dd21bb887aad1160d78e30c 100644 (file)
@@ -1,6 +1,5 @@
-### @file\r
-#\r
-#   TPM Platform Hierarchy configuration library.\r
+## @file\r
+# TPM Platform Hierarchy configuration library.\r
 #\r
 #   This library provides functions for customizing the TPM's Platform Hierarchy\r
 #   Authorization Value (platformAuth) and Platform Hierarchy Authorization\r