Skip to content

Commit 4a5c755

Browse files
authored
Merge pull request #437 from LinuxJedi/zp-fixes
Fix things found using ZeroPath
2 parents de4f085 + 4f6282b commit 4a5c755

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/tpm2.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,21 @@ static int TPM2_ResponseProcess(TPM2_CTX* ctx, TPM2_Packet* packet,
332332
}
333333

334334
#if !defined(WOLFTPM2_NO_WOLFCRYPT) && !defined(NO_HMAC)
335-
if (authRsp.hmac.size > 0) {
335+
if (TPM2_IS_HMAC_SESSION(session->sessionHandle) ||
336+
TPM2_IS_POLICY_SESSION(session->sessionHandle))
337+
{
338+
UINT16 expectedHmacSz = TPM2_GetHashDigestSize(session->authHash);
336339
TPM2B_DIGEST hash;
337340
TPM2B_AUTH hmac;
338341

342+
if (expectedHmacSz == 0 || authRsp.hmac.size != expectedHmacSz) {
343+
#ifdef DEBUG_WOLFTPM
344+
printf("Response HMAC size mismatch! expected=%u got=%u\n",
345+
expectedHmacSz, authRsp.hmac.size);
346+
#endif
347+
return TPM_RC_HMAC;
348+
}
349+
339350
/* calculate "rpHash" hash for command code and parameters */
340351
rc = TPM2_CalcRpHash(session->authHash, cmdCode, param, paramSz,
341352
&hash);
@@ -5472,9 +5483,16 @@ TPM_RC TPM2_GetProductInfo(uint8_t* info, uint16_t size)
54725483
*/
54735484

54745485
/* start of product info starts at byte 26 */
5475-
if (size > packet.size - 26)
5476-
size = packet.size - 26;
5477-
XMEMCPY(info, &packet.buf[25], size);
5486+
if (packet.size <= 26) {
5487+
rc = TPM_RC_SIZE;
5488+
}
5489+
else if (size > 0) {
5490+
size_t payloadSz = (size_t)(packet.size - 26);
5491+
if (payloadSz > (size_t)size) {
5492+
payloadSz = (size_t)size;
5493+
}
5494+
XMEMCPY(info, &packet.buf[25], payloadSz);
5495+
}
54785496
}
54795497
TPM2_ReleaseLock(ctx);
54805498
}

0 commit comments

Comments
 (0)