From: Gregory Price <gourry@gourry.net>
To: Usama Arif <usamaarif642@gmail.com>
Cc: ardb@kernel.org, linux-efi@vger.kernel.org,
linux-kernel@vger.kernel.org, leitao@debian.org
Subject: Re: [PATCH] efi: reserve memory for tpm_log only if TPM final events table is valid
Date: Fri, 30 Aug 2024 17:54:59 -0400 [thread overview]
Message-ID: <ZtI_swMhk04eeYUm@PC2K9PVX.TheFacebook.com> (raw)
In-Reply-To: <30f285bc-7540-4d70-8b6c-11675b68e9e4@gmail.com>
On Fri, Aug 30, 2024 at 10:49:46PM +0100, Usama Arif wrote:
>
>
> On 30/08/2024 17:42, Gregory Price wrote:
> > On Fri, Aug 30, 2024 at 10:28:52PM +0100, Usama Arif wrote:
> >> If efi.tpm_log is corrupted, log_tbl->size can be garbage (and
> >> negative). This can result in a large memblock reservation, resulting
> >> in the kernel booting without sufficient memory. Move the memblock
> >> reservation after log_tbl->version check, and check the value of
> >> both tbl_size and memblock_reserve.
> >>
> >> Signed-off-by: Usama Arif <usamaarif642@gmail.com>
> >> ---
> >> drivers/firmware/efi/tpm.c | 16 +++++++++++++---
> >> 1 file changed, 13 insertions(+), 3 deletions(-)
> >>
> >> diff --git a/drivers/firmware/efi/tpm.c b/drivers/firmware/efi/tpm.c
> >> index e8d69bd548f3..cfc6a065f441 100644
> >> --- a/drivers/firmware/efi/tpm.c
> >> +++ b/drivers/firmware/efi/tpm.c
> >> @@ -59,9 +59,6 @@ int __init efi_tpm_eventlog_init(void)
> >> return -ENOMEM;
> >> }
> >>
> >> - tbl_size = sizeof(*log_tbl) + log_tbl->size;
> >> - memblock_reserve(efi.tpm_log, tbl_size);
> >> -
> >> if (efi.tpm_final_log == EFI_INVALID_TABLE_ADDR) {
> >> pr_info("TPM Final Events table not present\n");
> >> goto out;
> >
> > The final event table is not present in TCG 1_2 format, but the
> > tpm log still needs to be mapped. So this change is incorrect for
> > v1_2.
>
> hmm so we have
>
> if (efi.tpm_final_log == EFI_INVALID_TABLE_ADDR) {
> pr_info("TPM Final Events table not present\n");
> goto out;
> } else if (log_tbl->version != EFI_TCG2_EVENT_LOG_FORMAT_TCG_2) {
> pr_warn(FW_BUG "TPM Final Events table invalid\n");
> goto out;
> }
>
> If the format is TCG 1_2, then log_tbl is not used?
>
>
if format is tcg 1_2 then log_tbl is used, which is reflected in libstub
drivers/firmware/efi/libstub/tpm.c
efi_guid_t tpm2_guid = EFI_TCG2_PROTOCOL_GUID;
int version = EFI_TCG2_EVENT_LOG_FORMAT_TCG_2;
status = efi_bs_call(locate_protocol, &tpm2_guid, NULL, (void **)&tpm2);
if (status == EFI_SUCCESS) {
status = efi_call_proto(tpm2, get_event_log, version, &log_location,
&log_last_entry, &truncated);
if (status != EFI_SUCCESS || !log_location) {
version = EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2;
status = efi_call_proto(tpm2, get_event_log, version,
&log_location, &log_last_entry,
&truncated);
^^^^^^^^ log still present in TCG 1_2 ^^^^^^^^^^^
} else {
final_events_table =
get_efi_config_table(EFI_TCG2_FINAL_EVENTS_TABLE_GUID);
}
} else {
~Gregory
prev parent reply other threads:[~2024-08-30 21:55 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-30 21:28 [PATCH] efi: reserve memory for tpm_log only if TPM final events table is valid Usama Arif
2024-08-30 21:42 ` Gregory Price
2024-08-30 21:49 ` Usama Arif
2024-08-30 21:52 ` Usama Arif
2024-08-30 21:58 ` Gregory Price
2024-08-30 22:24 ` Usama Arif
2024-08-30 21:54 ` Gregory Price [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZtI_swMhk04eeYUm@PC2K9PVX.TheFacebook.com \
--to=gourry@gourry.net \
--cc=ardb@kernel.org \
--cc=leitao@debian.org \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=usamaarif642@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox