Skip to content

Commit 36fad4d

Browse files
committed
- Fixed SPDM cleartext fallback in TPM2_SendCommand(): positive error codes from SPDM now return immediately
instead of falling through to cleartext retry - Fixed same SPDM cleartext fallback in TPM2_SendCommandAuth(): same pattern applied - Added VdCode validation in wolfTPM2_SPDM_SecuredExchange(): verifies response matches expected TPM2_CMD vendor code before accepting payload
1 parent 965a810 commit 36fad4d

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/tpm2.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,11 @@ static TPM_RC TPM2_SendCommandAuth(TPM2_CTX* ctx, TPM2_Packet* packet,
497497
/* submit command and wait for response */
498498
#ifdef WOLFTPM_SPDM
499499
rc = TPM2_SPDM_SendCommand(ctx, packet);
500-
if (rc < 0) /* SPDM not active, use normal transport */
500+
if (rc >= 0) {
501+
if (rc != TPM_RC_SUCCESS)
502+
return rc; /* SPDM active but failed, do not retry cleartext */
503+
}
504+
else /* rc < 0: SPDM not active, use normal transport */
501505
#endif
502506
{
503507
rc = (TPM_RC)INTERNAL_SEND_COMMAND(ctx, packet);
@@ -533,8 +537,11 @@ static TPM_RC TPM2_SendCommand(TPM2_CTX* ctx, TPM2_Packet* packet)
533537

534538
#ifdef WOLFTPM_SPDM
535539
rc = TPM2_SPDM_SendCommand(ctx, packet);
536-
if (rc == TPM_RC_SUCCESS)
540+
if (rc >= 0) {
541+
if (rc != TPM_RC_SUCCESS)
542+
return rc; /* SPDM active but failed, do not retry cleartext */
537543
return TPM2_Packet_Parse(rc, packet);
544+
}
538545
/* rc < 0 means SPDM not active, fall through to normal transport */
539546
#endif
540547

src/tpm2_spdm.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,12 @@ int wolfTPM2_SPDM_SecuredExchange(
245245
return rc;
246246
}
247247

248+
/* Verify response is for our TPM2_CMD request */
249+
if (XMEMCMP(rspVdCode, WOLFSPDM_VDCODE_TPM2_CMD,
250+
WOLFSPDM_VDCODE_LEN) != 0) {
251+
return WOLFSPDM_E_PEER_ERROR;
252+
}
253+
248254
return TPM_RC_SUCCESS;
249255
}
250256
#endif /* WOLFTPM_SPDM_TCG */

0 commit comments

Comments
 (0)