Skip to content

Commit 3e95d5f

Browse files
authored
Merge pull request #561 from aidangarske/fenrir-fixes-7263-7285
Fix fwTPM response buffer overflow, SPDM clear-frame command bypass, and other misc hardening
2 parents e49da0f + 6cbf2d1 commit 3e95d5f

25 files changed

Lines changed: 943 additions & 128 deletions

examples/bench/bench.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ static int bench_sym_aes(WOLFTPM2_DEV* dev, WOLFTPM2_KEY* storageKey,
191191
if (rc != 0) goto exit;
192192
rc = wolfTPM2_CreateAndLoadKey(dev, &aesKey, &storageKey->handle,
193193
&publicTemplate, (byte*)gUsageAuth, sizeof(gUsageAuth)-1);
194-
if ((rc & TPM_RC_MODE) == TPM_RC_MODE || (rc & TPM_RC_VALUE) == TPM_RC_VALUE) {
194+
if ((rc & RC_MAX_FMT1) == TPM_RC_MODE ||
195+
(rc & RC_MAX_FMT1) == TPM_RC_VALUE) {
195196
printf("Benchmark symmetric %s not supported!\n", desc);
196197
rc = 0; goto exit;
197198
}
@@ -234,6 +235,7 @@ static int bench_pqc_mldsa(WOLFTPM2_DEV* dev, double maxDuration,
234235
XMEMSET(&mldsaKey, 0, sizeof(mldsaKey));
235236
XMEMSET(&publicTemplate, 0, sizeof(publicTemplate));
236237
XMEMSET(message, 0x11, sizeof(message));
238+
XMEMSET(sig, 0, sizeof(sig));
237239

238240
rc = wolfTPM2_GetKeyTemplate_MLDSA(&publicTemplate,
239241
TPMA_OBJECT_sign | TPMA_OBJECT_fixedTPM | TPMA_OBJECT_fixedParent |
@@ -275,6 +277,8 @@ static int bench_pqc_mldsa(WOLFTPM2_DEV* dev, double maxDuration,
275277
} while (bench_stats_check(start, &count, maxDuration));
276278
rc = bench_asym_done("ML-DSA", 65, "sign", count, start, rc);
277279
if (rc != 0) goto exit;
280+
if (count == 0)
281+
goto exit; /* no signature produced; nothing to verify */
278282

279283
bench_stats_start(&count, &start);
280284
do {

examples/nvram/read.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ int TPM2_NVRAM_Read_Example(void* userCtx, int argc, char *argv[])
187187

188188
printf("NV Read: Attributes 0x%08x\n", nv.attributes);
189189

190-
if (((nv.attributes & TPMA_NV_TPM_NT) >> 4) & TPM_NT_EXTEND) {
190+
if (((nv.attributes & TPMA_NV_TPM_NT) >> 4) == TPM_NT_EXTEND) {
191191
byte digest[TPM_SHA256_DIGEST_SIZE];
192192
word32 digestLen = (word32)sizeof(digest);
193193
printf("NV Read Extend\n");

examples/pcr/policy.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,15 @@ int TPM2_PCR_Policy_Test(void* userCtx, int argc, char *argv[])
145145
}
146146
printf("wolfTPM2_Init: success\n");
147147

148-
if (paramEncAlg != TPM_ALG_NULL) {
149-
/* Start an authenticated policy session (salted / unbound) */
150-
rc = wolfTPM2_StartSession(&dev, &tpmSession, NULL, NULL,
151-
TPM_SE_POLICY, paramEncAlg);
152-
if (rc != 0) goto exit;
153-
printf("TPM2_StartAuthSession: sessionHandle 0x%x\n",
154-
(word32)tpmSession.handle.hndl);
148+
/* Start an authenticated policy session (salted / unbound) */
149+
rc = wolfTPM2_StartSession(&dev, &tpmSession, NULL, NULL,
150+
TPM_SE_POLICY, paramEncAlg);
151+
if (rc != 0) goto exit;
152+
printf("TPM2_StartAuthSession: sessionHandle 0x%x\n",
153+
(word32)tpmSession.handle.hndl);
155154

156-
/* set session for authorization of the storage key */
155+
if (paramEncAlg != TPM_ALG_NULL) {
156+
/* set session for parameter encryption */
157157
rc = wolfTPM2_SetAuthSession(&dev, 0, &tpmSession,
158158
(TPMA_SESSION_decrypt | TPMA_SESSION_encrypt | TPMA_SESSION_continueSession));
159159
if (rc != 0) goto exit;

examples/pcr/quote.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ int TPM2_PCR_Quote_Test(void* userCtx, int argc, char *argv[])
210210
pubKey = (byte*)XMALLOC(pubKeySz, NULL, DYNAMIC_TYPE_PUBLIC_KEY);
211211
if (pubKey == NULL) {
212212
printf("Failed to malloc buffer for public key\n");
213+
rc = MEMORY_E;
213214
goto exit;
214215
}
215216

examples/run_examples.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,23 @@ if [ $WOLFCRYPT_ENABLE -eq 1 ]; then
835835
fi
836836
rm -f zip.quote
837837

838+
# PCR Policy tests
839+
echo -e "PCR Policy tests"
840+
./examples/pcr/policy 16 >> $TPMPWD/run.out 2>&1
841+
RESULT=$?
842+
[ $RESULT -ne 0 ] && echo -e "pcr policy failed! $RESULT" && exit 1
843+
if [ $WOLFCRYPT_ENABLE -eq 1 ]; then
844+
./examples/pcr/policy 16 -xor >> $TPMPWD/run.out 2>&1
845+
RESULT=$?
846+
[ $RESULT -ne 0 ] && echo -e "pcr policy param enc xor failed! $RESULT" && exit 1
847+
848+
if [ $WOLFCRYPT_DEFAULT -eq 0 ]; then
849+
./examples/pcr/policy 16 -aes >> $TPMPWD/run.out 2>&1
850+
RESULT=$?
851+
[ $RESULT -ne 0 ] && echo -e "pcr policy param enc aes failed! $RESULT" && exit 1
852+
fi
853+
fi
854+
838855

839856
# Benchmark tests
840857
echo -e "Benchmark tests"

hal/tpm_io.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@ int TPM2_IoCb(TPM2_CTX* ctx, INT32 isRead, UINT32 addr,
208208
}
209209
#endif
210210

211+
#if !defined(WOLFTPM_I2C) && !defined(WOLFTPM_MMIO) && !defined(WOLFTPM_FWTPM_HAL)
212+
/* the FIFO register transfers plaintext command/response payload */
213+
TPM2_ForceZero(txBuf, sizeof(txBuf));
214+
TPM2_ForceZero(rxBuf, sizeof(rxBuf));
215+
#endif
216+
211217
(void)ctx;
212218

213219
return ret;

0 commit comments

Comments
 (0)