History

efi: Fix boot panic because of invalid BGRT image address

Maniaxx reported a kernel boot crash in the EFI code, which I emulated by using same invalid phys addr in code: BUG: unable to handle kernel paging request at ffffffffff280001 IP: efi_bgrt_init+0xfb/0x153 ... Call Trace: ? bgrt_init+0xbc/0xbc acpi_parse_bgrt+0xe/0x12 acpi_table_parse+0x89/0xb8 acpi_boot_init+0x445/0x4e2 ? acpi_parse_x2apic+0x79/0x79 ? dmi_ignore_irq0_timer_override+0x33/0x33 setup_arch+0xb63/0xc82 ? early_idt_handler_array+0x120/0x120 start_kernel+0xb7/0x443 ? early_idt_handler_array+0x120/0x120 x86_64_start_reservations+0x29/0x2b x86_64_start_kernel+0x154/0x177 secondary_startup_64+0x9f/0x9f There is also a similar bug filed in bugzilla.kernel.org: https://bugzilla.kernel.org/show_bug.cgi?id=195633 The crash is caused by this commit: 7b0a911478c7 efi/x86: Move the EFI BGRT init code to early init code The root cause is the firmware on those machines provides invalid BGRT image addresses. In a kernel before above commit BGRT initializes late and uses ioremap() to map the image address. Ioremap validates the address, if it is not a valid physical address ioremap() just fails and returns. However in current kernel EFI BGRT initializes early and uses early_memremap() which does not validate the image address, and kernel panic happens. According to ACPI spec the BGRT image address should fall into EFI_BOOT_SERVICES_DATA, see the section 5.2.22.4 of below document: http://www.uefi.org/sites/default/files/resources/ACPI_6_1.pdf Fix this issue by validating the image address in efi_bgrt_init(). If the image address does not fall into any EFI_BOOT_SERVICES_DATA areas we just bail out with a warning message.

Dave Young committed 9 years ago

Commit 792ef141 parent 0d22df91 file · +25 −1Browse files

Unified · Split

drivers/firmware/efi/efi-bgrt.c+25−1
@@ -27,6 +27,26 @@ struct bmp_header { · 26 unmodified lines
27 u32 size;27 u32 size;
28} __packed;28} __packed;
29 29
30static bool efi_bgrt_addr_valid(u64 addr)
31{
32 efi_memory_desc_t *md;
33
34 for_each_efi_memory_desc(md) {
35 u64 size;
36 u64 end;
37
38 if (md->type != EFI_BOOT_SERVICES_DATA)
39 continue;
40
41 size = md->num_pages << EFI_PAGE_SHIFT;
42 end = md->phys_addr + size;
43 if (addr >= md->phys_addr && addr < end)
44 return true;
45 }
46
47 return false;
48}
49
30void __init efi_bgrt_init(struct acpi_table_header *table)50void __init efi_bgrt_init(struct acpi_table_header *table)
31{51{
32 void *image;52 void *image;
@@ -36,7 +56,7 @@ void __init efi_bgrt_init(struct acpi_table_header *table) · 3 unmodified lines
36 if (acpi_disabled)56 if (acpi_disabled)
37 return;57 return;
38 58
39 if (!efi_enabled(EFI_BOOT))59 if (!efi_enabled(EFI_MEMMAP))
40 return;60 return;
41 61
42 if (table->length < sizeof(bgrt_tab)) {62 if (table->length < sizeof(bgrt_tab)) {
@@ -65,6 +85,10 @@ void __init efi_bgrt_init(struct acpi_table_header *table) · 22 unmodified lines
65 goto out;85 goto out;
66 }86 }
67 87
88 if (!efi_bgrt_addr_valid(bgrt->image_address)) {
89 pr_notice("Ignoring BGRT: invalid image address\n");
90 goto out;
91 }
68 image = early_memremap(bgrt->image_address, sizeof(bmp_header));92 image = early_memremap(bgrt->image_address, sizeof(bmp_header));
69 if (!image) {93 if (!image) {
70 pr_notice("Ignoring BGRT: failed to map image header memory\n");94 pr_notice("Ignoring BGRT: failed to map image header memory\n");

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t