Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp4350384imd; Mon, 29 Oct 2018 23:57:35 -0700 (PDT) X-Google-Smtp-Source: AJdET5eAwvarzthUDR8Lp+3XaFpJh06RdFmaiBXBIDU5QcQ+mhRvYaVigmL0ZPLyz75fR9glDIw7 X-Received: by 2002:a62:1e83:: with SMTP id e125-v6mr1666944pfe.231.1540882655244; Mon, 29 Oct 2018 23:57:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540882655; cv=none; d=google.com; s=arc-20160816; b=ahyRVOuT/fAXxnQWeWr6pYqu38EhYxciRxkTIT3Id6fAmV9fe+Ru7C5v4VqPwA5Py4 Oqjmeo/2vFVsvU6MVwG6rM2AsWd12qMiE0bNixG7E+IRptkZWOOGezEhXKn5cXaGco4K Exw32pkfCE7ha7lvR0kcqI8ozlge/YJ5k20TN6bwRuPBkHQwIycpPLr6XD5RvlIMkOWe ijMw4TIlp4te50MSF/bUw+6ltfZq1LiitpC62scj0qD/j1VAb8yH+vD4msfLUkXCmZJT 8HEehmITYpN0WCeCODYtVig1B1Ri6/KEMK1GtGFR8uZL/iHzS9XzCOMg7ar+SpLDwTkw ZO4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:subject:cc:to:from:date:message-id :mime-version:dkim-signature; bh=fk3o7cmibQ7f9C3D4wKwG3V2IgdJiu07HiMQaRgbgi8=; b=QfAFrqku8SR4l6JoIADAm0K9HASmNLazx4y69U4o9N+8pBapLIBGgDylez/ZecMutZ +MqTlJtUz+AYdXc7loNfjVHM0mvFcoqtEmWOhZimhzOCa36yFFNuXZcf8fjI2q9MrqNa E7O0ewxGKezBnumL540opkz8UN6xIY0qz/4WQ23rtnu7/qWp0f+36hBm9QdNm6HrrRTr f6U56JKTMHfgvukU913UL2Q8BuMzud5ylutxqq1PxAH6KprUvLZ+ajjQ+ae81v7/w5/i JEYfhLjxmdx6UFCtjFIHOEdbdJw7ST3f9pkbpnbxWH+NnVZSpMlwZBXvHWta7S5jaZl4 /i9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b="G3aGv/O3"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p6-v6si23093309pgp.243.2018.10.29.23.57.20; Mon, 29 Oct 2018 23:57:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b="G3aGv/O3"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726840AbeJ3Psd (ORCPT + 99 others); Tue, 30 Oct 2018 11:48:33 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:39314 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726225AbeJ3Psd (ORCPT ); Tue, 30 Oct 2018 11:48:33 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w9U6rtVI115038; Tue, 30 Oct 2018 06:55:09 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=mime-version : message-id : date : from : to : cc : subject : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=fk3o7cmibQ7f9C3D4wKwG3V2IgdJiu07HiMQaRgbgi8=; b=G3aGv/O3McVO5NC7Ue5Q05bVUphPAIwu5+S18l8YtGU7YEekxIkwxxRzx7GFJTZ1irvR baw/JAwfkFpQjJm1Ka9trrdY3dfkbRktfjNtF+uEuqctaf8z2oD/BqRVrTyMZtU+COso p39rGWdHUaoQGl6uaPac9cOIdnqqi70Jgp/M+47eg1d/2DWqv7DKjKcU6Z73b/iTFVDM gNTYNYKn6PYloGBCF2TGQ4A5HL8Kx6UbYJkK7IuxeYU7CnXDmuCLtHSokUDJpTDyrXb0 d7f49i2CAOuuVWcium36dSq0TJkarNu+wCaLOI2n9utbg0dx5hbJ/t8eJOF29gm+vUEJ hA== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2120.oracle.com with ESMTP id 2ncfypt01y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 30 Oct 2018 06:55:09 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w9U6t7xS017955 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 30 Oct 2018 06:55:08 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w9U6t5qr019539; Tue, 30 Oct 2018 06:55:05 GMT MIME-Version: 1.0 Message-ID: Date: Mon, 29 Oct 2018 23:55:04 -0700 (PDT) From: Zhenzhong Duan To: Linux-Kernel Cc: , , , , , Srinivas REDDY Eeda , , , , , , Subject: [PATCH 1/3] retpolines: Only enable retpoline when compiler support it X-Mailer: Zimbra on Oracle Beehive Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9061 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810300060 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since retpoline capable compilers are widely available, make CONFIG_RETPOLINE hard depend on it. Change KBUILD to use CONFIG_RETPOLINE_SUPPORT to avoid conflict with CONFIG_RETPOLINE which is used by kernel. With all that stuff, the check of RETPOLINE is changed to CONFIG_RETPOLINE. This change is based on suggestion in https://lkml.org/lkml/2018/9/18/1016 Signed-off-by: Zhenzhong Duan Cc: Thomas Gleixner Cc: Peter Zijlstra Cc: Borislav Petkov Cc: Daniel Borkmann Cc: David Woodhouse Cc: H. Peter Anvin Cc: Ingo Molnar Cc: Konrad Rzeszutek Wilk Cc: Andy Lutomirski Cc: Masahiro Yamada Cc: Michal Marek --- Documentation/admin-guide/kernel-parameters.txt | 2 +- arch/x86/Kconfig | 8 ++++---- arch/x86/Makefile | 5 +++-- arch/x86/entry/vdso/Makefile | 4 ++-- arch/x86/include/asm/nospec-branch.h | 10 ++++++---- arch/x86/kernel/cpu/bugs.c | 2 +- arch/x86/kernel/vmlinux.lds.S | 2 +- arch/x86/lib/Makefile | 2 +- arch/x86/lib/retpoline.S | 2 ++ scripts/Makefile.build | 2 +- 10 files changed, 22 insertions(+), 17 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index e129cd8..c26264e 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -4187,7 +4187,7 @@ =09=09=09Selecting 'on' will, and 'auto' may, choose a =09=09=09mitigation method at run time according to the =09=09=09CPU, the available microcode, the setting of the -=09=09=09CONFIG_RETPOLINE configuration option, and the +=09=09=09CONFIG_RETPOLINE_SUPPORT configuration option, and the =09=09=09compiler with which the kernel was built. =20 =09=09=09Specific mitigations can also be selected manually: diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index cbd5f28..766563f 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -433,7 +433,7 @@ config GOLDFISH def_bool y depends on X86_GOLDFISH =20 -config RETPOLINE +config RETPOLINE_SUPPORT =09bool "Avoid speculative indirect branches in kernel" =09default y =09select STACK_VALIDATION if HAVE_STACK_VALIDATION @@ -443,9 +443,9 @@ config RETPOLINE =09 branches. Requires a compiler with -mindirect-branch=3Dthunk-extern =09 support for full protection. The kernel may run slower. =20 -=09 Without compiler support, at least indirect branches in assembler -=09 code are eliminated. Since this includes the syscall entry path, -=09 it is not entirely pointless. +=09 Since retpoline capable compilers are widely available, kernel doesn'= t +=09 use CONFIG_RETPOLINE_SUPPORT directly but use CONFIG_RETPOLINE which +=09 is enabled when compiler support retpoline. =20 config INTEL_RDT =09bool "Intel Resource Director Technology support" diff --git a/arch/x86/Makefile b/arch/x86/Makefile index 5b562e4..7ed35b1 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -221,9 +221,10 @@ KBUILD_CFLAGS +=3D -Wno-sign-compare KBUILD_CFLAGS +=3D -fno-asynchronous-unwind-tables =20 # Avoid indirect branches in kernel to deal with Spectre -ifdef CONFIG_RETPOLINE +ifdef CONFIG_RETPOLINE_SUPPORT ifneq ($(RETPOLINE_CFLAGS),) - KBUILD_CFLAGS +=3D $(RETPOLINE_CFLAGS) -DRETPOLINE + KBUILD_CFLAGS +=3D $(RETPOLINE_CFLAGS) -DCONFIG_RETPOLINE + KBUILD_AFLAGS +=3D -DCONFIG_RETPOLINE endif endif =20 diff --git a/arch/x86/entry/vdso/Makefile b/arch/x86/entry/vdso/Makefile index 141d415..87acde1 100644 --- a/arch/x86/entry/vdso/Makefile +++ b/arch/x86/entry/vdso/Makefile @@ -70,7 +70,7 @@ CFL :=3D $(PROFILING) -mcmodel=3Dsmall -fPIC -O2 -fasynch= ronous-unwind-tables -m64 \ -fno-omit-frame-pointer -foptimize-sibling-calls \ -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO =20 -ifdef CONFIG_RETPOLINE +ifdef CONFIG_RETPOLINE_SUPPORT ifneq ($(RETPOLINE_VDSO_CFLAGS),) CFL +=3D $(RETPOLINE_VDSO_CFLAGS) endif @@ -145,7 +145,7 @@ KBUILD_CFLAGS_32 +=3D $(call cc-option, -foptimize-sibl= ing-calls) KBUILD_CFLAGS_32 +=3D -fno-omit-frame-pointer KBUILD_CFLAGS_32 +=3D -DDISABLE_BRANCH_PROFILING =20 -ifdef CONFIG_RETPOLINE +ifdef CONFIG_RETPOLINE_SUPPORT ifneq ($(RETPOLINE_VDSO_CFLAGS),) KBUILD_CFLAGS_32 +=3D $(RETPOLINE_VDSO_CFLAGS) endif diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/no= spec-branch.h index 80dc144..8b09cbb 100644 --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -162,11 +162,12 @@ =09_ASM_PTR " 999b\n\t"=09=09=09=09=09\ =09".popsection\n\t" =20 -#if defined(CONFIG_X86_64) && defined(RETPOLINE) +#ifdef CONFIG_RETPOLINE +#ifdef CONFIG_X86_64 =20 /* - * 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=09=09=09=09=09=09\ =09ANNOTATE_NOSPEC_ALTERNATIVE=09=09=09=09\ @@ -181,7 +182,7 @@ =09X86_FEATURE_RETPOLINE_AMD) # define THUNK_TARGET(addr) [thunk_target] "r" (addr) =20 -#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 @@ -211,6 +212,7 @@ =09X86_FEATURE_RETPOLINE_AMD) =20 # 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.c b/arch/x86/kernel/cpu/bugs.c index c37e66e..d0108fb 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -252,7 +252,7 @@ static void __init spec2_print_if_secure(const char *re= ason) =20 static inline bool retp_compiler(void) { -=09return __is_defined(RETPOLINE); +=09return __is_defined(CONFIG_RETPOLINE); } =20 static inline bool match_option(const char *arg, int arglen, const char *o= pt) diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S index 0d618ee..07533f7 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -136,7 +136,7 @@ SECTIONS =09=09*(.fixup) =09=09*(.gnu.warning) =20 -#ifdef CONFIG_RETPOLINE +#ifdef CONFIG_RETPOLINE_SUPPORT =09=09__indirect_thunk_start =3D .; =09=09*(.text.__x86.indirect_thunk) =09=09__indirect_thunk_end =3D .; diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile index 25a972c..edfa7ab 100644 --- a/arch/x86/lib/Makefile +++ b/arch/x86/lib/Makefile @@ -27,7 +27,7 @@ lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) +=3D rwsem.o lib-$(CONFIG_INSTRUCTION_DECODER) +=3D insn.o inat.o insn-eval.o lib-$(CONFIG_RANDOMIZE_BASE) +=3D kaslr.o lib-$(CONFIG_FUNCTION_ERROR_INJECTION)=09+=3D error-inject.o -lib-$(CONFIG_RETPOLINE) +=3D retpoline.o +lib-$(CONFIG_RETPOLINE_SUPPORT) +=3D retpoline.o =20 obj-y +=3D msr.o msr-reg.o msr-reg-export.o hweight.o =20 diff --git a/arch/x86/lib/retpoline.S b/arch/x86/lib/retpoline.S index c909961..81366ad 100644 --- a/arch/x86/lib/retpoline.S +++ b/arch/x86/lib/retpoline.S @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0 */ =20 +#ifdef CONFIG_RETPOLINE #include #include #include @@ -46,3 +47,4 @@ GENERATE_THUNK(r13) GENERATE_THUNK(r14) GENERATE_THUNK(r15) #endif +#endif diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 54da4b0..259d9c6 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -247,7 +247,7 @@ endif ifdef CONFIG_GCOV_KERNEL objtool_args +=3D --no-unreachable endif -ifdef CONFIG_RETPOLINE +ifdef CONFIG_RETPOLINE_SUPPORT ifneq ($(RETPOLINE_CFLAGS),) objtool_args +=3D --retpoline endif --=20 1.8.3.1