|
Message-Id: <1519382538-15143-14-git-send-email-jinpu.wangl@profitbricks.com> Date: Fri, 23 Feb 2018 11:42:02 +0100 From: Jack Wang <jinpu.wang@...fitbricks.com> To: gregkh@...uxfoundation.org, stable@...r.kernel.org Cc: Dan Williams <dan.j.williams@...el.com>, Thomas Gleixner <tglx@...utronix.de>, linux-arch@...r.kernel.org, Tom Lendacky <thomas.lendacky@....com>, Kees Cook <keescook@...omium.org>, kernel-hardening@...ts.openwall.com, Al Viro <viro@...iv.linux.org.uk>, alan@...ux.intel.com, David Woodhouse <dwmw@...zon.co.uk>, Jack Wang <jinpu.wang@...fitbricks.com> Subject: [stable 4.4 13/29] x86: Introduce barrier_nospec From: Dan Williams <dan.j.williams@...el.com> (cherry picked from commit b3d7ad85b80bbc404635dca80f5b129f6242bc7a) Rename the open coded form of this instruction sequence from rdtsc_ordered() into a generic barrier primitive, barrier_nospec(). One of the mitigations for Spectre variant1 vulnerabilities is to fence speculative execution after successfully validating a bounds check. I.e. force the result of a bounds check to resolve in the instruction pipeline to ensure speculative execution honors that result before potentially operating on out-of-bounds data. No functional changes. Suggested-by: Linus Torvalds <torvalds@...ux-foundation.org> Suggested-by: Andi Kleen <ak@...ux.intel.com> Suggested-by: Ingo Molnar <mingo@...hat.com> Signed-off-by: Dan Williams <dan.j.williams@...el.com> Signed-off-by: Thomas Gleixner <tglx@...utronix.de> Cc: linux-arch@...r.kernel.org Cc: Tom Lendacky <thomas.lendacky@....com> Cc: Kees Cook <keescook@...omium.org> Cc: kernel-hardening@...ts.openwall.com Cc: gregkh@...uxfoundation.org Cc: Al Viro <viro@...iv.linux.org.uk> Cc: alan@...ux.intel.com Link: https://lkml.kernel.org/r/151727415361.33451.9049453007262764675.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: David Woodhouse <dwmw@...zon.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@...uxfoundation.org> [jwang: cherry pick to 4.4] Signed-off-by: Jack Wang <jinpu.wang@...fitbricks.com> --- arch/x86/include/asm/barrier.h | 4 ++++ arch/x86/include/asm/msr.h | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h index b5028e3..814ef83 100644 --- a/arch/x86/include/asm/barrier.h +++ b/arch/x86/include/asm/barrier.h @@ -48,6 +48,10 @@ static inline unsigned long array_index_mask_nospec(unsigned long index, /* Override the default implementation from linux/nospec.h. */ #define array_index_mask_nospec array_index_mask_nospec +/* Prevent speculative execution past this barrier. */ +#define barrier_nospec() alternative_2("", "mfence", X86_FEATURE_MFENCE_RDTSC, \ + "lfence", X86_FEATURE_LFENCE_RDTSC) + #ifdef CONFIG_X86_PPRO_FENCE #define dma_rmb() rmb() #else diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h index 77d8b28..5a10ac8 100644 --- a/arch/x86/include/asm/msr.h +++ b/arch/x86/include/asm/msr.h @@ -147,8 +147,7 @@ static __always_inline unsigned long long rdtsc_ordered(void) * that some other imaginary CPU is updating continuously with a * time stamp. */ - alternative_2("", "mfence", X86_FEATURE_MFENCE_RDTSC, - "lfence", X86_FEATURE_LFENCE_RDTSC); + barrier_nospec(); return rdtsc(); } -- 2.7.4
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.