Skip to content

Commit 2914a77

Browse files
committed
fwTPM v1.85: CI fixes + MSan uninit-read in FwCmd_Create
Fixes 5 v1.85 PR CI/build issues: 1. src/tpm2_wrap.c: add #include <wolfssl/wolfcrypt/mlkem.h> inside the v185 MLKEM guard. Builds with --disable-fwtpm against wolfSSL with --enable-mlkem failed because the MLKEM symbol declarations were only pulled in transitively by src/fwtpm/fwtpm_crypto.c. 2. src/fwtpm/fwtpm_command.c: switch FWTPM_ALLOC_BUF(privKeyDer) to FWTPM_CALLOC_BUF in 4 sites (Create, Load, LoadExternal, Import, CreateLoaded). MSan-v185 flagged uninit-value reads in SocketSend originating from FwCmd_Create's keyedHash branch — when caller supplies undersized inSensitive material, FwComputeUniqueHash hashed beyond what was written. Zero-initialising the buffer eliminates the class of issue. 3. examples/keygen/keygen.c: pass allowExternalMu=NO for MLDSA. The v1.85 EXT_MU enforcement now correctly rejects allowExternalMu=YES at object creation per Part 2 §12.2.3.6. 4. .github/workflows/make-test-swtpm.yml: convert v185-pqc-swtpm lane to build-only. swtpm has no v1.85 PQC, so unit.test PQC blocks fail on TPM_RC_SIZE; runtime PQC coverage stays in the fwtpm-v185 lane. 5. .github/workflows/sanitizer.yml: UBSan-v185 now uses the same sanitizer flags as the classical UBSan lane (drops ). Pre-existing wolfSSL UB at misc.c:117 (440<<24 in Hash_df) only surfaces under -fsanitize=integer.
1 parent 39e613f commit 2914a77

5 files changed

Lines changed: 16 additions & 16 deletions

File tree

.github/workflows/make-test-swtpm.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,12 @@ jobs:
304304
needs_install: true
305305

306306
# v1.85 PQC: swtpm-backed wrapper coverage. Triggers run_examples.sh
307-
# auto-detect of WOLFTPM_V185 (config.h) and runs the 18-way keygen
308-
# PQC matrix (-mldsa=44|65|87, -hash_mldsa=44|65|87, -mlkem=512|768|1024).
309-
# Complements the fwtpm-v185 entry — different command-dispatch route.
310-
# SWTPM transport is the Linux configure default (configure.ac:287).
311-
- name: v185-pqc-swtpm
307+
# Build-only: --enable-v185 against PQC+pkcallbacks wolfSSL. swtpm
308+
# has no PQC, so runtime PQC tests live in fwtpm-v185.
309+
- name: v185-pqc-swtpm-build
312310
wolfssl_config: "--enable-wolftpm --enable-pkcallbacks --enable-keygen --enable-dilithium --enable-mlkem --enable-experimental --enable-harden"
313311
wolftpm_config: "--enable-v185"
314-
test_command: "make check && WOLFSSL_PATH=./wolfssl ./examples/run_examples.sh"
312+
test_command: "make"
315313

316314
# Regression: build the v185-pq-support branch WITHOUT --enable-v185
317315
# to catch #ifdef WOLFTPM_V185 drift in tpm2_packet.c / tpm2_wrap.c

.github/workflows/sanitizer.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,11 @@ jobs:
4343
wolftpm_extra_config: "--enable-v185"
4444
wolfssl_extra_config: "--enable-dilithium --enable-mlkem --enable-experimental --enable-harden"
4545

46-
# UBSan-v185: required because v1.85 lifts FWTPM_MAX_COMMAND_SIZE
47-
# 4096->8192, FWTPM_MAX_DER_SIG_BUF 256->4736, FWTPM_NV_PUBAREA_EST
48-
# 600->2720 — these introduce int/size_t conversion + signed-overflow
49-
# risk that ASan does NOT catch.
46+
# UBSan-v185: same flags as the classical UBSan lane (no `integer`
47+
# sanitizer — pre-existing wolfSSL UB at misc.c:117 in Hash_df).
5048
- name: "UBSan-v185"
5149
cc: clang
52-
cflags: "-fsanitize=undefined,integer -fno-sanitize-recover=all -O1 -g"
50+
cflags: "-fsanitize=undefined -fno-sanitize-recover=all -fno-omit-frame-pointer -g"
5351
ldflags: "-fsanitize=undefined"
5452
ubsan_options: "halt_on_error=1:print_stacktrace=1"
5553
wolftpm_extra_config: "--enable-v185"

