]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c
SecurityPkg Tpm2CommandLib: Fix TPM2.0 response memory overflow
[mirror_edk2.git] / SecurityPkg / Library / Tpm2CommandLib / Tpm2Help.c
index 180f36083096f86e76011bb195e0aa9c89fb8387..cc77785de1c040bb87812a4b3b3b4d2f06b8d95c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Implement TPM2 help.\r
 \r
-Copyright (c) 2013 - 2017, Intel Corporation. All rights reserved. <BR>\r
+Copyright (c) 2013 - 2018, 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
@@ -150,7 +150,8 @@ CopyAuthSessionCommand (
   @param [in]  AuthSessionIn   Input AuthSession data in TPM2 response buffer\r
   @param [out] AuthSessionOut  Output AuthSession data\r
 \r
-  @return AuthSession size\r
+  @return 0    copy failed\r
+          else AuthSession size\r
 **/\r
 UINT32\r
 EFIAPI\r
@@ -171,6 +172,10 @@ CopyAuthSessionResponse (
   // nonce\r
   AuthSessionOut->nonce.size = SwapBytes16 (ReadUnaligned16 ((UINT16 *)Buffer));\r
   Buffer += sizeof(UINT16);\r
+  if (AuthSessionOut->nonce.size > sizeof(TPMU_HA)) {\r
+    DEBUG ((DEBUG_ERROR, "CopyAuthSessionResponse - nonce.size error %x\n", AuthSessionOut->nonce.size));\r
+    return 0;\r
+  }\r
 \r
   CopyMem (AuthSessionOut->nonce.buffer, Buffer, AuthSessionOut->nonce.size);\r
   Buffer += AuthSessionOut->nonce.size;\r
@@ -182,6 +187,10 @@ CopyAuthSessionResponse (
   // hmac\r
   AuthSessionOut->hmac.size = SwapBytes16 (ReadUnaligned16 ((UINT16 *)Buffer));\r
   Buffer += sizeof(UINT16);\r
+  if (AuthSessionOut->hmac.size > sizeof(TPMU_HA)) {\r
+    DEBUG ((DEBUG_ERROR, "CopyAuthSessionResponse - hmac.size error %x\n", AuthSessionOut->hmac.size));\r
+    return 0;\r
+  }\r
 \r
   CopyMem (AuthSessionOut->hmac.buffer, Buffer, AuthSessionOut->hmac.size);\r
   Buffer += AuthSessionOut->hmac.size;\r