Skip to content

Commit 5c23cb0

Browse files
committed
security/tpm: detect and use all active PCR banks
All of the client has already been updated to permit use of multiple banks, but at most one was ever enabled. TPM 2 log was also updated to permit handling of multiple digests, but similarly only one was in use. From now on, it's possible to configure more than one digest (only SHA1 and SHA256 are selected by default). This changes previous TSPI API of `tpm_log_alg()` (single hash) to `tpm_log_alg_active(enum vb2_hash_algorithm)` coupled with `enabled_tpm_algs` array (multiple hashes). The bulk of the code here is for dealing with the set of banks of TPM: - querying it from the device to know what digests should be used - synchronizing set of digests in the log with the actual set of active banks The latter is needed in case TPM is initialized in ramstage while measurements are accumulated starting from the bootblock. An alternative was to require initializing TPM in the bootblock, but bootblock may not have enough space for the extra code required for TPM, hence a different approach was taken: take all supported hashes before TPM is initialized, trim unnecessary digests after the initialization. Change-Id: Ia326b22869c4983fc4e02e150461e7a9ff94dc4e Upstream-Status: Pending Signed-off-by: Sergii Dmytruk <[email protected]>
1 parent be8a10d commit 5c23cb0

File tree

7 files changed

+297
-45
lines changed

7 files changed

+297
-45
lines changed

configs/config.emulation_qemu_x86_q35_uefi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ CONFIG_DRIVERS_EFI_MAIN_FW_LSV=0x00020101
1414
CONFIG_DRIVERS_EFI_UPDATE_CAPSULES=y
1515
CONFIG_TPM1=y
1616
CONFIG_TPM2=y
17-
CONFIG_TPM_HASH_SHA256=y
1817
CONFIG_DEFAULT_CONSOLE_LOGLEVEL_0=y
1918
# CONFIG_CONSOLE_USE_LOGLEVEL_PREFIX is not set
2019
# CONFIG_CONSOLE_USE_ANSI_ESCAPES is not set

configs/config.emulation_qemu_x86_q35_uefi_all_menus

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ CONFIG_UDK_202005_BINDING=y
99
CONFIG_DRIVERS_EFI_VARIABLE_STORE=y
1010
CONFIG_TPM1=y
1111
CONFIG_TPM2=y
12-
CONFIG_TPM_HASH_SHA256=y
1312
CONFIG_DEFAULT_CONSOLE_LOGLEVEL_0=y
1413
# CONFIG_CONSOLE_USE_LOGLEVEL_PREFIX is not set
1514
# CONFIG_CONSOLE_USE_ANSI_ESCAPES is not set

src/security/tpm/Kconfig

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,22 +108,20 @@ config TPM_LOG_TPM2
108108

109109
endchoice
110110

111-
choice
112-
prompt "TPM2 hashing algorithm"
113-
depends on TPM_MEASURED_BOOT && (TPM_LOG_TCG || TPM_LOG_TPM2)
114-
default TPM_HASH_SHA1 if TPM1
115-
default TPM_HASH_SHA256 if TPM2
111+
if TPM_MEASURED_BOOT && (TPM_LOG_TCG || TPM_LOG_TPM2)
116112

117113
config TPM_HASH_SHA1
118-
bool "SHA1"
114+
bool "SHA1 PCR hashing"
115+
default y if TPM1 || TPM2
119116
config TPM_HASH_SHA256
120-
bool "SHA256"
117+
bool "SHA256 PCR hashing"
118+
default y if TPM2
121119
config TPM_HASH_SHA384
122-
bool "SHA384"
120+
bool "SHA384 PCR hashing"
123121
config TPM_HASH_SHA512
124-
bool "SHA512"
122+
bool "SHA512 PCR hashing"
125123

126-
endchoice
124+
endif
127125

128126
config TPM_MEASURED_BOOT_INIT_BOOTBLOCK
129127
bool

src/security/tpm/tspi.h

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,36 +43,20 @@ static inline bool tpm_log_use_tpm2_format(void)
4343
}
4444

4545
/**
46-
* Retrieves hash algorithm used by TPM event log or VB2_HASH_INVALID.
46+
* Checks whether a PCR banks corresponding to a hash algorithm is active.
4747
*/
48-
static inline enum vb2_hash_algorithm tpm_log_alg(void)
48+
static inline bool tpm_log_alg_active(enum vb2_hash_algorithm alg)
4949
{
5050
if (CONFIG(TPM_LOG_CB))
51-
return (tlcl_get_family() == TPM_1 ? VB2_HASH_SHA1 : VB2_HASH_SHA256);
51+
return alg == (tlcl_get_family() == TPM_1 ? VB2_HASH_SHA1 : VB2_HASH_SHA256);
5252

5353
if (tpm_log_use_tpm1_format())
54-
return VB2_HASH_SHA1;
55-
56-
if (tpm_log_use_tpm2_format()) {
57-
if (CONFIG(TPM_HASH_SHA1))
58-
return VB2_HASH_SHA1;
59-
if (CONFIG(TPM_HASH_SHA256))
60-
return VB2_HASH_SHA256;
61-
if (CONFIG(TPM_HASH_SHA384))
62-
return VB2_HASH_SHA384;
63-
if (CONFIG(TPM_HASH_SHA512))
64-
return VB2_HASH_SHA512;
65-
}
54+
return alg == VB2_HASH_SHA1;
6655

67-
return VB2_HASH_INVALID;
68-
}
56+
if (tpm_log_use_tpm2_format())
57+
return tpm2_log_alg_active(alg);
6958

70-
/**
71-
* Checks whether a PCR banks corresponding to a hash algorithm is active.
72-
*/
73-
static inline bool tpm_log_alg_active(enum vb2_hash_algorithm alg)
74-
{
75-
return alg == tpm_log_alg();
59+
return false;
7660
}
7761

7862
/**
@@ -179,6 +163,15 @@ static inline void tpm_log_startup_locality(int locality)
179163
tpm2_log_startup_locality(locality);
180164
}
181165

166+
/**
167+
* Align TPM log with the TPM if necessary.
168+
*/
169+
static inline void tpm_log_align_with_tpm(void)
170+
{
171+
if (tpm_log_use_tpm2_format())
172+
tpm2_log_align_with_tpm();
173+
}
174+
182175
/**
183176
* Dump TPM log entries on console
184177
*/

src/security/tpm/tspi/crtm.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@ tpm_result_t tspi_measure_cache_to_pcr(void)
180180
return TPM_CB_FAIL;
181181
}
182182

183+
/*
184+
* At this point TPM has been initialized, but none of coreboot's measurements have been
185+
* submitted to it yet. Before extending cached digests, invoke a log-specific function
186+
* to do modifications based on the information queried from a TPM.
187+
*/
188+
tpm_log_align_with_tpm();
189+
183190
printk(BIOS_DEBUG, "TPM: Write digests cached in TPM log to PCR\n");
184191
i = 0;
185192
while (!tpm_log_get(i++, &pcr, digests, &event_name)) {

0 commit comments

Comments
 (0)