<p>Philipp Deppenwiese <strong>merged</strong> this change.</p><p><a href="https://review.coreboot.org/22867">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  build bot (Jenkins): Verified
  Patrick Rudolph: Looks good to me, approved

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">security/tpm: Add TCPA logging functionality<br><br>* TCG spec only applies to BIOS or UEFI.<br>* Therefore implement coreboot TCPA compliant log<br>in CBMEM.<br>* Write CBMEM log into the coreboot table for CBMEM tool access<br><br>Change-Id: I0a52494f647d21e2587231af26ed13d62b3a72f5<br>Signed-off-by: Philipp Deppenwiese <zaolin@das-labor.org><br>Reviewed-on: https://review.coreboot.org/22867<br>Tested-by: build bot (Jenkins) <no-reply@coreboot.org><br>Reviewed-by: Patrick Rudolph <siro@das-labor.org><br>---<br>M src/commonlib/include/commonlib/cbmem_id.h<br>A src/commonlib/include/commonlib/tcpa_log_serialized.h<br>M src/drivers/tpm/tpm.c<br>M src/security/tpm/Makefile.inc<br>M src/security/tpm/tspi.h<br>A src/security/tpm/tspi/log.c<br>6 files changed, 141 insertions(+), 8 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/commonlib/include/commonlib/cbmem_id.h b/src/commonlib/include/commonlib/cbmem_id.h</span><br><span>index 3529fef..cc2fed1 100644</span><br><span>--- a/src/commonlib/include/commonlib/cbmem_id.h</span><br><span>+++ b/src/commonlib/include/commonlib/cbmem_id.h</span><br><span>@@ -64,6 +64,7 @@</span><br><span> #define CBMEM_ID_STAGEx_RAW    0x57a9e200</span><br><span> #define CBMEM_ID_STORAGE_DATA     0x53746f72</span><br><span> #define CBMEM_ID_TCPA_LOG 0x54435041</span><br><span style="color: hsl(120, 100%, 40%);">+#define CBMEM_ID_TCPA_COMPLIANT_LOG 0x54445041</span><br><span> #define CBMEM_ID_TIMESTAMP        0x54494d45</span><br><span> #define CBMEM_ID_VBOOT_HANDOFF    0x780074f0</span><br><span> #define CBMEM_ID_VBOOT_SEL_REG    0x780074f1</span><br><span>@@ -120,6 +121,7 @@</span><br><span>     { CBMEM_ID_SMM_SAVE_SPACE,      "SMM BACKUP " }, \</span><br><span>         { CBMEM_ID_STORAGE_DATA,        "SD/MMC/eMMC" }, \</span><br><span>         { CBMEM_ID_TCPA_LOG,            "TCPA LOG   " }, \</span><br><span style="color: hsl(120, 100%, 40%);">+  { CBMEM_ID_TCPA_COMPLIANT_LOG,  "TCPA COMPLIANT LOG   " }, \</span><br><span>       { CBMEM_ID_TIMESTAMP,           "TIME STAMP " }, \</span><br><span>         { CBMEM_ID_VBOOT_HANDOFF,       "VBOOT      " }, \</span><br><span>         { CBMEM_ID_VBOOT_SEL_REG,       "VBOOT SEL  " }, \</span><br><span>diff --git a/src/commonlib/include/commonlib/tcpa_log_serialized.h b/src/commonlib/include/commonlib/tcpa_log_serialized.h</span><br><span>new file mode 100644</span><br><span>index 0000000..cd6fbec</span><br><span>--- /dev/null</span><br><span>+++ b/src/commonlib/include/commonlib/tcpa_log_serialized.h</span><br><span>@@ -0,0 +1,41 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * This file is part of the coreboot project.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Copyright (C) 2018 Facebook Inc.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+ * it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Free Software Foundation; version 2 of the License.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+ * GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#ifndef __TCPA_LOG_SERIALIZED_H__</span><br><span style="color: hsl(120, 100%, 40%);">+#define __TCPA_LOG_SERIALIZED_H__</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <compiler.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <stdint.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#define MAX_TCPA_LOG_ENTRIES 50</span><br><span style="color: hsl(120, 100%, 40%);">+#define TCPA_LOG_STRING_LENGTH 512</span><br><span style="color: hsl(120, 100%, 40%);">+#define TCPA_FORMAT_HASH_LENGTH 128</span><br><span style="color: hsl(120, 100%, 40%);">+#define TCPA_DIGEST_MAX_LENGTH 64</span><br><span style="color: hsl(120, 100%, 40%);">+#define TCPA_PCR_HASH_NAME 256</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+struct tcpa_entry {</span><br><span style="color: hsl(120, 100%, 40%);">+   uint32_t pcr;</span><br><span style="color: hsl(120, 100%, 40%);">+ uint8_t digest[TCPA_DIGEST_MAX_LENGTH];</span><br><span style="color: hsl(120, 100%, 40%);">+       uint32_t digest_length;</span><br><span style="color: hsl(120, 100%, 40%);">+       uint8_t name[TCPA_PCR_HASH_NAME];</span><br><span style="color: hsl(120, 100%, 40%);">+} __packed;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+struct tcpa_table {</span><br><span style="color: hsl(120, 100%, 40%);">+ uint16_t max_entries;</span><br><span style="color: hsl(120, 100%, 40%);">+ uint16_t num_entries;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct tcpa_entry entries[0]; /* Variable number of entries */</span><br><span style="color: hsl(120, 100%, 40%);">+} __packed;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span>diff --git a/src/drivers/tpm/tpm.c b/src/drivers/tpm/tpm.c</span><br><span>index e4a81c3..8c68159 100644</span><br><span>--- a/src/drivers/tpm/tpm.c</span><br><span>+++ b/src/drivers/tpm/tpm.c</span><br><span>@@ -30,6 +30,9 @@</span><br><span> #else</span><br><span>  tpm_setup(false);</span><br><span> #endif</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ // TCPA cbmem log</span><br><span style="color: hsl(120, 100%, 40%);">+     tcpa_log_init();</span><br><span> }</span><br><span> </span><br><span> BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_ENTRY, init_tpm_dev, NULL);</span><br><span>diff --git a/src/security/tpm/Makefile.inc b/src/security/tpm/Makefile.inc</span><br><span>index 9157fec..34ead8f 100644</span><br><span>--- a/src/security/tpm/Makefile.inc</span><br><span>+++ b/src/security/tpm/Makefile.inc</span><br><span>@@ -12,11 +12,11 @@</span><br><span> </span><br><span> ## TSPI</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-ramstage-y += tspi/tspi.c</span><br><span style="color: hsl(0, 100%, 40%);">-romstage-y += tspi/tspi.c</span><br><span style="color: hsl(120, 100%, 40%);">+ramstage-y += tspi/tspi.c tspi/log.c</span><br><span style="color: hsl(120, 100%, 40%);">+romstage-y += tspi/tspi.c tspi/log.c</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-verstage-$(CONFIG_VBOOT) += tspi/tspi.c</span><br><span style="color: hsl(0, 100%, 40%);">-postcar-$(CONFIG_VBOOT) += tspi/tspi.c</span><br><span style="color: hsl(120, 100%, 40%);">+verstage-$(CONFIG_VBOOT) += tspi/tspi.c tspi/log.c</span><br><span style="color: hsl(120, 100%, 40%);">+postcar-$(CONFIG_VBOOT) += tspi/tspi.c tspi/log.c</span><br><span> </span><br><span> endif # CONFIG_TPM1</span><br><span> </span><br><span>@@ -36,10 +36,10 @@</span><br><span> </span><br><span> ## TSPI</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-ramstage-y += tspi/tspi.c</span><br><span style="color: hsl(0, 100%, 40%);">-romstage-y += tspi/tspi.c</span><br><span style="color: hsl(120, 100%, 40%);">+ramstage-y += tspi/tspi.c tspi/log.c</span><br><span style="color: hsl(120, 100%, 40%);">+romstage-y += tspi/tspi.c tspi/log.c</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-verstage-$(CONFIG_VBOOT) += tspi/tspi.c</span><br><span style="color: hsl(0, 100%, 40%);">-postcar-$(CONFIG_VBOOT) += tspi/tspi.c</span><br><span style="color: hsl(120, 100%, 40%);">+verstage-$(CONFIG_VBOOT) += tspi/tspi.c tspi/log.c</span><br><span style="color: hsl(120, 100%, 40%);">+postcar-$(CONFIG_VBOOT) += tspi/tspi.c tspi/log.c</span><br><span> </span><br><span> endif # CONFIG_TPM2</span><br><span>diff --git a/src/security/tpm/tspi.h b/src/security/tpm/tspi.h</span><br><span>index fdc9e1c..01b2984 100644</span><br><span>--- a/src/security/tpm/tspi.h</span><br><span>+++ b/src/security/tpm/tspi.h</span><br><span>@@ -18,6 +18,18 @@</span><br><span> #define TSPI_H_</span><br><span> </span><br><span> #include <security/tpm/tss.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <commonlib/tcpa_log_serialized.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/**</span><br><span style="color: hsl(120, 100%, 40%);">+ * Setup TCPA cbmem log.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+void tcpa_log_init(void);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/**</span><br><span style="color: hsl(120, 100%, 40%);">+ * Add table entry for cbmem TCPA log.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+int tcpa_log_add_table_entry(const char *name, const uint32_t pcr,</span><br><span style="color: hsl(120, 100%, 40%);">+                          const uint8_t *digest, const size_t digest_length);</span><br><span> </span><br><span> /**</span><br><span>  * Ask vboot for a digest and extend a TPM PCR with it.</span><br><span>diff --git a/src/security/tpm/tspi/log.c b/src/security/tpm/tspi/log.c</span><br><span>new file mode 100644</span><br><span>index 0000000..6091dfe</span><br><span>--- /dev/null</span><br><span>+++ b/src/security/tpm/tspi/log.c</span><br><span>@@ -0,0 +1,75 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * This file is part of the coreboot project.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Copyright 2018 Facebook Inc.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+ * it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Free Software Foundation; version 2 of the License.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+ * GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <string.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <cbmem.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <console/console.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <security/tpm/tspi.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+void tcpa_log_init(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+   const struct cbmem_entry *ce;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct tcpa_table *tclt;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    if (!cbmem_possibly_online())</span><br><span style="color: hsl(120, 100%, 40%);">+         return;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     ce = cbmem_entry_find(CBMEM_ID_TCPA_LOG);</span><br><span style="color: hsl(120, 100%, 40%);">+     if (ce)</span><br><span style="color: hsl(120, 100%, 40%);">+               return;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     tclt = cbmem_add(CBMEM_ID_TCPA_LOG,</span><br><span style="color: hsl(120, 100%, 40%);">+                    sizeof(struct tcpa_table) +</span><br><span style="color: hsl(120, 100%, 40%);">+                           MAX_TCPA_LOG_ENTRIES *</span><br><span style="color: hsl(120, 100%, 40%);">+                                        sizeof(struct tcpa_entry));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        if (!tclt)</span><br><span style="color: hsl(120, 100%, 40%);">+            return;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     tclt->max_entries = MAX_TCPA_LOG_ENTRIES;</span><br><span style="color: hsl(120, 100%, 40%);">+  tclt->num_entries = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   printk(BIOS_DEBUG, "TCPA log created at %p\n", tclt);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+int tcpa_log_add_table_entry(const char *name, const uint32_t pcr,</span><br><span style="color: hsl(120, 100%, 40%);">+                           const uint8_t *digest, const size_t digest_length)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+    MAYBE_STATIC struct tcpa_table *tclt = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+  struct tcpa_entry *tce;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     if (!cbmem_possibly_online())</span><br><span style="color: hsl(120, 100%, 40%);">+         return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  tclt = cbmem_find(CBMEM_ID_TCPA_LOG);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!tclt) {</span><br><span style="color: hsl(120, 100%, 40%);">+          printk(BIOS_ERR, "ERROR: No TCPA log table found\n");</span><br><span style="color: hsl(120, 100%, 40%);">+               return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+    }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   if (tclt->num_entries == tclt->max_entries) {</span><br><span style="color: hsl(120, 100%, 40%);">+           printk(BIOS_WARNING, "ERROR: TCPA log table is full\n");</span><br><span style="color: hsl(120, 100%, 40%);">+            return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+    }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   tce = &tclt->entries[tclt->num_entries++];</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        memcpy(tce->name, name, TCPA_PCR_HASH_NAME);</span><br><span style="color: hsl(120, 100%, 40%);">+       tce->pcr = pcr;</span><br><span style="color: hsl(120, 100%, 40%);">+    memcpy(tce->digest, digest, digest_length);</span><br><span style="color: hsl(120, 100%, 40%);">+        tce->digest_length = digest_length;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span></span><br></pre><p>To view, visit <a href="https://review.coreboot.org/22867">change 22867</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://review.coreboot.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://review.coreboot.org/22867"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: coreboot </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I0a52494f647d21e2587231af26ed13d62b3a72f5 </div>
<div style="display:none"> Gerrit-Change-Number: 22867 </div>
<div style="display:none"> Gerrit-PatchSet: 41 </div>
<div style="display:none"> Gerrit-Owner: Philipp Deppenwiese <zaolin.daisuki@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Patrick Rudolph <siro@das-labor.org> </div>
<div style="display:none"> Gerrit-Reviewer: Paul Menzel <paulepanter@users.sourceforge.net> </div>
<div style="display:none"> Gerrit-Reviewer: Philipp Deppenwiese <zaolin.daisuki@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Werner Zeh <werner.zeh@siemens.com> </div>
<div style="display:none"> Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org> </div>