Skip to contentSkip to conversation

Call GetEventLog before ExitBootServices

PATCH Superseded Thiebaud Weksteen 7 participants 26 messages Sep 11, 2017 – Nov 3, 2017 1 message not in the archive

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Call GetEventLog before ExitBootServices

With TPM 1.2, the ACPI table ("TCPA") has two fields to recover the Event Log Area (LAML and LASA). These logs are useful to understand and rebuild the final values of PCRs.

With TPM 2.0, the ACPI table ("TPM2") does not contain these fields anymore. The recommended method is now to call the GetEventLog EFI protocol before ExitBootServices.

Implement this method within the EFI stub and create copy of the logs for the TPM device. This will create /sys/kernel/security/tpm0/binary_bios_measurements for TPM 2.0 devices (similarly to the current behaviour for TPM 1.2 devices).

-------------------------------------------------------------------------------

Patchset Changelog:

Version 2:
- Move tpm_eventlog.h to top include directory, add commit for this.
- Use EFI_LOADER_DATA to store the configuration table
- Whitespace and new lines fixes

Thiebaud Weksteen (3):
tpm: move tpm_eventlog.h outside of drivers folder
efi: call get_event_log before ExitBootServices
tpm: parse TPM event logs based on EFI table

 arch/x86/boot/compressed/eboot.c                   |  1 +
 drivers/char/tpm/Makefile                          |  2 +-
 drivers/char/tpm/tpm-chip.c                        |  3 +-
 drivers/char/tpm/tpm-interface.c                   |  2 +-
 drivers/char/tpm/tpm.h                             | 35 ++++++++--
 drivers/char/tpm/tpm1_eventlog.c                   | 17 +++--
 drivers/char/tpm/tpm2_eventlog.c                   |  2 +-
 drivers/char/tpm/tpm_acpi.c                        |  2 +-
 drivers/char/tpm/tpm_efi.c                         | 66 ++++++++++++++++++
 drivers/char/tpm/tpm_of.c                          |  2 +-
 drivers/firmware/efi/Makefile                      |  2 +-
 drivers/firmware/efi/efi.c                         |  4 ++
 drivers/firmware/efi/libstub/Makefile              |  3 +-
 drivers/firmware/efi/libstub/tpm.c                 | 81 ++++++++++++++++++++++
 drivers/firmware/efi/tpm.c                         | 39 +++++++++++
 include/linux/efi.h                                | 50 +++++++++++++
 {drivers/char/tpm => include/linux}/tpm_eventlog.h | 32 ++-------
 17 files changed, 301 insertions(+), 42 deletions(-)
 create mode 100644 drivers/char/tpm/tpm_efi.c
 create mode 100644 drivers/firmware/efi/tpm.c
 rename {drivers/char/tpm => include/linux}/tpm_eventlog.h (77%)
Signature · 1 line
2.14.1.581.gf28d330327-goog
#1 lore raw

PATCH v2 1/3 tpm: move tpm_eventlog.h outside of drivers folder

The generic definitions of data structures in tpm_eventlog.h are required by other part of the kernel (namely, the EFI stub).

---
 drivers/char/tpm/tpm-chip.c                        |  3 +-
 drivers/char/tpm/tpm-interface.c                   |  2 +-
 drivers/char/tpm/tpm.h                             | 27 +++++++++++++++---
 drivers/char/tpm/tpm1_eventlog.c                   |  2 +-
 drivers/char/tpm/tpm2_eventlog.c                   |  2 +-
 drivers/char/tpm/tpm_acpi.c                        |  2 +-
 drivers/char/tpm/tpm_of.c                          |  2 +-
 {drivers/char/tpm => include/linux}/tpm_eventlog.h | 32 +++++-----------------
 8 files changed, 37 insertions(+), 35 deletions(-)
 rename {drivers/char/tpm => include/linux}/tpm_eventlog.h (77%)
drivers/char/tpm/tpm-chip.c +2 -1
index 67ec9d3d04f5..de2680118181 100644
@@ -26,8 +26,9 @@
 #include <linux/spinlock.h>
 #include <linux/freezer.h>
 #include <linux/major.h>
+#include <linux/tpm_eventlog.h>
+
 #include "tpm.h"
-#include "tpm_eventlog.h"
 
 DEFINE_IDR(dev_nums_idr);
 static DEFINE_MUTEX(idr_lock);
drivers/char/tpm/tpm-interface.c +1 -1
index fe597e6c55c4..bd7091d510bd 100644
@@ -30,9 +30,9 @@
 #include <linux/spinlock.h>
 #include <linux/freezer.h>
 #include <linux/pm_runtime.h>
+#include <linux/tpm_eventlog.h>
 
 #include "tpm.h"
-#include "tpm_eventlog.h"
 
 #define TPM_MAX_ORDINAL 243
 #define TSC_MAX_ORDINAL 12
drivers/char/tpm/tpm.h +23 -4
index 04fbff2edbf3..46caccf6fd1a 100644
@@ -34,6 +34,7 @@
 #include <linux/acpi.h>
 #include <linux/cdev.h>
 #include <linux/highmem.h>
+#include <linux/tpm_eventlog.h>
 #include <crypto/hash_info.h>
 
 #ifdef CONFIG_X86
@@ -397,10 +398,6 @@ struct tpm_cmd_t {
 	tpm_cmd_params	params;
 } __packed;
 
-struct tpm2_digest {
-	u16 alg_id;
-	u8 digest[SHA512_DIGEST_SIZE];
-} __packed;
 
 /* A string buffer type for constructing TPM commands. This is based on the
  * ideas of string buffer code in security/keys/trusted.h but is heap based
@@ -581,4 +578,26 @@ int tpm2_prepare_space(struct tpm_chip *chip, struct tpm_space *space, u32 cc,
 		       u8 *cmd);
 int tpm2_commit_space(struct tpm_chip *chip, struct tpm_space *space,
 		      u32 cc, u8 *buf, size_t *bufsiz);
+
+extern const struct seq_operations tpm2_binary_b_measurements_seqops;
+
+#if defined(CONFIG_ACPI)
+int tpm_read_log_acpi(struct tpm_chip *chip);
+#else
+static inline int tpm_read_log_acpi(struct tpm_chip *chip)
+{
+	return -ENODEV;
+}
+#endif
+#if defined(CONFIG_OF)
+int tpm_read_log_of(struct tpm_chip *chip);
+#else
+static inline int tpm_read_log_of(struct tpm_chip *chip)
+{
+	return -ENODEV;
+}
+#endif
+
+int tpm_bios_log_setup(struct tpm_chip *chip);
+void tpm_bios_log_teardown(struct tpm_chip *chip);
 #endif
drivers/char/tpm/tpm1_eventlog.c +1 -1
index 9a8605e500b5..d6f70f365443 100644
@@ -25,9 +25,9 @@
 #include <linux/security.h>
 #include <linux/module.h>
 #include <linux/slab.h>
+#include <linux/tpm_eventlog.h>
 
 #include "tpm.h"
-#include "tpm_eventlog.h"
 
 
 static const char* tcpa_event_type_strings[] = {
drivers/char/tpm/tpm2_eventlog.c +1 -1
index 34a8afa69138..1ce4411292ba 100644
@@ -21,9 +21,9 @@
 #include <linux/security.h>
 #include <linux/module.h>
 #include <linux/slab.h>
+#include <linux/tpm_eventlog.h>
 
 #include "tpm.h"
-#include "tpm_eventlog.h"
 
 /*
  * calc_tpm2_event_size() - calculate the event size, where event
drivers/char/tpm/tpm_acpi.c +1 -1
index 169edf3ce86d..acc990ba376a 100644
@@ -25,9 +25,9 @@
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/acpi.h>
+#include <linux/tpm_eventlog.h>
 
 #include "tpm.h"
-#include "tpm_eventlog.h"
 
 struct acpi_tcpa {
 	struct acpi_table_header hdr;
drivers/char/tpm/tpm_of.c +1 -1
index aadb7f464076..4a2f8c79231e 100644
@@ -17,9 +17,9 @@
 
 #include <linux/slab.h>
 #include <linux/of.h>
+#include <linux/tpm_eventlog.h>
 
 #include "tpm.h"
-#include "tpm_eventlog.h"
 
 int tpm_read_log_of(struct tpm_chip *chip)
 {
include/linux/tpm_eventlog.h renamed from drivers/char/tpm/tpm_eventlog.h +7 -25
similarity index 77%
rename from drivers/char/tpm/tpm_eventlog.h
rename to include/linux/tpm_eventlog.h
index b4b549559203..446656d1f317 100644
@@ -1,6 +1,5 @@
-
-#ifndef __TPM_EVENTLOG_H__
-#define __TPM_EVENTLOG_H__
+#ifndef __LINUX_TPM_EVENTLOG_H__
+#define __LINUX_TPM_EVENTLOG_H__
 
 #include <crypto/hash_info.h>
 
@@ -104,6 +103,11 @@ struct tcg_event_field {
 	u8 event[0];
 } __packed;
 
+struct tpm2_digest {
+	u16 alg_id;
+	u8 digest[SHA512_DIGEST_SIZE];
+} __packed;
+
 struct tcg_pcr_event2 {
 	u32 pcr_idx;
 	u32 event_type;
@@ -112,26 +116,4 @@ struct tcg_pcr_event2 {
 	struct tcg_event_field event;
 } __packed;
 
-extern const struct seq_operations tpm2_binary_b_measurements_seqops;
-
-#if defined(CONFIG_ACPI)
-int tpm_read_log_acpi(struct tpm_chip *chip);
-#else
-static inline int tpm_read_log_acpi(struct tpm_chip *chip)
-{
-	return -ENODEV;
-}
-#endif
-#if defined(CONFIG_OF)
-int tpm_read_log_of(struct tpm_chip *chip);
-#else
-static inline int tpm_read_log_of(struct tpm_chip *chip)
-{
-	return -ENODEV;
-}
-#endif
-
-int tpm_bios_log_setup(struct tpm_chip *chip);
-void tpm_bios_log_teardown(struct tpm_chip *chip);
-
 #endif
Signature · 1 line
2.14.1.581.gf28d330327-goog
#2 lore raw

PATCH v2 2/3 efi: call get_event_log before ExitBootServices

In reply to Thiebaud Weksteen

With TPM 2.0 specification, the event logs may only be accessible by calling an EFI Boot Service. Modify the EFI stub to copy the log area to a new Linux-specific EFI configuration table so it remains accessible once booted.

When calling this service, it is possible to specify the expected format of the logs: TPM 1.2 (SHA1) or TPM 2.0 ("Crypto Agile"). For now, only the first format is retrieved.

---
 arch/x86/boot/compressed/eboot.c      |  1 +
 drivers/firmware/efi/Makefile         |  2 +-
 drivers/firmware/efi/efi.c            |  2 +
 drivers/firmware/efi/libstub/Makefile |  3 +-
 drivers/firmware/efi/libstub/tpm.c    | 81 +++++++++++++++++++++++++++++++++++
 drivers/firmware/efi/tpm.c            | 39 +++++++++++++++++
 include/linux/efi.h                   | 49 +++++++++++++++++++++
 7 files changed, 174 insertions(+), 3 deletions(-)
 create mode 100644 drivers/firmware/efi/tpm.c
arch/x86/boot/compressed/eboot.c +1 -0
index a1686f3dc295..ef6abe8b3788 100644
@@ -999,6 +999,7 @@ struct boot_params *efi_main(struct efi_config *c,
 
 	/* Ask the firmware to clear memory on unclean shutdown */
 	efi_enable_reset_attack_mitigation(sys_table);
