Add support for the TCG2 event log on UEFI systems
Subsystems (3)
There are several complexities associated with handling the crypto-agile log format from TPM2 systems on UEFI platforms. The first is that each log entry may be of variable length, necessitating parsing the log in-kernel to determine its length. The second is that the log is kept in boot services memory (which is reclaimed by the OS after ExitBootServices() is called), but ExitBootServices() may introduce additional log entries. These additional log entries are added to a separate log which should then be merged into the initial log.
This patchset makes the existing support for calculating TPM events more general (in order to allow it to be used from the EFI boot stub), adds support for copying up crypto agile logs from the boot environment to the running kernel and adds support for merging the final events log into the initial events log.
PATCH 1/5 tpm: Abstract crypto agile event size calculations
From: Matthew Garrett <[email protected]>
We need to calculate the size of crypto agile events in multiple locations, including in the EFI boot stub. The easiest way to do this is to put it in a header file as an inline and leave a wrapper to ensure we don't end up with multiple copies of it embedded in the existing code.
--- drivers/char/tpm/eventlog/tpm2.c | 47 +----------------------------- include/linux/tpm_eventlog.h | 50 ++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 46 deletions(-)
drivers/char/tpm/eventlog/tpm2.c +1 -46
@@ -40,52 +40,7 @@static int calc_tpm2_event_size (struct tcg_pcr_event2 *event,struct tcg_pcr_event *event_header) { -struct tcg_efi_specid_event *efispecid; -struct tcg_event_field *event_field; -void *marker; -void *marker_start; -u32 halg_size; -size_t size; -u16 halg; -int i; -int j; - - marker = event; - marker_start = marker; - marker = marker +sizeof (event->pcr_idx) +sizeof (event->event_type) - +sizeof (event->count); - - efispecid = (struct tcg_efi_specid_event *)event_header->event; - -/* Check if event is malformed. */ -if (event->count > efispecid->num_algs) -return 0 ; - -for (i =0 ; i < event->count; i++) { - halg_size =sizeof (event->digests[i].alg_id); -memcpy (&halg, marker, halg_size); - marker = marker + halg_size; -for (j =0 ; j < efispecid->num_algs; j++) { -if (halg == efispecid->digest_sizes[j].alg_id) { - marker += - efispecid->digest_sizes[j].digest_size; -break ; - } - } -/* Algorithm without known length. Such event is unparseable. */ -if (j == efispecid->num_algs) -return 0 ; - } - - event_field = (struct tcg_event_field *)marker; - marker = marker +sizeof (event_field->event_size) - + event_field->event_size; - size = marker - marker_start; - -if ((event->event_type ==0 ) && (event_field->event_size ==0 )) -return 0 ; - -return size; +return _calc_tpm2_event_size (event, event_header); }static void *tpm2_bios_measurements_start (struct seq_file *m,loff_t *pos)
include/linux/tpm_eventlog.h +50 -0
54 lines not on this page · raw message
Signature · 1 line
2.20.1.97.g81188d93c3-goog
Re: [PATCH 1/5] tpm: Abstract crypto agile event size calculations
include/linux/tpm_eventlog.h struct tcg_pcr_event2 { · line 125
Quoted 2 lines · Matthew Garrett
include/linux/tpm_eventlog.h +2
-0+static inline int _calc_tpm2_event_size (struct tcg_pcr_event2 *event, +struct tcg_pcr_event *event_header)
I'm more used to having two underscores i.e. __calc_tpm2_event_size() for functions that are wrapped. Otherwise, looks good to me.
/Jarkko
PATCH 2/5 tpm: Fix event log types for TPM2
In reply to Matthew GarrettFrom: Matthew Garrett <[email protected]>
These structs are defined as having variable length members, not fixed size ones. Fix that up and rename them to more accurately describe the only safe way they can be used, and fix the code that relied on having fixed structures.
--- drivers/char/tpm/eventlog/tpm2.c | 8 ++++---- drivers/char/tpm/tpm-interface.c | 32 ++++++++++++++++++++++++-------- drivers/char/tpm/tpm.h | 3 ++- drivers/char/tpm/tpm2-cmd.c | 15 ++++++++++++++- include/linux/tpm_eventlog.h | 27 +++++++++++++++++++++------ 5 files changed, 65 insertions(+), 20 deletions(-)
drivers/char/tpm/eventlog/tpm2.c +4 -4
@@ -37,7 +37,7 @@* * Returns size of the event. If it is an invalid event, returns 0. */ -static int calc_tpm2_event_size (struct tcg_pcr_event2 *event, +static int calc_tpm2_event_size (struct tcg_pcr_event2_hdr *event,struct tcg_pcr_event *event_header) {return _calc_tpm2_event_size (event, event_header);
@@ -50,7 +50,7 @@ static void *tpm2_bios_measurements_start(struct seq_file *m, loff_t *pos)void *addr = log->bios_event_log;void *limit = log->bios_event_log_end;struct tcg_pcr_event *event_header; -struct tcg_pcr_event2 *event; +struct tcg_pcr_event2_hdr *event;size_t size;int i;
@@ -91,7 +91,7 @@ static void *tpm2_bios_measurements_next(struct seq_file *m, void *v, loff_t *pos) {struct tcg_pcr_event *event_header; -struct tcg_pcr_event2 *event; +struct tcg_pcr_event2_hdr *event;struct tpm_chip *chip = m->private;struct tpm_bios_log *log = &chip->log;void *limit = log->bios_event_log_end;
@@ -135,7 +135,7 @@ static int tpm2_binary_bios_measurements_show(struct seq_file *m, void *v)struct tpm_chip *chip = m->private;struct tpm_bios_log *log = &chip->log;struct tcg_pcr_event *event_header = log->bios_event_log; -struct tcg_pcr_event2 *event = v; +struct tcg_pcr_event2_hdr *event = v;void *temp_ptr;size_t size;
drivers/char/tpm/tpm-interface.c +24 -8
@@ -488,21 +488,37 @@ EXPORT_SYMBOL_GPL(tpm_pcr_read);int tpm_pcr_extend (struct tpm_chip *chip,u32 pcr_idx,const u8 *hash) {int rc; -struct tpm2_digest digest_list[ARRAY_SIZE (chip->active_banks)];u32 count =0 ; -int i; +int i, size =0 ; +void *tmp, *digest_list =NULL ; chip =tpm_find_get_ops (chip);if (!chip)return -ENODEV ;if (chip->flags &TPM_CHIP_FLAG_TPM2 ) { -memset (digest_list,0 ,sizeof (digest_list)); - -for (i =0 ; i <ARRAY_SIZE (chip->active_banks) && - chip->active_banks[i] !=TPM2_ALG_ERROR ; i++) { - digest_list[i].alg_id = chip->active_banks[i]; -memcpy (digest_list[i].digest, hash,TPM_DIGEST_SIZE ); +for (i =0 ; i <ARRAY_SIZE (chip->active_banks); i++) { +int digest_size; +struct tpm2_digest_hdr *digest; + +if (chip->active_banks[i] ==TPM2_ALG_ERROR ) +continue ; + + digest_size =tpm2_digest_size (chip->active_banks[i]); +if (digest_size <0 ) +continue ; + + digest = (struct tpm2_digest_hdr *)(digest_list + size); + size +=sizeof (struct tpm2_digest_hdr ) + digest_size; + + tmp =krealloc (digest_list, size,GFP_KERNEL ); +if (!tmp) { +kfree (digest_list); +return -ENOMEM ; + } + digest_list = tmp; + digest->alg_id = chip->active_banks[i]; +memcpy (digest->digest, hash, digest_size); count++; }
drivers/char/tpm/tpm.h +2 -1
@@ -560,7 +560,7 @@ static inline u32 tpm2_rc_value(u32 rc)int tpm2_get_timeouts (struct tpm_chip *chip);int tpm2_pcr_read (struct tpm_chip *chip,u32 pcr_idx,u8 *res_buf);int tpm2_pcr_extend (struct tpm_chip *chip,u32 pcr_idx,u32 count, -struct tpm2_digest *digests); +struct tpm2_digest_hdr *digests);int tpm2_get_random (struct tpm_chip *chip,u8 *dest,size_t max);void tpm2_flush_context_cmd (struct tpm_chip *chip,u32 handle,unsigned int flags);
@@ -584,6 +584,7 @@ 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); +int tpm2_digest_size (int algo_id);int tpm_bios_log_setup (struct tpm_chip *chip);void tpm_bios_log_teardown (struct tpm_chip *chip);
drivers/char/tpm/tpm2-cmd.c +14 -1
@@ -226,7 +226,7 @@ struct tpm2_null_auth_area {* Return: Same as with tpm_transmit_cmd. */ int tpm2_pcr_extend (struct tpm_chip *chip,u32 pcr_idx,u32 count, -struct tpm2_digest *digests) +struct tpm2_digest_hdr *digests) {struct tpm_buf buf;struct tpm2_null_auth_area auth_area;
@@ -1027,3 +1027,16 @@ int tpm2_find_cc(struct tpm_chip *chip, u32 cc)return -1 ; } + +int tpm2_digest_size (int algo_id) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (tpm2_hash_map); i++) { +if (algo_id != tpm2_hash_map[i].tpm_id) +continue ; +return hash_digest_size[tpm2_hash_map[i].crypto_id]; + } + +return -1 ; +}
include/linux/tpm_eventlog.h +21 -6
@@ -108,20 +108,35 @@ struct tcg_event_field {u8 event[0 ]; } __packed; -struct tpm2_digest { +struct tpm2_digest_hdr {u16 alg_id; -u8 digest[SHA512_DIGEST_SIZE ]; +u8 digest[0 ]; } __packed; -struct tcg_pcr_event2 { +struct tcg_pcr_event2_hdr {u32 pcr_idx;u32 event_type;u32 count; -struct tpm2_digest digests[TPM2_ACTIVE_PCR_BANKS ]; -struct tcg_event_field event; +struct tpm2_digest_hdr digests[0 ]; } __packed; -static inline int _calc_tpm2_event_size (struct tcg_pcr_event2 *event, +struct tcg_algorithm_size { +u16 algorithm_id; +u16 algorithm_size; +}; + +struct tcg_algorithm_info { +u8 signature[16 ]; +u32 platform_class; +u8 spec_version_minor; +u8 spec_version_major; +u8 spec_errata; +u8 uintn_size; +u32 number_of_algorithms; +struct tcg_algorithm_size digest_sizes[]; +}; + +static inline int _calc_tpm2_event_size (struct tcg_pcr_event2_hdr *event,struct tcg_pcr_event *event_header) {struct tcg_efi_specid_event *efispecid;
Signature · 1 line
2.20.1.97.g81188d93c3-goog
Re: [PATCH 2/5] tpm: Fix event log types for TPM2
Quoted 8 lines · Matthew Garrett
From: Matthew Garrett <[email protected]>
These structs are defined as having variable length members, not fixed size ones. Fix that up and rename them to more accurately describe the only safe way they can be used, and fix the code that relied on having fixed structures.
Signed-off-by Matthew Garrett <[email protected]>
This collides with Roberto's work. How this must be worked out is to first merge Roberto's patches and then this patch set should be aligned with that baseline.
Roberto, are you ready to send soon an updated version? When you do, please cc the patches to Matthew. Matthew, what you should do is to review Roberto's patches and give him feedback so that his changes will work for you. Right now the only "customer" is IMA.
So yeah, this how I would like to prioritize things. I'll hold on for detailed review for your patches up until Roberto's patches have been merged because there is just too much intersection.
/Jarkko
Re: [PATCH 2/5] tpm: Fix event log types for TPM2
Quoted 10 lines · Jarkko Sakkinen
Quoted 8 lines · Matthew Garrett
From: Matthew Garrett <[email protected]>
These structs are defined as having variable length members, not fixed size ones. Fix that up and rename them to more accurately describe the only safe way they can be used, and fix the code that relied on having fixed structures.
Signed-off-by Matthew Garrett <[email protected]>
Quoted 8 lines
This collides with Roberto's work. How this must be worked out is to first merge Roberto's patches and then this patch set should be aligned with that baseline.
Roberto, are you ready to send soon an updated version? When you do, please cc the patches to Matthew. Matthew, what you should do is to review Roberto's patches and give him feedback so that his changes will work for you. Right now the only "customer" is IMA.
I will check your comment about patch 5/5 and reply.
Roberto
Quoted 6 lines
So yeah, this how I would like to prioritize things. I'll hold on for detailed review for your patches up until Roberto's patches have been merged because there is just too much intersection.
/Jarkko
Signature · 2 lines
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063 Managing Director: Bo PENG, Jian LI, Yanli SHI
Re: [PATCH 2/5] tpm: Fix event log types for TPM2
Quoted 15 lines · Roberto Sassu
Quoted 14 lines · Jarkko Sakkinen
Quoted 8 lines · Matthew Garrett
From: Matthew Garrett <[email protected]>
These structs are defined as having variable length members, not fixed size ones. Fix that up and rename them to more accurately describe the only safe way they can be used, and fix the code that relied on having fixed structures.
Signed-off-by Matthew Garrett <[email protected]>This collides with Roberto's work. How this must be worked out is to first merge Roberto's patches and then this patch set should be aligned with that baseline.
Quoted 6 lines
Quoted 4 lines
Roberto, are you ready to send soon an updated version? When you do, please cc the patches to Matthew. Matthew, what you should do is to review Roberto's patches and give him feedback so that his changes will work for you. Right now the only "customer" is IMA.
I will check your comment about patch 5/5 and reply.
Great, thank you. And CC everything to Matthew.
/Jarkko
PATCH 3/5 tpm: Reserve the TPM final events table
In reply to Matthew GarrettFrom: Matthew Garrett <[email protected]>
UEFI systems provide a boot services protocol for obtaining the TPM event log, but this is unusable after ExitBootServices() is called. Unfortunately ExitBootServices() itself triggers additional TPM events that then can't be obtained using this protocol. The platform provides a mechanism for the OS to obtain these events by recording them to a separate UEFI configuration table which the OS can then map.
Unfortunately this table isn't self describing in terms of providing its length, so we need to parse the events inside it to figure out how long it is. Since the table isn't mapped at this point, we need to extend the length calculation function to be able to map the event as it goes along.
--- drivers/char/tpm/eventlog/tpm2.c | 2 +- drivers/firmware/efi/efi.c | 2 + drivers/firmware/efi/tpm.c | 67 ++++++++++++++++++++++---- include/linux/efi.h | 9 ++++ include/linux/tpm_eventlog.h | 82 +++++++++++++++++++++++++++++--- 5 files changed, 144 insertions(+), 18 deletions(-)
drivers/char/tpm/eventlog/tpm2.c +1 -1
@@ -40,7 +40,7 @@static int calc_tpm2_event_size (struct tcg_pcr_event2_hdr *event,struct tcg_pcr_event *event_header) { -return _calc_tpm2_event_size (event, event_header); +return _calc_tpm2_event_size (event, event_header,NULL ,NULL ); }static void *tpm2_bios_measurements_start (struct seq_file *m,loff_t *pos)
drivers/firmware/efi/efi.c +2 -0
@@ -53,6 +53,7 @@ struct efi __read_mostly efi = { .mem_attr_table = EFI_INVALID_TABLE_ADDR, .rng_seed = EFI_INVALID_TABLE_ADDR, .tpm_log = EFI_INVALID_TABLE_ADDR, + .tpm_final_log = EFI_INVALID_TABLE_ADDR, .mem_reserve = EFI_INVALID_TABLE_ADDR, };EXPORT_SYMBOL (efi);
@@ -485,6 +486,7 @@ static __initdata efi_config_table_type_t common_tables[] = { {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}, + {LINUX_EFI_TPM_FINAL_LOG_GUID, "TPMFinalLog", &efi.tpm_final_log}, {LINUX_EFI_MEMRESERVE_TABLE_GUID, "MEMRESERVE", &efi.mem_reserve}, {NULL_GUID, NULL, NULL}, };
drivers/firmware/efi/tpm.c +57 -10
88 lines not on this page · raw message
include/linux/efi.h +9 -0
@@ -676,6 +676,7 @@ void efi_native_runtime_setup(void);#define LINUX_EFI_LOADER_ENTRY_GUID EFI_GUID(0x4a67b082, 0x0a4c, 0x41cf, 0xb6, 0xc7, 0x44, 0x0b, 0x29, 0xbb, 0x8c, 0x4f)#define LINUX_EFI_RANDOM_SEED_TABLE_GUID EFI_GUID(0x1ce1e5bc, 0x7ceb, 0x42f2, 0x81, 0xe5, 0x8a, 0xad, 0xf1, 0x80, 0xf5, 0x7b)#define LINUX_EFI_TPM_EVENT_LOG_GUID EFI_GUID(0xb7799cb0, 0xeca2, 0x4943, 0x96, 0x67, 0x1f, 0xae, 0x07, 0xb7, 0x47, 0xfa) +#define LINUX_EFI_TPM_FINAL_LOG_GUID EFI_GUID(0x1e2ed096, 0x30e2, 0x4254, 0xbd, 0x89, 0x86, 0x3b, 0xbe, 0xf8, 0x23, 0x25)#define LINUX_EFI_MEMRESERVE_TABLE_GUID EFI_GUID(0x888eb0c6, 0x8ede, 0x4ff5, 0xa8, 0xf0, 0x9a, 0xee, 0x5c, 0xb9, 0x77, 0xc2) typedef struct {
@@ -983,6 +984,7 @@ extern struct efi {unsigned long mem_attr_table;/* memory attributes table */ unsigned long rng_seed;/* UEFI firmware random seed */ unsigned long tpm_log;/* TPM2 Event Log table */ +unsigned long tpm_final_log;/* TPM2 Final Events Log table */ unsigned long mem_reserve;/* Linux EFI memreserve table */ efi_get_time_t *get_time;efi_set_time_t *set_time;
@@ -1700,6 +1702,13 @@ struct linux_efi_tpm_eventlog {extern int efi_tpm_eventlog_init (void ); +struct efi_tcg2_final_events_table { +u64 version; +u64 number_of_events; +u8 events[]; +}; +extern int efi_tpm_final_log_size; +/* * efi_runtime_service() function identifiers. * "NONE" is used by efi_recover_from_page_fault() to check if the page
include/linux/tpm_eventlog.h +75 -7
122 lines not on this page · raw message
Signature · 1 line
2.20.1.97.g81188d93c3-goog
PATCH 4/5 tpm: Append the final event log to the TPM event log
In reply to Matthew GarrettFrom: Matthew Garrett <[email protected]>
Any events that are logged after GetEventsLog() is called are logged to the EFI Final Events table. These events are defined as being in the crypto agile log format, so we can just append them directly to the existing log if it's in the same format. In theory we can also construct old-style SHA1 log entries for devices that only return logs in that format, but EDK2 doesn't generate the final event log in that case so it doesn't seem worth it at the moment.
--- drivers/char/tpm/eventlog/efi.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-)
drivers/char/tpm/eventlog/efi.c +32 -1
@@ -21,10 +21,12 @@int tpm_read_log_efi (struct tpm_chip *chip) { +struct efi_tcg2_final_events_table *final_tbl =NULL ;struct linux_efi_tpm_eventlog *log_tbl;struct tpm_bios_log *log;u32 log_size;u8 tpm_log_version; +void *tmp;if (!(chip->flags &TPM_CHIP_FLAG_TPM2 ))return -ENODEV ;
@@ -55,12 +57,41 @@ int tpm_read_log_efi(struct tpm_chip *chip)if (!log->bios_event_log) goto err_memunmap; log->bios_event_log_end = log->bios_event_log + log_size; - tpm_log_version = log_tbl->version; + +if (efi.tpm_final_log !=EFI_INVALID_TABLE_ADDR && + efi_tpm_final_log_size !=0 ) { +if (tpm_log_version ==EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 ) { + final_tbl =memremap (efi.tpm_final_log, +sizeof (*final_tbl) + efi_tpm_final_log_size, +MEMREMAP_WB ); +if (!final_tbl) { +pr_err ("Could not map UEFI TPM final log\n" ); +kfree (log->bios_event_log); + goto err_memunmap; + } + + tmp =krealloc (log->bios_event_log, + log_size + efi_tpm_final_log_size, +GFP_KERNEL ); +if (!tmp) { +kfree (log->bios_event_log); + goto err_memunmap; + } + + log->bios_event_log = tmp; +memcpy ((void *)log->bios_event_log + log_size, + final_tbl->events, efi_tpm_final_log_size); + log->bios_event_log_end = log->bios_event_log + + log_size + efi_tpm_final_log_size; + } + } +memunmap (final_tbl);memunmap (log_tbl);return tpm_log_version; err_memunmap: +memunmap (final_tbl);memunmap (log_tbl);return -ENOMEM ; }
Signature · 1 line
2.20.1.97.g81188d93c3-goog
PATCH 5/5 efi: Attempt to get the TCG2 event log in the boot stub
In reply to Matthew GarrettFrom: Matthew Garrett <[email protected]>
Right now we only attempt to obtain the SHA1-only event log. The protocol also supports a crypto agile log format, which contains digests for all algorithms in use. Attempt to obtain this first, and fall back to obtaining the older format if the system doesn't support it. This is lightly complicated by the event sizes being variable (as we don't know in advance which algorithms are in use), and the interface giving us back a pointer to the start of the final entry rather than a pointer to the end of the log - as a result, we need to parse the final entry to figure out its length in order to know how much data to copy up to the OS.
--- drivers/firmware/efi/libstub/tpm.c | 50 ++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 17 deletions(-)
drivers/firmware/efi/libstub/tpm.c +33 -17
@@ -59,7 +59,7 @@ void efi_enable_reset_attack_mitigation(efi_system_table_t *sys_table_arg)#endif -static void efi_retrieve_tpm2_eventlog_1_2 (efi_system_table_t *sys_table_arg) +void efi_retrieve_tpm2_eventlog (efi_system_table_t *sys_table_arg) {efi_guid_t tcg2_guid =EFI_TCG2_PROTOCOL_GUID ;efi_guid_t linux_eventlog_guid =LINUX_EFI_TPM_EVENT_LOG_GUID ;
@@ -69,6 +69,7 @@ static void efi_retrieve_tpm2_eventlog_1_2(efi_system_table_t *sys_table_arg)unsigned long first_entry_addr, last_entry_addr;size_t log_size, last_entry_size;efi_bool_t truncated; +int version =EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 ;void *tcg2_protocol =NULL ; status = efi_call_early(locate_protocol, &tcg2_guid, NULL,
@@ -76,14 +77,20 @@ static void efi_retrieve_tpm2_eventlog_1_2(efi_system_table_t *sys_table_arg)if (status !=EFI_SUCCESS )return ; - status =efi_call_proto (efi_tcg2_protocol, get_event_log, tcg2_protocol, -EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2 , - &log_location, &log_last_entry, &truncated); -if (status !=EFI_SUCCESS ) -return ; + status =efi_call_proto (efi_tcg2_protocol, get_event_log, + tcg2_protocol, version, &log_location, + &log_last_entry, &truncated); + +if (status !=EFI_SUCCESS || !log_location) { + version =EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2 ; + status =efi_call_proto (efi_tcg2_protocol, get_event_log, + tcg2_protocol, version, &log_location, + &log_last_entry, &truncated); +if (status !=EFI_SUCCESS || !log_location) +return ; + + } -if (!log_location) -return ; first_entry_addr = (unsigned long ) log_location;/*
@@ -98,8 +105,23 @@ static void efi_retrieve_tpm2_eventlog_1_2(efi_system_table_t *sys_table_arg)* We need to calculate its size to deduce the full size of * the logs. */ - last_entry_size =sizeof (struct tcpa_event ) + - ((struct tcpa_event *) last_entry_addr)->event_size; +if (version ==EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 ) { +/* +* The TCG2 log format has variable length entries, +* and the information to decode the hash algorithms +* back into a size is contained in the first entry - +* pass a pointer to the final entry (to calculate its +* size) and the first entry (so we know how long each +* digest is) +*/ + last_entry_size = +_calc_tpm2_event_size ((void *)last_entry_addr, + (void *)log_location, +NULL ,NULL ); + }else { + last_entry_size =sizeof (struct tcpa_event ) + + ((struct tcpa_event *) last_entry_addr)->event_size; + } log_size = log_last_entry - log_location + last_entry_size; }
@@ -116,7 +138,7 @@ static void efi_retrieve_tpm2_eventlog_1_2(efi_system_table_t *sys_table_arg)memset (log_tbl,0 ,sizeof (*log_tbl) + log_size); log_tbl->size = log_size; - log_tbl->version =EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2 ; + log_tbl->version = version;memcpy (log_tbl->log, (void *) first_entry_addr, log_size); status = efi_call_early(install_configuration_table,
@@ -128,9 +150,3 @@ static void efi_retrieve_tpm2_eventlog_1_2(efi_system_table_t *sys_table_arg) err_free:efi_call_early (free_pool, log_tbl); } - -void efi_retrieve_tpm2_eventlog (efi_system_table_t *sys_table_arg) -{ -/* Only try to retrieve the logs in 1.2 format. */ -efi_retrieve_tpm2_eventlog_1_2 (sys_table_arg); -}
Signature · 1 line
2.20.1.97.g81188d93c3-goog
Quoted 9 lines · Matthew Garrett
There are several complexities associated with handling the crypto-agile log format from TPM2 systems on UEFI platforms. The first is that each log entry may be of variable length, necessitating parsing the log in-kernel to determine its length. The second is that the log is kept in boot services memory (which is reclaimed by the OS after
ExitBootServices()is called), butExitBootServices()may introduce additional log entries. These additional log entries are added to a separate log which should then be merged into the initial log.
Quoted 5 lines
This patchset makes the existing support for calculating TPM events more general (in order to allow it to be used from the EFI boot stub), adds support for copying up crypto agile logs from the boot environment to the running kernel and adds support for merging the final events log into the initial events log.
With a brief look, looks really good. I'll probably don't have time to do a detailed review this week (still catching up after holidays).
/Jarkko