Skip to content

Commit 253ca48

Browse files
efi/libstub: Add get_event_log() support for CC platforms
JIRA: https://issues.redhat.com/browse/RHEL-30322 commit d228814 Author: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com> Date: Thu Feb 15 03:00:02 2024 +0000 efi/libstub: Add get_event_log() support for CC platforms To allow event log info access after boot, EFI boot stub extracts the event log information and installs it in an EFI configuration table. Currently, EFI boot stub only supports installation of event log only for TPM 1.2 and TPM 2.0 protocols. Extend the same support for CC protocol. Since CC platform also uses TCG2 format, reuse TPM2 support code as much as possible. Link: https://uefi.org/specs/UEFI/2.10/38_Confidential_Computing.html#efi-cc-measurement-protocol [1] Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com> Link: https://lkml.kernel.org/r/0229a87e-fb19-4dad-99fc-4afd7ed4099a%40collabora.com [ardb: Split out final events table handling to avoid version confusion] Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Lenny Szubowicz <lszubowi@redhat.com>
1 parent f6e8e6a commit 253ca48

File tree

6 files changed

+61
-31
lines changed

6 files changed

+61
-31
lines changed

drivers/firmware/efi/efi.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ static const efi_config_table_type_t common_tables[] __initconst = {
591591
{LINUX_EFI_RANDOM_SEED_TABLE_GUID, &efi_rng_seed, "RNG" },
592592
{LINUX_EFI_TPM_EVENT_LOG_GUID, &efi.tpm_log, "TPMEventLog" },
593593
{EFI_TCG2_FINAL_EVENTS_TABLE_GUID, &efi.tpm_final_log, "TPMFinalLog" },
594+
{EFI_CC_FINAL_EVENTS_TABLE_GUID, &efi.tpm_final_log, "CCFinalLog" },
594595
{LINUX_EFI_MEMRESERVE_TABLE_GUID, &mem_reserve, "MEMRESERVE" },
595596
{LINUX_EFI_INITRD_MEDIA_GUID, &initrd, "INITRD" },
596597
{EFI_RT_PROPERTIES_TABLE_GUID, &rt_prop, "RTPROP" },

drivers/firmware/efi/libstub/efi-stub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ efi_status_t efi_stub_common(efi_handle_t handle,
159159

160160
si = setup_graphics();
161161

162-
efi_retrieve_tpm2_eventlog();
162+
efi_retrieve_eventlog();
163163

164164
/* Ask the firmware to clear memory on unclean shutdown */
165165
efi_enable_reset_attack_mitigation();

drivers/firmware/efi/libstub/efistub.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,8 @@ typedef struct {
929929

930930
#define EFI_CC_BOOT_HASH_ALG_SHA384 0x00000004
931931

932+
#define EFI_CC_EVENT_LOG_FORMAT_TCG_2 0x00000002
933+
932934
typedef union efi_cc_protocol efi_cc_protocol_t;
933935

934936
union efi_cc_protocol {
@@ -1132,7 +1134,7 @@ static inline void
11321134
efi_enable_reset_attack_mitigation(void) { }
11331135
#endif
11341136

1135-
void efi_retrieve_tpm2_eventlog(void);
1137+
void efi_retrieve_eventlog(void);
11361138

11371139
struct screen_info *alloc_screen_info(void);
11381140
struct screen_info *__alloc_screen_info(void);

drivers/firmware/efi/libstub/tpm.c

Lines changed: 54 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
165144
err_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+
}

drivers/firmware/efi/libstub/x86-stub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ void __noreturn efi_stub_entry(efi_handle_t handle,
918918

919919
efi_random_get_seed();
920920

921-
efi_retrieve_tpm2_eventlog();
921+
efi_retrieve_eventlog();
922922

923923
setup_graphics(boot_params);
924924

include/linux/efi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ void efi_native_runtime_setup(void);
403403
#define EFI_CERT_X509_SHA256_GUID EFI_GUID(0x3bd2a492, 0x96c0, 0x4079, 0xb4, 0x20, 0xfc, 0xf9, 0x8e, 0xf1, 0x03, 0xed)
404404
#define EFI_CC_BLOB_GUID EFI_GUID(0x067b1f5f, 0xcf26, 0x44c5, 0x85, 0x54, 0x93, 0xd7, 0x77, 0x91, 0x2d, 0x42)
405405
#define EFI_CC_MEASUREMENT_PROTOCOL_GUID EFI_GUID(0x96751a3d, 0x72f4, 0x41a6, 0xa7, 0x94, 0xed, 0x5d, 0x0e, 0x67, 0xae, 0x6b)
406+
#define EFI_CC_FINAL_EVENTS_TABLE_GUID EFI_GUID(0xdd4a4648, 0x2de7, 0x4665, 0x96, 0x4d, 0x21, 0xd9, 0xef, 0x5f, 0xb4, 0x46)
406407

407408
/*
408409
* This GUID is used to pass to the kernel proper the struct screen_info

0 commit comments

Comments
 (0)