+	efi_retrieve_tpm2_eventlog(sys_table);
 
 	setup_graphics(boot_params);
 
drivers/firmware/efi/Makefile +1 -1
index 0329d319d89a..2f074b5cde87 100644
@@ -10,7 +10,7 @@
 KASAN_SANITIZE_runtime-wrappers.o	:= n
 
 obj-$(CONFIG_ACPI_BGRT) 		+= efi-bgrt.o
-obj-$(CONFIG_EFI)			+= efi.o vars.o reboot.o memattr.o
+obj-$(CONFIG_EFI)			+= efi.o vars.o reboot.o memattr.o tpm.o
 obj-$(CONFIG_EFI)			+= capsule.o memmap.o
 obj-$(CONFIG_EFI_VARS)			+= efivars.o
 obj-$(CONFIG_EFI_ESRT)			+= esrt.o
drivers/firmware/efi/efi.c +2 -0
index f97f272e16ee..03fbaf8eb248 100644
@@ -532,6 +532,8 @@ int __init efi_config_parse_tables(void *config_tables, int count, int sz,
 	if (efi_enabled(EFI_MEMMAP))
 		efi_memattr_init();
 
+	efi_tpm_eventlog_init();
+
 	/* Parse the EFI Properties table if it exists */
 	if (efi.properties_table != EFI_INVALID_TABLE_ADDR) {
 		efi_properties_table_t *tbl;
drivers/firmware/efi/libstub/Makefile +1 -2
index dedf9bde44db..2abe6d22dc5f 100644
@@ -29,8 +29,7 @@ OBJECT_FILES_NON_STANDARD	:= y
 # Prevents link failures: __sanitizer_cov_trace_pc() is not linked in.
 KCOV_INSTRUMENT			:= n
 
-lib-y				:= efi-stub-helper.o gop.o secureboot.o
-lib-$(CONFIG_RESET_ATTACK_MITIGATION) += tpm.o
+lib-y				:= efi-stub-helper.o gop.o secureboot.o tpm.o
 
 # include the stub's generic dependencies from lib/ when building for ARM/arm64
 arm-deps := fdt_rw.c fdt_ro.c fdt_wip.c fdt.c fdt_empty_tree.c fdt_sw.c sort.c
drivers/firmware/efi/libstub/tpm.c +81 -0

99 lines not on this page · raw message

drivers/firmware/efi/tpm.c new file +39 -0
new file mode 100644
index 000000000000..07d217d68f47
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2017 Google, Inc.
+ *     Thiebaud Weksteen <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/efi.h>
+#include <linux/init.h>
+#include <linux/memblock.h>
+
+#include <asm/early_ioremap.h>
+
+/*
+ * Reserve the memory associated with the TPM Event Log configuration table.
+ */
+int __init efi_tpm_eventlog_init(void)
+{
+	struct linux_efi_tpm_eventlog *tbl;
+	unsigned int tbl_size;
+
+	if (efi.tpm_log == EFI_INVALID_TABLE_ADDR)
+		return 0;
+
+	tbl = early_memremap(efi.tpm_log, sizeof(*tbl));
+	if (!tbl) {
+		pr_err("Failed to map TPM Event Log table @ 0x%lx\n",
+			efi.tpm_log);
+		return -ENOMEM;
+	}
+
+	tbl_size = sizeof(*tbl) + tbl->size;
+	memblock_reserve(efi.tpm_log, tbl_size);
+	early_memunmap(tbl, sizeof(*tbl));
+	return 0;
+}
+
include/linux/efi.h +49 -0

77 lines not on this page · raw message

Signature · 1 line
2.14.1.581.gf28d330327-goog
#15 lore raw

PATCH v2 3/3 tpm: parse TPM event logs based on EFI table

In reply to Thiebaud Weksteen

If we are not able to retrieve the TPM event logs from the ACPI table, check the EFI configuration table (Linux-specific GUID).

The format version of the log may be returned by the function. If not specified (by previous implementation: tpm_acpi and tpm_of), we default to the version of the chip (previous behaviour).

---
 drivers/char/tpm/Makefile        |  2 +-
 drivers/char/tpm/tpm.h           |  8 +++++
 drivers/char/tpm/tpm1_eventlog.c | 15 +++++++--
 drivers/char/tpm/tpm_efi.c       | 66 ++++++++++++++++++++++++++++++++++++++++
 drivers/firmware/efi/efi.c       |  2 ++
 include/linux/efi.h              |  1 +
 6 files changed, 90 insertions(+), 4 deletions(-)
 create mode 100644 drivers/char/tpm/tpm_efi.c
drivers/char/tpm/Makefile +1 -1
index 23681f01f95a..74182a63eef2 100644
@@ -4,7 +4,7 @@
 obj-$(CONFIG_TCG_TPM) += tpm.o
 tpm-y := tpm-interface.o tpm-dev.o tpm-sysfs.o tpm-chip.o tpm2-cmd.o \
 	 tpm-dev-common.o tpmrm-dev.o tpm1_eventlog.o tpm2_eventlog.o \
-         tpm2-space.o
+         tpm2-space.o tpm_efi.o
 tpm-$(CONFIG_ACPI) += tpm_ppi.o tpm_acpi.o
 tpm-$(CONFIG_OF) += tpm_of.o
 obj-$(CONFIG_TCG_TIS_CORE) += tpm_tis_core.o
drivers/char/tpm/tpm.h +8 -0
index 46caccf6fd1a..1bd97e01df50 100644
@@ -597,6 +597,14 @@ static inline int tpm_read_log_of(struct tpm_chip *chip)
 	return -ENODEV;
 }
 #endif
+#if defined(CONFIG_EFI)
+int tpm_read_log_efi(struct tpm_chip *chip);
+#else
+static inline int tpm_read_log_efi(struct tpm_chip *chip)
+{
+	return -ENODEV;
+}
+#endif
 
 int tpm_bios_log_setup(struct tpm_chip *chip);
 void tpm_bios_log_teardown(struct tpm_chip *chip);
drivers/char/tpm/tpm1_eventlog.c +12 -3
index d6f70f365443..7e25e6bff6ce 100644
@@ -21,6 +21,7 @@
  */
 
 #include <linux/seq_file.h>
+#include <linux/efi.h>
 #include <linux/fs.h>
 #include <linux/security.h>
 #include <linux/module.h>
@@ -371,6 +372,10 @@ static int tpm_read_log(struct tpm_chip *chip)
 	if (rc != -ENODEV)
 		return rc;
 
+	rc = tpm_read_log_efi(chip);
+	if (rc != -ENODEV)
+		return rc;
+
 	return tpm_read_log_of(chip);
 }
 
