@@ -47,39 +47,18 @@ void efi_enable_reset_attack_mitigation(void)
4747
4848#endif
4949
50- void efi_retrieve_tpm2_eventlog (void )
50+ static void efi_retrieve_tcg2_eventlog (int version , efi_physical_addr_t log_location ,
51+ efi_physical_addr_t log_last_entry ,
52+ efi_bool_t truncated ,
53+ struct efi_tcg2_final_events_table * final_events_table )
5154{
52- efi_guid_t tcg2_guid = EFI_TCG2_PROTOCOL_GUID ;
5355 efi_guid_t linux_eventlog_guid = LINUX_EFI_TPM_EVENT_LOG_GUID ;
5456 efi_status_t status ;
55- efi_physical_addr_t log_location = 0 , log_last_entry = 0 ;
5657 struct linux_efi_tpm_eventlog * log_tbl = NULL ;
57- struct efi_tcg2_final_events_table * final_events_table = NULL ;
5858 unsigned long first_entry_addr , last_entry_addr ;
5959 size_t log_size , last_entry_size ;
60- efi_bool_t truncated ;
61- int version = EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 ;
62- efi_tcg2_protocol_t * tcg2_protocol = NULL ;
6360 int final_events_size = 0 ;
6461
65- status = efi_bs_call (locate_protocol , & tcg2_guid , NULL ,
66- (void * * )& tcg2_protocol );
67- if (status != EFI_SUCCESS )
68- return ;
69-
70- status = efi_call_proto (tcg2_protocol , get_event_log , version ,
71- & log_location , & log_last_entry , & truncated );
72-
73- if (status != EFI_SUCCESS || !log_location ) {
74- version = EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2 ;
75- status = efi_call_proto (tcg2_protocol , get_event_log , version ,
76- & log_location , & log_last_entry ,
77- & truncated );
78- if (status != EFI_SUCCESS || !log_location )
79- return ;
80-
81- }
82-
8362 first_entry_addr = (unsigned long ) log_location ;
8463
8564 /*
@@ -93,8 +72,10 @@ void efi_retrieve_tpm2_eventlog(void)
9372 * get_event_log only returns the address of the last entry.
9473 * We need to calculate its size to deduce the full size of
9574 * the logs.
75+ *
76+ * CC Event log also uses TCG2 format, handle it same as TPM2.
9677 */
97- if (version == EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 ) {
78+ if (version > EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2 ) {
9879 /*
9980 * The TCG2 log format has variable length entries,
10081 * and the information to decode the hash algorithms
@@ -127,8 +108,6 @@ void efi_retrieve_tpm2_eventlog(void)
127108 * Figure out whether any events have already been logged to the
128109 * final events structure, and if so how much space they take up
129110 */
130- if (version == EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 )
131- final_events_table = get_efi_config_table (EFI_TCG2_FINAL_EVENTS_TABLE_GUID );
132111 if (final_events_table && final_events_table -> nr_events ) {
133112 struct tcg_pcr_event2_head * header ;
134113 int offset ;
@@ -165,3 +144,50 @@ void efi_retrieve_tpm2_eventlog(void)
165144err_free :
166145 efi_bs_call (free_pool , log_tbl );
167146}
147+
148+ void efi_retrieve_eventlog (void )
149+ {
150+ struct efi_tcg2_final_events_table * final_events_table = NULL ;
151+ efi_physical_addr_t log_location = 0 , log_last_entry = 0 ;
152+ efi_guid_t tpm2_guid = EFI_TCG2_PROTOCOL_GUID ;
153+ int version = EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 ;
154+ efi_tcg2_protocol_t * tpm2 = NULL ;
155+ efi_bool_t truncated ;
156+ efi_status_t status ;
157+
158+ status = efi_bs_call (locate_protocol , & tpm2_guid , NULL , (void * * )& tpm2 );
159+ if (status == EFI_SUCCESS ) {
160+ status = efi_call_proto (tpm2 , get_event_log , version , & log_location ,
161+ & log_last_entry , & truncated );
162+
163+ if (status != EFI_SUCCESS || !log_location ) {
164+ version = EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2 ;
165+ status = efi_call_proto (tpm2 , get_event_log , version ,
166+ & log_location , & log_last_entry ,
167+ & truncated );
168+ } else {
169+ final_events_table =
170+ get_efi_config_table (EFI_TCG2_FINAL_EVENTS_TABLE_GUID );
171+ }
172+ } else {
173+ efi_guid_t cc_guid = EFI_CC_MEASUREMENT_PROTOCOL_GUID ;
174+ efi_cc_protocol_t * cc = NULL ;
175+
176+ status = efi_bs_call (locate_protocol , & cc_guid , NULL , (void * * )& cc );
177+ if (status != EFI_SUCCESS )
178+ return ;
179+
180+ version = EFI_CC_EVENT_LOG_FORMAT_TCG_2 ;
181+ status = efi_call_proto (cc , get_event_log , version , & log_location ,
182+ & log_last_entry , & truncated );
183+
184+ final_events_table =
185+ get_efi_config_table (EFI_CC_FINAL_EVENTS_TABLE_GUID );
186+ }
187+
188+ if (status != EFI_SUCCESS || !log_location )
189+ return ;
190+
191+ efi_retrieve_tcg2_eventlog (version , log_location , log_last_entry ,
192+ truncated , final_events_table );
193+ }
0 commit comments