efi/tpm: Verify event log header before parsing
authorFabian Vogt <fvogt@suse.de>
Mon, 15 Jun 2020 07:16:36 +0000 (09:16 +0200)
committerSasha Levin <sashal@kernel.org>
Tue, 30 Jun 2020 19:36:54 +0000 (15:36 -0400)
commit8c236ac4376aa838f62fb86d21f73ffe1852b551
tree5949fa3627a3248e2e32053bf4cc7bc7cf21c6d9
parente50cf858d118eb2c792b206ac26a2f9845321b20
efi/tpm: Verify event log header before parsing

[ Upstream commit 7dfc06a0f25b593a9f51992f540c0f80a57f3629 ]

It is possible that the first event in the event log is not actually a
log header at all, but rather a normal event. This leads to the cast in
__calc_tpm2_event_size being an invalid conversion, which means that
the values read are effectively garbage. Depending on the first event's
contents, this leads either to apparently normal behaviour, a crash or
a freeze.

While this behaviour of the firmware is not in accordance with the
TCG Client EFI Specification, this happens on a Dell Precision 5510
with the TPM enabled but hidden from the OS ("TPM On" disabled, state
otherwise untouched). The EFI firmware claims that the TPM is present
and active and that it supports the TCG 2.0 event log format.

Fortunately, this can be worked around by simply checking the header
of the first event and the event log header signature itself.

Commit b4f1874c6216 ("tpm: check event log version before reading final
events") addressed a similar issue also found on Dell models.

Fixes: 6b0326190205 ("efi: Attempt to get the TCG2 event log in the boot stub")
Signed-off-by: Fabian Vogt <fvogt@suse.de>
Link: https://lore.kernel.org/r/1927248.evlx2EsYKh@linux-e202.suse.de
Bugzilla: https://bugzilla.suse.com/show_bug.cgi?id=1165773
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/linux/tpm_eventlog.h