From: Zhenzhong Duan Date: Fri, 2 Nov 2018 08:45:41 +0000 (-0700) Subject: x86/retpoline: Make CONFIG_RETPOLINE depend on compiler support X-Git-Tag: v4.1.12-124.31.3~292 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=1f45fc74b3e6422f71cb687b78c3677f29e7d8b1;p=users%2Fjedix%2Flinux-maple.git x86/retpoline: Make CONFIG_RETPOLINE depend on compiler support Since retpoline capable compilers are widely available, make CONFIG_RETPOLINE hard depend on the compiler capability. Break the build when CONFIG_RETPOLINE is enabled and the compiler does not support it. Emit an error message in that case: "arch/x86/Makefile:226: *** You are building kernel with non-retpoline compiler, please update your compiler.. Stop." [dwmw: Fail the build with non-retpoline compiler] Suggested-by: Peter Zijlstra Signed-off-by: Zhenzhong Duan Signed-off-by: Thomas Gleixner Cc: David Woodhouse Cc: Borislav Petkov Cc: Daniel Borkmann Cc: H. Peter Anvin Cc: Konrad Rzeszutek Wilk Cc: Andy Lutomirski Cc: Masahiro Yamada Cc: Michal Marek Cc: Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/cca0cb20-f9e2-4094-840b-fb0f8810cd34@default (cherry picked from commit 4cd24de3a0980bf3100c9dcb08ef65ca7c31af48) Orabug: 29211617 Signed-off-by: Alejandro Jimenez Reviewed-by: Boris Ostrovsky Signed-off-by: Brian Maly Conflicts: arch/x86/Kconfig arch/x86/include/asm/nospec-branch.h Minor differences between UEK and upstream. arch/x86/Makefile Need to add line defining RETPOLINE_CFLAGS. arch/x86/kernel/cpu/bugs.c UEK4 has the corresponding code in bugs_64.c scripts/Makefile.build Commit e699314 (objtool: Add retpoline validation) has not been ported to UEK4, nothing to change. Signed-off-by: Brian Maly --- diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index e73c64fec231..40b60ecf8fe5 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -389,10 +389,6 @@ config RETPOLINE branches. Requires a compiler with -mindirect-branch=thunk-extern support for full protection. The kernel may run slower. - Without compiler support, at least indirect branches in assembler - code are eliminated. Since this includes the syscall entry path, - it is not entirely pointless. - if X86_32 config X86_EXTENDED_PLATFORM bool "Support for extended (non-PC) x86 platforms" diff --git a/arch/x86/Makefile b/arch/x86/Makefile index a6186d4cef23..dfc305b91e2a 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -174,9 +174,10 @@ KBUILD_AFLAGS += $(mflags-y) # Avoid indirect branches in kernel to deal with Spectre ifdef CONFIG_RETPOLINE RETPOLINE_CFLAGS += $(call cc-option,-mindirect-branch=thunk-extern -mindirect-branch-register) - ifneq ($(RETPOLINE_CFLAGS),) - KBUILD_CFLAGS += $(RETPOLINE_CFLAGS) -DRETPOLINE + ifeq ($(RETPOLINE_CFLAGS),) + $(error You are building kernel with non-retpoline compiler, please update your compiler.) endif + KBUILD_CFLAGS += $(RETPOLINE_CFLAGS) endif archscripts: scripts_basic diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h index ccfd20a9ef19..b8bd9da307fb 100644 --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -131,11 +131,12 @@ #else /* __ASSEMBLY__ */ -#if defined(CONFIG_X86_64) && defined(RETPOLINE) +#ifdef CONFIG_RETPOLINE +#ifdef CONFIG_X86_64 /* - * Since the inline asm uses the %V modifier which is only in newer GCC, - * the 64-bit one is dependent on RETPOLINE not CONFIG_RETPOLINE. + * Inline asm uses the %V modifier which is only in newer GCC + * which is ensured when CONFIG_RETPOLINE is defined. */ # define CALL_NOSPEC \ "901: .byte " __stringify(STATIC_KEY_INIT_NOP) "\n" \ @@ -151,7 +152,7 @@ # define THUNK_TARGET(addr) [thunk_target] "r" (addr) -#elif defined(CONFIG_X86_32) && defined(CONFIG_RETPOLINE) +#else /* CONFIG_X86_32 */ /* * For i386 we use the original ret-equivalent retpoline, because * otherwise we'll run out of registers. We don't care about CET @@ -179,6 +180,7 @@ "905:" # define THUNK_TARGET(addr) [thunk_target] "rm" (addr) +#endif #else /* No retpoline for C / inline asm */ # define CALL_NOSPEC "call *%[thunk_target]\n" # define THUNK_TARGET(addr) [thunk_target] "rm" (addr) diff --git a/arch/x86/kernel/cpu/bugs_64.c b/arch/x86/kernel/cpu/bugs_64.c index f6f9c459a5aa..5dd4b258dcc4 100644 --- a/arch/x86/kernel/cpu/bugs_64.c +++ b/arch/x86/kernel/cpu/bugs_64.c @@ -436,7 +436,7 @@ void find_retpoline_alternative(void) static inline bool retp_compiler(void) { - return __is_defined(RETPOLINE); + return __is_defined(CONFIG_RETPOLINE); } bool retpoline_enabled(void)