Received: by 10.223.176.5 with SMTP id f5csp715450wra; Fri, 9 Feb 2018 06:08:03 -0800 (PST) X-Google-Smtp-Source: AH8x2247s6R6tQZS9Hz4FNSqisVt1LfNb1lyeSa+cINW7nzpGzZjboYyDMtCqZZCyFzAAEh31h7J X-Received: by 10.99.126.85 with SMTP id o21mr2504204pgn.406.1518185283134; Fri, 09 Feb 2018 06:08:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518185283; cv=none; d=google.com; s=arc-20160816; b=fnjeTB3g7zG3Zcu9TtJtRiLq9Ct6EOscDrlILroSbLgxrhNLNCrLpvYd7m787SFETS qTvrdZM1liYg8ZvY8GDeyvRC+cD2aUeO3vc2TED9bMhPGRh5PRSy27Kr6Z1ONBX1ZqcS LkJ6VBxdQwOR4mAwDPwRYno0MxYVMO0WazQn3WlVZiJGCclG9C+pjJNVEThBL7Y7xncP eMw6ctdduQFDnZjBS8pdt5oa1IoC6z/Ad0e8e/0muYu1Kw9mGsIQuj+BfsP+prSxPWUP UnmvUoIe29J0HlkQBrVYEnm6RI156kBDv5C5hTlmam32DY4zzwTAfvIfmplwgWv0TpfO Q7aA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=kjtrU5i1/ZicKHxq/smXclSBWzkz1a7rI0CXrqf6+0c=; b=e456Rk4CQ3ZF3bleB9I7MqP46NQM+/UCFkUiKNw+MhKz2sVvCLun9NyPGwCsF1vp62 WNu2WD89S5Xo9BcutOEcyZs5Yu5u+NQNyijtlGgsY9dTY5oErbguHGj77Onn3j677Dij yXBzbWHxlsbbTyo11b9PW8QdAwUxcbQT46hhSsVbpIOuF1VIJmNE5UorfnG9gGfS0QMh 8MfvMnN/JU7WhaR4XtheSLbuQZqNScKB1WJic6Amsd4069oLZ5qwj94gm8D2um6xW6jX MkvsIYCsuRagNv8QONwc1rWG7hKijepTD5hhA4cOLgS2YUFQ4WPdfa1Sg5QTsLqKBpvH uc6w== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a9si1408697pgw.132.2018.02.09.06.07.40; Fri, 09 Feb 2018 06:08:03 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753147AbeBINm7 (ORCPT + 99 others); Fri, 9 Feb 2018 08:42:59 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:50086 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753128AbeBINm5 (ORCPT ); Fri, 9 Feb 2018 08:42:57 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 068F7FE5; Fri, 9 Feb 2018 13:42:56 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Linus Torvalds , Andi Kleen , Ingo Molnar , Dan Williams , Thomas Gleixner , linux-arch@vger.kernel.org, Tom Lendacky , Kees Cook , kernel-hardening@lists.openwall.com, Al Viro , alan@linux.intel.com, David Woodhouse Subject: [PATCH 4.9 59/92] x86: Introduce barrier_nospec Date: Fri, 9 Feb 2018 14:39:28 +0100 Message-Id: <20180209133935.497488184@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180209133931.211869118@linuxfoundation.org> References: <20180209133931.211869118@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dan Williams (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 Suggested-by: Andi Kleen Suggested-by: Ingo Molnar Signed-off-by: Dan Williams Signed-off-by: Thomas Gleixner Cc: linux-arch@vger.kernel.org Cc: Tom Lendacky Cc: Kees Cook Cc: kernel-hardening@lists.openwall.com Cc: gregkh@linuxfoundation.org Cc: Al Viro Cc: alan@linux.intel.com Link: https://lkml.kernel.org/r/151727415361.33451.9049453007262764675.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: David Woodhouse Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/barrier.h | 4 ++++ arch/x86/include/asm/msr.h | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) --- a/arch/x86/include/asm/barrier.h +++ b/arch/x86/include/asm/barrier.h @@ -47,6 +47,10 @@ static inline unsigned long array_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 --- a/arch/x86/include/asm/msr.h +++ b/arch/x86/include/asm/msr.h @@ -188,8 +188,7 @@ static __always_inline unsigned long lon * 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(); }