Pull EFI fix from Ingo Molnar: "A boot crash fix for certain systems where the kernel would trust a piece of firmware data it should not have" * 'efi-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: efi: Fix boot panic because of invalid BGRT image address
Unified · Split
| @@ -27,6 +27,26 @@ struct bmp_header { · 26 unmodified lines | ||
| 27 | 27 | u32 size; |
| 28 | 28 | } __packed; |
| 29 | 29 | |
| 30 | +static 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 | + | |
| 30 | 50 | void __init efi_bgrt_init(struct acpi_table_header *table) |
| 31 | 51 | { |
| 32 | 52 | void *image; |
| @@ -36,7 +56,7 @@ void __init efi_bgrt_init(struct acpi_table_header *table) · 3 unmodified lines | ||
| 36 | 56 | if (acpi_disabled) |
| 37 | 57 | return; |
| 38 | 58 | |
| 39 | − if (!efi_enabled(EFI_BOOT)) | |
| 59 | + if (!efi_enabled(EFI_MEMMAP)) | |
| 40 | 60 | return; |
| 41 | 61 | |
| 42 | 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 | 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 | 92 | image = early_memremap(bgrt->image_address, sizeof(bmp_header)); |
| 69 | 93 | if (!image) { |
| 70 | 94 | pr_notice("Ignoring BGRT: failed to map image header memory\n"); |