Skip to content

Commit ae73063

Browse files
committed
Enforce TPM response HMAC length checks
Reject zero-length or mismatched response HMACs for authenticated sessions so forged SWTPM replies fail verification.
1 parent de4f085 commit ae73063

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/tpm2.c

Lines changed: 12 additions & 1 deletion
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);

0 commit comments

Comments
 (0)