Received: by 2002:a4a:311b:0:0:0:0:0 with SMTP id k27-v6csp4779933ooa; Tue, 14 Aug 2018 10:26:17 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzuLPoCo99o2ep0PceGdgCfX0B9MQi/ii3ldW1KYi2pUDZ5zg4gj3lRWAhOnSE05JaVFIC2 X-Received: by 2002:a17:902:e088:: with SMTP id cb8-v6mr21423239plb.189.1534267577938; Tue, 14 Aug 2018 10:26:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534267577; cv=none; d=google.com; s=arc-20160816; b=z4e4URc/jmARZLlLWussT7AV1Frs2hddcsRrkn5mvh4s8VwxK0wB48lKZM67a+nQPg NmG5PmUZHAw1RKeqyYcPBmgTRFskDLrlh5eqCiKe6/qkb/FxEbebNdVkyH1RhC0VNrZ2 ZiTK7oCCQuSjlO2O9vcb7T9vhCVA/0rbEZ3b9eGbW/LXS9Pce31sLzWlxV5Wah31lN09 qSZh0Wkw6jymGZd4mgQyo4yBJ/83xhAdEWzhpIr2hkASXSCj2Dg8htaZxyEeEmndZ9lt 2sEQKJjUUH+TDNfWtvioPyU8L4NV2cRz/jKmcKdpgooQTiQ1jP2gDJQUKXurRR6bC0Bj X6Sw== 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=zl+nRbEmcDQZQNRi+lgOnDiJJMdvnVu5c11iHU9CDPM=; b=CaBF0IYC9nVUr1JQr0aWmhJ815kl9Dg4mrXCQDgQzS21Q3sUoIBwIQAbta5zFh031C KZ5OS9bMYZ3KH50ElEN2zi5isifk/7giUpqwpdLXb8yDVO0JrmaSuBYaQ95O7a4y0ksn GY2uqz6irJZ2Kh4KLioHmniDoDqjj3H4xY+rYEKI6wJYShDqQzdSLsaBrQgQdO56nxAI RoJn695ryWEeeK65ix64VXZiGS6BNSXzEsJUyxAmlALuxlALhw0tLH/GWhHpwwB4oRpv u3xNnjHjPAaILA5kV8rXiHP/36+84BMA3IXheyF6AMPur9ok66BZnpJEheGTQEYSKyLs 9eHw== 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 194-v6si21124004pgc.116.2018.08.14.10.26.03; Tue, 14 Aug 2018 10:26:17 -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; 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 S2387994AbeHNUMs (ORCPT + 99 others); Tue, 14 Aug 2018 16:12:48 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:51422 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387747AbeHNUMs (ORCPT ); Tue, 14 Aug 2018 16:12:48 -0400 Received: from localhost (unknown [194.244.16.108]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 300ABCBA; Tue, 14 Aug 2018 17:24:41 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiri Kosina , Thomas Gleixner , Josh Poimboeuf , Tim Chen , Konrad Rzeszutek Wilk , Borislav Petkov , David Woodhouse , Peter Zijlstra , Linus Torvalds Subject: [PATCH 4.18 02/79] x86/speculation: Protect against userspace-userspace spectreRSB Date: Tue, 14 Aug 2018 19:16:21 +0200 Message-Id: <20180814171336.888584491@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180814171336.799314117@linuxfoundation.org> References: <20180814171336.799314117@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.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jiri Kosina commit fdf82a7856b32d905c39afc85e34364491e46346 upstream. The article "Spectre Returns! Speculation Attacks using the Return Stack Buffer" [1] describes two new (sub-)variants of spectrev2-like attacks, making use solely of the RSB contents even on CPUs that don't fallback to BTB on RSB underflow (Skylake+). Mitigate userspace-userspace attacks by always unconditionally filling RSB on context switch when the generic spectrev2 mitigation has been enabled. [1] https://arxiv.org/pdf/1807.07940.pdf Signed-off-by: Jiri Kosina Signed-off-by: Thomas Gleixner Reviewed-by: Josh Poimboeuf Acked-by: Tim Chen Cc: Konrad Rzeszutek Wilk Cc: Borislav Petkov Cc: David Woodhouse Cc: Peter Zijlstra Cc: Linus Torvalds Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/nycvar.YFH.7.76.1807261308190.997@cbobk.fhfr.pm Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/cpu/bugs.c | 38 +++++++------------------------------- 1 file changed, 7 insertions(+), 31 deletions(-) --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -313,23 +313,6 @@ static enum spectre_v2_mitigation_cmd __ return cmd; } -/* Check for Skylake-like CPUs (for RSB handling) */ -static bool __init is_skylake_era(void) -{ - if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL && - boot_cpu_data.x86 == 6) { - switch (boot_cpu_data.x86_model) { - case INTEL_FAM6_SKYLAKE_MOBILE: - case INTEL_FAM6_SKYLAKE_DESKTOP: - case INTEL_FAM6_SKYLAKE_X: - case INTEL_FAM6_KABYLAKE_MOBILE: - case INTEL_FAM6_KABYLAKE_DESKTOP: - return true; - } - } - return false; -} - static void __init spectre_v2_select_mitigation(void) { enum spectre_v2_mitigation_cmd cmd = spectre_v2_parse_cmdline(); @@ -390,22 +373,15 @@ retpoline_auto: pr_info("%s\n", spectre_v2_strings[mode]); /* - * If neither SMEP nor PTI are available, there is a risk of - * hitting userspace addresses in the RSB after a context switch - * from a shallow call stack to a deeper one. To prevent this fill - * the entire RSB, even when using IBRS. + * If spectre v2 protection has been enabled, unconditionally fill + * RSB during a context switch; this protects against two independent + * issues: * - * Skylake era CPUs have a separate issue with *underflow* of the - * RSB, when they will predict 'ret' targets from the generic BTB. - * The proper mitigation for this is IBRS. If IBRS is not supported - * or deactivated in favour of retpolines the RSB fill on context - * switch is required. + * - RSB underflow (and switch to BTB) on Skylake+ + * - SpectreRSB variant of spectre v2 on X86_BUG_SPECTRE_V2 CPUs */ - if ((!boot_cpu_has(X86_FEATURE_PTI) && - !boot_cpu_has(X86_FEATURE_SMEP)) || is_skylake_era()) { - setup_force_cpu_cap(X86_FEATURE_RSB_CTXSW); - pr_info("Spectre v2 mitigation: Filling RSB on context switch\n"); - } + setup_force_cpu_cap(X86_FEATURE_RSB_CTXSW); + pr_info("Spectre v2 / SpectreRSB mitigation: Filling RSB on context switch\n"); /* Initialize Indirect Branch Prediction Barrier if supported */ if (boot_cpu_has(X86_FEATURE_IBPB)) {