From: Kevin O'Connor Date: Mon, 23 Nov 2015 00:16:16 +0000 (-0500) Subject: tpm: Merge tpm_log_extend_event() and tpm_extend(); extend before logging X-Git-Tag: rel-1.10.0~140 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=948f3c9b5f74f265bd171ee367a632a8f7c81f68;p=seabios.git tpm: Merge tpm_log_extend_event() and tpm_extend(); extend before logging Merge tpm_extend() into tpm_log_extend_event(). Also, the spec states that a log entry should only be added if the extend succeeds, so attempt the extend prior to adding to the log. Signed-off-by: Kevin O'Connor --- diff --git a/src/tcgbios.c b/src/tcgbios.c index 704993f..d1a7f6b 100644 --- a/src/tcgbios.c +++ b/src/tcgbios.c @@ -446,42 +446,35 @@ err_exit: } static u32 -tpm_extend(u8 *hash, u32 pcrindex) +tpm_log_extend_event(struct pcpes *pcpes, const void *event) { + if (!has_working_tpm()) + return TCG_GENERAL_ERROR; + + if (pcpes->pcrindex >= 24) + return TCG_INVALID_INPUT_PARA; + struct tpm_req_extend tre = { .tag = cpu_to_be16(TPM_TAG_RQU_CMD), .totlen = cpu_to_be32(sizeof(tre)), .ordinal = cpu_to_be32(TPM_ORD_Extend), - .pcrindex = cpu_to_be32(pcrindex), + .pcrindex = cpu_to_be32(pcpes->pcrindex), }; + memcpy(tre.digest, pcpes->digest, sizeof(tre.digest)); + struct tpm_rsp_extend rsp; u32 resp_length = sizeof(rsp); - - memcpy(tre.digest, hash, sizeof(tre.digest)); - u32 rc = transmit(0, (void*)&tre, &rsp, &resp_length, TPM_DURATION_TYPE_SHORT); - if (rc || resp_length != sizeof(rsp)) - tpm_set_failure(); - - return rc; -} - -static u32 -tpm_log_extend_event(struct pcpes *pcpes, const void *event) -{ - if (!has_working_tpm()) - return TCG_GENERAL_ERROR; - - if (pcpes->pcrindex >= 24) - return TCG_INVALID_INPUT_PARA; - - u32 rc = tpm_log_event(pcpes, event); - if (rc) { + if (rc || resp_length != sizeof(rsp)) { tpm_set_failure(); return rc; } - return tpm_extend(pcpes->digest, pcpes->pcrindex); + + rc = tpm_log_event(pcpes, event); + if (rc) + tpm_set_failure(); + return rc; } static void