From f50f6a13c635b5dcadeeb3bed1f64f5c1d5c6dca Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 16 Sep 2019 21:24:46 +0200 Subject: [PATCH] 4.19-stable patches added patches: x86-purgatory-change-compiler-flags-from-mcmodel-kernel-to-mcmodel-large-to-fix-kexec-relocation-errors.patch --- queue-4.19/series | 1 + ...large-to-fix-kexec-relocation-errors.patch | 133 ++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 queue-4.19/x86-purgatory-change-compiler-flags-from-mcmodel-kernel-to-mcmodel-large-to-fix-kexec-relocation-errors.patch diff --git a/queue-4.19/series b/queue-4.19/series index 44a80908b15..b7d5065164f 100644 --- a/queue-4.19/series +++ b/queue-4.19/series @@ -22,4 +22,5 @@ kvm-s390-kvm_s390_vm_start_migration-check-dirty_bitmap-before-using-it-as-targe kvm-s390-do-not-leak-kernel-stack-data-in-the-kvm_s390_interrupt-ioctl.patch kvm-x86-work-around-leak-of-uninitialized-stack-contents.patch kvm-nvmx-handle-page-fault-in-vmread.patch +x86-purgatory-change-compiler-flags-from-mcmodel-kernel-to-mcmodel-large-to-fix-kexec-relocation-errors.patch gpio-fix-line-flag-validation-in-lineevent_create.patch diff --git a/queue-4.19/x86-purgatory-change-compiler-flags-from-mcmodel-kernel-to-mcmodel-large-to-fix-kexec-relocation-errors.patch b/queue-4.19/x86-purgatory-change-compiler-flags-from-mcmodel-kernel-to-mcmodel-large-to-fix-kexec-relocation-errors.patch new file mode 100644 index 00000000000..45b36864b85 --- /dev/null +++ b/queue-4.19/x86-purgatory-change-compiler-flags-from-mcmodel-kernel-to-mcmodel-large-to-fix-kexec-relocation-errors.patch @@ -0,0 +1,133 @@ +From e16c2983fba0fa6763e43ad10916be35e3d8dc05 Mon Sep 17 00:00:00 2001 +From: Steve Wahl +Date: Thu, 5 Sep 2019 15:23:46 -0500 +Subject: x86/purgatory: Change compiler flags from -mcmodel=kernel to -mcmodel=large to fix kexec relocation errors + +From: Steve Wahl + +commit e16c2983fba0fa6763e43ad10916be35e3d8dc05 upstream. + +The last change to this Makefile caused relocation errors when loading +a kdump kernel. Restore -mcmodel=large (not -mcmodel=kernel), +-ffreestanding, and -fno-zero-initialized-bsss, without reverting to +the former practice of resetting KBUILD_CFLAGS. + +Purgatory.ro is a standalone binary that is not linked against the +rest of the kernel. Its image is copied into an array that is linked +to the kernel, and from there kexec relocates it wherever it desires. + +With the previous change to compiler flags, the error "kexec: Overflow +in relocation type 11 value 0x11fffd000" was encountered when trying +to load the crash kernel. This is from kexec code trying to relocate +the purgatory.ro object. + +From the error message, relocation type 11 is R_X86_64_32S. The +x86_64 ABI says: + + "The R_X86_64_32 and R_X86_64_32S relocations truncate the + computed value to 32-bits. The linker must verify that the + generated value for the R_X86_64_32 (R_X86_64_32S) relocation + zero-extends (sign-extends) to the original 64-bit value." + +This type of relocation doesn't work when kexec chooses to place the +purgatory binary in memory that is not reachable with 32 bit +addresses. + +The compiler flag -mcmodel=kernel allows those type of relocations to +be emitted, so revert to using -mcmodel=large as was done before. + +Also restore the -ffreestanding and -fno-zero-initialized-bss flags +because they are appropriate for a stand alone piece of object code +which doesn't explicitly zero the bss, and one other report has said +undefined symbols are encountered without -ffreestanding. + +These identical compiler flag changes need to happen for every object +that becomes part of the purgatory.ro object, so gather them together +first into PURGATORY_CFLAGS_REMOVE and PURGATORY_CFLAGS, and then +apply them to each of the objects that have C source. Do not apply +any of these flags to kexec-purgatory.o, which is not part of the +standalone object but part of the kernel proper. + +Tested-by: Vaibhav Rustagi +Tested-by: Andreas Smas +Signed-off-by: Steve Wahl +Reviewed-by: Nick Desaulniers +Cc: Borislav Petkov +Cc: H. Peter Anvin +Cc: Linus Torvalds +Cc: None +Cc: Peter Zijlstra +Cc: Thomas Gleixner +Cc: clang-built-linux@googlegroups.com +Cc: dimitri.sivanich@hpe.com +Cc: mike.travis@hpe.com +Cc: russ.anderson@hpe.com +Fixes: b059f801a937 ("x86/purgatory: Use CFLAGS_REMOVE rather than reset KBUILD_CFLAGS") +Link: https://lkml.kernel.org/r/20190905202346.GA26595@swahl-linux +Signed-off-by: Ingo Molnar +Cc: Andreas Smas +Signed-off-by: Greg Kroah-Hartman + +--- + arch/x86/purgatory/Makefile | 35 +++++++++++++++++++---------------- + 1 file changed, 19 insertions(+), 16 deletions(-) + +--- a/arch/x86/purgatory/Makefile ++++ b/arch/x86/purgatory/Makefile +@@ -18,37 +18,40 @@ targets += purgatory.ro + KASAN_SANITIZE := n + KCOV_INSTRUMENT := n + ++# These are adjustments to the compiler flags used for objects that ++# make up the standalone purgatory.ro ++ ++PURGATORY_CFLAGS_REMOVE := -mcmodel=kernel ++PURGATORY_CFLAGS := -mcmodel=large -ffreestanding -fno-zero-initialized-in-bss ++ + # Default KBUILD_CFLAGS can have -pg option set when FTRACE is enabled. That + # in turn leaves some undefined symbols like __fentry__ in purgatory and not + # sure how to relocate those. + ifdef CONFIG_FUNCTION_TRACER +-CFLAGS_REMOVE_sha256.o += $(CC_FLAGS_FTRACE) +-CFLAGS_REMOVE_purgatory.o += $(CC_FLAGS_FTRACE) +-CFLAGS_REMOVE_string.o += $(CC_FLAGS_FTRACE) +-CFLAGS_REMOVE_kexec-purgatory.o += $(CC_FLAGS_FTRACE) ++PURGATORY_CFLAGS_REMOVE += $(CC_FLAGS_FTRACE) + endif + + ifdef CONFIG_STACKPROTECTOR +-CFLAGS_REMOVE_sha256.o += -fstack-protector +-CFLAGS_REMOVE_purgatory.o += -fstack-protector +-CFLAGS_REMOVE_string.o += -fstack-protector +-CFLAGS_REMOVE_kexec-purgatory.o += -fstack-protector ++PURGATORY_CFLAGS_REMOVE += -fstack-protector + endif + + ifdef CONFIG_STACKPROTECTOR_STRONG +-CFLAGS_REMOVE_sha256.o += -fstack-protector-strong +-CFLAGS_REMOVE_purgatory.o += -fstack-protector-strong +-CFLAGS_REMOVE_string.o += -fstack-protector-strong +-CFLAGS_REMOVE_kexec-purgatory.o += -fstack-protector-strong ++PURGATORY_CFLAGS_REMOVE += -fstack-protector-strong + endif + + ifdef CONFIG_RETPOLINE +-CFLAGS_REMOVE_sha256.o += $(RETPOLINE_CFLAGS) +-CFLAGS_REMOVE_purgatory.o += $(RETPOLINE_CFLAGS) +-CFLAGS_REMOVE_string.o += $(RETPOLINE_CFLAGS) +-CFLAGS_REMOVE_kexec-purgatory.o += $(RETPOLINE_CFLAGS) ++PURGATORY_CFLAGS_REMOVE += $(RETPOLINE_CFLAGS) + endif + ++CFLAGS_REMOVE_purgatory.o += $(PURGATORY_CFLAGS_REMOVE) ++CFLAGS_purgatory.o += $(PURGATORY_CFLAGS) ++ ++CFLAGS_REMOVE_sha256.o += $(PURGATORY_CFLAGS_REMOVE) ++CFLAGS_sha256.o += $(PURGATORY_CFLAGS) ++ ++CFLAGS_REMOVE_string.o += $(PURGATORY_CFLAGS_REMOVE) ++CFLAGS_string.o += $(PURGATORY_CFLAGS) ++ + $(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE + $(call if_changed,ld) + -- 2.47.3