Received: by 10.223.176.5 with SMTP id f5csp2855143wra; Mon, 5 Feb 2018 11:01:24 -0800 (PST) X-Google-Smtp-Source: AH8x226in20TexsAzdrD9IQuXcYp9iE2mm4/E0/cj4xDPoL2CSh2wTkZbFrdcClCb+UGqXvn+7ZF X-Received: by 10.98.200.22 with SMTP id z22mr8198992pff.228.1517857284757; Mon, 05 Feb 2018 11:01:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517857284; cv=none; d=google.com; s=arc-20160816; b=gObNlxkQimJYjQ/V04fQFeQHoCHPnkudW7en9Uf4YxA4Lwf8TNUMOnISdJPJXB2O2Q 4NkZFpJ6KP0S0USHD+XTYpIF5GO8bi0VOn/mKcM2uZc4tzqsehjRvYsAnPd1RdlE+PHf j96j0FAnorMb7qram3j0hmOaPpX1DsBmy9qXk5erEM1WxW2Fg1h3B2utM+Bo0dVbU1AN sZNavD3gerQQohtGpW0qax2G37n5+S89OwrkdAHLtzyY5G7hjA5MCHmfPApaSLbpxHGv cb5Xfg5SxuJEtvnnudsPbFXbQWZiQ/AZS4vW0GgiASi4y3JTJqaOfTAlpHXjKVQHGSfX cTFQ== 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=KRP0WrPPQri2MXtKgWyAXxyT1GB5lYXjVJjuWBMQCwU=; b=ZQ4DKrGqYZNoV33StxcQ7hqrnR/rGOuKL1cwt04ajoRwtZJ12jto63Lz4xMaRYjNVk dQG4xwqGZ5Gzvsb47juJodwM9voNXkj9bqADnNGRv0qqgnelK8Zu5IsZ74GMf/oDIB/k pCVXwuAbxm4/aIhwKhIdY9QKvKo+4CEkHQ6SV37fxBOIq5+nA30kP09+I8C+rSd6KNCk UwN7v6VAsD137USYnJ24bJvnxXBKrL1wtl2/hMP5J0JJo4aHYS9YXxkyVXn8gqHQz7NQ N0qsHYwTGQjmohpBYKj2jMXWdwLPryQxkKwuVkdhdqrqdQxJS8j4gF/i0ifvbdLNk5jb Jtlw== 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 o14-v6si5503522pll.386.2018.02.05.11.01.10; Mon, 05 Feb 2018 11:01:24 -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 S1753635AbeBETAt (ORCPT + 99 others); Mon, 5 Feb 2018 14:00:49 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:51692 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753598AbeBESYk (ORCPT ); Mon, 5 Feb 2018 13:24:40 -0500 Received: from localhost (unknown [104.132.1.108]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id E02DB10B4; Mon, 5 Feb 2018 18:24:37 +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 Subject: [PATCH 4.14 39/64] x86: Introduce barrier_nospec Date: Mon, 5 Feb 2018 10:22:58 -0800 Message-Id: <20180205182140.182282620@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180205182138.571333346@linuxfoundation.org> References: <20180205182138.571333346@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.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dan Williams dan.j.williams@intel.com 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: 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 @@ -214,8 +214,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(); }