Commit 98790bba authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'efi-urgent-2020-05-24' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull EFI fixes from Thomas Gleixner:
 "A set of EFI fixes:

   - Don't return a garbage screen info when EFI framebuffer is not
     available

   - Make the early EFI console work properly with wider fonts instead
     of drawing garbage

   - Prevent a memory buffer leak in allocate_e820()

   - Print the firmware error record properly so it can be decoded by
     users

   - Fix a symbol clash in the host tool build which only happens with
     newer compilers.

   - Add a missing check for the event log version of TPM which caused
     boot failures on several Dell systems due to an attempt to decode
     SHA-1 format with the crypto agile algorithm"

* tag 'efi-urgent-2020-05-24' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  tpm: check event log version before reading final events
  efi: Pull up arch-specific prototype efi_systab_show_arch()
  x86/boot: Mark global variables as static
  efi: cper: Add support for printing Firmware Error Record Reference
  efi/libstub/x86: Avoid EFI map buffer alloc in allocate_e820()
  efi/earlycon: Fix early printk for wider fonts
  efi/libstub: Avoid returning uninitialized data from setup_graphics()
parents 667b6249 9bb4cbf4
......@@ -59,14 +59,14 @@ u8 buf[SETUP_SECT_MAX*512];
#define PECOFF_COMPAT_RESERVE 0x0
#endif
unsigned long efi32_stub_entry;
unsigned long efi64_stub_entry;
unsigned long efi_pe_entry;
unsigned long efi32_pe_entry;
unsigned long kernel_info;
unsigned long startup_64;
unsigned long _ehead;
unsigned long _end;
static unsigned long efi32_stub_entry;
static unsigned long efi64_stub_entry;
static unsigned long efi_pe_entry;
static unsigned long efi32_pe_entry;
static unsigned long kernel_info;
static unsigned long startup_64;
static unsigned long _ehead;
static unsigned long _end;
/*----------------------------------------------------------------------*/
......
......@@ -407,6 +407,58 @@ static void cper_print_pcie(const char *pfx, const struct cper_sec_pcie *pcie,
}
}
static const char * const fw_err_rec_type_strs[] = {
"IPF SAL Error Record",
"SOC Firmware Error Record Type1 (Legacy CrashLog Support)",
"SOC Firmware Error Record Type2",
};
static void cper_print_fw_err(const char *pfx,
struct acpi_hest_generic_data *gdata,
const struct cper_sec_fw_err_rec_ref *fw_err)
{
void *buf = acpi_hest_get_payload(gdata);
u32 offset, length = gdata->error_data_length;
printk("%s""Firmware Error Record Type: %s\n", pfx,
fw_err->record_type < ARRAY_SIZE(fw_err_rec_type_strs) ?
fw_err_rec_type_strs[fw_err->record_type] : "unknown");
printk("%s""Revision: %d\n", pfx, fw_err->revision);
/* Record Type based on UEFI 2.7 */
if (fw_err->revision == 0) {
printk("%s""Record Identifier: %08llx\n", pfx,
fw_err->record_identifier);
} else if (fw_err->revision == 2) {
printk("%s""Record Identifier: %pUl\n", pfx,
&fw_err->record_identifier_guid);
}
/*
* The FW error record may contain trailing data beyond the
* structure defined by the specification. As the fields
* defined (and hence the offset of any trailing data) vary
* with the revision, set the offset to account for this
* variation.
*/
if (fw_err->revision == 0) {
/* record_identifier_guid not defined */
offset = offsetof(struct cper_sec_fw_err_rec_ref,
record_identifier_guid);
} else if (fw_err->revision == 1) {
/* record_identifier not defined */
offset = offsetof(struct cper_sec_fw_err_rec_ref,
record_identifier);
} else {
offset = sizeof(*fw_err);
}
buf += offset;
length -= offset;
print_hex_dump(pfx, "", DUMP_PREFIX_OFFSET, 16, 4, buf, length, true);
}
static void cper_print_tstamp(const char *pfx,
struct acpi_hest_generic_data_v300 *gdata)
{
......@@ -494,6 +546,16 @@ cper_estatus_print_section(const char *pfx, struct acpi_hest_generic_data *gdata
else
goto err_section_too_small;
#endif
} else if (guid_equal(sec_type, &CPER_SEC_FW_ERR_REC_REF)) {
struct cper_sec_fw_err_rec_ref *fw_err = acpi_hest_get_payload(gdata);
printk("%ssection_type: Firmware Error Record Reference\n",
newpfx);
/* The minimal FW Error Record contains 16 bytes */
if (gdata->error_data_length >= SZ_16)
cper_print_fw_err(newpfx, gdata, fw_err);
else
goto err_section_too_small;
} else {
const void *err = acpi_hest_get_payload(gdata);
......
......@@ -114,14 +114,16 @@ static void efi_earlycon_write_char(u32 *dst, unsigned char c, unsigned int h)
const u32 color_black = 0x00000000;
const u32 color_white = 0x00ffffff;
const u8 *src;
u8 s8;
int m;
int m, n, bytes;
u8 x;
src = font->data + c * font->height;
s8 = *(src + h);
bytes = BITS_TO_BYTES(font->width);
src = font->data + c * font->height * bytes + h * bytes;
for (m = 0; m < 8; m++) {
if ((s8 >> (7 - m)) & 1)
for (m = 0; m < font->width; m++) {
n = m % 8;
x = *(src + m / 8);
if ((x >> (7 - n)) & 1)
*dst = color_white;
else
*dst = color_black;
......
......@@ -130,11 +130,8 @@ static ssize_t systab_show(struct kobject *kobj,
if (efi.smbios != EFI_INVALID_TABLE_ADDR)
str += sprintf(str, "SMBIOS=0x%lx\n", efi.smbios);
if (IS_ENABLED(CONFIG_IA64) || IS_ENABLED(CONFIG_X86)) {
extern char *efi_systab_show_arch(char *str);
if (IS_ENABLED(CONFIG_IA64) || IS_ENABLED(CONFIG_X86))
str = efi_systab_show_arch(str);
}
return str - buf;
}
......
......@@ -60,7 +60,11 @@ static struct screen_info *setup_graphics(void)
si = alloc_screen_info();
if (!si)
return NULL;
efi_setup_gop(si, &gop_proto, size);
status = efi_setup_gop(si, &gop_proto, size);
if (status != EFI_SUCCESS) {
free_screen_info(si);
return NULL;
}
}
return si;
}
......
......@@ -92,6 +92,19 @@ extern __pure efi_system_table_t *efi_system_table(void);
#define EFI_LOCATE_BY_REGISTER_NOTIFY 1
#define EFI_LOCATE_BY_PROTOCOL 2
/*
* An efi_boot_memmap is used by efi_get_memory_map() to return the
* EFI memory map in a dynamically allocated buffer.
*
* The buffer allocated for the EFI memory map includes extra room for
* a minimum of EFI_MMAP_NR_SLACK_SLOTS additional EFI memory descriptors.
* This facilitates the reuse of the EFI memory map buffer when a second
* call to ExitBootServices() is needed because of intervening changes to
* the EFI memory map. Other related structures, e.g. x86 e820ext, need
* to factor in this headroom requirement as well.
*/
#define EFI_MMAP_NR_SLACK_SLOTS 8
struct efi_boot_memmap {
efi_memory_desc_t **map;
unsigned long *map_size;
......
......@@ -5,8 +5,6 @@
#include "efistub.h"
#define EFI_MMAP_NR_SLACK_SLOTS 8
static inline bool mmap_has_headroom(unsigned long buff_size,
unsigned long map_size,
unsigned long desc_size)
......
......@@ -54,7 +54,7 @@ void efi_retrieve_tpm2_eventlog(void)
efi_status_t status;
efi_physical_addr_t log_location = 0, log_last_entry = 0;
struct linux_efi_tpm_eventlog *log_tbl = NULL;
struct efi_tcg2_final_events_table *final_events_table;
struct efi_tcg2_final_events_table *final_events_table = NULL;
unsigned long first_entry_addr, last_entry_addr;
size_t log_size, last_entry_size;
efi_bool_t truncated;
......@@ -127,7 +127,8 @@ void efi_retrieve_tpm2_eventlog(void)
* Figure out whether any events have already been logged to the
* final events structure, and if so how much space they take up
*/
final_events_table = get_efi_config_table(LINUX_EFI_TPM_FINAL_LOG_GUID);
if (version == EFI_TCG2_EVENT_LOG_FORMAT_TCG_2)
final_events_table = get_efi_config_table(LINUX_EFI_TPM_FINAL_LOG_GUID);
if (final_events_table && final_events_table->nr_events) {
struct tcg_pcr_event2_head *header;
int offset;
......
......@@ -606,24 +606,18 @@ static efi_status_t allocate_e820(struct boot_params *params,
struct setup_data **e820ext,
u32 *e820ext_size)
{
unsigned long map_size, desc_size, buff_size;
struct efi_boot_memmap boot_map;
efi_memory_desc_t *map;
unsigned long map_size, desc_size, map_key;
efi_status_t status;
__u32 nr_desc;
__u32 nr_desc, desc_version;
boot_map.map = &map;
boot_map.map_size = &map_size;
boot_map.desc_size = &desc_size;
boot_map.desc_ver = NULL;
boot_map.key_ptr = NULL;
boot_map.buff_size = &buff_size;
/* Only need the size of the mem map and size of each mem descriptor */
map_size = 0;
status = efi_bs_call(get_memory_map, &map_size, NULL, &map_key,
&desc_size, &desc_version);
if (status != EFI_BUFFER_TOO_SMALL)
return (status != EFI_SUCCESS) ? status : EFI_UNSUPPORTED;
status = efi_get_memory_map(&boot_map);
if (status != EFI_SUCCESS)
return status;
nr_desc = buff_size / desc_size;
nr_desc = map_size / desc_size + EFI_MMAP_NR_SLACK_SLOTS;
if (nr_desc > ARRAY_SIZE(params->e820_table)) {
u32 nr_e820ext = nr_desc - ARRAY_SIZE(params->e820_table);
......
......@@ -62,8 +62,11 @@ int __init efi_tpm_eventlog_init(void)
tbl_size = sizeof(*log_tbl) + log_tbl->size;
memblock_reserve(efi.tpm_log, tbl_size);
if (efi.tpm_final_log == EFI_INVALID_TABLE_ADDR)
if (efi.tpm_final_log == EFI_INVALID_TABLE_ADDR ||
log_tbl->version != EFI_TCG2_EVENT_LOG_FORMAT_TCG_2) {
pr_warn(FW_BUG "TPM Final Events table missing or invalid\n");
goto out;
}
final_tbl = early_memremap(efi.tpm_final_log, sizeof(*final_tbl));
......
......@@ -521,6 +521,15 @@ struct cper_sec_pcie {
u8 aer_info[96];
};
/* Firmware Error Record Reference, UEFI v2.7 sec N.2.10 */
struct cper_sec_fw_err_rec_ref {
u8 record_type;
u8 revision;
u8 reserved[6];
u64 record_identifier;
guid_t record_identifier_guid;
};
/* Reset to default packing */
#pragma pack()
......
......@@ -1245,4 +1245,6 @@ struct linux_efi_memreserve {
void __init efi_arch_mem_reserve(phys_addr_t addr, u64 size);
char *efi_systab_show_arch(char *str);
#endif /* _LINUX_EFI_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment