Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TpmFailureMode: Add missing request size checks #105

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions TPMCmd/tpm/src/support/TpmFail.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,9 @@ void TpmFailureMode(unsigned int inRequestSize, // IN: command buffer size
UINT8* buffer = inRequest;
INT32 size = inRequestSize;

// If there is no command buffer, then just return TPM_RC_FAILURE
if(inRequestSize == 0 || inRequest == NULL)
// If there is no command buffer or it is too small,
// then just return TPM_RC_FAILURE
if(inRequestSize < 10 || inRequest == NULL)
goto FailureModeReturn;
// If the header is not correct for TPM2_GetCapability() or
// TPM2_GetTestResult() then just return the in failure mode response;
Expand All @@ -257,6 +258,8 @@ void TpmFailureMode(unsigned int inRequestSize, // IN: command buffer size
goto FailureModeReturn;
if(header.tag != TPM_ST_NO_SESSIONS || header.size < 10)
goto FailureModeReturn;
if(header.size != inRequestSize || header.size > MAX_COMMAND_SIZE)
goto FailureModeReturn;
switch(header.code)
{
case TPM_CC_GetTestResult:
Expand Down Expand Up @@ -420,4 +423,4 @@ void UnmarshalFail(void* type, BYTE** buffer, INT32* size)
NOT_REFERENCED(buffer);
NOT_REFERENCED(size);
FAIL(FATAL_ERROR_INTERNAL);
}
}