[SeaBIOS] [PATCH 8/8] tpm: Merge tpm_log_extend_event() and tpm_extend(); extend before logging

Kevin O'Connor kevin at koconnor.net
Mon Nov 23 02:02:38 CET 2015


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 at koconnor.net>
---
 src/tcgbios.c | 33 +++++++++++++--------------------
 1 file changed, 13 insertions(+), 20 deletions(-)

diff --git a/src/tcgbios.c b/src/tcgbios.c
index 16eb699..9184300 100644
--- a/src/tcgbios.c
+++ b/src/tcgbios.c
@@ -448,39 +448,32 @@ err_exit:
 }
 
 static u32
-tpm_extend(u8 *hash, u32 pcrindex)
+tpm_log_extend_event(struct pcpes *pcpes)
 {
+    if (!has_working_tpm())
+        return TCG_GENERAL_ERROR;
+
     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)
-{
-    if (!has_working_tpm())
-        return TCG_GENERAL_ERROR;
-
-    u32 rc = tpm_log_event(pcpes);
-    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);
+    if (rc)
+        tpm_set_failure();
+    return rc;
 }
 
 static void
-- 
2.5.0




More information about the SeaBIOS mailing list