Instead of passing in the event data to tpm_extend_acpi_log() via parameters, use the event[] field in the pcpes. Update those callers that don't populate the pcpes->event to do so prior to calling tpm_extend_acpi_log().
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/std/tcg.h | 2 +- src/tcgbios.c | 76 +++++++++++++++++++++++++++++------------------------------ 2 files changed, 39 insertions(+), 39 deletions(-)
diff --git a/src/std/tcg.h b/src/std/tcg.h index 88b2688..5f9cad9 100644 --- a/src/std/tcg.h +++ b/src/std/tcg.h @@ -207,7 +207,7 @@ struct pcpes u32 eventtype; u8 digest[SHA1_BUFSIZE]; u32 eventdatasize; - u32 event; + u8 event[0]; } PACKED;
struct pcctes diff --git a/src/tcgbios.c b/src/tcgbios.c index 0c28935..e7adf3f 100644 --- a/src/tcgbios.c +++ b/src/tcgbios.c @@ -290,18 +290,15 @@ reset_acpi_log(void) * Returns an error code in case of faiure, 0 in case of success */ static u32 -tpm_extend_acpi_log(struct pcpes *pcpes, - const char *event, u32 event_length) +tpm_extend_acpi_log(struct pcpes *pcpes) { - u32 size; - dprintf(DEBUG_tcg, "TCGBIOS: LASA = %p, next entry = %p\n", tpm_state.log_area_start_address, tpm_state.log_area_next_entry);
if (tpm_state.log_area_next_entry == NULL) return TCG_PC_LOGOVERFLOW;
- size = offsetof(struct pcpes, event) + event_length; + u32 size = sizeof(*pcpes) + pcpes->eventdatasize;
if ((tpm_state.log_area_next_entry + size - tpm_state.log_area_start_address) > tpm_state.log_area_minimum_length) { @@ -309,11 +306,7 @@ tpm_extend_acpi_log(struct pcpes *pcpes, return TCG_PC_LOGOVERFLOW; }
- pcpes->eventdatasize = event_length; - - memcpy(tpm_state.log_area_next_entry, pcpes, offsetof(struct pcpes, event)); - memcpy(tpm_state.log_area_next_entry + offsetof(struct pcpes, event), - event, event_length); + memcpy(tpm_state.log_area_next_entry, pcpes, size);
tpm_state.log_area_last_entry = tpm_state.log_area_next_entry; tpm_state.log_area_next_entry += size; @@ -513,7 +506,7 @@ tpm_extend(u8 *hash, u32 pcrindex) }
static u32 -tpm_log_event(struct pcpes *pcpes, const char *event, u32 event_length) +tpm_log_event(struct pcpes *pcpes) { if (pcpes->pcrindex >= 24) return TCG_INVALID_INPUT_PARA; @@ -521,16 +514,16 @@ tpm_log_event(struct pcpes *pcpes, const char *event, u32 event_length) if (!has_working_tpm()) return TCG_GENERAL_ERROR;
- u32 rc = tpm_extend_acpi_log(pcpes, event, event_length); + u32 rc = tpm_extend_acpi_log(pcpes); if (rc) tpm_set_failure(); return rc; }
static u32 -tpm_log_extend_event(struct pcpes *pcpes, const char *event, u32 event_length) +tpm_log_extend_event(struct pcpes *pcpes) { - u32 rc = tpm_log_event(pcpes, event, event_length); + u32 rc = tpm_log_event(pcpes); if (rc) return rc; return tpm_extend(pcpes->digest, pcpes->pcrindex); @@ -560,12 +553,21 @@ tpm_add_measurement_to_log(u32 pcrindex, u32 event_type, const char *event, u32 event_length, const u8 *hashdata, u32 hashdata_length) { - struct pcpes pcpes = { - .pcrindex = pcrindex, - .eventtype = event_type, + struct { + struct pcpes pcpes; + u8 event[128]; + } PACKED ev = { + .pcpes.pcrindex = pcrindex, + .pcpes.eventtype = event_type, + .pcpes.eventdatasize = event_length, }; - tpm_fill_hash(&pcpes, hashdata, hashdata_length); - return tpm_log_extend_event(&pcpes, event, event_length); + if (event_length > sizeof(ev.event)) { + warn_internalerror(); + return TCG_FIRMWARE_ERROR; + } + memcpy(ev.event, event, event_length); + tpm_fill_hash(&ev.pcpes, hashdata, hashdata_length); + return tpm_log_extend_event(&ev.pcpes); }
@@ -975,16 +977,14 @@ hash_log_extend_event_int(const struct hleei_short *hleei_s,
pcpes = (struct pcpes *)logdataptr;
- if (pcpes->pcrindex >= 24 || - pcpes->pcrindex != pcrindex || - logdatalen != offsetof(struct pcpes, event) + pcpes->eventdatasize) { + if (pcpes->pcrindex >= 24 || pcpes->pcrindex != pcrindex + || logdatalen != sizeof(*pcpes) + pcpes->eventdatasize) { rc = TCG_INVALID_INPUT_PARA; goto err_exit; }
tpm_fill_hash(pcpes, hleei_s->hashdataptr, hleei_s->hashdatalen); - rc = tpm_log_extend_event(pcpes - , (char *)&pcpes->event, pcpes->eventdatasize); + rc = tpm_log_extend_event(pcpes); if (rc) goto err_exit;
@@ -1077,17 +1077,15 @@ hash_log_event_int(const struct hlei *hlei, struct hleo *hleo)
pcpes = (struct pcpes *)hlei->logdataptr;
- if (pcpes->pcrindex >= 24 || - pcpes->pcrindex != hlei->pcrindex || - pcpes->eventtype != hlei->logeventtype || - hlei->logdatalen != - offsetof(struct pcpes, event) + pcpes->eventdatasize) { + if (pcpes->pcrindex >= 24 || pcpes->pcrindex != hlei->pcrindex + || pcpes->eventtype != hlei->logeventtype + || hlei->logdatalen != sizeof(*pcpes) + pcpes->eventdatasize) { rc = TCG_INVALID_INPUT_PARA; goto err_exit; }
tpm_fill_hash(pcpes, hlei->hashdataptr, hlei->hashdatalen); - rc = tpm_log_event(pcpes, (char *)&pcpes->event, pcpes->eventdatasize); + rc = tpm_log_event(pcpes); if (rc) goto err_exit;
@@ -1144,19 +1142,21 @@ compact_hash_log_extend_event_int(u8 *buffer, u32 pcrindex, u32 *edx_ptr) { - struct pcpes pcpes = { - .pcrindex = pcrindex, - .eventtype = EV_COMPACT_HASH, - .eventdatasize = sizeof(info), - .event = info, + struct { + struct pcpes pcpes; + u32 event; + } PACKED ev = { + .pcpes.pcrindex = pcrindex, + .pcpes.eventtype = EV_COMPACT_HASH, + .pcpes.eventdatasize = sizeof(info), + .event = info, };
if (is_preboot_if_shutdown() != 0) return TCG_INTERFACE_SHUTDOWN;
- tpm_fill_hash(&pcpes, buffer, length); - u32 rc = tpm_log_extend_event(&pcpes, - (char *)&pcpes.event, pcpes.eventdatasize); + tpm_fill_hash(&ev.pcpes, buffer, length); + u32 rc = tpm_log_extend_event(&ev.pcpes); if (rc == 0) *edx_ptr = tpm_state.entry_count;