Skip to content

Commit 3e60895

Browse files
kukrimatevathpela
authored andcommitted
tpm: Boot with a warning if the event log is full
The extend operation still occurs even if `*_log_extend_event` returns EFI_VOLUME_FULL. Let's print a warning when we first see this error code, but otherwise continue booting. Bailing on this condition has caused machines with limited event log space to become unbootable with TPM 2.0 enabled. (fixes #654) Signed-off-by: Mate Kukri <[email protected]>
1 parent 7864c10 commit 3e60895

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tpm.c

+35
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ typedef struct {
1111
UINTN measuredcount = 0;
1212
VARIABLE_RECORD *measureddata = NULL;
1313
static BOOLEAN tpm_defective = FALSE;
14+
static BOOLEAN log_full_already_warned = FALSE;
1415

1516
static BOOLEAN tpm_present(efi_tpm_protocol_t *tpm)
1617
{
@@ -108,6 +109,16 @@ static EFI_STATUS tpm_locate_protocol(efi_tpm_protocol_t **tpm,
108109
return EFI_NOT_FOUND;
109110
}
110111

112+
static void warn_first_log_full(void)
113+
{
114+
if (!log_full_already_warned) {
115+
perror(L"TPM extend operation occurred, but the event could"
116+
" not be written to one or more event logs. Applications"
117+
" reliant on a valid event log will not function.\n");
118+
log_full_already_warned = TRUE;
119+
}
120+
}
121+
111122
static EFI_STATUS cc_log_event_raw(EFI_PHYSICAL_ADDRESS buf, UINTN size,
112123
UINT8 pcr, const CHAR8 *log, UINTN logsize,
113124
UINT32 type, BOOLEAN is_pe_image)
@@ -143,6 +154,14 @@ static EFI_STATUS cc_log_event_raw(EFI_PHYSICAL_ADDRESS buf, UINTN size,
143154
CopyMem(event->Event, (VOID *)log, logsize);
144155
efi_status = cc->hash_log_extend_event(cc, flags, buf, (UINT64)size,
145156
event);
157+
/* Per spec: The extend operation occurred, but the event could
158+
* not be written to one or more event logs. We can still safely
159+
* boot in this case, but also show a warning to let the user know.
160+
*/
161+
if (efi_status == EFI_VOLUME_FULL) {
162+
warn_first_log_full();
163+
efi_status = EFI_SUCCESS;
164+
}
146165
FreePool(event);
147166
return efi_status;
148167
}
@@ -201,11 +220,19 @@ static EFI_STATUS tpm_log_event_raw(EFI_PHYSICAL_ADDRESS buf, UINTN size,
201220
*/
202221
efi_status = tpm2->hash_log_extend_event(tpm2,
203222
PE_COFF_IMAGE, buf, (UINT64) size, event);
223+
if (efi_status == EFI_VOLUME_FULL) {
224+
warn_first_log_full();
225+
efi_status = EFI_SUCCESS;
226+
}
204227
}
205228

206229
if (!hash || EFI_ERROR(efi_status)) {
207230
efi_status = tpm2->hash_log_extend_event(tpm2,
208231
0, buf, (UINT64) size, event);
232+
if (efi_status == EFI_VOLUME_FULL) {
233+
warn_first_log_full();
234+
efi_status = EFI_SUCCESS;
235+
}
209236
}
210237
FreePool(event);
211238
return efi_status;
@@ -239,10 +266,18 @@ static EFI_STATUS tpm_log_event_raw(EFI_PHYSICAL_ADDRESS buf, UINTN size,
239266
CopyMem(event->digest, hash, sizeof(event->digest));
240267
efi_status = tpm->log_extend_event(tpm, 0, 0,
241268
TPM_ALG_SHA, event, &eventnum, &lastevent);
269+
if (efi_status == EFI_VOLUME_FULL) {
270+
warn_first_log_full();
271+
efi_status = EFI_SUCCESS;
272+
}
242273
} else {
243274
efi_status = tpm->log_extend_event(tpm, buf,
244275
(UINT64)size, TPM_ALG_SHA, event, &eventnum,
245276
&lastevent);
277+
if (efi_status == EFI_VOLUME_FULL) {
278+
warn_first_log_full();
279+
efi_status = EFI_SUCCESS;
280+
}
246281
}
247282
if (efi_status == EFI_UNSUPPORTED) {
248283
perror(L"Could not write TPM event: %r. Considering "

0 commit comments

Comments
 (0)