SecurityPkg Tpm2CommandLib: Fix TPM2.0 response memory overflow
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>
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
Implement TPM2 NVStorage related command.
|
||||
|
||||
Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved. <BR>
|
||||
Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>
|
||||
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
|
||||
@ -234,10 +234,19 @@ Tpm2NvReadPublic (
|
||||
// Basic check
|
||||
//
|
||||
NvPublicSize = SwapBytes16 (RecvBuffer.NvPublic.size);
|
||||
if (NvPublicSize > sizeof(TPMS_NV_PUBLIC)) {
|
||||
DEBUG ((DEBUG_ERROR, "Tpm2NvReadPublic - NvPublic.size error %x\n", NvPublicSize));
|
||||
return EFI_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
NvNameSize = SwapBytes16 (ReadUnaligned16 ((UINT16 *)((UINT8 *)&RecvBuffer + sizeof(TPM2_RESPONSE_HEADER) + sizeof(UINT16) + NvPublicSize)));
|
||||
if (NvNameSize > sizeof(TPMU_NAME)){
|
||||
DEBUG ((DEBUG_ERROR, "Tpm2NvReadPublic - NvNameSize error %x\n", NvNameSize));
|
||||
return EFI_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
if (RecvBufferSize != sizeof(TPM2_RESPONSE_HEADER) + sizeof(UINT16) + NvPublicSize + sizeof(UINT16) + NvNameSize) {
|
||||
DEBUG ((EFI_D_ERROR, "Tpm2NvReadPublic - RecvBufferSize Error - NvPublicSize %x, NvNameSize %x\n", RecvBufferSize, NvNameSize));
|
||||
DEBUG ((EFI_D_ERROR, "Tpm2NvReadPublic - RecvBufferSize Error - NvPublicSize %x\n", RecvBufferSize));
|
||||
return EFI_NOT_FOUND;
|
||||
}
|
||||
|
||||
@ -632,6 +641,12 @@ Tpm2NvRead (
|
||||
// Return the response
|
||||
//
|
||||
OutData->size = SwapBytes16 (RecvBuffer.Data.size);
|
||||
if (OutData->size > MAX_DIGEST_BUFFER) {
|
||||
DEBUG ((DEBUG_ERROR, "Tpm2NvRead - OutData->size error %x\n", OutData->size));
|
||||
Status = EFI_DEVICE_ERROR;
|
||||
goto Done;
|
||||
}
|
||||
|
||||
CopyMem (OutData->buffer, &RecvBuffer.Data.buffer, OutData->size);
|
||||
|
||||
Done:
|
||||
|
Reference in New Issue
Block a user