TPM2.0 command lib always assumes TPM device and transmission channel can
respond correctly. But it is not true when communication channel is exploited
and wrong data is spoofed. Add more logic to prohibit memory overflow attack.
Cc: Long Qin <qin.long@intel.com>
Cc: Yao Jiewen <jiewen.yao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chao Zhang <chao.b.zhang@intel.com>
Reviewed-by: Long Qin <qin.long@intel.com>
Reviewed-by: Yao Jiewen <jiewen.yao@intel.com>
/** @file\r
Implement TPM2 Capability related command.\r
\r
/** @file\r
Implement TPM2 Capability related command.\r
\r
-Copyright (c) 2013 - 2016, 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
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
return EFI_DEVICE_ERROR;\r
}\r
\r
return EFI_DEVICE_ERROR;\r
}\r
\r
+ //\r
+ // Fail if command failed\r
+ //\r
+ if (SwapBytes32(RecvBuffer.Header.responseCode) != TPM_RC_SUCCESS) {\r
+ DEBUG ((EFI_D_ERROR, "Tpm2GetCapability: Response Code error! 0x%08x\r\n", SwapBytes32(RecvBuffer.Header.responseCode)));\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
+\r
//\r
// Return the response\r
//\r
//\r
// Return the response\r
//\r
CopyMem (AlgList, &TpmCap.data.algorithms, sizeof (TPML_ALG_PROPERTY));\r
\r
AlgList->count = SwapBytes32 (AlgList->count);\r
CopyMem (AlgList, &TpmCap.data.algorithms, sizeof (TPML_ALG_PROPERTY));\r
\r
AlgList->count = SwapBytes32 (AlgList->count);\r
+ if (AlgList->count > MAX_CAP_ALGS) {\r
+ DEBUG ((DEBUG_ERROR, "Tpm2GetCapabilitySupportedAlg - AlgList->count error %x\n", AlgList->count));\r
+ return EFI_DEVICE_ERROR; \r
+ }\r
+\r
for (Index = 0; Index < AlgList->count; Index++) {\r
AlgList->algProperties[Index].alg = SwapBytes16 (AlgList->algProperties[Index].alg);\r
WriteUnaligned32 ((UINT32 *)&AlgList->algProperties[Index].algProperties, SwapBytes32 (ReadUnaligned32 ((UINT32 *)&AlgList->algProperties[Index].algProperties)));\r
for (Index = 0; Index < AlgList->count; Index++) {\r
AlgList->algProperties[Index].alg = SwapBytes16 (AlgList->algProperties[Index].alg);\r
WriteUnaligned32 ((UINT32 *)&AlgList->algProperties[Index].algProperties, SwapBytes32 (ReadUnaligned32 ((UINT32 *)&AlgList->algProperties[Index].algProperties)));\r
}\r
\r
Pcrs->count = SwapBytes32 (TpmCap.data.assignedPCR.count);\r
}\r
\r
Pcrs->count = SwapBytes32 (TpmCap.data.assignedPCR.count);\r
+ if (Pcrs->count > HASH_COUNT) {\r
+ DEBUG ((DEBUG_ERROR, "Tpm2GetCapabilityPcrs - Pcrs->count error %x\n", Pcrs->count));\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
+\r
for (Index = 0; Index < Pcrs->count; Index++) {\r
Pcrs->pcrSelections[Index].hash = SwapBytes16 (TpmCap.data.assignedPCR.pcrSelections[Index].hash);\r
Pcrs->pcrSelections[Index].sizeofSelect = TpmCap.data.assignedPCR.pcrSelections[Index].sizeofSelect;\r
for (Index = 0; Index < Pcrs->count; Index++) {\r
Pcrs->pcrSelections[Index].hash = SwapBytes16 (TpmCap.data.assignedPCR.pcrSelections[Index].hash);\r
Pcrs->pcrSelections[Index].sizeofSelect = TpmCap.data.assignedPCR.pcrSelections[Index].sizeofSelect;\r
+ if (Pcrs->pcrSelections[Index].sizeofSelect > PCR_SELECT_MAX) {\r
+ DEBUG ((DEBUG_ERROR, "Tpm2GetCapabilityPcrs - sizeofSelect error %x\n", Pcrs->pcrSelections[Index].sizeofSelect));\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
CopyMem (Pcrs->pcrSelections[Index].pcrSelect, TpmCap.data.assignedPCR.pcrSelections[Index].pcrSelect, Pcrs->pcrSelections[Index].sizeofSelect);\r
}\r
\r
CopyMem (Pcrs->pcrSelections[Index].pcrSelect, TpmCap.data.assignedPCR.pcrSelections[Index].pcrSelect, Pcrs->pcrSelections[Index].sizeofSelect);\r
}\r
\r
/** @file\r
Implement TPM2 EnhancedAuthorization related command.\r
\r
/** @file\r
Implement TPM2 EnhancedAuthorization related command.\r
\r
-Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved. <BR>\r
+Copyright (c) 2014 - 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
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
//\r
Buffer = (UINT8 *)&RecvBuffer.Timeout;\r
Timeout->size = SwapBytes16(ReadUnaligned16 ((UINT16 *)Buffer));\r
//\r
Buffer = (UINT8 *)&RecvBuffer.Timeout;\r
Timeout->size = SwapBytes16(ReadUnaligned16 ((UINT16 *)Buffer));\r
+ if (Timeout->size > sizeof(UINT64)) {\r
+ DEBUG ((DEBUG_ERROR, "Tpm2PolicySecret - Timeout->size error %x\n", Timeout->size));\r
+ Status = EFI_DEVICE_ERROR;\r
+ goto Done;\r
+ }\r
+\r
Buffer += sizeof(UINT16);\r
CopyMem (Timeout->buffer, Buffer, Timeout->size);\r
\r
Buffer += sizeof(UINT16);\r
CopyMem (Timeout->buffer, Buffer, Timeout->size);\r
\r
Buffer += sizeof(UINT32);\r
PolicyTicket->digest.size = SwapBytes16(ReadUnaligned16 ((UINT16 *)Buffer));\r
Buffer += sizeof(UINT16);\r
Buffer += sizeof(UINT32);\r
PolicyTicket->digest.size = SwapBytes16(ReadUnaligned16 ((UINT16 *)Buffer));\r
Buffer += sizeof(UINT16);\r
+ if (PolicyTicket->digest.size > sizeof(TPMU_HA)) {\r
+ DEBUG ((DEBUG_ERROR, "Tpm2PolicySecret - digest.size error %x\n", PolicyTicket->digest.size));\r
+ Status = EFI_DEVICE_ERROR;\r
+ goto Done;\r
+ }\r
+\r
CopyMem (PolicyTicket->digest.buffer, Buffer, PolicyTicket->digest.size);\r
\r
Done:\r
CopyMem (PolicyTicket->digest.buffer, Buffer, PolicyTicket->digest.size);\r
\r
Done:\r
// Return the response\r
//\r
PolicyHash->size = SwapBytes16 (RecvBuffer.PolicyHash.size);\r
// Return the response\r
//\r
PolicyHash->size = SwapBytes16 (RecvBuffer.PolicyHash.size);\r
+ if (PolicyHash->size > sizeof(TPMU_HA)) {\r
+ DEBUG ((DEBUG_ERROR, "Tpm2PolicyGetDigest - PolicyHash->size error %x\n", PolicyHash->size));\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
+\r
CopyMem (PolicyHash->buffer, &RecvBuffer.PolicyHash.buffer, PolicyHash->size);\r
\r
return EFI_SUCCESS;\r
CopyMem (PolicyHash->buffer, &RecvBuffer.PolicyHash.buffer, PolicyHash->size);\r
\r
return EFI_SUCCESS;\r
/** @file\r
Implement TPM2 help.\r
\r
/** @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
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
@param [in] AuthSessionIn Input AuthSession data in TPM2 response buffer\r
@param [out] AuthSessionOut Output AuthSession data\r
\r
@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
// nonce\r
AuthSessionOut->nonce.size = SwapBytes16 (ReadUnaligned16 ((UINT16 *)Buffer));\r
Buffer += sizeof(UINT16);\r
// 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
\r
CopyMem (AuthSessionOut->nonce.buffer, Buffer, AuthSessionOut->nonce.size);\r
Buffer += AuthSessionOut->nonce.size;\r
// hmac\r
AuthSessionOut->hmac.size = SwapBytes16 (ReadUnaligned16 ((UINT16 *)Buffer));\r
Buffer += sizeof(UINT16);\r
// 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
\r
CopyMem (AuthSessionOut->hmac.buffer, Buffer, AuthSessionOut->hmac.size);\r
Buffer += AuthSessionOut->hmac.size;\r
/** @file\r
Implement TPM2 Integrity related command.\r
\r
/** @file\r
Implement TPM2 Integrity related command.\r
\r
-Copyright (c) 2013 - 2016, 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
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
Buffer = (UINT8 *)&Res.Digests;\r
\r
Digests->count = SwapBytes32 (ReadUnaligned32 ((UINT32 *)Buffer));\r
Buffer = (UINT8 *)&Res.Digests;\r
\r
Digests->count = SwapBytes32 (ReadUnaligned32 ((UINT32 *)Buffer));\r
+ if (Digests->count > HASH_COUNT) {\r
+ DEBUG ((DEBUG_ERROR, "Tpm2PcrEvent - Digests->count error %x\n", Digests->count));\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
+\r
Buffer += sizeof(UINT32);\r
for (Index = 0; Index < Digests->count; Index++) {\r
Digests->digests[Index].hashAlg = SwapBytes16 (ReadUnaligned16 ((UINT16 *)Buffer));\r
Buffer += sizeof(UINT32);\r
for (Index = 0; Index < Digests->count; Index++) {\r
Digests->digests[Index].hashAlg = SwapBytes16 (ReadUnaligned16 ((UINT16 *)Buffer));\r
return EFI_DEVICE_ERROR;\r
}\r
PcrSelectionOut->count = SwapBytes32(RecvBuffer.PcrSelectionOut.count);\r
return EFI_DEVICE_ERROR;\r
}\r
PcrSelectionOut->count = SwapBytes32(RecvBuffer.PcrSelectionOut.count);\r
+ if (PcrSelectionOut->count > HASH_COUNT) {\r
+ DEBUG ((DEBUG_ERROR, "Tpm2PcrRead - PcrSelectionOut->count error %x\n", PcrSelectionOut->count));\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
+\r
if (RecvBufferSize < sizeof (TPM2_RESPONSE_HEADER) + sizeof(RecvBuffer.PcrUpdateCounter) + sizeof(RecvBuffer.PcrSelectionOut.count) + sizeof(RecvBuffer.PcrSelectionOut.pcrSelections[0]) * PcrSelectionOut->count) {\r
DEBUG ((EFI_D_ERROR, "Tpm2PcrRead - RecvBufferSize Error - %x\n", RecvBufferSize));\r
return EFI_DEVICE_ERROR;\r
if (RecvBufferSize < sizeof (TPM2_RESPONSE_HEADER) + sizeof(RecvBuffer.PcrUpdateCounter) + sizeof(RecvBuffer.PcrSelectionOut.count) + sizeof(RecvBuffer.PcrSelectionOut.pcrSelections[0]) * PcrSelectionOut->count) {\r
DEBUG ((EFI_D_ERROR, "Tpm2PcrRead - RecvBufferSize Error - %x\n", RecvBufferSize));\r
return EFI_DEVICE_ERROR;\r
for (Index = 0; Index < PcrSelectionOut->count; Index++) {\r
PcrSelectionOut->pcrSelections[Index].hash = SwapBytes16(RecvBuffer.PcrSelectionOut.pcrSelections[Index].hash);\r
PcrSelectionOut->pcrSelections[Index].sizeofSelect = RecvBuffer.PcrSelectionOut.pcrSelections[Index].sizeofSelect;\r
for (Index = 0; Index < PcrSelectionOut->count; Index++) {\r
PcrSelectionOut->pcrSelections[Index].hash = SwapBytes16(RecvBuffer.PcrSelectionOut.pcrSelections[Index].hash);\r
PcrSelectionOut->pcrSelections[Index].sizeofSelect = RecvBuffer.PcrSelectionOut.pcrSelections[Index].sizeofSelect;\r
+ if (PcrSelectionOut->pcrSelections[Index].sizeofSelect > PCR_SELECT_MAX) {\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
CopyMem (&PcrSelectionOut->pcrSelections[Index].pcrSelect, &RecvBuffer.PcrSelectionOut.pcrSelections[Index].pcrSelect, PcrSelectionOut->pcrSelections[Index].sizeofSelect);\r
}\r
\r
CopyMem (&PcrSelectionOut->pcrSelections[Index].pcrSelect, &RecvBuffer.PcrSelectionOut.pcrSelections[Index].pcrSelect, PcrSelectionOut->pcrSelections[Index].sizeofSelect);\r
}\r
\r
//\r
PcrValuesOut = (TPML_DIGEST *)((UINT8 *)&RecvBuffer + sizeof (TPM2_RESPONSE_HEADER) + sizeof(RecvBuffer.PcrUpdateCounter) + sizeof(RecvBuffer.PcrSelectionOut.count) + sizeof(RecvBuffer.PcrSelectionOut.pcrSelections[0]) * PcrSelectionOut->count);\r
PcrValues->count = SwapBytes32(PcrValuesOut->count);\r
//\r
PcrValuesOut = (TPML_DIGEST *)((UINT8 *)&RecvBuffer + sizeof (TPM2_RESPONSE_HEADER) + sizeof(RecvBuffer.PcrUpdateCounter) + sizeof(RecvBuffer.PcrSelectionOut.count) + sizeof(RecvBuffer.PcrSelectionOut.pcrSelections[0]) * PcrSelectionOut->count);\r
PcrValues->count = SwapBytes32(PcrValuesOut->count);\r
+ //\r
+ // The number of digests in list is not greater than 8 per TPML_DIGEST definition\r
+ //\r
+ if (PcrValues->count > 8) {\r
+ DEBUG ((DEBUG_ERROR, "Tpm2PcrRead - PcrValues->count error %x\n", PcrValues->count));\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
Digests = PcrValuesOut->digests;\r
for (Index = 0; Index < PcrValues->count; Index++) {\r
PcrValues->digests[Index].size = SwapBytes16(Digests->size);\r
Digests = PcrValuesOut->digests;\r
for (Index = 0; Index < PcrValues->count; Index++) {\r
PcrValues->digests[Index].size = SwapBytes16(Digests->size);\r
+ if (PcrValues->digests[Index].size > sizeof(TPMU_HA)) {\r
+ DEBUG ((DEBUG_ERROR, "Tpm2PcrRead - Digest.size error %x\n", PcrValues->digests[Index].size));\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
CopyMem (&PcrValues->digests[Index].buffer, &Digests->buffer, PcrValues->digests[Index].size);\r
Digests = (TPM2B_DIGEST *)((UINT8 *)Digests + sizeof(Digests->size) + PcrValues->digests[Index].size);\r
}\r
CopyMem (&PcrValues->digests[Index].buffer, &Digests->buffer, PcrValues->digests[Index].size);\r
Digests = (TPM2B_DIGEST *)((UINT8 *)Digests + sizeof(Digests->size) + PcrValues->digests[Index].size);\r
}\r
/** @file\r
Implement TPM2 NVStorage related command.\r
\r
/** @file\r
Implement TPM2 NVStorage related command.\r
\r
-Copyright (c) 2013 - 2016, 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
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
// Basic check\r
//\r
NvPublicSize = SwapBytes16 (RecvBuffer.NvPublic.size);\r
// Basic check\r
//\r
NvPublicSize = SwapBytes16 (RecvBuffer.NvPublic.size);\r
+ if (NvPublicSize > sizeof(TPMS_NV_PUBLIC)) {\r
+ DEBUG ((DEBUG_ERROR, "Tpm2NvReadPublic - NvPublic.size error %x\n", NvPublicSize));\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
+\r
NvNameSize = SwapBytes16 (ReadUnaligned16 ((UINT16 *)((UINT8 *)&RecvBuffer + sizeof(TPM2_RESPONSE_HEADER) + sizeof(UINT16) + NvPublicSize)));\r
NvNameSize = SwapBytes16 (ReadUnaligned16 ((UINT16 *)((UINT8 *)&RecvBuffer + sizeof(TPM2_RESPONSE_HEADER) + sizeof(UINT16) + NvPublicSize)));\r
+ if (NvNameSize > sizeof(TPMU_NAME)){\r
+ DEBUG ((DEBUG_ERROR, "Tpm2NvReadPublic - NvNameSize error %x\n", NvNameSize));\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
\r
if (RecvBufferSize != sizeof(TPM2_RESPONSE_HEADER) + sizeof(UINT16) + NvPublicSize + sizeof(UINT16) + NvNameSize) {\r
\r
if (RecvBufferSize != sizeof(TPM2_RESPONSE_HEADER) + sizeof(UINT16) + NvPublicSize + sizeof(UINT16) + NvNameSize) {\r
- DEBUG ((EFI_D_ERROR, "Tpm2NvReadPublic - RecvBufferSize Error - NvPublicSize %x, NvNameSize %x\n", RecvBufferSize, NvNameSize));\r
+ DEBUG ((EFI_D_ERROR, "Tpm2NvReadPublic - RecvBufferSize Error - NvPublicSize %x\n", RecvBufferSize));\r
return EFI_NOT_FOUND;\r
}\r
\r
return EFI_NOT_FOUND;\r
}\r
\r
// Return the response\r
//\r
OutData->size = SwapBytes16 (RecvBuffer.Data.size);\r
// Return the response\r
//\r
OutData->size = SwapBytes16 (RecvBuffer.Data.size);\r
+ if (OutData->size > MAX_DIGEST_BUFFER) {\r
+ DEBUG ((DEBUG_ERROR, "Tpm2NvRead - OutData->size error %x\n", OutData->size));\r
+ Status = EFI_DEVICE_ERROR;\r
+ goto Done;\r
+ }\r
+\r
CopyMem (OutData->buffer, &RecvBuffer.Data.buffer, OutData->size);\r
\r
Done:\r
CopyMem (OutData->buffer, &RecvBuffer.Data.buffer, OutData->size);\r
\r
Done:\r
/** @file\r
Implement TPM2 Object related command.\r
\r
/** @file\r
Implement TPM2 Object related command.\r
\r
-Copyright (c) 2017, Intel Corporation. All rights reserved. <BR>\r
+Copyright (c) 2017 - 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
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
// Basic check\r
//\r
OutPublicSize = SwapBytes16 (RecvBuffer.OutPublic.size);\r
// Basic check\r
//\r
OutPublicSize = SwapBytes16 (RecvBuffer.OutPublic.size);\r
+ if (OutPublicSize > sizeof(TPMT_PUBLIC)) {\r
+ DEBUG ((DEBUG_ERROR, "Tpm2ReadPublic - OutPublicSize error %x\n", OutPublicSize));\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
+\r
NameSize = SwapBytes16 (ReadUnaligned16 ((UINT16 *)((UINT8 *)&RecvBuffer + sizeof(TPM2_RESPONSE_HEADER) +\r
sizeof(UINT16) + OutPublicSize)));\r
NameSize = SwapBytes16 (ReadUnaligned16 ((UINT16 *)((UINT8 *)&RecvBuffer + sizeof(TPM2_RESPONSE_HEADER) +\r
sizeof(UINT16) + OutPublicSize)));\r
+ if (NameSize > sizeof(TPMU_NAME)) {\r
+ DEBUG ((DEBUG_ERROR, "Tpm2ReadPublic - NameSize error %x\n", NameSize));\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
+\r
QualifiedNameSize = SwapBytes16 (ReadUnaligned16 ((UINT16 *)((UINT8 *)&RecvBuffer + sizeof(TPM2_RESPONSE_HEADER) +\r
sizeof(UINT16) + OutPublicSize +\r
sizeof(UINT16) + NameSize)));\r
QualifiedNameSize = SwapBytes16 (ReadUnaligned16 ((UINT16 *)((UINT8 *)&RecvBuffer + sizeof(TPM2_RESPONSE_HEADER) +\r
sizeof(UINT16) + OutPublicSize +\r
sizeof(UINT16) + NameSize)));\r
+ if (QualifiedNameSize > sizeof(TPMU_NAME)) {\r
+ DEBUG ((DEBUG_ERROR, "Tpm2ReadPublic - QualifiedNameSize error %x\n", QualifiedNameSize));\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
\r
if (RecvBufferSize != sizeof(TPM2_RESPONSE_HEADER) + sizeof(UINT16) + OutPublicSize + sizeof(UINT16) + NameSize + sizeof(UINT16) + QualifiedNameSize) {\r
DEBUG ((DEBUG_ERROR, "Tpm2ReadPublic - RecvBufferSize %x Error - OutPublicSize %x, NameSize %x, QualifiedNameSize %x\n", RecvBufferSize, OutPublicSize, NameSize, QualifiedNameSize));\r
\r
if (RecvBufferSize != sizeof(TPM2_RESPONSE_HEADER) + sizeof(UINT16) + OutPublicSize + sizeof(UINT16) + NameSize + sizeof(UINT16) + QualifiedNameSize) {\r
DEBUG ((DEBUG_ERROR, "Tpm2ReadPublic - RecvBufferSize %x Error - OutPublicSize %x, NameSize %x, QualifiedNameSize %x\n", RecvBufferSize, OutPublicSize, NameSize, QualifiedNameSize));\r
Buffer = (UINT8 *)&RecvBuffer.OutPublic.publicArea.authPolicy;\r
OutPublic->publicArea.authPolicy.size = SwapBytes16 (ReadUnaligned16 ((UINT16 *)Buffer));\r
Buffer += sizeof(UINT16);\r
Buffer = (UINT8 *)&RecvBuffer.OutPublic.publicArea.authPolicy;\r
OutPublic->publicArea.authPolicy.size = SwapBytes16 (ReadUnaligned16 ((UINT16 *)Buffer));\r
Buffer += sizeof(UINT16);\r
+ if (OutPublic->publicArea.authPolicy.size > sizeof(TPMU_HA)) {\r
+ DEBUG ((DEBUG_ERROR, "Tpm2ReadPublic - authPolicy.size error %x\n", OutPublic->publicArea.authPolicy.size));\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
+\r
CopyMem (OutPublic->publicArea.authPolicy.buffer, Buffer, OutPublic->publicArea.authPolicy.size);\r
Buffer += OutPublic->publicArea.authPolicy.size;\r
\r
CopyMem (OutPublic->publicArea.authPolicy.buffer, Buffer, OutPublic->publicArea.authPolicy.size);\r
Buffer += OutPublic->publicArea.authPolicy.size;\r
\r
case TPM_ALG_KEYEDHASH:\r
OutPublic->publicArea.unique.keyedHash.size = SwapBytes16 (ReadUnaligned16 ((UINT16 *)Buffer));\r
Buffer += sizeof(UINT16);\r
case TPM_ALG_KEYEDHASH:\r
OutPublic->publicArea.unique.keyedHash.size = SwapBytes16 (ReadUnaligned16 ((UINT16 *)Buffer));\r
Buffer += sizeof(UINT16);\r
+ if(OutPublic->publicArea.unique.keyedHash.size > sizeof(TPMU_HA)) {\r
+ DEBUG ((DEBUG_ERROR, "Tpm2ReadPublic - keyedHash.size error %x\n", OutPublic->publicArea.unique.keyedHash.size));\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
CopyMem (OutPublic->publicArea.unique.keyedHash.buffer, Buffer, OutPublic->publicArea.unique.keyedHash.size);\r
Buffer += OutPublic->publicArea.unique.keyedHash.size;\r
break;\r
case TPM_ALG_SYMCIPHER:\r
OutPublic->publicArea.unique.sym.size = SwapBytes16 (ReadUnaligned16 ((UINT16 *)Buffer));\r
Buffer += sizeof(UINT16);\r
CopyMem (OutPublic->publicArea.unique.keyedHash.buffer, Buffer, OutPublic->publicArea.unique.keyedHash.size);\r
Buffer += OutPublic->publicArea.unique.keyedHash.size;\r
break;\r
case TPM_ALG_SYMCIPHER:\r
OutPublic->publicArea.unique.sym.size = SwapBytes16 (ReadUnaligned16 ((UINT16 *)Buffer));\r
Buffer += sizeof(UINT16);\r
+ if(OutPublic->publicArea.unique.sym.size > sizeof(TPMU_HA)) {\r
+ DEBUG ((DEBUG_ERROR, "Tpm2ReadPublic - sym.size error %x\n", OutPublic->publicArea.unique.sym.size));\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
CopyMem (OutPublic->publicArea.unique.sym.buffer, Buffer, OutPublic->publicArea.unique.sym.size);\r
Buffer += OutPublic->publicArea.unique.sym.size;\r
break;\r
case TPM_ALG_RSA:\r
OutPublic->publicArea.unique.rsa.size = SwapBytes16 (ReadUnaligned16 ((UINT16 *)Buffer));\r
Buffer += sizeof(UINT16);\r
CopyMem (OutPublic->publicArea.unique.sym.buffer, Buffer, OutPublic->publicArea.unique.sym.size);\r
Buffer += OutPublic->publicArea.unique.sym.size;\r
break;\r
case TPM_ALG_RSA:\r
OutPublic->publicArea.unique.rsa.size = SwapBytes16 (ReadUnaligned16 ((UINT16 *)Buffer));\r
Buffer += sizeof(UINT16);\r
+ if(OutPublic->publicArea.unique.rsa.size > MAX_RSA_KEY_BYTES) {\r
+ DEBUG ((DEBUG_ERROR, "Tpm2ReadPublic - rsa.size error %x\n", OutPublic->publicArea.unique.rsa.size));\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
CopyMem (OutPublic->publicArea.unique.rsa.buffer, Buffer, OutPublic->publicArea.unique.rsa.size);\r
Buffer += OutPublic->publicArea.unique.rsa.size;\r
break;\r
case TPM_ALG_ECC:\r
OutPublic->publicArea.unique.ecc.x.size = SwapBytes16 (ReadUnaligned16 ((UINT16 *)Buffer));\r
Buffer += sizeof(UINT16);\r
CopyMem (OutPublic->publicArea.unique.rsa.buffer, Buffer, OutPublic->publicArea.unique.rsa.size);\r
Buffer += OutPublic->publicArea.unique.rsa.size;\r
break;\r
case TPM_ALG_ECC:\r
OutPublic->publicArea.unique.ecc.x.size = SwapBytes16 (ReadUnaligned16 ((UINT16 *)Buffer));\r
Buffer += sizeof(UINT16);\r
+ if (OutPublic->publicArea.unique.ecc.x.size > MAX_ECC_KEY_BYTES) {\r
+ DEBUG ((DEBUG_ERROR, "Tpm2ReadPublic - ecc.x.size error %x\n", OutPublic->publicArea.unique.ecc.x.size));\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
CopyMem (OutPublic->publicArea.unique.ecc.x.buffer, Buffer, OutPublic->publicArea.unique.ecc.x.size);\r
Buffer += OutPublic->publicArea.unique.ecc.x.size;\r
OutPublic->publicArea.unique.ecc.y.size = SwapBytes16 (ReadUnaligned16 ((UINT16 *)Buffer));\r
Buffer += sizeof(UINT16);\r
CopyMem (OutPublic->publicArea.unique.ecc.x.buffer, Buffer, OutPublic->publicArea.unique.ecc.x.size);\r
Buffer += OutPublic->publicArea.unique.ecc.x.size;\r
OutPublic->publicArea.unique.ecc.y.size = SwapBytes16 (ReadUnaligned16 ((UINT16 *)Buffer));\r
Buffer += sizeof(UINT16);\r
+ if (OutPublic->publicArea.unique.ecc.y.size > MAX_ECC_KEY_BYTES) {\r
+ DEBUG ((DEBUG_ERROR, "Tpm2ReadPublic - ecc.y.size error %x\n", OutPublic->publicArea.unique.ecc.y.size));\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
CopyMem (OutPublic->publicArea.unique.ecc.y.buffer, Buffer, OutPublic->publicArea.unique.ecc.y.size);\r
Buffer += OutPublic->publicArea.unique.ecc.y.size;\r
break;\r
CopyMem (OutPublic->publicArea.unique.ecc.y.buffer, Buffer, OutPublic->publicArea.unique.ecc.y.size);\r
Buffer += OutPublic->publicArea.unique.ecc.y.size;\r
break;\r
/** @file\r
Implement TPM2 Sequences related command.\r
\r
/** @file\r
Implement TPM2 Sequences related command.\r
\r
-Copyright (c) 2013, 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
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
\r
// count\r
Results->count = SwapBytes32(ReadUnaligned32 ((UINT32 *)BufferPtr));\r
\r
// count\r
Results->count = SwapBytes32(ReadUnaligned32 ((UINT32 *)BufferPtr));\r
+ if (Results->count > HASH_COUNT) {\r
+ DEBUG ((DEBUG_ERROR, "Tpm2EventSequenceComplete - Results->count error %x\n", Results->count));\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
+\r
BufferPtr += sizeof(UINT32);\r
\r
for (Index = 0; Index < Results->count; Index++) {\r
BufferPtr += sizeof(UINT32);\r
\r
for (Index = 0; Index < Results->count; Index++) {\r
\r
// digestSize\r
Result->size = SwapBytes16(ReadUnaligned16 ((UINT16 *)BufferPtr));\r
\r
// digestSize\r
Result->size = SwapBytes16(ReadUnaligned16 ((UINT16 *)BufferPtr));\r
+ if (Result->size > sizeof(TPMU_HA)){\r
+ DEBUG ((DEBUG_ERROR, "Tpm2SequenceComplete - Result->size error %x\n", Result->size));\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
+\r
BufferPtr += sizeof(UINT16);\r
\r
CopyMem(\r
BufferPtr += sizeof(UINT16);\r
\r
CopyMem(\r
/** @file\r
Implement TPM2 Session related command.\r
\r
/** @file\r
Implement TPM2 Session related command.\r
\r
-Copyright (c) 2014, Intel Corporation. All rights reserved. <BR>\r
+Copyright (c) 2014 - 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
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
//\r
*SessionHandle = SwapBytes32 (RecvBuffer.SessionHandle);\r
NonceTPM->size = SwapBytes16 (RecvBuffer.NonceTPM.size);\r
//\r
*SessionHandle = SwapBytes32 (RecvBuffer.SessionHandle);\r
NonceTPM->size = SwapBytes16 (RecvBuffer.NonceTPM.size);\r
+ if (NonceTPM->size > sizeof(TPMU_HA)) {\r
+ DEBUG ((DEBUG_ERROR, "Tpm2StartAuthSession - NonceTPM->size error %x\n", NonceTPM->size));\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
+\r
CopyMem (NonceTPM->buffer, &RecvBuffer.NonceTPM.buffer, NonceTPM->size);\r
\r
return EFI_SUCCESS;\r
CopyMem (NonceTPM->buffer, &RecvBuffer.NonceTPM.buffer, NonceTPM->size);\r
\r
return EFI_SUCCESS;\r