[PATCH 4.20 060/171] x86/kexec: Dont setup EFI info if EFI runtime is not enabled

From: Greg Kroah-Hartman
Date: Tue Mar 12 2019 - 14:06:13 EST

4.20-stable review patch. If anyone has any objections, please let me know.


[ Upstream commit 2aa958c99c7fd3162b089a1a56a34a0cdb778de1 ]

Kexec-ing a kernel with "efi=noruntime" on the first kernel's command
line causes the following null pointer dereference:

BUG: unable to handle kernel NULL pointer dereference at 0000000000000000
#PF error: [normal kernel read fault]
Call Trace:

Just skip the EFI info setup if EFI runtime services are not enabled.

[ bp: Massage commit message. ]

Suggested-by: Dave Young <dyoung@xxxxxxxxxx>
Signed-off-by: Kairui Song <kasong@xxxxxxxxxx>
Signed-off-by: Borislav Petkov <bp@xxxxxxx>
Acked-by: Dave Young <dyoung@xxxxxxxxxx>
Cc: AKASHI Takahiro <takahiro.akashi@xxxxxxxxxx>
Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Cc: Ard Biesheuvel <ard.biesheuvel@xxxxxxxxxx>
Cc: bhe@xxxxxxxxxx
Cc: David Howells <dhowells@xxxxxxxxxx>
Cc: erik.schmauss@xxxxxxxxx
Cc: fanc.fnst@xxxxxxxxxxxxxx
Cc: "H. Peter Anvin" <hpa@xxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: kexec@xxxxxxxxxxxxxxxxxxx
Cc: lenb@xxxxxxxxxx
Cc: linux-acpi@xxxxxxxxxxxxxxx
Cc: Philipp Rudo <prudo@xxxxxxxxxxxxxxxxxx>
Cc: rafael.j.wysocki@xxxxxxxxx
Cc: robert.moore@xxxxxxxxx
Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Cc: x86-ml <x86@xxxxxxxxxx>
Cc: Yannik Sembritzki <yannik@xxxxxxxxxxxxx>
Link: https://lkml.kernel.org/r/20190118111310.29589-2-kasong@xxxxxxxxxx
Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
arch/x86/kernel/kexec-bzimage64.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c
index 278cd07228dd..9490a2845f14 100644
--- a/arch/x86/kernel/kexec-bzimage64.c
+++ b/arch/x86/kernel/kexec-bzimage64.c
@@ -167,6 +167,9 @@ setup_efi_state(struct boot_params *params, unsigned long params_load_addr,
struct efi_info *current_ei = &boot_params.efi_info;
struct efi_info *ei = &params->efi_info;

+ if (!efi_enabled(EFI_RUNTIME_SERVICES))
+ return 0;
if (!current_ei->efi_memmap_size)
return 0;