From: Kairui Song <kas...@redhat.com> [ 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: efi_runtime_map_copy+0x28/0x30 bzImage64_load+0x688/0x872 arch_kexec_kernel_image_load+0x6d/0x70 kimage_file_alloc_init+0x13e/0x220 __x64_sys_kexec_file_load+0x144/0x290 do_syscall_64+0x55/0x1a0 entry_SYSCALL_64_after_hwframe+0x44/0xa9 Just skip the EFI info setup if EFI runtime services are not enabled. [ bp: Massage commit message. ] Suggested-by: Dave Young <dyo...@redhat.com> Signed-off-by: Kairui Song <kas...@redhat.com> Signed-off-by: Borislav Petkov <b...@suse.de> Acked-by: Dave Young <dyo...@redhat.com> Cc: AKASHI Takahiro <takahiro.aka...@linaro.org> Cc: Andrew Morton <a...@linux-foundation.org> Cc: Ard Biesheuvel <ard.biesheu...@linaro.org> Cc: b...@redhat.com Cc: David Howells <dhowe...@redhat.com> Cc: erik.schma...@intel.com Cc: fanc.f...@cn.fujitsu.com Cc: "H. Peter Anvin" <h...@zytor.com> Cc: Ingo Molnar <mi...@redhat.com> Cc: ke...@lists.infradead.org Cc: l...@kernel.org Cc: linux-a...@vger.kernel.org Cc: Philipp Rudo <pr...@linux.vnet.ibm.com> Cc: rafael.j.wyso...@intel.com Cc: robert.mo...@intel.com Cc: Thomas Gleixner <t...@linutronix.de> Cc: x86-ml <x...@kernel.org> Cc: Yannik Sembritzki <yan...@sembritzki.me> Link: https://lkml.kernel.org/r/20190118111310.29589-2-kas...@redhat.com Signed-off-by: Sasha Levin <sas...@kernel.org> --- 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 278cd07228dd8..9490a2845f14b 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 = ¶ms->efi_info; + if (!efi_enabled(EFI_RUNTIME_SERVICES)) + return 0; + if (!current_ei->efi_memmap_size) return 0; -- 2.19.1