Skip to content

Commit 98790bb

Browse files
committed
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()
2 parents 667b624 + 9bb4cbf commit 98790bb

File tree

12 files changed

+124
-39
lines changed

12 files changed

+124
-39
lines changed

arch/x86/boot/tools/build.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ u8 buf[SETUP_SECT_MAX*512];
5959
#define PECOFF_COMPAT_RESERVE 0x0
6060
#endif
6161

62-
unsigned long efi32_stub_entry;
63-
unsigned long efi64_stub_entry;
64-
unsigned long efi_pe_entry;
65-
unsigned long efi32_pe_entry;
66-
unsigned long kernel_info;
67-
unsigned long startup_64;
68-
unsigned long _ehead;
69-
unsigned long _end;
62+
static unsigned long efi32_stub_entry;
63+
static unsigned long efi64_stub_entry;
64+
static unsigned long efi_pe_entry;
65+
static unsigned long efi32_pe_entry;
66+
static unsigned long kernel_info;
67+
static unsigned long startup_64;
68+
static unsigned long _ehead;
69+
static unsigned long _end;
7070

7171
/*----------------------------------------------------------------------*/
7272

drivers/firmware/efi/cper.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,58 @@ static void cper_print_pcie(const char *pfx, const struct cper_sec_pcie *pcie,
407407
}
408408
}
409409

410+
static const char * const fw_err_rec_type_strs[] = {
411+
"IPF SAL Error Record",
412+
"SOC Firmware Error Record Type1 (Legacy CrashLog Support)",
413+
"SOC Firmware Error Record Type2",
414+
};
415+
416+
static void cper_print_fw_err(const char *pfx,
417+
struct acpi_hest_generic_data *gdata,
418+
const struct cper_sec_fw_err_rec_ref *fw_err)
419+
{
420+
void *buf = acpi_hest_get_payload(gdata);
421+
u32 offset, length = gdata->error_data_length;
422+
423+
printk("%s""Firmware Error Record Type: %s\n", pfx,
424+
fw_err->record_type < ARRAY_SIZE(fw_err_rec_type_strs) ?
425+
fw_err_rec_type_strs[fw_err->record_type] : "unknown");
426+
printk("%s""Revision: %d\n", pfx, fw_err->revision);
427+
428+
/* Record Type based on UEFI 2.7 */
429+
if (fw_err->revision == 0) {
430+
printk("%s""Record Identifier: %08llx\n", pfx,
431+
fw_err->record_identifier);
432+
} else if (fw_err->revision == 2) {
433+
printk("%s""Record Identifier: %pUl\n", pfx,
434+
&fw_err->record_identifier_guid);
435+
}
436+
437+
/*
438+
* The FW error record may contain trailing data beyond the
439+
* structure defined by the specification. As the fields
440+
* defined (and hence the offset of any trailing data) vary
441+
* with the revision, set the offset to account for this
442+
* variation.
443+
*/
444+
if (fw_err->revision == 0) {
445+
/* record_identifier_guid not defined */
446+
offset = offsetof(struct cper_sec_fw_err_rec_ref,
447+
record_identifier_guid);
448+
} else if (fw_err->revision == 1) {
449+
/* record_identifier not defined */
450+
offset = offsetof(struct cper_sec_fw_err_rec_ref,
451+
record_identifier);
452+
} else {
453+
offset = sizeof(*fw_err);
454+
}
455+
456+
buf += offset;
457+
length -= offset;
458+
459+
print_hex_dump(pfx, "", DUMP_PREFIX_OFFSET, 16, 4, buf, length, true);
460+
}
461+
410462
static void cper_print_tstamp(const char *pfx,
411463
struct acpi_hest_generic_data_v300 *gdata)
412464
{
@@ -494,6 +546,16 @@ cper_estatus_print_section(const char *pfx, struct acpi_hest_generic_data *gdata
494546
else
495547
goto err_section_too_small;
496548
#endif
549+
} else if (guid_equal(sec_type, &CPER_SEC_FW_ERR_REC_REF)) {
550+
struct cper_sec_fw_err_rec_ref *fw_err = acpi_hest_get_payload(gdata);
551+
552+
printk("%ssection_type: Firmware Error Record Reference\n",
553+
newpfx);
554+
/* The minimal FW Error Record contains 16 bytes */
555+
if (gdata->error_data_length >= SZ_16)
556+
cper_print_fw_err(newpfx, gdata, fw_err);
557+
else
558+
goto err_section_too_small;
497559
} else {
498560
const void *err = acpi_hest_get_payload(gdata);
499561

drivers/firmware/efi/earlycon.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,16 @@ static void efi_earlycon_write_char(u32 *dst, unsigned char c, unsigned int h)
114114
const u32 color_black = 0x00000000;
115115
const u32 color_white = 0x00ffffff;
116116
const u8 *src;
117-
u8 s8;
118-
int m;
117+
int m, n, bytes;
118+
u8 x;
119119

120-
src = font->data + c * font->height;
121-
s8 = *(src + h);
120+
bytes = BITS_TO_BYTES(font->width);
121+
src = font->data + c * font->height * bytes + h * bytes;
122122

123-
for (m = 0; m < 8; m++) {
124-
if ((s8 >> (7 - m)) & 1)
123+
for (m = 0; m < font->width; m++) {
124+
n = m % 8;
125+
x = *(src + m / 8);
126+
if ((x >> (7 - n)) & 1)
125127
*dst = color_white;
126128
else
127129
*dst = color_black;

drivers/firmware/efi/efi.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,8 @@ static ssize_t systab_show(struct kobject *kobj,
130130
if (efi.smbios != EFI_INVALID_TABLE_ADDR)
131131
str += sprintf(str, "SMBIOS=0x%lx\n", efi.smbios);
132132

133-
if (IS_ENABLED(CONFIG_IA64) || IS_ENABLED(CONFIG_X86)) {
134-
extern char *efi_systab_show_arch(char *str);
135-
133+
if (IS_ENABLED(CONFIG_IA64) || IS_ENABLED(CONFIG_X86))
136134
str = efi_systab_show_arch(str);
137-
}
138135

139136
return str - buf;
140137
}

drivers/firmware/efi/libstub/arm-stub.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ static struct screen_info *setup_graphics(void)
6060
si = alloc_screen_info();
6161
if (!si)
6262
return NULL;
63-
efi_setup_gop(si, &gop_proto, size);
63+
status = efi_setup_gop(si, &gop_proto, size);
64+
if (status != EFI_SUCCESS) {
65+
free_screen_info(si);
66+
return NULL;
67+
}
6468
}
6569
return si;
6670
}

drivers/firmware/efi/libstub/efistub.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,19 @@ extern __pure efi_system_table_t *efi_system_table(void);
9292
#define EFI_LOCATE_BY_REGISTER_NOTIFY 1
9393
#define EFI_LOCATE_BY_PROTOCOL 2
9494

95+
/*
96+
* An efi_boot_memmap is used by efi_get_memory_map() to return the
97+
* EFI memory map in a dynamically allocated buffer.
98+
*
99+
* The buffer allocated for the EFI memory map includes extra room for
100+
* a minimum of EFI_MMAP_NR_SLACK_SLOTS additional EFI memory descriptors.
101+
* This facilitates the reuse of the EFI memory map buffer when a second
102+
* call to ExitBootServices() is needed because of intervening changes to
103+
* the EFI memory map. Other related structures, e.g. x86 e820ext, need
104+
* to factor in this headroom requirement as well.
105+
*/
106+
#define EFI_MMAP_NR_SLACK_SLOTS 8
107+
95108
struct efi_boot_memmap {
96109
efi_memory_desc_t **map;
97110
unsigned long *map_size;

drivers/firmware/efi/libstub/mem.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
#include "efistub.h"
77

8-
#define EFI_MMAP_NR_SLACK_SLOTS 8
9-
108
static inline bool mmap_has_headroom(unsigned long buff_size,
119
unsigned long map_size,
1210
unsigned long desc_size)

drivers/firmware/efi/libstub/tpm.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void efi_retrieve_tpm2_eventlog(void)
5454
efi_status_t status;
5555
efi_physical_addr_t log_location = 0, log_last_entry = 0;
5656
struct linux_efi_tpm_eventlog *log_tbl = NULL;
57-
struct efi_tcg2_final_events_table *final_events_table;
57+
struct efi_tcg2_final_events_table *final_events_table = NULL;
5858
unsigned long first_entry_addr, last_entry_addr;
5959
size_t log_size, last_entry_size;
6060
efi_bool_t truncated;
@@ -127,7 +127,8 @@ void efi_retrieve_tpm2_eventlog(void)
127127
* Figure out whether any events have already been logged to the
128128
* final events structure, and if so how much space they take up
129129
*/
130-
final_events_table = get_efi_config_table(LINUX_EFI_TPM_FINAL_LOG_GUID);
130+
if (version == EFI_TCG2_EVENT_LOG_FORMAT_TCG_2)
131+
final_events_table = get_efi_config_table(LINUX_EFI_TPM_FINAL_LOG_GUID);
131132
if (final_events_table && final_events_table->nr_events) {
132133
struct tcg_pcr_event2_head *header;
133134
int offset;

drivers/firmware/efi/libstub/x86-stub.c

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -606,24 +606,18 @@ static efi_status_t allocate_e820(struct boot_params *params,
606606
struct setup_data **e820ext,
607607
u32 *e820ext_size)
608608
{
609-
unsigned long map_size, desc_size, buff_size;
610-
struct efi_boot_memmap boot_map;
611-
efi_memory_desc_t *map;
609+
unsigned long map_size, desc_size, map_key;
612610
efi_status_t status;
613-
__u32 nr_desc;
611+
__u32 nr_desc, desc_version;
614612

615-
boot_map.map = &map;
616-
boot_map.map_size = &map_size;
617-
boot_map.desc_size = &desc_size;
618-
boot_map.desc_ver = NULL;
619-
boot_map.key_ptr = NULL;
620-
boot_map.buff_size = &buff_size;
613+
/* Only need the size of the mem map and size of each mem descriptor */
614+
map_size = 0;
615+
status = efi_bs_call(get_memory_map, &map_size, NULL, &map_key,
616+
&desc_size, &desc_version);
617+
if (status != EFI_BUFFER_TOO_SMALL)
618+
return (status != EFI_SUCCESS) ? status : EFI_UNSUPPORTED;
621619

622-
status = efi_get_memory_map(&boot_map);
623-
if (status != EFI_SUCCESS)
624-
return status;
625-
626-
nr_desc = buff_size / desc_size;
620+
nr_desc = map_size / desc_size + EFI_MMAP_NR_SLACK_SLOTS;
627621

628622
if (nr_desc > ARRAY_SIZE(params->e820_table)) {
629623
u32 nr_e820ext = nr_desc - ARRAY_SIZE(params->e820_table);

drivers/firmware/efi/tpm.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,11 @@ int __init efi_tpm_eventlog_init(void)
6262
tbl_size = sizeof(*log_tbl) + log_tbl->size;
6363
memblock_reserve(efi.tpm_log, tbl_size);
6464

65-
if (efi.tpm_final_log == EFI_INVALID_TABLE_ADDR)
65+
if (efi.tpm_final_log == EFI_INVALID_TABLE_ADDR ||
66+
log_tbl->version != EFI_TCG2_EVENT_LOG_FORMAT_TCG_2) {
67+
pr_warn(FW_BUG "TPM Final Events table missing or invalid\n");
6668
goto out;
69+
}
6770

6871
final_tbl = early_memremap(efi.tpm_final_log, sizeof(*final_tbl));
6972

0 commit comments

Comments
 (0)