@@ -388,11 +393,13 @@ int tpm_bios_log_setup(struct tpm_chip *chip)
 {
 	const char *name = dev_name(&chip->dev);
 	unsigned int cnt;
-	int rc = 0;
+	int rc = 0, log_version;
+
 
 	rc = tpm_read_log(chip);
-	if (rc)
+	if (rc < 0)
 		return rc;
+	log_version = rc;
 
 	cnt = 0;
 	chip->bios_dir[cnt] = securityfs_create_dir(name, NULL);
@@ -404,7 +411,9 @@ int tpm_bios_log_setup(struct tpm_chip *chip)
 	cnt++;
 
 	chip->bin_log_seqops.chip = chip;
-	if (chip->flags & TPM_CHIP_FLAG_TPM2)
+
+	if (log_version == EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 ||
+	    (!log_version && (chip->flags & TPM_CHIP_FLAG_TPM2)))
 		chip->bin_log_seqops.seqops =
 			&tpm2_binary_b_measurements_seqops;
 	else
drivers/char/tpm/tpm_efi.c new file +66 -0

66 lines not on this page · raw message

drivers/firmware/efi/efi.c +2 -0
index 03fbaf8eb248..0308acfaaf76 100644
@@ -52,6 +52,7 @@ struct efi __read_mostly efi = {
 	.properties_table	= EFI_INVALID_TABLE_ADDR,
 	.mem_attr_table		= EFI_INVALID_TABLE_ADDR,
 	.rng_seed		= EFI_INVALID_TABLE_ADDR,
+	.tpm_log		= EFI_INVALID_TABLE_ADDR
 };
 EXPORT_SYMBOL(efi);
 
@@ -444,6 +445,7 @@ static __initdata efi_config_table_type_t common_tables[] = {
 	{EFI_PROPERTIES_TABLE_GUID, "PROP", &efi.properties_table},
 	{EFI_MEMORY_ATTRIBUTES_TABLE_GUID, "MEMATTR", &efi.mem_attr_table},
 	{LINUX_EFI_RANDOM_SEED_TABLE_GUID, "RNG", &efi.rng_seed},
+	{LINUX_EFI_TPM_EVENT_LOG_GUID, "TPMEventLog", &efi.tpm_log},
 	{NULL_GUID, NULL, NULL},
 };
 
include/linux/efi.h +1 -0
index e671ea9a462e..ab78950e6911 100644
@@ -943,6 +943,7 @@ extern struct efi {
 	unsigned long properties_table;	/* properties table */
 	unsigned long mem_attr_table;	/* memory attributes table */
 	unsigned long rng_seed;		/* UEFI firmware random seed */
+	unsigned long tpm_log;		/* TPM2 Event Log table */
 	efi_get_time_t *get_time;
 	efi_set_time_t *set_time;
 	efi_get_wakeup_time_t *get_wakeup_time;
Signature · 1 line
2.14.1.581.gf28d330327-goog
#16 lore raw

Re: [PATCH v2 3/3] tpm: parse TPM event logs based on EFI table

drivers/char/tpm/tpm1_eventlog.c int tpm_bios_log_setup(struct tpm_chip *chip) · line 418

Quoted 7 lines · Thiebaud Weksteen
drivers/char/tpm/tpm1_eventlog.c +3 -1
 	chip->bin_log_seqops.chip = chip;
-	if (chip->flags & TPM_CHIP_FLAG_TPM2)
+
+	if (log_version == EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 ||
+	    (!log_version && (chip->flags & TPM_CHIP_FLAG_TPM2)))
 		chip->bin_log_seqops.seqops =
 			&tpm2_binary_b_measurements_seqops;

Lets have all the read_log_* versions return the postitive log_version and get rid of the chip->flags check here.

ie Doesn't ACPI always return the TPM 1 version?

Jason

#17 lore raw

Re: [PATCH v2 3/3] tpm: parse TPM event logs based on EFI table

Quoted 13 lines · Jason Gunthorpe

drivers/char/tpm/tpm1_eventlog.c int tpm_bios_log_setup(struct tpm_chip *chip) · line 418

Quoted 7 lines · Thiebaud Weksteen
drivers/char/tpm/tpm1_eventlog.c +3 -1
 	chip->bin_log_seqops.chip = chip;
-	if (chip->flags & TPM_CHIP_FLAG_TPM2)
+
+	if (log_version == EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 ||
+	    (!log_version && (chip->flags & TPM_CHIP_FLAG_TPM2)))
 		chip->bin_log_seqops.seqops =
 			&tpm2_binary_b_measurements_seqops;

Lets have all the read_log_* versions return the postitive log_version and get rid of the chip->flags check here.

Quoted 1 line

ie Doesn't ACPI always return the TPM 1 version?

That is my understanding. Ashley, Nayna, could you confirm the format version expected by tpm_of? Could it be both?

Quoted 2 lines

Jason

#3 lore raw

Re: [PATCH v2 2/3] efi: call get_event_log before ExitBootServices

In reply to Thiebaud Weksteen
reproduce: wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree make.cross…

Hi Thiebaud,

[auto build test ERROR on efi/next]
[also build test ERROR on next-20170913]
[cannot apply to char-misc/char-misc-testing linus/master v4.13]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Thiebaud-Weksteen/Call-GetEventLog-before-ExitBootServices/20170913-221312
base:   https://git.kernel.org/pub/scm/linux/kernel/git/efi/efi.git next
config: ia64-allmodconfig (attached as .config)
compiler: ia64-linux-gcc (GCC) 6.2.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=ia64

Note: the linux-review/Thiebaud-Weksteen/Call-GetEventLog-before-ExitBootServices/20170913-221312 HEAD 58dc8ee5de3bb5fb1ef216b80a76102d2de2b141 builds fine.
It only hurts bisectibility.

All errors (new ones prefixed by >>):

drivers/firmware/efi/tpm.c: In function 'efi_tpm_eventlog_init':

>> drivers/firmware/efi/tpm.c:24:9: error: 'struct efi' has no member named 'tpm_log'
     if (efi.tpm_log == EFI_INVALID_TABLE_ADDR)
            ^
   In file included from arch/ia64/include/asm/io.h:23:0,
                    from arch/ia64/include/asm/smp.h:20,
                    from include/linux/smp.h:59,
                    from include/linux/percpu.h:6,
                    from include/linux/percpu-rwsem.h:6,
                    from include/linux/fs.h:32,
                    from include/linux/proc_fs.h:8,
                    from include/linux/efi.h:18,
                    from drivers/firmware/efi/tpm.c:10:
   drivers/firmware/efi/tpm.c:27:26: error: 'struct efi' has no member named 'tpm_log'
     tbl = early_memremap(efi.tpm_log, sizeof(*tbl));
                             ^
   arch/ia64/include/asm/early_ioremap.h:5:62: note: in definition of macro 'early_memremap'
    #define early_memremap(phys_addr, size)        early_ioremap(phys_addr, size)
                                                                 ^~~~~~~~~
   In file included from include/linux/kernel.h:13:0,
                    from include/linux/list.h:8,
                    from include/linux/preempt.h:10,
                    from include/linux/spinlock.h:50,
                    from include/linux/seqlock.h:35,
                    from include/linux/time.h:5,
                    from include/linux/efi.h:16,
                    from drivers/firmware/efi/tpm.c:10:
   drivers/firmware/efi/tpm.c:30:7: error: 'struct efi' has no member named 'tpm_log'
       efi.tpm_log);
          ^
   include/linux/printk.h:301:33: note: in definition of macro 'pr_err'
     printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
                                    ^~~~~~~~~~~
   drivers/firmware/efi/tpm.c:35:22: error: 'struct efi' has no member named 'tpm_log'
     memblock_reserve(efi.tpm_log, tbl_size);
                         ^

vim +24 drivers/firmware/efi/tpm.c

    15	
    16	/*
    17	 * Reserve the memory associated with the TPM Event Log configuration table.
    18	 */
    19	int __init efi_tpm_eventlog_init(void)
    20	{
    21		struct linux_efi_tpm_eventlog *tbl;
    22		unsigned int tbl_size;
    23	
  > 24		if (efi.tpm_log == EFI_INVALID_TABLE_ADDR)
    25			return 0;
    26	
    27		tbl = early_memremap(efi.tpm_log, sizeof(*tbl));
    28		if (!tbl) {
    29			pr_err("Failed to map TPM Event Log table @ 0x%lx\n",
    30				efi.tpm_log);
    31			return -ENOMEM;
    32		}
    33	
    34		tbl_size = sizeof(*tbl) + tbl->size;
    35		memblock_reserve(efi.tpm_log, tbl_size);
    36		early_memunmap(tbl, sizeof(*tbl));
    37		return 0;
    38	}
    39	

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#20 lore raw

Re: [PATCH v2 3/3] tpm: parse TPM event logs based on EFI table

In reply to Thiebaud Weksteen
reproduce:

Hi Thiebaud,

[auto build test ERROR on efi/next]
[also build test ERROR on next-20170913]
[cannot apply to char-misc/char-misc-testing linus/master v4.13]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Thiebaud-Weksteen/Call-GetEventLog-before-ExitBootServices/20170913-221312
base:   https://git.kernel.org/pub/scm/linux/kernel/git/efi/efi.git next
config: i386-randconfig-x076-201737 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

>> drivers/char/tpm/tpm_efi.c:20:5: error: redefinition of 'tpm_read_log_efi'

int tpm_read_log_efi(struct tpm_chip *chip)
^~~~~~~~~~~~~~~~
In file included from drivers/char/tpm/tpm_efi.c:17:0:
drivers/char/tpm/tpm.h:603:19: note: previous definition of 'tpm_read_log_efi' was here
static inline int tpm_read_log_efi(struct tpm_chip *chip)
^~~~~~~~~~~~~~~~

vim +/tpm_read_log_efi +20 drivers/char/tpm/tpm_efi.c

18
19 /* read binary bios log from EFI configuration table */

  > 20	int tpm_read_log_efi(struct tpm_chip *chip)

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#5 lore raw

Re: [PATCH v2 2/3] efi: call get_event_log before ExitBootServices

In reply to a message not in the archive

efi_tpm_eventlog_init should be in patch 0003 and not 0002. I'll send a new version of the patch set once I've received more feedback.

Quoted 100 lines · kbuild test robot

Hi Thiebaud,

[auto build test ERROR on efi/next]
[also build test ERROR on next-20170913]
[cannot apply to char-misc/char-misc-testing linus/master v4.13] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Thiebaud-
Weksteen/Call-GetEventLog-before-ExitBootServices/20170913-221312
base: https://git.kernel.org/pub/scm/linux/kernel/git/efi/efi.git next
config: ia64-allmodconfig (attached as .config)
compiler: ia64-linux-gcc (GCC) 6.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/
sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree make.cross ARCH=ia64

Note: the linux-review/Thiebaud-Weksteen/Call-GetEventLog- before-ExitBootServices/20170913-221312 HEAD 58dc8ee5de3bb5fb1ef216b80a76102d2de2b141 builds fine.
It only hurts bisectibility.

All errors (new ones prefixed by >>):

drivers/firmware/efi/tpm.c: In function 'efi_tpm_eventlog_init':

Quoted 1 line
Quoted 1 line

drivers/firmware/efi/tpm.c:24:9: error: 'struct efi' has no member

named 'tpm_log'

     if (efi.tpm_log == EFI_INVALID_TABLE_ADDR)
            ^
   In file included from arch/ia64/include/asm/io.h:23:0,
                    from arch/ia64/include/asm/smp.h:20,
                    from include/linux/smp.h:59,
                    from include/linux/percpu.h:6,
                    from include/linux/percpu-rwsem.h:6,
                    from include/linux/fs.h:32,
                    from include/linux/proc_fs.h:8,
                    from include/linux/efi.h:18,
                    from drivers/firmware/efi/tpm.c:10:
   drivers/firmware/efi/tpm.c:27:26: error: 'struct efi' has no member
named 'tpm_log'
     tbl = early_memremap(efi.tpm_log, sizeof(*tbl));
                             ^
   arch/ia64/include/asm/early_ioremap.h:5:62: note: in definition of
macro 'early_memremap'
    #define early_memremap(phys_addr, size)
early_ioremap(phys_addr, size)
                                                                 ^~~~~~~~~

In file included from include/linux/kernel.h:13:0,
from include/linux/list.h:8,
from include/linux/preempt.h:10,
from include/linux/spinlock.h:50,
from include/linux/seqlock.h:35,
from include/linux/time.h:5,
from include/linux/efi.h:16,
from drivers/firmware/efi/tpm.c:10:
drivers/firmware/efi/tpm.c:30:7: error: 'struct efi' has no member
named 'tpm_log'

       efi.tpm_log);
          ^
   include/linux/printk.h:301:33: note: in definition of macro 'pr_err'
     printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
                                    ^~~~~~~~~~~
   drivers/firmware/efi/tpm.c:35:22: error: 'struct efi' has no member
named 'tpm_log'
     memblock_reserve(efi.tpm_log, tbl_size);
                         ^

vim +24 drivers/firmware/efi/tpm.c

    15
    16  /*
    17   * Reserve the memory associated with the TPM Event Log
configuration table.
    18   */
    19  int __init efi_tpm_eventlog_init(void)
    20  {
    21          struct linux_efi_tpm_eventlog *tbl;
    22          unsigned int tbl_size;
    23
Quoted 1 line

24 if (efi.tpm_log == EFI_INVALID_TABLE_ADDR)

    25                  return 0;
    26
    27          tbl = early_memremap(efi.tpm_log, sizeof(*tbl));
    28          if (!tbl) {
    29                  pr_err("Failed to map TPM Event Log table @
0x%lx\n",
    30                          efi.tpm_log);
    31                  return -ENOMEM;
    32          }
    33
    34          tbl_size = sizeof(*tbl) + tbl->size;
    35          memblock_reserve(efi.tpm_log, tbl_size);
    36          early_memunmap(tbl, sizeof(*tbl));
    37          return 0;
    38  }
    39
Quoted 6 lines

---
0-DAY kernel test infrastructure Open Source Technology
Center
https://lists.01.org/pipermail/kbuild-all Intel
Corporation

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

_______________________________________________
tpmdd-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel

#21 lore raw

Re: [PATCH v2 3/3] tpm: parse TPM event logs based on EFI table

In reply to kbuild test robot

Fixed in next patch set

Quoted 34 lines · kbuild test robot

Hi Thiebaud,

[auto build test ERROR on efi/next]
[also build test ERROR on next-20170913]
[cannot apply to char-misc/char-misc-testing linus/master v4.13]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Thiebaud-Weksteen/Call-GetEventLog-before-ExitBootServices/20170913-221312
base:   https://git.kernel.org/pub/scm/linux/kernel/git/efi/efi.git next
config: i386-randconfig-x076-201737 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386

All errors (new ones prefixed by >>):

Quoted 1 line
Quoted 1 line

drivers/char/tpm/tpm_efi.c:20:5: error: redefinition of 'tpm_read_log_efi'

int tpm_read_log_efi(struct tpm_chip *chip)
^~~~~~~~~~~~~~~~
In file included from drivers/char/tpm/tpm_efi.c:17:0:
drivers/char/tpm/tpm.h:603:19: note: previous definition of 'tpm_read_log_efi' was here
static inline int tpm_read_log_efi(struct tpm_chip *chip)
^~~~~~~~~~~~~~~~

vim +/tpm_read_log_efi +20 drivers/char/tpm/tpm_efi.c

18
19 /* read binary bios log from EFI configuration table */

Quoted 1 line

20 int tpm_read_log_efi(struct tpm_chip *chip)

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#24 lore raw
In reply to Thiebaud Weksteen
Quoted 27 lines · Thiebaud Weksteen

With TPM 1.2, the ACPI table ("TCPA") has two fields to recover the Event Log Area (LAML and LASA). These logs are useful to understand and rebuild the final values of PCRs.

With TPM 2.0, the ACPI table ("TPM2") does not contain these fields anymore. The recommended method is now to call the GetEventLog EFI protocol before ExitBootServices.

Implement this method within the EFI stub and create copy of the logs for the TPM device. This will create /sys/kernel/security/tpm0/binary_bios_measurements for TPM 2.0 devices (similarly to the current behaviour for TPM 1.2 devices).

-------------------------------------------------------------------------------

Patchset Changelog:

Version 2:
- Move tpm_eventlog.h to top include directory, add commit for this.
- Use EFI_LOADER_DATA to store the configuration table
- Whitespace and new lines fixes

Thiebaud Weksteen (3):
tpm: move tpm_eventlog.h outside of drivers folder
efi: call get_event_log before ExitBootServices
tpm: parse TPM event logs based on EFI table

Quoted 10 lines
 arch/x86/boot/compressed/eboot.c                   |  1 +
 drivers/char/tpm/Makefile                          |  2 +-
 drivers/char/tpm/tpm-chip.c                        |  3 +-
 drivers/char/tpm/tpm-interface.c                   |  2 +-
 drivers/char/tpm/tpm.h                             | 35 ++++++++--
 drivers/char/tpm/tpm1_eventlog.c                   | 17 +++--
 drivers/char/tpm/tpm2_eventlog.c                   |  2 +-
 drivers/char/tpm/tpm_acpi.c                        |  2 +-
 drivers/char/tpm/tpm_efi.c                         | 66 ++++++++++++++++++
 drivers/char/tpm/tpm_of.c                          |  2 +-

I think these filenames are just awful. Now that you are introducing completely a new file, it would make sense rename these as

* tpm_eventlog_acpi.c
* tpm_eventlog_efi.c
* tpm_eventlog_of.c

Please wait for further review comments before sending a refined patch set. Please have renames for tpm_acpi.c and tpm_of.c in its own commit before introducing other changes.

/Jarkko

Tested-by on the v2 series
#25 lore raw
In reply to Thiebaud Weksteen

Hello Thiebaud,

Quoted 4 lines · Thiebaud Weksteen via tpmdd-devel

With TPM 1.2, the ACPI table ("TCPA") has two fields to recover the Event Log Area (LAML and LASA). These logs are useful to understand and rebuild the final values of PCRs.

Quoted 8 lines

With TPM 2.0, the ACPI table ("TPM2") does not contain these fields anymore. The recommended method is now to call the GetEventLog EFI protocol before ExitBootServices.

Implement this method within the EFI stub and create copy of the logs for the TPM device. This will create /sys/kernel/security/tpm0/binary_bios_measurements for TPM 2.0 devices (similarly to the current behaviour for TPM 1.2 devices).

I've tested your patches on a system with an Intel PTT firmware based TPM2.0 and the measurements securityfs entry was correctly created and was able to read it:

$ cat /sys/class/tpm/tpm0/device/description
TPM 2.0 Device
$ hexdump /sys/kernel/security/tpm0/binary_bios_measurements | head -n2
0000000 0000 0000 0008 0000 f504 15a0 1810 bf44
0000010 63d0 4fdb b8a4 f278 8dc7 c8aa 0014 0000

So please feel free to add:

I also reviewed the patches and look good to me, I have just one question for patch #2, but I'll comment there.

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Software Engineer - Desktop Hardware Enablement
Red Hat
#6 lore raw

Re: [tpmdd-devel] [PATCH v2 2/3] efi: call get_event_log before ExitBootServices

In reply to Thiebaud Weksteen
Quoted 11 lines · Thiebaud Weksteen via tpmdd-devel

With TPM 2.0 specification, the event logs may only be accessible by calling an EFI Boot Service. Modify the EFI stub to copy the log area to a new Linux-specific EFI configuration table so it remains accessible once booted.

When calling this service, it is possible to specify the expected format of the logs: TPM 1.2 (SHA1) or TPM 2.0 ("Crypto Agile"). For now, only the first format is retrieved.

---

[snip]

