Received: by 10.223.185.116 with SMTP id b49csp1119321wrg; Fri, 23 Feb 2018 12:15:35 -0800 (PST) X-Google-Smtp-Source: AH8x226ikQjriGMMxAo5eCBG7mOAdrzY+epBPYq/FSIceBZ8rXLBg0Yxkr2/UreVJ0369N1mG9l9 X-Received: by 10.101.102.2 with SMTP id w2mr2330490pgv.326.1519416935032; Fri, 23 Feb 2018 12:15:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519416934; cv=none; d=google.com; s=arc-20160816; b=0oHLf3Ck9J9Pv/eb5XaOot9CRuYyJNKbg+gJlG3E2s2yivm5evYYygB94FM8LQkNYm ZOrq0399kEktlMbmrR8pipO/bqqflR0DEHjRVu3T1T8qna1Dsb0RNwn1Oi7oanNoZJS4 WC4/g4oK1ngLA7yav6nt1g3tTcZiCltjEFD8AS1RgNlWn2bCVXrqK/Jb/l58rJjcrcMw n3UN2aAN7IWEcZ0JbE9AunzjR6IXAEPuHa66N6bQBEpOn15dQqz25VozGUnFYbFAMsK7 MLoi76rADu5kxR9DpTg/Y+iDLG44JEeOVR4TziFNVbyP++/99/SrqTAg6I3F3DNZXldy kUcw== 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=Ecao++3B3zNc3TYjnVVXUqOu6JsvnRkcAtF1QrG/D9g=; b=PYhA3J+s2u2W7A0NY/UPveyv1iW/++nN9wkWeJrpgtB9APkFGOiNJQd/3q0wMD2Q0M C30nD9uNhYMmJE1LzN/2+CeEQMNIcKdixriExDm8dABP1qkn3vjqiQW0irovjrco4OjS AyUDB2vx9LQ5tneOEjCdBuJgDPJjp0R0i5ultCxOkcez2KCqIv/FqKDDkcr5/tdsJy7l 0J2Df8CjTujDsws53KKiSnx0t5E5zRwK0puHCk/fLJN8XttxIKksW/Du9mIHgcJuW8Iw UNNUoIrqnqW+zxgPt1lYDSv6RpSc3o20rMgs8xzzQmTEq37nwxHeruTCw+Ga0I8X11tK Tx2A== 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 c1si1881650pgq.109.2018.02.23.12.15.20; Fri, 23 Feb 2018 12:15:34 -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 S1755202AbeBWUOp (ORCPT + 99 others); Fri, 23 Feb 2018 15:14:45 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:40358 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754256AbeBWSlA (ORCPT ); Fri, 23 Feb 2018 13:41:00 -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 A3C6F1225; Fri, 23 Feb 2018 18:40:59 +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 , Jack Wang Subject: [PATCH 4.4 176/193] x86: Introduce barrier_nospec Date: Fri, 23 Feb 2018 19:26:49 +0100 Message-Id: <20180223170353.649405309@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170325.997716448@linuxfoundation.org> References: <20180223170325.997716448@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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.4-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 [jwang: cherry pick to 4.4] Signed-off-by: Jack Wang 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 @@ -48,6 +48,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 @@ -147,8 +147,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(); }