Message ID | 20240912155159.1951792-2-ardb+git@google.com |
---|---|
State | New |
Headers | show |
Series | efistub/tpm: Use ACPI reclaim memory for event log to avoid corruption | expand |
On Thu, 12 Sept 2024 at 18:52, Ard Biesheuvel <ardb+git@google.com> wrote: > > From: Ard Biesheuvel <ardb@kernel.org> > > The TPM event log table is a Linux specific construct, where the data > produced by the GetEventLog() boot service is cached in memory, and > passed on to the OS using a EFI configuration table. an EFI* > > The use of EFI_LOADER_DATA here results in the region being left > unreserved in the E820 memory map constructed by the EFI stub, and this > is the memory description that is passed on to the incoming kernel by > kexec, which is therefore unaware that the region should be reserved. > > Even though the utility of the TPM2 event log after a kexec is > questionable, any corruption might send the parsing code off into the > weeds and crash the kernel. So let's use EFI_ACPI_RECLAIM_MEMORY > instead, which is always treated as reserved by the E820 conversion > logic. > > Cc: <stable@vger.kernel.org> > Reported-by: Breno Leitao <leitao@debian.org> > Tested-by: Usama Arif <usamaarif642@gmail.com> > Signed-off-by: Ard Biesheuvel <ardb@kernel.org> > --- > drivers/firmware/efi/libstub/tpm.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/firmware/efi/libstub/tpm.c b/drivers/firmware/efi/libstub/tpm.c > index df3182f2e63a..1fd6823248ab 100644 > --- a/drivers/firmware/efi/libstub/tpm.c > +++ b/drivers/firmware/efi/libstub/tpm.c > @@ -96,7 +96,7 @@ static void efi_retrieve_tcg2_eventlog(int version, efi_physical_addr_t log_loca > } > > /* Allocate space for the logs and copy them. */ > - status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, > + status = efi_bs_call(allocate_pool, EFI_ACPI_RECLAIM_MEMORY, > sizeof(*log_tbl) + log_size, (void **)&log_tbl); > > if (status != EFI_SUCCESS) { > -- > 2.46.0.662.g92d0881bb0-goog > > Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Hello Ard, Thanks for the fix! On Thu, Sep 12, 2024 at 05:52:00PM +0200, Ard Biesheuvel wrote: > From: Ard Biesheuvel <ardb@kernel.org> > > The TPM event log table is a Linux specific construct, where the data > produced by the GetEventLog() boot service is cached in memory, and > passed on to the OS using a EFI configuration table. > > The use of EFI_LOADER_DATA here results in the region being left > unreserved in the E820 memory map constructed by the EFI stub, and this > is the memory description that is passed on to the incoming kernel by > kexec, which is therefore unaware that the region should be reserved. > > Even though the utility of the TPM2 event log after a kexec is > questionable, any corruption might send the parsing code off into the > weeds and crash the kernel. So let's use EFI_ACPI_RECLAIM_MEMORY > instead, which is always treated as reserved by the E820 conversion > logic. > > Cc: <stable@vger.kernel.org> > Reported-by: Breno Leitao <leitao@debian.org> > Tested-by: Usama Arif <usamaarif642@gmail.com> > Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Tested-by: Breno Leitao <leitao@debian.org> For stable, having the fixes will help stable folks to decide where to pick. Based on investigation, this was introduced by 33b6d03469b22, so, we might want to have the following line: Fixes: 33b6d03469b22 ("efi: call get_event_log before ExitBootServices") Thanks again! --breno
diff --git a/drivers/firmware/efi/libstub/tpm.c b/drivers/firmware/efi/libstub/tpm.c index df3182f2e63a..1fd6823248ab 100644 --- a/drivers/firmware/efi/libstub/tpm.c +++ b/drivers/firmware/efi/libstub/tpm.c @@ -96,7 +96,7 @@ static void efi_retrieve_tcg2_eventlog(int version, efi_physical_addr_t log_loca } /* Allocate space for the logs and copy them. */ - status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, + status = efi_bs_call(allocate_pool, EFI_ACPI_RECLAIM_MEMORY, sizeof(*log_tbl) + log_size, (void **)&log_tbl); if (status != EFI_SUCCESS) {