Quoted 2 lines
drivers/firmware/efi/libstub/tpm.c +2 -0
+void efi_retrieve_tpm2_eventlog_1_2(efi_system_table_t *sys_table_arg)
+{

[snip]

drivers/firmware/efi/libstub/tpm.c void efi_enable_reset_attack_mitigation(efi_system_table_t *sys_table_arg) · line 118

Quoted 11 lines
drivers/firmware/efi/libstub/tpm.c +11 -0
+
+	/* Allocate space for the logs and copy them. */
+	status = efi_call_early(allocate_pool, EFI_LOADER_DATA,
+				sizeof(*log_tbl) + log_size,
+				(void **) &log_tbl);
+
+	if (status != EFI_SUCCESS) {
+		efi_printk(sys_table_arg,
+			   "Unable to allocate memory for event log\n");
+		return;
+	}

If this fails or any previous error that will prevent the event log table + logs to be allocated, shouldn't tpm_read_log_efi() be notified somehow? Since AFAICT it will still try to access them even if the EFI allocate_pool did not succeed.

drivers/firmware/efi/tpm.c line 23

Quoted 6 lines

+ */

drivers/firmware/efi/tpm.c new file +5 -0
+int __init efi_tpm_eventlog_init(void)
+{
+	struct linux_efi_tpm_eventlog *tbl;
+	unsigned int tbl_size;
+

The functions efi_retrieve_tpm2_eventlog_1_2() and tpm_read_log_efi() are using log_tbl as variable name, so I would use it here too for consistency.

drivers/firmware/efi/tpm.c line 33

Quoted 10 lines
drivers/firmware/efi/tpm.c new file +10 -0
+	if (efi.tpm_log == EFI_INVALID_TABLE_ADDR)
+		return 0;
+
+	tbl = early_memremap(efi.tpm_log, sizeof(*tbl));
+	if (!tbl) {
+		pr_err("Failed to map TPM Event Log table @ 0x%lx\n",
+			efi.tpm_log);
+		return -ENOMEM;
+	}
+

Same question than before, if this fails then the table + logs memory won't be reserved but tpm_read_log_efi() will still try to access it. I'm not sure what is the correct way to notify though, maybe setting efi.tpm_log to 0 and then in tpm_read_log_efi() check efi.tpm_log for 0 or EFI_INVALID_TABLE_ADDR instead?

drivers/firmware/efi/tpm.c line 37

Quoted 4 lines
drivers/firmware/efi/tpm.c new file +4 -0
+	tbl_size = sizeof(*tbl) + tbl->size;
+	memblock_reserve(efi.tpm_log, tbl_size);
+	early_memunmap(tbl, sizeof(*tbl));
+	return 0;

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Software Engineer - Desktop Hardware Enablement
Red Hat
#9 lore raw

Re: [PATCH v2 2/3] efi: call get_event_log before ExitBootServices

In reply to Thiebaud Weksteen
Quoted 10 lines · Thiebaud Weksteen

With TPM 2.0 specification, the event logs may only be accessible by calling an EFI Boot Service. Modify the EFI stub to copy the log area to a new Linux-specific EFI configuration table so it remains accessible once booted.

When calling this service, it is possible to specify the expected format of the logs: TPM 1.2 (SHA1) or TPM 2.0 ("Crypto Agile"). For now, only the first format is retrieved.

With a quick skim the code change looks good but I remember from Matthew's talk that there was this issue that ExitBootServices() would cause a yet another event?

I guess you could manually synthetize that event by reading the PCR values right after ExitBootServices()?

Anyway, great work, thanks for making this effort.

/Jarkko

#22 lore raw

Re: [PATCH v2 3/3] tpm: parse TPM event logs based on EFI table

In reply to Thiebaud Weksteen
Quoted 8 lines · Thiebaud Weksteen

If we are not able to retrieve the TPM event logs from the ACPI table, check the EFI configuration table (Linux-specific GUID).

The format version of the log may be returned by the function. If not specified (by previous implementation: tpm_acpi and tpm_of), we default to the version of the chip (previous behaviour).

You saw my comment about file naming. I.e. tpm_eventlog_efi.c would be a more senseful name.

Quoted 66 lines
---
 drivers/char/tpm/Makefile        |  2 +-
 drivers/char/tpm/tpm.h           |  8 +++++
 drivers/char/tpm/tpm1_eventlog.c | 15 +++++++--
 drivers/char/tpm/tpm_efi.c       | 66 ++++++++++++++++++++++++++++++++++++++++
 drivers/firmware/efi/efi.c       |  2 ++
 include/linux/efi.h              |  1 +
 6 files changed, 90 insertions(+), 4 deletions(-)
 create mode 100644 drivers/char/tpm/tpm_efi.c
drivers/char/tpm/Makefile +1 -1
index 23681f01f95a..74182a63eef2 100644
@@ -4,7 +4,7 @@
 obj-$(CONFIG_TCG_TPM) += tpm.o
 tpm-y := tpm-interface.o tpm-dev.o tpm-sysfs.o tpm-chip.o tpm2-cmd.o \
 	 tpm-dev-common.o tpmrm-dev.o tpm1_eventlog.o tpm2_eventlog.o \
-         tpm2-space.o
+         tpm2-space.o tpm_efi.o
 tpm-$(CONFIG_ACPI) += tpm_ppi.o tpm_acpi.o
 tpm-$(CONFIG_OF) += tpm_of.o
 obj-$(CONFIG_TCG_TIS_CORE) += tpm_tis_core.o
drivers/char/tpm/tpm.h +8 -0
index 46caccf6fd1a..1bd97e01df50 100644
@@ -597,6 +597,14 @@ static inline int tpm_read_log_of(struct tpm_chip *chip)
 	return -ENODEV;
 }
 #endif
+#if defined(CONFIG_EFI)
+int tpm_read_log_efi(struct tpm_chip *chip);
+#else
+static inline int tpm_read_log_efi(struct tpm_chip *chip)
+{
+	return -ENODEV;
+}
+#endif
 
 int tpm_bios_log_setup(struct tpm_chip *chip);
 void tpm_bios_log_teardown(struct tpm_chip *chip);
drivers/char/tpm/tpm1_eventlog.c +5 -0
index d6f70f365443..7e25e6bff6ce 100644
@@ -21,6 +21,7 @@
  */
 
 #include <linux/seq_file.h>
+#include <linux/efi.h>
 #include <linux/fs.h>
 #include <linux/security.h>
 #include <linux/module.h>
@@ -371,6 +372,10 @@ static int tpm_read_log(struct tpm_chip *chip)
 	if (rc != -ENODEV)
 		return rc;
 
+	rc = tpm_read_log_efi(chip);
+	if (rc != -ENODEV)
+		return rc;
+
 	return tpm_read_log_of(chip);
 }
 

drivers/char/tpm/tpm1_eventlog.c int tpm_bios_log_setup(struct tpm_chip *chip) · line 396

Quoted 5 lines
drivers/char/tpm/tpm1_eventlog.c +1 -1
@@ -388,11 +393,13 @@ int tpm_bios_log_setup(struct tpm_chip *chip)
 {
 	const char *name = dev_name(&chip->dev);
 	unsigned int cnt;
-	int rc = 0;
+	int rc = 0, log_version;

A tid bit, one declaration per line.

Quoted 128 lines
drivers/char/tpm/tpm1_eventlog.c +6 -2
+
 
 	rc = tpm_read_log(chip);
-	if (rc)
+	if (rc < 0)
 		return rc;
+	log_version = rc;
 
 	cnt = 0;
 	chip->bios_dir[cnt] = securityfs_create_dir(name, NULL);
@@ -404,7 +411,9 @@ int tpm_bios_log_setup(struct tpm_chip *chip)
 	cnt++;
 
 	chip->bin_log_seqops.chip = chip;
-	if (chip->flags & TPM_CHIP_FLAG_TPM2)
+
+	if (log_version == EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 ||
+	    (!log_version && (chip->flags & TPM_CHIP_FLAG_TPM2)))
 		chip->bin_log_seqops.seqops =
 			&tpm2_binary_b_measurements_seqops;
 	else
drivers/char/tpm/tpm_efi.c new file +66 -0
new file mode 100644
index 000000000000..c8247fc45bb0
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2017 Google
+ *
+ * Authors:
+ *      Thiebaud Weksteen <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ */
+
+#include <linux/efi.h>
+#include <linux/tpm_eventlog.h>
+
+#include "tpm.h"
+
+/* read binary bios log from EFI configuration table */
+int tpm_read_log_efi(struct tpm_chip *chip)
+{
+
+	struct linux_efi_tpm_eventlog *log_tbl;
+	struct tpm_bios_log *log;
+	u32 log_size;
+	u8 tpm_log_version;
+
+	if (!(chip->flags & TPM_CHIP_FLAG_TPM2))
+		return -ENODEV;
+
+	if (efi.tpm_log == EFI_INVALID_TABLE_ADDR)
+		return -ENODEV;
+
+	log = &chip->log;
+
+	log_tbl = memremap(efi.tpm_log, sizeof(*log_tbl), MEMREMAP_WB);
+	if (!log_tbl) {
+		pr_err("Could not map UEFI TPM log table !\n");
+		return -ENOMEM;
+	}
+
+	log_size = log_tbl->size;
+	iounmap(log_tbl);
+
+	log_tbl = memremap(efi.tpm_log, sizeof(*log_tbl) + log_size,
+			   MEMREMAP_WB);
+	if (!log_tbl) {
+		pr_err("Could not map UEFI TPM log table payload!\n");
+		return -ENOMEM;
+	}
+
+	/* malloc EventLog space */
+	log->bios_event_log = kmalloc(log_size, GFP_KERNEL);
+	if (!log->bios_event_log)
+		goto err_iounmap;
+	memcpy(log->bios_event_log, log_tbl->log, log_size);
+	log->bios_event_log_end = log->bios_event_log + log_size;
+
+	tpm_log_version = log_tbl->version;
+	iounmap(log_tbl);
+	return tpm_log_version;
+
+err_iounmap:
+	iounmap(log_tbl);
+	return -ENOMEM;
+}
drivers/firmware/efi/efi.c +2 -0
index 03fbaf8eb248..0308acfaaf76 100644
@@ -52,6 +52,7 @@ struct efi __read_mostly efi = {
 	.properties_table	= EFI_INVALID_TABLE_ADDR,
 	.mem_attr_table		= EFI_INVALID_TABLE_ADDR,
 	.rng_seed		= EFI_INVALID_TABLE_ADDR,
+	.tpm_log		= EFI_INVALID_TABLE_ADDR
 };
 EXPORT_SYMBOL(efi);
 
@@ -444,6 +445,7 @@ static __initdata efi_config_table_type_t common_tables[] = {
 	{EFI_PROPERTIES_TABLE_GUID, "PROP", &efi.properties_table},
 	{EFI_MEMORY_ATTRIBUTES_TABLE_GUID, "MEMATTR", &efi.mem_attr_table},
 	{LINUX_EFI_RANDOM_SEED_TABLE_GUID, "RNG", &efi.rng_seed},
+	{LINUX_EFI_TPM_EVENT_LOG_GUID, "TPMEventLog", &efi.tpm_log},
 	{NULL_GUID, NULL, NULL},
 };
 
include/linux/efi.h +1 -0
index e671ea9a462e..ab78950e6911 100644
@@ -943,6 +943,7 @@ extern struct efi {
 	unsigned long properties_table;	/* properties table */
 	unsigned long mem_attr_table;	/* memory attributes table */
 	unsigned long rng_seed;		/* UEFI firmware random seed */
+	unsigned long tpm_log;		/* TPM2 Event Log table */
 	efi_get_time_t *get_time;
 	efi_set_time_t *set_time;
 	efi_get_wakeup_time_t *get_wakeup_time;
Signature · 1 line
2.14.1.581.gf28d330327-goog

I would not put efi changes to the same commit.

I did not have too detailed look but code changes look nice and clean overally. I'll give this more detailed review once it is sent to [email protected] and CC'd to [email protected].

/Jarkko

#10 lore raw

Re: [PATCH v2 2/3] efi: call get_event_log before ExitBootServices

In reply to Jarkko Sakkinen
Quoted 10 lines · Jarkko Sakkinen
Quoted 9 lines · Thiebaud Weksteen

With TPM 2.0 specification, the event logs may only be accessible by calling an EFI Boot Service. Modify the EFI stub to copy the log area to a new Linux-specific EFI configuration table so it remains accessible once booted.

When calling this service, it is possible to specify the expected format of the logs: TPM 1.2 (SHA1) or TPM 2.0 ("Crypto Agile"). For now, only the first format is retrieved.

Quoted 8 lines
Quoted 1 line

With a quick skim the code change looks good but I remember from Matthew's talk that there was this issue that ExitBootServices() would cause a yet another event?

I guess you could manually synthetize that event by reading the PCR values right after ExitBootServices()?

I think that would involve breaking SHA1… the information should be available in the TCG_TREE_FINAL_EVENTS configuration table, so it /should/ just be a matter of merging the events from that into the event log.

#11 lore raw

Re: [PATCH v2 2/3] efi: call get_event_log before ExitBootServices

Quoted 14 lines · Matthew Garrett
Quoted 12 lines · Jarkko Sakkinen
Quoted 10 lines · Thiebaud Weksteen

With TPM 2.0 specification, the event logs may only be accessible by calling an EFI Boot Service. Modify the EFI stub to copy the log area to a new Linux-specific EFI configuration table so it remains accessible once booted.

When calling this service, it is possible to specify the expected format of the logs: TPM 1.2 (SHA1) or TPM 2.0 ("Crypto Agile"). For now, only the first format is retrieved.

Quoted 8 lines
Quoted 6 lines

With a quick skim the code change looks good but I remember from Matthew's talk that there was this issue that ExitBootServices() would cause a yet another event?

I guess you could manually synthetize that event by reading the PCR values right after ExitBootServices()?

I think that would involve breaking SHA1… the information should be

You are absolutely right, was not thinking clearly :-)

Quoted 3 lines

available in the TCG_TREE_FINAL_EVENTS configuration table, so it /should/ just be a matter of merging the events from that into the event log.

Right, it is available through runtime services. Why this isn't part of the patch set?

/Jrakko

/Jarkko

#12 lore raw

Re: [PATCH v2 2/3] efi: call get_event_log before ExitBootServices

Quoted 24 lines · Jarkko Sakkinen
Quoted 14 lines · Matthew Garrett
Quoted 12 lines · Jarkko Sakkinen
Quoted 10 lines · Thiebaud Weksteen

With TPM 2.0 specification, the event logs may only be accessible by calling an EFI Boot Service. Modify the EFI stub to copy the log area to a new Linux-specific EFI configuration table so it remains accessible once booted.

When calling this service, it is possible to specify the expected format of the logs: TPM 1.2 (SHA1) or TPM 2.0 ("Crypto Agile"). For now, only the first format is retrieved.

Quoted 8 lines
Quoted 6 lines

With a quick skim the code change looks good but I remember from Matthew's talk that there was this issue that ExitBootServices() would cause a yet another event?

I guess you could manually synthetize that event by reading the PCR values right after ExitBootServices()?

I think that would involve breaking SHA1… the information should be

Quoted 8 lines

You are absolutely right, was not thinking clearly :-)

