1 From 6f913de3231e1d70a871135b38219da7810df218 Mon Sep 17 00:00:00 2001
2 From: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
3 Date: Tue, 19 Feb 2019 10:52:24 +0300
4 Subject: x86/boot/compressed/64: Do not read legacy ROM on EFI system
6 From: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
8 commit 6f913de3231e1d70a871135b38219da7810df218 upstream.
10 EFI systems do not necessarily provide a legacy ROM. If the ROM is missing
11 the memory is not mapped at all.
13 Trying to dereference values in the legacy ROM area leads to a crash on
16 Only look for values in the legacy ROM area for non-EFI system.
18 Fixes: 3548e131ec6a ("x86/boot/compressed/64: Find a place for 32-bit trampoline")
19 Reported-by: Pitam Mitra <pitamm@gmail.com>
20 Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
21 Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
22 Tested-by: Bockjoo Kim <bockjoo@phys.ufl.edu>
25 Cc: stable@vger.kernel.org
26 Link: https://lkml.kernel.org/r/20190219075224.35058-1-kirill.shutemov@linux.intel.com
27 Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=202351
28 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
31 arch/x86/boot/compressed/pgtable_64.c | 19 ++++++++++++++++---
32 1 file changed, 16 insertions(+), 3 deletions(-)
34 --- a/arch/x86/boot/compressed/pgtable_64.c
35 +++ b/arch/x86/boot/compressed/pgtable_64.c
37 +#include <linux/efi.h>
38 #include <asm/e820/types.h>
39 #include <asm/processor.h>
42 #include "../string.h"
44 @@ -37,9 +39,10 @@ int cmdline_find_option_bool(const char
46 static unsigned long find_trampoline_placement(void)
48 - unsigned long bios_start, ebda_start;
49 + unsigned long bios_start = 0, ebda_start = 0;
50 unsigned long trampoline_start;
51 struct boot_e820_entry *entry;
56 @@ -47,8 +50,18 @@ static unsigned long find_trampoline_pla
57 * This code is based on reserve_bios_regions().
60 - ebda_start = *(unsigned short *)0x40e << 4;
61 - bios_start = *(unsigned short *)0x413 << 10;
63 + * EFI systems may not provide legacy ROM. The memory may not be mapped
66 + * Only look for values in the legacy ROM for non-EFI system.
68 + signature = (char *)&boot_params->efi_info.efi_loader_signature;
69 + if (strncmp(signature, EFI32_LOADER_SIGNATURE, 4) &&
70 + strncmp(signature, EFI64_LOADER_SIGNATURE, 4)) {
71 + ebda_start = *(unsigned short *)0x40e << 4;
72 + bios_start = *(unsigned short *)0x413 << 10;
75 if (bios_start < BIOS_START_MIN || bios_start > BIOS_START_MAX)
76 bios_start = BIOS_START_MAX;