]> git.proxmox.com Git - mirror_edk2.git/commitdiff
SecurityPkg: Add Tpm2Startup return code check.
authorYao, Jiewen <jiewen.yao@intel.com>
Mon, 11 Jan 2016 05:15:18 +0000 (05:15 +0000)
committerjyao1 <jyao1@Edk2>
Mon, 11 Jan 2016 05:15:18 +0000 (05:15 +0000)
Tpm2Startup does not check TPM device return code.
It might cause problem, that error is not detected
in Tcg2Peim, for example, S3 resume case.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: "Yao, Jiewen" <jiewen.yao@intel.com>
Reviewed-by: "Zhang, Chao B" <chao.b.zhang@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19634 6f19259b-4bc3-4df7-8a09-765794883524

SecurityPkg/Library/Tpm2CommandLib/Tpm2Startup.c

index e8af4033ce81509d035e4b677ba7939a4bab79ff..f67043b84b9d6e4df49427bd3f92dfcf9ca6b56f 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Implement TPM2 Startup related command.\r
 \r
 /** @file\r
   Implement TPM2 Startup related command.\r
 \r
-Copyright (c) 2013, Intel Corporation. All rights reserved. <BR>\r
+Copyright (c) 2013 - 2016, 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
@@ -59,6 +59,7 @@ Tpm2Startup (
   TPM2_STARTUP_COMMAND              Cmd;\r
   TPM2_STARTUP_RESPONSE             Res;\r
   UINT32                            ResultBufSize;\r
   TPM2_STARTUP_COMMAND              Cmd;\r
   TPM2_STARTUP_RESPONSE             Res;\r
   UINT32                            ResultBufSize;\r
+  TPM_RC                            ResponseCode;\r
 \r
   Cmd.Header.tag         = SwapBytes16(TPM_ST_NO_SESSIONS);\r
   Cmd.Header.paramSize   = SwapBytes32(sizeof(Cmd));\r
 \r
   Cmd.Header.tag         = SwapBytes16(TPM_ST_NO_SESSIONS);\r
   Cmd.Header.paramSize   = SwapBytes32(sizeof(Cmd));\r
@@ -67,8 +68,20 @@ Tpm2Startup (
 \r
   ResultBufSize = sizeof(Res);\r
   Status = Tpm2SubmitCommand (sizeof(Cmd), (UINT8 *)&Cmd, &ResultBufSize, (UINT8 *)&Res);\r
 \r
   ResultBufSize = sizeof(Res);\r
   Status = Tpm2SubmitCommand (sizeof(Cmd), (UINT8 *)&Cmd, &ResultBufSize, (UINT8 *)&Res);\r
-\r
-  return Status;\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  ResponseCode = SwapBytes32(Res.Header.responseCode);\r
+  switch (ResponseCode)  {\r
+  case TPM_RC_SUCCESS:\r
+  case TPM_RC_INITIALIZE:\r
+    // TPM_RC_INITIALIZE can be returned if Tpm2Startup is not required.\r
+    return EFI_SUCCESS;\r
+  default:\r
+    DEBUG ((EFI_D_ERROR, "Tpm2Startup: Response Code error! 0x%08x\r\n", ResponseCode));\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
@@ -97,6 +110,14 @@ Tpm2Shutdown (
 \r
   ResultBufSize = sizeof(Res);\r
   Status = Tpm2SubmitCommand (sizeof(Cmd), (UINT8 *)&Cmd, &ResultBufSize, (UINT8 *)&Res);\r
 \r
   ResultBufSize = sizeof(Res);\r
   Status = Tpm2SubmitCommand (sizeof(Cmd), (UINT8 *)&Cmd, &ResultBufSize, (UINT8 *)&Res);\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  if (SwapBytes32(Res.Header.responseCode) != TPM_RC_SUCCESS) {\r
+    DEBUG ((EFI_D_ERROR, "Tpm2Shutdown: Response Code error! 0x%08x\r\n", SwapBytes32(Res.Header.responseCode)));\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
 \r
 \r
-  return Status;\r
+  return EFI_SUCCESS;\r
 }\r
 }\r