SecurityPkg: Fix TPM 1.2 NV Storage Command Size byte order
authorSamer El-Haj-Mahmoud <samer.el-haj-mahmoud@hpe.com>
Thu, 28 Apr 2016 20:24:04 +0000 (04:24 +0800)
committerZhang, Chao B <chao.b.zhang@intel.com>
Tue, 3 May 2016 02:10:58 +0000 (10:10 +0800)
Fix Tpm12NvWriteValue() command/response length byte order.
Tpm12SubmitCommand() was using the value from Command.Hdr.paramSize
which was swapped to be Big Endian, but the function was
expecting it in UINT32 Little Endian

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Samer El-Haj-Mahmoud <elhaj@hpe.com>
Signed-off-by: Derek Lin <derek.lin2@hpe.com>
Reviewed-by: Chao Zhang <chao.b.zhang@intel.com>
Reviewed-by: Yao Jiewen <jiewen.yao@intel.com>
SecurityPkg/Library/Tpm12CommandLib/Tpm12NvStorage.c

index 7baafa8..e176b00 100644 (file)
@@ -2,6 +2,7 @@
   Implement TPM1.2 NV storage related command.\r
 \r
 Copyright (c) 2015 - 2016, 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
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -199,8 +200,9 @@ Tpm12NvWriteValue (
 {\r
   EFI_STATUS              Status;\r
   TPM_CMD_NV_WRITE_VALUE  Command;\r
+  UINT32                  CommandLength;\r
   TPM_RSP_COMMAND_HDR     Response;\r
-  UINT32                  Length;\r
+  UINT32                  ResponseLength;\r
 \r
   if (DataSize > sizeof (Command.Data)) {\r
     return EFI_UNSUPPORTED;\r
@@ -210,14 +212,15 @@ Tpm12NvWriteValue (
   // send Tpm command TPM_ORD_NV_WriteValue\r
   //\r
   Command.Hdr.tag       = SwapBytes16 (TPM_TAG_RQU_COMMAND);\r
-  Command.Hdr.paramSize = SwapBytes32 (sizeof (Command) - sizeof(Command.Data) + DataSize);\r
+  CommandLength = sizeof (Command) - sizeof(Command.Data) + DataSize;\r
+  Command.Hdr.paramSize = SwapBytes32 (CommandLength);\r
   Command.Hdr.ordinal   = SwapBytes32 (TPM_ORD_NV_WriteValue);\r
   Command.NvIndex       = SwapBytes32 (NvIndex);\r
   Command.Offset        = SwapBytes32 (Offset);\r
   Command.DataSize      = SwapBytes32 (DataSize);\r
   CopyMem (Command.Data, Data, DataSize);\r
-  Length = sizeof (Response);\r
-  Status = Tpm12SubmitCommand (Command.Hdr.paramSize, (UINT8 *)&Command, &Length, (UINT8 *)&Response);\r
+  ResponseLength = sizeof (Response);\r
+  Status = Tpm12SubmitCommand (CommandLength, (UINT8 *)&Command, &ResponseLength, (UINT8 *)&Response);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r