Skip to content

Commit 14b9445

Browse files
JuergenReppSITAndreasFuchsTPM
authored andcommitted
tpm2_checkquote: Add size checks for PCR desearialization
When a binary blob in the PCR file written in the form 'serialized' is used the size fields are not checked after reading the file. These field are no checked and an error is produced if the max values are exceeded. Signed-off-by: Juergen Repp <juergen_repp@web.de>
1 parent 56800e4 commit 14b9445

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tools/misc/tpm2_checkquote.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,10 @@ static bool parse_selection_data_from_file(FILE *pcr_input,
347347
return false;
348348
}
349349
pcr_select->count = le32toh(pcr_select->count);
350+
if (pcr_select->count > TPM2_NUM_PCR_BANKS) {
351+
LOG_ERR("Failed to read PCR selection from file");
352+
return false;
353+
}
350354
for (i = 0; i < pcr_select->count; i++) {
351355
pcr_select->pcrSelections[i].hash = le16toh(pcr_select->pcrSelections[i].hash);
352356
}
@@ -373,9 +377,19 @@ static bool parse_selection_data_from_file(FILE *pcr_input,
373377
}
374378
// Convert TPML_DIGEST from little endian to host endian.
375379
pcrs->pcr_values[j].count = le32toh( pcrs->pcr_values[j].count);
380+
if (pcrs->pcr_values[j].count > ARRAY_LEN(pcrs->pcr_values[j].digests)) {
381+
LOG_ERR("Malformed PCR file, TPML_DIGEST count cannot be greater than %" PRIu64,
382+
ARRAY_LEN(pcrs->pcr_values[j].digests));
383+
return false;
384+
}
376385
for (i = 0; i < pcrs->pcr_values[j].count; i++) {
377386
pcrs->pcr_values[j].digests[i].size =
378387
le16toh(pcrs->pcr_values[j].digests[i].size);
388+
if (pcrs->pcr_values[j].digests[i].size > sizeof(TPMU_HA)) {
389+
LOG_ERR("Malformed PCR file, TPML_DIGEST count cannot be greater than %" PRIu64,
390+
sizeof(TPMU_HA));
391+
return false;
392+
}
379393
}
380394
}
381395

0 commit comments

Comments
 (0)