Quoted 3 lines

available in the TCG_TREE_FINAL_EVENTS configuration table, so it /should/ just be a matter of merging the events from that into the event log.

Right, it is available through runtime services. Why this isn't part of the patch set?

Anyway, I'll try this out out when I get back to Finland. Still before landing this to mainline I think it would make sense to make it complete wouldn't it?

/Jarkko

#7 lore raw

Re: [tpmdd-devel] [PATCH v2 2/3] efi: call get_event_log before ExitBootServices

In reply to Javier Martinez Canillas
Quoted 20 lines · Javier Martinez Canillas
Quoted 11 lines · Thiebaud Weksteen via tpmdd-devel

With TPM 2.0 specification, the event logs may only be accessible by calling an EFI Boot Service. Modify the EFI stub to copy the log area to a new Linux-specific EFI configuration table so it remains accessible once booted.

When calling this service, it is possible to specify the expected format of the logs: TPM 1.2 (SHA1) or TPM 2.0 ("Crypto Agile"). For now, only the first format is retrieved.

---

[snip]

Quoted 2 lines
drivers/firmware/efi/libstub/tpm.c +2 -0
+void efi_retrieve_tpm2_eventlog_1_2(efi_system_table_t *sys_table_arg)
+{

[snip]

Quoted 16 lines

drivers/firmware/efi/libstub/tpm.c void efi_enable_reset_attack_mitigation(efi_system_table_t *sys_table_arg) · line 118

Quoted 11 lines
drivers/firmware/efi/libstub/tpm.c +11 -0
+
+     /* Allocate space for the logs and copy them. */
+     status = efi_call_early(allocate_pool, EFI_LOADER_DATA,
+                             sizeof(*log_tbl) + log_size,
+                             (void **) &log_tbl);
+
+     if (status != EFI_SUCCESS) {
+             efi_printk(sys_table_arg,
+                        "Unable to allocate memory for event log\n");
+             return;
+     }

If this fails or any previous error that will prevent the event log table + logs to be allocated, shouldn't tpm_read_log_efi() be notified somehow? Since AFAICT it will still try to access them even if the EFI allocate_pool did not succeed.

The implicit part that covers this case is in drivers/firmware/efi/efi.c. The match_config_table function will go through all the installed configuration tables and only fill up the associated member of the efi structure if it exists. In this case, .tpm_log will remains at EFI_INVALID_TABLE_ADDR unless efi_call_early(install_configuration_table, ...) is called. So no further processing is to be expected should the allocation failed.

Quoted 10 lines

drivers/firmware/efi/tpm.c line 23

Quoted 6 lines

+ */

drivers/firmware/efi/tpm.c new file +5 -0
+int __init efi_tpm_eventlog_init(void)
+{
+     struct linux_efi_tpm_eventlog *tbl;
+     unsigned int tbl_size;
+

The functions efi_retrieve_tpm2_eventlog_1_2() and tpm_read_log_efi() are using log_tbl as variable name, so I would use it here too for consistency.

Done.

Quoted 7 lines
Quoted 7 lines
drivers/firmware/efi/tpm.c new file +7 -0
+     if (efi.tpm_log == EFI_INVALID_TABLE_ADDR)
+             return 0;
+
+     tbl = early_memremap(efi.tpm_log, sizeof(*tbl));
+     if (!tbl) {
+             pr_err("Failed to map TPM Event Log table @ 0x%lx\n",
+                     efi.tpm_log);
Quoted 9 lines

drivers/firmware/efi/tpm.c line 33

Quoted 3 lines
drivers/firmware/efi/tpm.c new file +3 -0
+             return -ENOMEM;
+     }
+

Same question than before, if this fails then the table + logs memory won't be reserved but tpm_read_log_efi() will still try to access it. I'm not sure what is the correct way to notify though, maybe setting efi.tpm_log to 0 and then in tpm_read_log_efi() check efi.tpm_log for 0 or EFI_INVALID_TABLE_ADDR instead?

That's right. To keep it simple, it might be easier to just set tpm_log to EFI_INVALID_TABLE_ADDR if that happens. Added in the next version of the patch set.

Quoted 10 lines

drivers/firmware/efi/tpm.c line 37

Quoted 4 lines
drivers/firmware/efi/tpm.c new file +4 -0
+     tbl_size = sizeof(*tbl) + tbl->size;
+     memblock_reserve(efi.tpm_log, tbl_size);
+     early_memunmap(tbl, sizeof(*tbl));
+     return 0;

Best regards,
--
Javier Martinez Canillas
Software Engineer - Desktop Hardware Enablement
Red Hat

#13 lore raw

Re: [PATCH v2 2/3] efi: call get_event_log before ExitBootServices

In reply to Jarkko Sakkinen
Quoted 24 lines · Jarkko Sakkinen
Quoted 14 lines · Matthew Garrett
Quoted 12 lines · Jarkko Sakkinen
Quoted 10 lines · Thiebaud Weksteen

With TPM 2.0 specification, the event logs may only be accessible by calling an EFI Boot Service. Modify the EFI stub to copy the log area to a new Linux-specific EFI configuration table so it remains accessible once booted.

When calling this service, it is possible to specify the expected format of the logs: TPM 1.2 (SHA1) or TPM 2.0 ("Crypto Agile"). For now, only the first format is retrieved.

Quoted 8 lines
Quoted 6 lines

With a quick skim the code change looks good but I remember from Matthew's talk that there was this issue that ExitBootServices() would cause a yet another event?

I guess you could manually synthetize that event by reading the PCR values right after ExitBootServices()?

I think that would involve breaking SHA1… the information should be

Quoted 8 lines

You are absolutely right, was not thinking clearly :-)

Quoted 3 lines

available in the TCG_TREE_FINAL_EVENTS configuration table, so it /should/ just be a matter of merging the events from that into the event log.

Right, it is available through runtime services. Why this isn't part of the patch set?

This is not included yet as this table (EFI_TCG2_FINAL_EVENTS_TABLE_GUID) relies on the TPM2 format for the log entries (TCG_PCR_EVENT2, "Crypto Agile"). I first plan to add the parsing of this log version (ie, efi_retrieve_tpm2_eventlog_2) before adding the merging of both tables. But these will be separate patch sets.

Quoted 4 lines

/Jrakko

/Jarkko

#23 lore raw

Re: [PATCH v2 3/3] tpm: parse TPM event logs based on EFI table

In reply to Jarkko Sakkinen
Quoted 4 lines · Jarkko Sakkinen
Quoted 3 lines · Thiebaud Weksteen

If we are not able to retrieve the TPM event logs from the ACPI table, check the EFI configuration table (Linux-specific GUID).

Quoted 8 lines
Quoted 5 lines

The format version of the log may be returned by the function. If not specified (by previous implementation: tpm_acpi and tpm_of), we default to the version of the chip (previous behaviour).

You saw my comment about file naming. I.e. tpm_eventlog_efi.c would be a more senseful name.

Done.

Quoted 66 lines
Quoted 66 lines
---
 drivers/char/tpm/Makefile        |  2 +-
 drivers/char/tpm/tpm.h           |  8 +++++
 drivers/char/tpm/tpm1_eventlog.c | 15 +++++++--
 drivers/char/tpm/tpm_efi.c       | 66 ++++++++++++++++++++++++++++++++++++++++
 drivers/firmware/efi/efi.c       |  2 ++
 include/linux/efi.h              |  1 +
 6 files changed, 90 insertions(+), 4 deletions(-)
 create mode 100644 drivers/char/tpm/tpm_efi.c
drivers/char/tpm/Makefile +1 -1
index 23681f01f95a..74182a63eef2 100644
@@ -4,7 +4,7 @@
 obj-$(CONFIG_TCG_TPM) += tpm.o
 tpm-y := tpm-interface.o tpm-dev.o tpm-sysfs.o tpm-chip.o tpm2-cmd.o \
       tpm-dev-common.o tpmrm-dev.o tpm1_eventlog.o tpm2_eventlog.o \
-         tpm2-space.o
+         tpm2-space.o tpm_efi.o
 tpm-$(CONFIG_ACPI) += tpm_ppi.o tpm_acpi.o
 tpm-$(CONFIG_OF) += tpm_of.o
 obj-$(CONFIG_TCG_TIS_CORE) += tpm_tis_core.o
drivers/char/tpm/tpm.h +8 -0
index 46caccf6fd1a..1bd97e01df50 100644
@@ -597,6 +597,14 @@ static inline int tpm_read_log_of(struct tpm_chip *chip)
      return -ENODEV;
 }
 #endif
