]> git.proxmox.com Git - mirror_edk2.git/commitdiff
SecurityPkg/Tpm12CommandLib: Always check response returnCode
authorMichael Kinney <michael.d.kinney@intel.com>
Tue, 10 Jan 2017 16:46:20 +0000 (08:46 -0800)
committerMichael Kinney <michael.d.kinney@intel.com>
Wed, 25 Jan 2017 22:18:30 +0000 (14:18 -0800)
https://bugzilla.tianocore.org/show_bug.cgi?id=338

Update the Tpm12CommandLib to consistently check the returnCode
field of a response packet.  These checks are missing from the
GetCapability and SelfTest commands.  The functions
Tpm12ContinueSelfTest(), Tpm12GetCapabilityFlagPermanent(), and
Tpm12GetCapabilityFlagVolatile() are updated to verify that the
response returnCode is not an error.

Cc: Chao Zhang <chao.b.zhang@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Michael Kinney <michael.d.kinney@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Chao Zhang <chao.b.zhang@intel.com>
SecurityPkg/Library/Tpm12CommandLib/Tpm12GetCapability.c
SecurityPkg/Library/Tpm12CommandLib/Tpm12SelfTest.c

index c33746a0b10b93c959d59096b2306db1565737d1..c6eb9e1050d446258a2ed98103e022fa5f0c29ae 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Implement TPM1.2 Get Capabilities related commands.\r
 \r
 /** @file\r
   Implement TPM1.2 Get Capabilities related commands.\r
 \r
-Copyright (c) 2016, Intel Corporation. All rights reserved. <BR>\r
+Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved. <BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -79,6 +79,11 @@ Tpm12GetCapabilityFlagPermanent (
     return Status;\r
   }\r
 \r
     return Status;\r
   }\r
 \r
+  if (SwapBytes32 (Response.Hdr.returnCode) != TPM_SUCCESS) {\r
+    DEBUG ((DEBUG_ERROR, "Tpm12GetCapabilityFlagPermanent: Response Code error! 0x%08x\r\n", SwapBytes32 (Response.Hdr.returnCode)));\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
   ZeroMem (TpmPermanentFlags, sizeof (*TpmPermanentFlags));\r
   CopyMem (TpmPermanentFlags, &Response.Flags, MIN (sizeof (*TpmPermanentFlags), Response.ResponseSize));\r
 \r
   ZeroMem (TpmPermanentFlags, sizeof (*TpmPermanentFlags));\r
   CopyMem (TpmPermanentFlags, &Response.Flags, MIN (sizeof (*TpmPermanentFlags), Response.ResponseSize));\r
 \r
@@ -120,6 +125,11 @@ Tpm12GetCapabilityFlagVolatile (
     return Status;\r
   }\r
 \r
     return Status;\r
   }\r
 \r
+  if (SwapBytes32 (Response.Hdr.returnCode) != TPM_SUCCESS) {\r
+    DEBUG ((DEBUG_ERROR, "Tpm12GetCapabilityFlagVolatile: Response Code error! 0x%08x\r\n", SwapBytes32 (Response.Hdr.returnCode)));\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
   ZeroMem (VolatileFlags, sizeof (*VolatileFlags));\r
   CopyMem (VolatileFlags, &Response.Flags, MIN (sizeof (*VolatileFlags), Response.ResponseSize));\r
 \r
   ZeroMem (VolatileFlags, sizeof (*VolatileFlags));\r
   CopyMem (VolatileFlags, &Response.Flags, MIN (sizeof (*VolatileFlags), Response.ResponseSize));\r
 \r
index 8e232ee5b857b47c34d46ac50000b743d5673369..579fed722bc54057348eec9509238d8e70ca5fd9 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Implement TPM1.2 NV Self Test related commands.\r
 \r
 /** @file\r
   Implement TPM1.2 NV Self Test related commands.\r
 \r
-Copyright (c) 2016, Intel Corporation. All rights reserved. <BR>\r
+Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved. <BR>\r
 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
@@ -16,6 +16,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <PiPei.h>\r
 #include <Library/Tpm12CommandLib.h>\r
 #include <Library/BaseLib.h>\r
 #include <PiPei.h>\r
 #include <Library/Tpm12CommandLib.h>\r
 #include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
 #include <Library/Tpm12DeviceLib.h>\r
 \r
 /**\r
 #include <Library/Tpm12DeviceLib.h>\r
 \r
 /**\r
@@ -33,6 +34,7 @@ Tpm12ContinueSelfTest (
   VOID\r
   )\r
 {\r
   VOID\r
   )\r
 {\r
+  EFI_STATUS           Status;\r
   TPM_RQU_COMMAND_HDR  Command;\r
   TPM_RSP_COMMAND_HDR  Response;\r
   UINT32               Length;\r
   TPM_RQU_COMMAND_HDR  Command;\r
   TPM_RSP_COMMAND_HDR  Response;\r
   UINT32               Length;\r
@@ -44,5 +46,15 @@ Tpm12ContinueSelfTest (
   Command.paramSize = SwapBytes32 (sizeof (Command));\r
   Command.ordinal   = SwapBytes32 (TPM_ORD_ContinueSelfTest);\r
   Length = sizeof (Response);\r
   Command.paramSize = SwapBytes32 (sizeof (Command));\r
   Command.ordinal   = SwapBytes32 (TPM_ORD_ContinueSelfTest);\r
   Length = sizeof (Response);\r
-  return Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, &Length, (UINT8 *)&Response);\r
+  Status = Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, &Length, (UINT8 *)&Response);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  if (SwapBytes32 (Response.returnCode) != TPM_SUCCESS) {\r
+    DEBUG ((DEBUG_ERROR, "Tpm12ContinueSelfTest: Response Code error! 0x%08x\r\n", SwapBytes32 (Response.returnCode)));\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  return Status;\r
 }\r
 }\r