F-13499 - Run the PolicyTemplate compare without short-circuiting on size

pull/604/head
Aidan Garske 2026-09-10 11:38:30 -07:00
parent 6ecdd4ba8b
commit c06f2c2cb8
1 changed files with 11 additions and 5 deletions

View File

@ -12408,11 +12408,17 @@ static TPM_RC FwCmd_PolicyTemplate(FWTPM_CTX* ctx, TPM2_Packet* cmd,
if (sess->cpHashA.size > 0 || sess->nameHash.size > 0) {
rc = TPM_RC_CPHASH;
}
else if (sess->templateHash.size > 0 &&
(sess->templateHash.size != templateHashSz ||
TPM2_ConstantCompare(sess->templateHash.buffer, templateHash,
templateHashSz) != 0)) {
rc = TPM_RC_VALUE;
else if (sess->templateHash.size > 0) {
/* Always run the compare so a size mismatch cannot short-circuit
* the constant-time path */
int sizeMismatch = (sess->templateHash.size != templateHashSz);
word32 cmpSz = (sess->templateHash.size < templateHashSz) ?
sess->templateHash.size : templateHashSz;
if (sizeMismatch |
(TPM2_ConstantCompare(sess->templateHash.buffer, templateHash,
cmpSz) != 0)) {
rc = TPM_RC_VALUE;
}
}
}
if (rc == 0) {