examples/keygen/keygen.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,9 @@ int TPM2_Keygen_Example(void* userCtx, int argc, char *argv[])
455455
TPMA_OBJECT_sign | TPMA_OBJECT_fixedTPM |
456456
TPMA_OBJECT_fixedParent | TPMA_OBJECT_sensitiveDataOrigin |
457457
TPMA_OBJECT_userWithAuth | TPMA_OBJECT_noDA,
458-
mldsaPs, 1 /* allowExternalMu */);
458+
mldsaPs, 0 /* allowExternalMu — TPM_RC_EXT_MU at create
459+
* per Part 2 §12.2.3.6 when SET on a TPM
460+
* without μ-direct sign support */);
459461
}
460462
else if (alg == TPM_ALG_HASH_MLDSA) {
461463
printf("Hash-ML-DSA template (parameter set %u, pre-hash %s)\n",

src/fwtpm/fwtpm_command.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3645,7 +3645,7 @@ static TPM_RC FwCmd_Create(FWTPM_CTX* ctx, TPM2_Packet* cmd,
36453645
UINT32 s;
36463646
UINT8 selectSize = 0;
36473647

3648-
FWTPM_ALLOC_BUF(privKeyDer, FWTPM_MAX_PRIVKEY_DER);
3648+
FWTPM_CALLOC_BUF(privKeyDer, FWTPM_MAX_PRIVKEY_DER);
36493649
FWTPM_CALLOC_BUF(sensData, FWTPM_MAX_DATA_BUF);
36503650
FWTPM_CALLOC_VAR(inPublic, TPM2B_PUBLIC);
36513651
FWTPM_CALLOC_VAR(outPrivate, TPM2B_PRIVATE);
@@ -4226,7 +4226,7 @@ static TPM_RC FwCmd_LoadExternal(FWTPM_CTX* ctx, TPM2_Packet* cmd,
42264226
int paramSzPos = 0, paramStart = 0;
42274227

42284228
FWTPM_ALLOC_BUF(qBuf, FWTPM_MAX_DER_SIG_BUF);
4229-
FWTPM_ALLOC_BUF(privKeyDer, FWTPM_MAX_PRIVKEY_DER);
4229+
FWTPM_CALLOC_BUF(privKeyDer, FWTPM_MAX_PRIVKEY_DER);
42304230

42314231
if (cmdSize < TPM2_HEADER_SIZE) {
42324232
rc = TPM_RC_COMMAND_SIZE;
@@ -4546,7 +4546,7 @@ static TPM_RC FwCmd_Import(FWTPM_CTX* ctx, TPM2_Packet* cmd,
45464546

45474547
FWTPM_ALLOC_BUF(dupBuf, FWTPM_MAX_PRIVKEY_DER + 256);
45484548
FWTPM_ALLOC_BUF(symSeedBuf, FWTPM_MAX_PUB_BUF);
4549-
FWTPM_ALLOC_BUF(privKeyDer, FWTPM_MAX_PRIVKEY_DER);
4549+
FWTPM_CALLOC_BUF(privKeyDer, FWTPM_MAX_PRIVKEY_DER);
45504550
FWTPM_ALLOC_BUF(pubAreaBuf, FWTPM_MAX_PUB_BUF);
45514551
FWTPM_ALLOC_BUF(plainSens, FWTPM_MAX_SENSITIVE_SIZE);
45524552
FWTPM_ALLOC_BUF(primeBuf, FWTPM_MAX_DER_SIG_BUF);
@@ -5629,7 +5629,7 @@ static TPM_RC FwCmd_CreateLoaded(FWTPM_CTX* ctx, TPM2_Packet* cmd,
56295629
int paramStart = 0;
56305630
FWTPM_DECLARE_VAR(outPub, TPM2B_PUBLIC);
56315631

5632-
FWTPM_ALLOC_BUF(privKeyDer, FWTPM_MAX_PRIVKEY_DER);
5632+
FWTPM_CALLOC_BUF(privKeyDer, FWTPM_MAX_PRIVKEY_DER);
56335633
FWTPM_CALLOC_BUF(sensData, FWTPM_MAX_DATA_BUF);
56345634
FWTPM_CALLOC_VAR(inPublic, TPM2B_PUBLIC);
56355635
FWTPM_CALLOC_VAR(outPrivate, TPM2B_PRIVATE);

src/tpm2_wrap.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2285,6 +2285,8 @@ static int wolfTPM2_EncryptSecret_RSA(WOLFTPM2_DEV* dev, const WOLFTPM2_KEY* tpm
22852285
#if defined(WOLFTPM_V185) && !defined(WOLFTPM2_NO_WOLFCRYPT) && \
22862286
(defined(WOLFSSL_HAVE_MLKEM) || defined(WOLFSSL_KYBER512) || \
22872287
defined(WOLFSSL_KYBER768) || defined(WOLFSSL_KYBER1024))
2288+
#include <wolfssl/wolfcrypt/mlkem.h>
2289+
22882290
/* ML-KEM session-salt path per TCG TPM 2.0 Library v1.85 Part 1 §24
22892291
* (p.316) and §47.4 Equation 66 (Labeled KEM): caller encapsulates under
22902292
* the TPM's ML-KEM public key, then post-processes the raw ML-KEM shared

0 commit comments

Comments
 (0)