Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp29505imm; Fri, 21 Sep 2018 17:25:33 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY99k04lRx8YeLTUH5qYjeGdrp+/Ybd8szIPxnzp0WOaRzFBxbkzRlzDCkLpZPsmws42UUN X-Received: by 2002:a62:9683:: with SMTP id s3-v6mr131631pfk.191.1537575933070; Fri, 21 Sep 2018 17:25:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537575933; cv=none; d=google.com; s=arc-20160816; b=CSmSlFWXFvbHTy2wGfTUMki6QH8G7El3+gJalLIAAjaIwM2HsYUWBnrzPvcZRILOrM kc8IMnaqcICzhBwzAp14vwlTIBxmsPPUFr0L7yP4VEFNRufEX3NAodnXBpmfXAfxq+AN 0F105YhqtCYXkxPSzaicEWH/gsEKoFqT6xp4ZfI2q5QYVy11uYjXnclkYDG4CdTEFavu eEMNaH/e7mnuL2z+qaNaKX5wPMlEv1dA26htd1HakFkWXhFM9nR7VBkowdVOjM3XU+T9 nR94VDBpjPNtMv9BdZLzsprYtAzuqrT0+QXDfhFOf7EKngPPaLxAlC0ByEbUMYIT6T+2 GMPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=0g/4qMEwXXZ7UhU6RNjY0BeZegIuVwnFj2ySJEYHzZU=; b=r6fKpPqEpMP1CQ1Ju95gD4JtDbH7L9u5NcfJ/6pqTZVW6CJnO5cSnOoBYqijzMkbhx p9fKGfb5f46S5oFWVNvfludRod4TG7laHbDBO8tXjgbKPwaOgapNtRE9FmQbl2PqdUpo GVnv2mIhY32AXwgFULvhDzSdPDx2gB7lc8ZZpp1Si4uWAggqe7cYwauF/otdR9eOfQgO ChmEGS3i2WTLPTcoRWdyo50XeoAMweWCS23jbO/HYdKblKaVkSkafBph8TWWTuFRW7Z7 PUEywkcez7fomNnBClahWcSZBg79s/Jd6sEknl9CvF8FRyVIHJhMm9Jz+xFZ9/fSZq2Y y0RQ== 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 z63-v6si28297290pfi.214.2018.09.21.17.25.16; Fri, 21 Sep 2018 17:25:33 -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 S2391810AbeIVGOZ (ORCPT + 99 others); Sat, 22 Sep 2018 02:14:25 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:44221 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391931AbeIVGKr (ORCPT ); Sat, 22 Sep 2018 02:10:47 -0400 Received: from [2a02:8011:400e:2:cbab:f00:c93f:614] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1g3Vdx-0008BO-OF; Sat, 22 Sep 2018 01:19:29 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1g3Vdo-0000tE-Kj; Sat, 22 Sep 2018 01:19:20 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Tim Chen" , "Thomas Gleixner" , "Linus Torvalds" , "David Woodhouse" , "Jiri Kosina" , "Peter Zijlstra" , "Konrad Rzeszutek Wilk" , "Josh Poimboeuf" , "Borislav Petkov" Date: Sat, 22 Sep 2018 01:15:42 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 44/63] x86/speculation: Protect against userspace-userspace spectreRSB In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:cbab:f00:c93f:614 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.58-rc1 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 Link: https://lkml.kernel.org/r/nycvar.YFH.7.76.1807261308190.997@cbobk.fhfr.pm Signed-off-by: Ben Hutchings --- 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 @@ -263,23 +263,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(); @@ -340,22 +323,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_KAISER) && - !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)) {