aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/x86/boot/compressed/eboot.c1
-rw-r--r--drivers/firmware/efi/Makefile2
-rw-r--r--drivers/firmware/efi/efi.c4
-rw-r--r--drivers/firmware/efi/libstub/Makefile3
-rw-r--r--drivers/firmware/efi/libstub/tpm.c81
-rw-r--r--drivers/firmware/efi/tpm.c40
-rw-r--r--include/linux/efi.h46
7 files changed, 174 insertions, 3 deletions
diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
index e56dbc67e837..353e20c3f114 100644
--- a/arch/x86/boot/compressed/eboot.c
+++ b/arch/x86/boot/compressed/eboot.c
@@ -999,6 +999,7 @@ struct boot_params *efi_main(struct efi_config *c,
999 999
1000 /* Ask the firmware to clear memory on unclean shutdown */ 1000 /* Ask the firmware to clear memory on unclean shutdown */
1001 efi_enable_reset_attack_mitigation(sys_table); 1001 efi_enable_reset_attack_mitigation(sys_table);
1002 efi_retrieve_tpm2_eventlog(sys_table);
1002 1003
1003 setup_graphics(boot_params); 1004 setup_graphics(boot_params);
1004 1005
diff --git a/drivers/firmware/efi/Makefile b/drivers/firmware/efi/Makefile
index 269501dfba53..1d7226fb7d2f 100644
--- a/drivers/firmware/efi/Makefile
+++ b/drivers/firmware/efi/Makefile
@@ -11,7 +11,7 @@
11KASAN_SANITIZE_runtime-wrappers.o := n 11KASAN_SANITIZE_runtime-wrappers.o := n
12 12
13obj-$(CONFIG_ACPI_BGRT) += efi-bgrt.o 13obj-$(CONFIG_ACPI_BGRT) += efi-bgrt.o
14obj-$(CONFIG_EFI) += efi.o vars.o reboot.o memattr.o 14obj-$(CONFIG_EFI) += efi.o vars.o reboot.o memattr.o tpm.o
15obj-$(CONFIG_EFI) += capsule.o memmap.o 15obj-$(CONFIG_EFI) += capsule.o memmap.o
16obj-$(CONFIG_EFI_VARS) += efivars.o 16obj-$(CONFIG_EFI_VARS) += efivars.o
17obj-$(CONFIG_EFI_ESRT) += esrt.o 17obj-$(CONFIG_EFI_ESRT) += esrt.o
diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
index 557a47829d03..cfa6fe786ab6 100644
--- a/drivers/firmware/efi/efi.c
+++ b/drivers/firmware/efi/efi.c
@@ -52,6 +52,7 @@ struct efi __read_mostly efi = {
52 .properties_table = EFI_INVALID_TABLE_ADDR, 52 .properties_table = EFI_INVALID_TABLE_ADDR,
53 .mem_attr_table = EFI_INVALID_TABLE_ADDR, 53 .mem_attr_table = EFI_INVALID_TABLE_ADDR,
54 .rng_seed = EFI_INVALID_TABLE_ADDR, 54 .rng_seed = EFI_INVALID_TABLE_ADDR,
55 .tpm_log = EFI_INVALID_TABLE_ADDR
55}; 56};
56EXPORT_SYMBOL(efi); 57EXPORT_SYMBOL(efi);
57 58
@@ -464,6 +465,7 @@ static __initdata efi_config_table_type_t common_tables[] = {
464 {EFI_PROPERTIES_TABLE_GUID, "PROP", &efi.properties_table}, 465 {EFI_PROPERTIES_TABLE_GUID, "PROP", &efi.properties_table},
465 {EFI_MEMORY_ATTRIBUTES_TABLE_GUID, "MEMATTR", &efi.mem_attr_table}, 466 {EFI_MEMORY_ATTRIBUTES_TABLE_GUID, "MEMATTR", &efi.mem_attr_table},
466 {LINUX_EFI_RANDOM_SEED_TABLE_GUID, "RNG", &efi.rng_seed}, 467 {LINUX_EFI_RANDOM_SEED_TABLE_GUID, "RNG", &efi.rng_seed},
468 {LINUX_EFI_TPM_EVENT_LOG_GUID, "TPMEventLog", &efi.tpm_log},
467 {NULL_GUID, NULL, NULL}, 469 {NULL_GUID, NULL, NULL},
468}; 470};
469 471
@@ -552,6 +554,8 @@ int __init efi_config_parse_tables(void *config_tables, int count, int sz,
552 if (efi_enabled(EFI_MEMMAP)) 554 if (efi_enabled(EFI_MEMMAP))
553 efi_memattr_init(); 555 efi_memattr_init();
554 556
557 efi_tpm_eventlog_init();
558
555 /* Parse the EFI Properties table if it exists */ 559 /* Parse the EFI Properties table if it exists */
556 if (efi.properties_table != EFI_INVALID_TABLE_ADDR) { 560 if (efi.properties_table != EFI_INVALID_TABLE_ADDR) {
557 efi_properties_table_t *tbl; 561 efi_properties_table_t *tbl;
diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile
index adaa4a964f0c..7b3ba40f0745 100644
--- a/drivers/firmware/efi/libstub/Makefile
+++ b/drivers/firmware/efi/libstub/Makefile
@@ -30,8 +30,7 @@ OBJECT_FILES_NON_STANDARD := y
30# Prevents link failures: __sanitizer_cov_trace_pc() is not linked in. 30# Prevents link failures: __sanitizer_cov_trace_pc() is not linked in.
31KCOV_INSTRUMENT := n 31KCOV_INSTRUMENT := n
32 32
33lib-y := efi-stub-helper.o gop.o secureboot.o 33lib-y := efi-stub-helper.o gop.o secureboot.o tpm.o
34lib-$(CONFIG_RESET_ATTACK_MITIGATION) += tpm.o
35 34
36# include the stub's generic dependencies from lib/ when building for ARM/arm64 35# include the stub's generic dependencies from lib/ when building for ARM/arm64
37arm-deps-y := fdt_rw.c fdt_ro.c fdt_wip.c fdt.c fdt_empty_tree.c fdt_sw.c 36arm-deps-y := fdt_rw.c fdt_ro.c fdt_wip.c fdt.c fdt_empty_tree.c fdt_sw.c
diff --git a/drivers/firmware/efi/libstub/tpm.c b/drivers/firmware/efi/libstub/tpm.c
index 6224cdbc9669..da661bf8cb96 100644
--- a/drivers/firmware/efi/libstub/tpm.c
+++ b/drivers/firmware/efi/libstub/tpm.c
@@ -4,15 +4,18 @@
4 * Copyright (C) 2016 CoreOS, Inc 4 * Copyright (C) 2016 CoreOS, Inc
5 * Copyright (C) 2017 Google, Inc. 5 * Copyright (C) 2017 Google, Inc.
6 * Matthew Garrett <mjg59@google.com> 6 * Matthew Garrett <mjg59@google.com>
7 * Thiebaud Weksteen <tweek@google.com>
7 * 8 *
8 * This file is part of the Linux kernel, and is made available under the 9 * This file is part of the Linux kernel, and is made available under the
9 * terms of the GNU General Public License version 2. 10 * terms of the GNU General Public License version 2.
10 */ 11 */
11#include <linux/efi.h> 12#include <linux/efi.h>
13#include <linux/tpm_eventlog.h>
12#include <asm/efi.h> 14#include <asm/efi.h>
13 15
14#include "efistub.h" 16#include "efistub.h"
15 17
18#ifdef CONFIG_RESET_ATTACK_MITIGATION
16static const efi_char16_t efi_MemoryOverWriteRequest_name[] = { 19static const efi_char16_t efi_MemoryOverWriteRequest_name[] = {
17 'M', 'e', 'm', 'o', 'r', 'y', 'O', 'v', 'e', 'r', 'w', 'r', 'i', 't', 20 'M', 'e', 'm', 'o', 'r', 'y', 'O', 'v', 'e', 'r', 'w', 'r', 'i', 't',
18 'e', 'R', 'e', 'q', 'u', 'e', 's', 't', 'C', 'o', 'n', 't', 'r', 'o', 21 'e', 'R', 'e', 'q', 'u', 'e', 's', 't', 'C', 'o', 'n', 't', 'r', 'o',
@@ -56,3 +59,81 @@ void efi_enable_reset_attack_mitigation(efi_system_table_t *sys_table_arg)
56 EFI_VARIABLE_BOOTSERVICE_ACCESS | 59 EFI_VARIABLE_BOOTSERVICE_ACCESS |
57 EFI_VARIABLE_RUNTIME_ACCESS, sizeof(val), &val); 60 EFI_VARIABLE_RUNTIME_ACCESS, sizeof(val), &val);
58} 61}
62
63#endif
64
65void efi_retrieve_tpm2_eventlog_1_2(efi_system_table_t *sys_table_arg)
66{
67 efi_guid_t tcg2_guid = EFI_TCG2_PROTOCOL_GUID;
68 efi_guid_t linux_eventlog_guid = LINUX_EFI_TPM_EVENT_LOG_GUID;
69 efi_status_t status;
70 efi_physical_addr_t log_location, log_last_entry;
71 struct linux_efi_tpm_eventlog *log_tbl;
72 unsigned long first_entry_addr, last_entry_addr;
73 size_t log_size, last_entry_size;
74 efi_bool_t truncated;
75 void *tcg2_protocol;
76
77 status = efi_call_early(locate_protocol, &tcg2_guid, NULL,
78 &tcg2_protocol);
79 if (status != EFI_SUCCESS)
80 return;
81
82 status = efi_call_proto(efi_tcg2_protocol, get_event_log, tcg2_protocol,
83 EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2,
84 &log_location, &log_last_entry, &truncated);
85 if (status != EFI_SUCCESS)
86 return;
87
88 if (!log_location)
89 return;
90 first_entry_addr = (unsigned long) log_location;
91
92 /*
93 * We populate the EFI table even if the logs are empty.
94 */
95 if (!log_last_entry) {
96 log_size = 0;
97 } else {
98 last_entry_addr = (unsigned long) log_last_entry;
99 /*
100 * get_event_log only returns the address of the last entry.
101 * We need to calculate its size to deduce the full size of
102 * the logs.
103 */
104 last_entry_size = sizeof(struct tcpa_event) +
105 ((struct tcpa_event *) last_entry_addr)->event_size;
106 log_size = log_last_entry - log_location + last_entry_size;
107 }
108
109 /* Allocate space for the logs and copy them. */
110 status = efi_call_early(allocate_pool, EFI_LOADER_DATA,
111 sizeof(*log_tbl) + log_size,
112 (void **) &log_tbl);
113
114 if (status != EFI_SUCCESS) {
115 efi_printk(sys_table_arg,
116 "Unable to allocate memory for event log\n");
117 return;
118 }
119
120 memset(log_tbl, 0, sizeof(*log_tbl) + log_size);
121 log_tbl->size = log_size;
122 log_tbl->version = EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2;
123 memcpy(log_tbl->log, (void *) first_entry_addr, log_size);
124
125 status = efi_call_early(install_configuration_table,
126 &linux_eventlog_guid, log_tbl);
127 if (status != EFI_SUCCESS)
128 goto err_free;
129 return;
130
131err_free:
132 efi_call_early(free_pool, log_tbl);
133}
134
135void efi_retrieve_tpm2_eventlog(efi_system_table_t *sys_table_arg)
136{
137 /* Only try to retrieve the logs in 1.2 format. */
138 efi_retrieve_tpm2_eventlog_1_2(sys_table_arg);
139}
diff --git a/drivers/firmware/efi/tpm.c b/drivers/firmware/efi/tpm.c
new file mode 100644
index 000000000000..0cbeb3d46b18
--- /dev/null
+++ b/drivers/firmware/efi/tpm.c
@@ -0,0 +1,40 @@
1/*
2 * Copyright (C) 2017 Google, Inc.
3 * Thiebaud Weksteen <tweek@google.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9
10#include <linux/efi.h>
11#include <linux/init.h>
12#include <linux/memblock.h>
13
14#include <asm/early_ioremap.h>
15
16/*
17 * Reserve the memory associated with the TPM Event Log configuration table.
18 */
19int __init efi_tpm_eventlog_init(void)
20{
21 struct linux_efi_tpm_eventlog *log_tbl;
22 unsigned int tbl_size;
23
24 if (efi.tpm_log == EFI_INVALID_TABLE_ADDR)
25 return 0;
26
27 log_tbl = early_memremap(efi.tpm_log, sizeof(*log_tbl));
28 if (!log_tbl) {
29 pr_err("Failed to map TPM Event Log table @ 0x%lx\n",
30 efi.tpm_log);
31 efi.tpm_log = EFI_INVALID_TABLE_ADDR;
32 return -ENOMEM;
33 }
34
35 tbl_size = sizeof(*log_tbl) + log_tbl->size;
36 memblock_reserve(efi.tpm_log, tbl_size);
37 early_memunmap(log_tbl, sizeof(*log_tbl));
38 return 0;
39}
40
diff --git a/include/linux/efi.h b/include/linux/efi.h
index d813f7b04da7..dcea82dc4b89 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -473,6 +473,39 @@ typedef struct {
473 u64 get_all; 473 u64 get_all;
474} apple_properties_protocol_64_t; 474} apple_properties_protocol_64_t;
475 475
476typedef struct {
477 u32 get_capability;
478 u32 get_event_log;
479 u32 hash_log_extend_event;
480 u32 submit_command;
481 u32 get_active_pcr_banks;
482 u32 set_active_pcr_banks;
483 u32 get_result_of_set_active_pcr_banks;
484} efi_tcg2_protocol_32_t;
485
486typedef struct {
487 u64 get_capability;
488 u64 get_event_log;
489 u64 hash_log_extend_event;
490 u64 submit_command;
491 u64 get_active_pcr_banks;
492 u64 set_active_pcr_banks;
493 u64 get_result_of_set_active_pcr_banks;
494} efi_tcg2_protocol_64_t;
495
496typedef u32 efi_tcg2_event_log_format;
497
498typedef struct {
499 void *get_capability;
500 efi_status_t (*get_event_log)(efi_handle_t, efi_tcg2_event_log_format,
501 efi_physical_addr_t *, efi_physical_addr_t *, efi_bool_t *);
502 void *hash_log_extend_event;
503 void *submit_command;
504 void *get_active_pcr_banks;
505 void *set_active_pcr_banks;
506 void *get_result_of_set_active_pcr_banks;
507} efi_tcg2_protocol_t;
508
476/* 509/*
477 * Types and defines for EFI ResetSystem 510 * Types and defines for EFI ResetSystem
478 */ 511 */
@@ -623,6 +656,7 @@ void efi_native_runtime_setup(void);
623#define EFI_MEMORY_ATTRIBUTES_TABLE_GUID EFI_GUID(0xdcfa911d, 0x26eb, 0x469f, 0xa2, 0x20, 0x38, 0xb7, 0xdc, 0x46, 0x12, 0x20) 656#define EFI_MEMORY_ATTRIBUTES_TABLE_GUID EFI_GUID(0xdcfa911d, 0x26eb, 0x469f, 0xa2, 0x20, 0x38, 0xb7, 0xdc, 0x46, 0x12, 0x20)
624#define EFI_CONSOLE_OUT_DEVICE_GUID EFI_GUID(0xd3b36f2c, 0xd551, 0x11d4, 0x9a, 0x46, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d) 657#define EFI_CONSOLE_OUT_DEVICE_GUID EFI_GUID(0xd3b36f2c, 0xd551, 0x11d4, 0x9a, 0x46, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
625#define APPLE_PROPERTIES_PROTOCOL_GUID EFI_GUID(0x91bd12fe, 0xf6c3, 0x44fb, 0xa5, 0xb7, 0x51, 0x22, 0xab, 0x30, 0x3a, 0xe0) 658#define APPLE_PROPERTIES_PROTOCOL_GUID EFI_GUID(0x91bd12fe, 0xf6c3, 0x44fb, 0xa5, 0xb7, 0x51, 0x22, 0xab, 0x30, 0x3a, 0xe0)
659#define EFI_TCG2_PROTOCOL_GUID EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f)
626 660
627#define EFI_IMAGE_SECURITY_DATABASE_GUID EFI_GUID(0xd719b2cb, 0x3d3a, 0x4596, 0xa3, 0xbc, 0xda, 0xd0, 0x0e, 0x67, 0x65, 0x6f) 661#define EFI_IMAGE_SECURITY_DATABASE_GUID EFI_GUID(0xd719b2cb, 0x3d3a, 0x4596, 0xa3, 0xbc, 0xda, 0xd0, 0x0e, 0x67, 0x65, 0x6f)
628#define EFI_SHIM_LOCK_GUID EFI_GUID(0x605dab50, 0xe046, 0x4300, 0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23) 662#define EFI_SHIM_LOCK_GUID EFI_GUID(0x605dab50, 0xe046, 0x4300, 0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23)
@@ -635,6 +669,7 @@ void efi_native_runtime_setup(void);
635#define LINUX_EFI_ARM_SCREEN_INFO_TABLE_GUID EFI_GUID(0xe03fc20a, 0x85dc, 0x406e, 0xb9, 0x0e, 0x4a, 0xb5, 0x02, 0x37, 0x1d, 0x95) 669#define LINUX_EFI_ARM_SCREEN_INFO_TABLE_GUID EFI_GUID(0xe03fc20a, 0x85dc, 0x406e, 0xb9, 0x0e, 0x4a, 0xb5, 0x02, 0x37, 0x1d, 0x95)
636#define LINUX_EFI_LOADER_ENTRY_GUID EFI_GUID(0x4a67b082, 0x0a4c, 0x41cf, 0xb6, 0xc7, 0x44, 0x0b, 0x29, 0xbb, 0x8c, 0x4f) 670#define LINUX_EFI_LOADER_ENTRY_GUID EFI_GUID(0x4a67b082, 0x0a4c, 0x41cf, 0xb6, 0xc7, 0x44, 0x0b, 0x29, 0xbb, 0x8c, 0x4f)
637#define LINUX_EFI_RANDOM_SEED_TABLE_GUID EFI_GUID(0x1ce1e5bc, 0x7ceb, 0x42f2, 0x81, 0xe5, 0x8a, 0xad, 0xf1, 0x80, 0xf5, 0x7b) 671#define LINUX_EFI_RANDOM_SEED_TABLE_GUID EFI_GUID(0x1ce1e5bc, 0x7ceb, 0x42f2, 0x81, 0xe5, 0x8a, 0xad, 0xf1, 0x80, 0xf5, 0x7b)
672#define LINUX_EFI_TPM_EVENT_LOG_GUID EFI_GUID(0xb7799cb0, 0xeca2, 0x4943, 0x96, 0x67, 0x1f, 0xae, 0x07, 0xb7, 0x47, 0xfa)
638 673
639typedef struct { 674typedef struct {
640 efi_guid_t guid; 675 efi_guid_t guid;
@@ -909,6 +944,7 @@ extern struct efi {
909 unsigned long properties_table; /* properties table */ 944 unsigned long properties_table; /* properties table */
910 unsigned long mem_attr_table; /* memory attributes table */ 945 unsigned long mem_attr_table; /* memory attributes table */
911 unsigned long rng_seed; /* UEFI firmware random seed */ 946 unsigned long rng_seed; /* UEFI firmware random seed */
947 unsigned long tpm_log; /* TPM2 Event Log table */
912 efi_get_time_t *get_time; 948 efi_get_time_t *get_time;
913 efi_set_time_t *set_time; 949 efi_set_time_t *set_time;
914 efi_get_wakeup_time_t *get_wakeup_time; 950 efi_get_wakeup_time_t *get_wakeup_time;
@@ -1534,6 +1570,8 @@ static inline void
1534efi_enable_reset_attack_mitigation(efi_system_table_t *sys_table_arg) { } 1570efi_enable_reset_attack_mitigation(efi_system_table_t *sys_table_arg) { }
1535#endif 1571#endif
1536 1572
1573void efi_retrieve_tpm2_eventlog(efi_system_table_t *sys_table);
1574
1537/* 1575/*
1538 * Arch code can implement the following three template macros, avoiding 1576 * Arch code can implement the following three template macros, avoiding
1539 * reptition for the void/non-void return cases of {__,}efi_call_virt(): 1577 * reptition for the void/non-void return cases of {__,}efi_call_virt():
@@ -1601,4 +1639,12 @@ struct linux_efi_random_seed {
1601 u8 bits[]; 1639 u8 bits[];
1602}; 1640};
1603 1641
1642struct linux_efi_tpm_eventlog {
1643 u32 size;
1644 u8 version;
1645 u8 log[];
1646};
1647
1648extern int efi_tpm_eventlog_init(void);
1649
1604#endif /* _LINUX_EFI_H */ 1650#endif /* _LINUX_EFI_H */