+#if defined(CONFIG_EFI)
+int tpm_read_log_efi(struct tpm_chip *chip);
+#else
+static inline int tpm_read_log_efi(struct tpm_chip *chip)
+{
+     return -ENODEV;
+}
+#endif
 
 int tpm_bios_log_setup(struct tpm_chip *chip);
 void tpm_bios_log_teardown(struct tpm_chip *chip);
drivers/char/tpm/tpm1_eventlog.c +5 -0
index d6f70f365443..7e25e6bff6ce 100644
@@ -21,6 +21,7 @@
  */
 
 #include <linux/seq_file.h>
+#include <linux/efi.h>
 #include <linux/fs.h>
 #include <linux/security.h>
 #include <linux/module.h>
@@ -371,6 +372,10 @@ static int tpm_read_log(struct tpm_chip *chip)
      if (rc != -ENODEV)
              return rc;
 
+     rc = tpm_read_log_efi(chip);
+     if (rc != -ENODEV)
+             return rc;
+
      return tpm_read_log_of(chip);
 }
 
Quoted 8 lines

drivers/char/tpm/tpm1_eventlog.c int tpm_bios_log_setup(struct tpm_chip *chip) · line 396

Quoted 6 lines
drivers/char/tpm/tpm1_eventlog.c +1 -1
@@ -388,11 +393,13 @@ int tpm_bios_log_setup(struct tpm_chip *chip)
 {
      const char *name = dev_name(&chip->dev);
      unsigned int cnt;
-     int rc = 0;
+     int rc = 0, log_version;

A tid bit, one declaration per line.

Done.

Quoted 123 lines
Quoted 123 lines
drivers/char/tpm/tpm1_eventlog.c +6 -2
+
 
      rc = tpm_read_log(chip);
-     if (rc)
+     if (rc < 0)
              return rc;
+     log_version = rc;
 
      cnt = 0;
      chip->bios_dir[cnt] = securityfs_create_dir(name, NULL);
@@ -404,7 +411,9 @@ int tpm_bios_log_setup(struct tpm_chip *chip)
      cnt++;
 
      chip->bin_log_seqops.chip = chip;
-     if (chip->flags & TPM_CHIP_FLAG_TPM2)
+
+     if (log_version == EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 ||
+         (!log_version && (chip->flags & TPM_CHIP_FLAG_TPM2)))
              chip->bin_log_seqops.seqops =
                      &tpm2_binary_b_measurements_seqops;
      else
drivers/char/tpm/tpm_efi.c new file +66 -0
new file mode 100644
index 000000000000..c8247fc45bb0
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2017 Google
+ *
+ * Authors:
+ *      Thiebaud Weksteen <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ */
+
+#include <linux/efi.h>
+#include <linux/tpm_eventlog.h>
+
+#include "tpm.h"
+
+/* read binary bios log from EFI configuration table */
+int tpm_read_log_efi(struct tpm_chip *chip)
+{
+
+     struct linux_efi_tpm_eventlog *log_tbl;
+     struct tpm_bios_log *log;
+     u32 log_size;
+     u8 tpm_log_version;
+
+     if (!(chip->flags & TPM_CHIP_FLAG_TPM2))
+             return -ENODEV;
+
+     if (efi.tpm_log == EFI_INVALID_TABLE_ADDR)
+             return -ENODEV;
+
+     log = &chip->log;
+
+     log_tbl = memremap(efi.tpm_log, sizeof(*log_tbl), MEMREMAP_WB);
+     if (!log_tbl) {
+             pr_err("Could not map UEFI TPM log table !\n");
+             return -ENOMEM;
+     }
+
+     log_size = log_tbl->size;
+     iounmap(log_tbl);
+
+     log_tbl = memremap(efi.tpm_log, sizeof(*log_tbl) + log_size,
+                        MEMREMAP_WB);
+     if (!log_tbl) {
+             pr_err("Could not map UEFI TPM log table payload!\n");
+             return -ENOMEM;
+     }
+
+     /* malloc EventLog space */
+     log->bios_event_log = kmalloc(log_size, GFP_KERNEL);
+     if (!log->bios_event_log)
+             goto err_iounmap;
+     memcpy(log->bios_event_log, log_tbl->log, log_size);
+     log->bios_event_log_end = log->bios_event_log + log_size;
+
+     tpm_log_version = log_tbl->version;
+     iounmap(log_tbl);
+     return tpm_log_version;
+
+err_iounmap:
+     iounmap(log_tbl);
+     return -ENOMEM;
+}
drivers/firmware/efi/efi.c +2 -0
index 03fbaf8eb248..0308acfaaf76 100644
@@ -52,6 +52,7 @@ struct efi __read_mostly efi = {
      .properties_table       = EFI_INVALID_TABLE_ADDR,
      .mem_attr_table         = EFI_INVALID_TABLE_ADDR,
      .rng_seed               = EFI_INVALID_TABLE_ADDR,
+     .tpm_log                = EFI_INVALID_TABLE_ADDR
 };
 EXPORT_SYMBOL(efi);
 
@@ -444,6 +445,7 @@ static __initdata efi_config_table_type_t common_tables[] = {
      {EFI_PROPERTIES_TABLE_GUID, "PROP", &efi.properties_table},
      {EFI_MEMORY_ATTRIBUTES_TABLE_GUID, "MEMATTR", &efi.mem_attr_table},
      {LINUX_EFI_RANDOM_SEED_TABLE_GUID, "RNG", &efi.rng_seed},
+     {LINUX_EFI_TPM_EVENT_LOG_GUID, "TPMEventLog", &efi.tpm_log},
      {NULL_GUID, NULL, NULL},
 };
 
include/linux/efi.h +1 -0
index e671ea9a462e..ab78950e6911 100644
@@ -943,6 +943,7 @@ extern struct efi {
      unsigned long properties_table; /* properties table */
      unsigned long mem_attr_table;   /* memory attributes table */
      unsigned long rng_seed;         /* UEFI firmware random seed */
+     unsigned long tpm_log;          /* TPM2 Event Log table */
Quoted 8 lines
Quoted 6 lines
include/linux/efi.h +0 -1
      efi_get_time_t *get_time;
      efi_set_time_t *set_time;
      efi_get_wakeup_time_t *get_wakeup_time;
--

2.14.1.581.gf28d330327-goog

I would not put efi changes to the same commit.

Done.

Quoted 5 lines

I did not have too detailed look but code changes look nice and clean overally. I'll give this more detailed review once it is sent to [email protected] and CC'd to linux-security-module-u79uwXL29TaiAVqoAR/[email protected]

Will do.

Quoted 2 lines

/Jarkko

#18 lore raw

Re: [PATCH v2 3/3] tpm: parse TPM event logs based on EFI table

In reply to Thiebaud Weksteen
Quoted 11 lines · Thiebaud Weksteen
Quoted 10 lines · Jason Gunthorpe
Quoted 7 lines · Thiebaud Weksteen
    chip->bin_log_seqops.chip = chip;
drivers/char/tpm/tpm1_eventlog.c +3 -1
-   if (chip->flags & TPM_CHIP_FLAG_TPM2)
+
+   if (log_version == EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 ||
+       (!log_version && (chip->flags & TPM_CHIP_FLAG_TPM2)))
            chip->bin_log_seqops.seqops =
                    &tpm2_binary_b_measurements_seqops;
Quoted 8 lines
Quoted 4 lines

Lets have all the read_log_* versions return the postitive log_version and get rid of the chip->flags check here.

ie Doesn't ACPI always return the TPM 1 version?

That is my understanding. Ashley, Nayna, could you confirm the format version expected by tpm_of? Could it be both?

I've changed the returned code for ACPI but not for DeviceTree. Without confirmation for tpm_of, I am reluctant to modify the current behaviour.

Quoted 2 lines
Quoted 2 lines

Jason

#8 lore raw

Re: [tpmdd-devel] [PATCH v2 2/3] efi: call get_event_log before ExitBootServices

In reply to Thiebaud Weksteen
Quoted 3 lines · Thiebaud Weksteen
Quoted 1 line · Javier Martinez Canillas

On 09/11/2017 12:00 PM, Thiebaud Weksteen via tpmdd-devel wrote:

[snip]

Quoted 12 lines
Quoted 11 lines

drivers/firmware/efi/libstub/tpm.c void efi_enable_reset_attack_mitigation(efi_system_table_t *sys_table_arg) · line 118

Quoted 6 lines
drivers/firmware/efi/libstub/tpm.c +6 -0
+
+     if (status != EFI_SUCCESS) {
+             efi_printk(sys_table_arg,
+                        "Unable to allocate memory for event log\n");
+             return;
+     }

If this fails or any previous error that will prevent the event log table + logs to be allocated, shouldn't tpm_read_log_efi() be notified somehow? Since AFAICT it will still try to access them even if the EFI allocate_pool did not succeed.

Quoted 8 lines

The implicit part that covers this case is in drivers/firmware/efi/efi.c. The match_config_table function will go through all the installed configuration tables and only fill up the associated member of the efi structure if it exists. In this case, .tpm_log will remains at EFI_INVALID_TABLE_ADDR unless efi_call_early(install_configuration_table, ...) is called. So no further processing is to be expected should the allocation failed.

I see, missed that. Thanks a lot for the explanation.

Quoted 30 lines
Quoted 10 lines

drivers/firmware/efi/tpm.c line 23

Quoted 6 lines

+ */

drivers/firmware/efi/tpm.c new file +5 -0
+int __init efi_tpm_eventlog_init(void)
+{
+     struct linux_efi_tpm_eventlog *tbl;
+     unsigned int tbl_size;
+

The functions efi_retrieve_tpm2_eventlog_1_2() and tpm_read_log_efi() are using log_tbl as variable name, so I would use it here too for consistency.

Done.

Quoted 7 lines
Quoted 7 lines
drivers/firmware/efi/tpm.c new file +7 -0
+     if (efi.tpm_log == EFI_INVALID_TABLE_ADDR)
+             return 0;
+
+     tbl = early_memremap(efi.tpm_log, sizeof(*tbl));
+     if (!tbl) {
+             pr_err("Failed to map TPM Event Log table @ 0x%lx\n",
+                     efi.tpm_log);
Quoted 9 lines

drivers/firmware/efi/tpm.c line 33

Quoted 3 lines
drivers/firmware/efi/tpm.c new file +3 -0
+             return -ENOMEM;
+     }
+

Same question than before, if this fails then the table + logs memory won't be reserved but tpm_read_log_efi() will still try to access it. I'm not sure what is the correct way to notify though, maybe setting efi.tpm_log to 0 and then in tpm_read_log_efi() check efi.tpm_log for 0 or EFI_INVALID_TABLE_ADDR instead?

Quoted 4 lines

That's right. To keep it simple, it might be easier to just set tpm_log to EFI_INVALID_TABLE_ADDR if that happens. Added in the next version of the patch set.

Right. I wasn't sure if you wanted to distinguish between the two cases, but that is simpler indeed.

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Software Engineer - Desktop Hardware Enablement
Red Hat
#19 lore raw

Re: [PATCH v2 3/3] tpm: parse TPM event logs based on EFI table

In reply to Thiebaud Weksteen
Quoted 17 lines · Thiebaud Weksteen
Quoted 16 lines · Thiebaud Weksteen
Quoted 14 lines · Jason Gunthorpe

drivers/char/tpm/tpm1_eventlog.c int tpm_bios_log_setup(struct tpm_chip *chip) · line 418

Quoted 7 lines · Thiebaud Weksteen
    chip->bin_log_seqops.chip = chip;
drivers/char/tpm/tpm1_eventlog.c +3 -1
-   if (chip->flags & TPM_CHIP_FLAG_TPM2)
+
+   if (log_version == EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 ||
+       (!log_version && (chip->flags & TPM_CHIP_FLAG_TPM2)))
            chip->bin_log_seqops.seqops =
                    &tpm2_binary_b_measurements_seqops;

Lets have all the read_log_* versions return the postitive log_version and get rid of the chip->flags check here.

ie Doesn't ACPI always return the TPM 1 version?

Quoted 7 lines
Quoted 3 lines

That is my understanding. Ashley, Nayna, could you confirm the format version expected by tpm_of? Could it be both?

I've changed the returned code for ACPI but not for DeviceTree. Without confirmation for tpm_of, I am reluctant to modify the current behaviour.

Move the TPM_CHIP_FLAG_TPM2 check into tpm_of to keep the current behavior but still return the code..

Jason

#14 lore raw

Re: [PATCH v2 2/3] efi: call get_event_log before ExitBootServices

In reply to Thiebaud Weksteen
Quoted 35 lines · Thiebaud Weksteen
Quoted 24 lines · Jarkko Sakkinen
Quoted 14 lines · Matthew Garrett
Quoted 12 lines · Jarkko Sakkinen
Quoted 10 lines · Thiebaud Weksteen

With TPM 2.0 specification, the event logs may only be accessible by calling an EFI Boot Service. Modify the EFI stub to copy the log area to a new Linux-specific EFI configuration table so it remains accessible once booted.

When calling this service, it is possible to specify the expected format of the logs: TPM 1.2 (SHA1) or TPM 2.0 ("Crypto Agile"). For now, only the first format is retrieved.

Quoted 8 lines
Quoted 6 lines

With a quick skim the code change looks good but I remember from Matthew's talk that there was this issue that ExitBootServices() would cause a yet another event?

I guess you could manually synthetize that event by reading the PCR values right after ExitBootServices()?

I think that would involve breaking SHA1… the information should be

Quoted 8 lines

You are absolutely right, was not thinking clearly :-)

Quoted 3 lines

available in the TCG_TREE_FINAL_EVENTS configuration table, so it /should/ just be a matter of merging the events from that into the event log.

Right, it is available through runtime services. Why this isn't part of the patch set?

Quoted 6 lines

This is not included yet as this table (EFI_TCG2_FINAL_EVENTS_TABLE_GUID) relies on the TPM2 format for the log entries (TCG_PCR_EVENT2, "Crypto Agile"). I first plan to add the parsing of this log version (ie, efi_retrieve_tpm2_eventlog_2) before adding the merging of both tables. But these will be separate patch sets.

OK, this should be documented to the commit message to make it clear.

[email protected] is now up and running. I'm still surviving from jetlag etc. so testing might be postponed either near end of the week or next week.

Thanks for doing this. This is really important stuff in order to get the Linux TPM 2.0 support feature complete.

/Jarkko

Tested-by Reviewed-by on the v2 series
#26 lore raw
In reply to Thiebaud Weksteen
Quoted 40 lines · Thiebaud Weksteen

With TPM 1.2, the ACPI table ("TCPA") has two fields to recover the Event Log Area (LAML and LASA). These logs are useful to understand and rebuild the final values of PCRs.

With TPM 2.0, the ACPI table ("TPM2") does not contain these fields anymore. The recommended method is now to call the GetEventLog EFI protocol before ExitBootServices.

Implement this method within the EFI stub and create copy of the logs for the TPM device. This will create /sys/kernel/security/tpm0/binary_bios_measurements for TPM 2.0 devices (similarly to the current behaviour for TPM 1.2 devices).

-------------------------------------------------------------------------------

Patchset Changelog:

Version 2:
- Move tpm_eventlog.h to top include directory, add commit for this.
- Use EFI_LOADER_DATA to store the configuration table
- Whitespace and new lines fixes

Thiebaud Weksteen (3):
tpm: move tpm_eventlog.h outside of drivers folder
efi: call get_event_log before ExitBootServices
tpm: parse TPM event logs based on EFI table

 arch/x86/boot/compressed/eboot.c                   |  1 +
 drivers/char/tpm/Makefile                          |  2 +-
 drivers/char/tpm/tpm-chip.c                        |  3 +-
 drivers/char/tpm/tpm-interface.c                   |  2 +-
 drivers/char/tpm/tpm.h                             | 35 ++++++++--
 drivers/char/tpm/tpm1_eventlog.c                   | 17 +++--
 drivers/char/tpm/tpm2_eventlog.c                   |  2 +-
 drivers/char/tpm/tpm_acpi.c                        |  2 +-
 drivers/char/tpm/tpm_efi.c                         | 66 ++++++++++++++++++
 drivers/char/tpm/tpm_of.c                          |  2 +-
 drivers/firmware/efi/Makefile                      |  2 +-
 drivers/firmware/efi/efi.c                         |  4 ++
 drivers/firmware/efi/libstub/Makefile              |  3 +-
Quoted 12 lines
 drivers/firmware/efi/libstub/tpm.c                 | 81 ++++++++++++++++++++++
 drivers/firmware/efi/tpm.c                         | 39 +++++++++++
 include/linux/efi.h                                | 50 +++++++++++++
 {drivers/char/tpm => include/linux}/tpm_eventlog.h | 32 ++-------
 17 files changed, 301 insertions(+), 42 deletions(-)
 create mode 100644 drivers/char/tpm/tpm_efi.c
 create mode 100644 drivers/firmware/efi/tpm.c
 rename {drivers/char/tpm => include/linux}/tpm_eventlog.h (77%)
Signature · 1 line
2.14.1.581.gf28d330327-goog

/Jarkko