From c193d9bd284565df4ddcdd1e9190d2ce718e9eb7 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 15 May 2021 18:07:47 +0200 Subject: smbios: error handling for invalid addresses SMBIOS tables only support 32bit addresses. If we don't have memory here handle the error gracefully: * on x86_64 fail to start U-Boot * during UEFI booting ignore the missing table Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- lib/efi_loader/efi_smbios.c | 15 ++++++++------- lib/smbios.c | 4 +++- 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/efi_loader/efi_smbios.c b/lib/efi_loader/efi_smbios.c index 719d3e8880..2eb4cb1c1a 100644 --- a/lib/efi_loader/efi_smbios.c +++ b/lib/efi_loader/efi_smbios.c @@ -5,6 +5,8 @@ * Copyright (c) 2016 Alexander Graf */ +#define LOG_CATEGORY LOGC_EFI + #include #include #include @@ -43,14 +45,13 @@ efi_status_t efi_smbios_register(void) * Generate SMBIOS tables - we know that efi_allocate_pages() returns * a 4k-aligned address, so it is safe to assume that * write_smbios_table() will write the table at that address. - * - * Note that on sandbox, efi_allocate_pages() unfortunately returns a - * pointer even though it uses a uint64_t type. Convert it. */ assert(!(dmi_addr & 0xf)); dmi = (void *)(uintptr_t)dmi_addr; - write_smbios_table(map_to_sysmem(dmi)); - - /* And expose them to our EFI payload */ - return efi_install_configuration_table(&smbios_guid, dmi); + if (write_smbios_table(map_to_sysmem(dmi))) + /* Install SMBIOS information as configuration table */ + return efi_install_configuration_table(&smbios_guid, dmi); + efi_free_pages(dmi_addr, 1); + log_err("Cannot create SMBIOS table\n"); + return EFI_SUCCESS; } diff --git a/lib/smbios.c b/lib/smbios.c index a892716d15..d7f4999e8b 100644 --- a/lib/smbios.c +++ b/lib/smbios.c @@ -530,7 +530,8 @@ ulong write_smbios_table(ulong addr) */ printf("WARNING: SMBIOS table_address overflow %llx\n", (unsigned long long)table_addr); - table_addr = 0; + addr = 0; + goto out; } se->struct_table_address = table_addr; @@ -541,6 +542,7 @@ ulong write_smbios_table(ulong addr) isize = sizeof(struct smbios_entry) - SMBIOS_INTERMEDIATE_OFFSET; se->intermediate_checksum = table_compute_checksum(istart, isize); se->checksum = table_compute_checksum(se, sizeof(struct smbios_entry)); +out: unmap_sysmem(se); return addr; -- cgit v1.2.3