]> xenbits.xensource.com Git - seabios.git/commitdiff
tpm: Merge tpm_log_extend_event() and tpm_extend(); extend before logging
authorKevin O'Connor <kevin@koconnor.net>
Mon, 23 Nov 2015 00:16:16 +0000 (19:16 -0500)
committerKevin O'Connor <kevin@koconnor.net>
Tue, 24 Nov 2015 03:54:33 +0000 (22:54 -0500)
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 <kevin@koconnor.net>
src/tcgbios.c

index 704993f78fa9202e7e2431d811c2748c61255b80..d1a7f6b8f8f08e67770d36fe333ffdad8cdea062 100644 (file)
@@ -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