From 8b1331df8b303b296c85883935caf84561f54e37 Mon Sep 17 00:00:00 2001 From: Samer El-Haj-Mahmoud Date: Fri, 29 Apr 2016 04:24:04 +0800 Subject: [PATCH 1/1] SecurityPkg: Fix TPM 1.2 NV Storage Command Size byte order 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 Signed-off-by: Derek Lin Reviewed-by: Chao Zhang Reviewed-by: Yao Jiewen --- SecurityPkg/Library/Tpm12CommandLib/Tpm12NvStorage.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/SecurityPkg/Library/Tpm12CommandLib/Tpm12NvStorage.c b/SecurityPkg/Library/Tpm12CommandLib/Tpm12NvStorage.c index 7baafa8f55..e176b00f6b 100644 --- a/SecurityPkg/Library/Tpm12CommandLib/Tpm12NvStorage.c +++ b/SecurityPkg/Library/Tpm12CommandLib/Tpm12NvStorage.c @@ -2,6 +2,7 @@ Implement TPM1.2 NV storage related command. Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
+(C) Copyright 2016 Hewlett Packard Enterprise Development LP
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -199,8 +200,9 @@ Tpm12NvWriteValue ( { EFI_STATUS Status; TPM_CMD_NV_WRITE_VALUE Command; + UINT32 CommandLength; TPM_RSP_COMMAND_HDR Response; - UINT32 Length; + UINT32 ResponseLength; if (DataSize > sizeof (Command.Data)) { return EFI_UNSUPPORTED; @@ -210,14 +212,15 @@ Tpm12NvWriteValue ( // send Tpm command TPM_ORD_NV_WriteValue // Command.Hdr.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND); - Command.Hdr.paramSize = SwapBytes32 (sizeof (Command) - sizeof(Command.Data) + DataSize); + CommandLength = sizeof (Command) - sizeof(Command.Data) + DataSize; + Command.Hdr.paramSize = SwapBytes32 (CommandLength); Command.Hdr.ordinal = SwapBytes32 (TPM_ORD_NV_WriteValue); Command.NvIndex = SwapBytes32 (NvIndex); Command.Offset = SwapBytes32 (Offset); Command.DataSize = SwapBytes32 (DataSize); CopyMem (Command.Data, Data, DataSize); - Length = sizeof (Response); - Status = Tpm12SubmitCommand (Command.Hdr.paramSize, (UINT8 *)&Command, &Length, (UINT8 *)&Response); + ResponseLength = sizeof (Response); + Status = Tpm12SubmitCommand (CommandLength, (UINT8 *)&Command, &ResponseLength, (UINT8 *)&Response); if (EFI_ERROR (Status)) { return Status; } -- 2.39.2