mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tim Chen <tim.c.chen@linux.intel.com>
To: Jiri Kosina <jikos@kernel.org>, Thomas Gleixner <tglx@linutronix.de>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Tom Lendacky <thomas.lendacky@amd.com>,
	Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	Andrea Arcangeli <aarcange@redhat.com>,
	David Woodhouse <dwmw@amazon.co.uk>,
	Andi Kleen <ak@linux.intel.com>,
	Dave Hansen <dave.hansen@intel.com>,
	Casey Schaufler <casey.schaufler@intel.com>,
	Asit Mallick <asit.k.mallick@intel.com>,
	Arjan van de Ven <arjan@linux.intel.com>,
	Jon Masters <jcm@redhat.com>, Waiman Long <longman9394@gmail.com>,
	Greg KH <gregkh@linuxfoundation.org>,
	Dave Stewart <david.c.stewart@intel.com>,
	linux-kernel@vger.kernel.org, x86@kernel.org,
	stable@vger.kernel.org, Jiri Kosina <jkosina@suse.cz>,
	Tim Chen <tim.c.chen@linux.intel.com>
Subject: [Patch v7 14/18] x86/speculation: Add 'seccomp' Spectre v2 app to app protection mode
Date: Tue, 20 Nov 2018 16:08:53 -0800	[thread overview]
Message-ID: <fc2524a59454509f505e120b0b63d60efcadfc98.1542758656.git.tim.c.chen@linux.intel.com> (raw)
In-Reply-To: <cover.1542758656.git.tim.c.chen@linux.intel.com>
In-Reply-To: <cover.1542758656.git.tim.c.chen@linux.intel.com>

From: Jiri Kosina <jikos@kernel.org>

From: Jiri Kosina <jkosina@suse.cz>

If 'prctl' mode of app2app protection from spectre_v2 is selected on
kernel command-line, we are currently applying STIBP protection to
tasks that restrict their indirect branch speculation via

	prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_INDIR_BRANCH, PR_SPEC_ENABLE, 0, 0);

Let's extend this to cover also SECCOMP tasks (analogically to how we
apply SSBD protection).

According to software guidance:

"Setting ... STIBP ... on a logical processor prevents the predicted
targets of indirect branches on any logical processor of that core
from being controlled by software that executes (or executed
previously) on another logical processor of the same core."

https://software.intel.com/security-software-guidance/insights/deep-dive-single-thread-indirect-branch-predictors

Hence setting STIBP on a sandboxed task will prevent the task
from attacking other sibling threads or getting attacked.

Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Tim Chen <tim.c.chen@linux.intel.com>
---
 Documentation/admin-guide/kernel-parameters.txt |  7 ++++++-
 arch/x86/include/asm/nospec-branch.h            |  1 +
 arch/x86/kernel/cpu/bugs.c                      | 21 +++++++++++++++++++--
 3 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index d2255f7..89b193c 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -4227,12 +4227,17 @@
 				  and STIBP mitigations against Spectre V2 attacks.
 				  If the CPU is not vulnerable, "off" is selected.
 				  If the CPU is vulnerable, the default mitigation
-				  is "prctl".
+				  is architecture and Kconfig dependent. See below.
 			prctl   - Enable mitigations per thread by restricting
 				  indirect branch speculation via prctl.
 				  Mitigation for a thread is not enabled by default to
 				  avoid mitigation overhead. The state of
 				  of the control is inherited on fork.
+			seccomp - Same as "prctl" above, but all seccomp threads
+				  will disable SSB unless they explicitly opt out.
+
+			Default mitigations:
+			If CONFIG_SECCOMP=y "seccomp", otherwise "prctl"
 
 			Not specifying this option is equivalent to
 			spectre_v2_app2app=auto.
diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h
index 69d2657..077ec54 100644
--- a/arch/x86/include/asm/nospec-branch.h
+++ b/arch/x86/include/asm/nospec-branch.h
@@ -231,6 +231,7 @@ enum spectre_v2_app2app_mitigation {
 	SPECTRE_V2_APP2APP_NONE,
 	SPECTRE_V2_APP2APP_STRICT,
 	SPECTRE_V2_APP2APP_PRCTL,
+	SPECTRE_V2_APP2APP_SECCOMP,
 };
 
 /* The Speculative Store Bypass disable variants */
diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index 44f7127..f349b3f 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -138,6 +138,7 @@ enum spectre_v2_app2app_mitigation_cmd {
 	SPECTRE_V2_APP2APP_CMD_FORCE,
 	SPECTRE_V2_APP2APP_CMD_AUTO,
 	SPECTRE_V2_APP2APP_CMD_PRCTL,
+	SPECTRE_V2_APP2APP_CMD_SECCOMP,
 };
 
 static const char *spectre_v2_strings[] = {
@@ -153,6 +154,7 @@ static const char *spectre_v2_app2app_strings[] = {
 	[SPECTRE_V2_APP2APP_NONE]    = "App-App Vulnerable",
 	[SPECTRE_V2_APP2APP_STRICT]  = "App-App Mitigation: Full app to app attack protection",
 	[SPECTRE_V2_APP2APP_PRCTL]   = "App-App Mitigation: Protect branch speculation restricted tasks",
+	[SPECTRE_V2_APP2APP_SECCOMP] = "App-App Mitigation: Protect branch speculation restricted and seccomp tasks",
 };
 
 /* Lightweight mitigation: mitigate only tasks with TIF_SPEC_INDIR_BRANCH */
@@ -573,10 +575,17 @@ static void __init spectre_v2_select_mitigation(void)
 		break;
 
 	case SPECTRE_V2_APP2APP_CMD_PRCTL:
-	case SPECTRE_V2_APP2APP_CMD_AUTO:
 		app2app_mode = SPECTRE_V2_APP2APP_PRCTL;
 		break;
 
+	case SPECTRE_V2_APP2APP_CMD_AUTO:
+	case SPECTRE_V2_APP2APP_CMD_SECCOMP:
+		if (IS_ENABLED(CONFIG_SECCOMP))
+			app2app_mode = SPECTRE_V2_APP2APP_SECCOMP;
+		else
+			app2app_mode = SPECTRE_V2_APP2APP_PRCTL;
+		break;
+
 	case SPECTRE_V2_APP2APP_CMD_FORCE:
 		app2app_mode = SPECTRE_V2_APP2APP_STRICT;
 		break;
@@ -595,7 +604,8 @@ static void __init spectre_v2_select_mitigation(void)
 set_app2app_mode:
 	spectre_v2_app2app_enabled = app2app_mode;
 	pr_info("%s\n", spectre_v2_app2app_strings[app2app_mode]);
-	if (app2app_mode == SPECTRE_V2_APP2APP_PRCTL)
+	if (app2app_mode == SPECTRE_V2_APP2APP_PRCTL ||
+	    app2app_mode == SPECTRE_V2_APP2APP_SECCOMP)
 		static_branch_enable(&spectre_v2_app_lite);
 
 	/* Enable STIBP if appropriate */
@@ -849,6 +859,8 @@ void arch_seccomp_spec_mitigate(struct task_struct *task)
 {
 	if (ssb_mode == SPEC_STORE_BYPASS_SECCOMP)
 		ssb_prctl_set(task, PR_SPEC_FORCE_DISABLE);
+	if (spectre_v2_app2app_enabled == SPECTRE_V2_APP2APP_SECCOMP)
+		set_task_restrict_indir_branch(task, true);
 }
 #endif
 
@@ -879,6 +891,7 @@ static int indir_branch_prctl_get(struct task_struct *task)
 	switch (spectre_v2_app2app_enabled) {
 	case SPECTRE_V2_APP2APP_NONE:
 		return PR_SPEC_ENABLE;
+	case SPECTRE_V2_APP2APP_SECCOMP:
 	case SPECTRE_V2_APP2APP_PRCTL:
 		if (task_spec_indir_branch_force_disable(task))
 			return PR_SPEC_PRCTL | PR_SPEC_FORCE_DISABLE;
@@ -1075,6 +1088,8 @@ static char *stibp_state(void)
 		return "";
 	else if (spectre_v2_app2app_enabled == SPECTRE_V2_APP2APP_PRCTL)
 		return ", STIBP-prctl";
+	else if (spectre_v2_app2app_enabled == SPECTRE_V2_APP2APP_SECCOMP)
+		return ", STIBP-seccomp";
 	else
 		return ", STIBP-all";
 }
@@ -1085,6 +1100,8 @@ static char *ibpb_state(void)
 		return "";
 	else if (spectre_v2_app2app_enabled == SPECTRE_V2_APP2APP_PRCTL)
 		return ", IBPB-prctl";
+	else if (spectre_v2_app2app_enabled == SPECTRE_V2_APP2APP_SECCOMP)
+		return ", IBPB-seccomp";
 	else
 		return ", IBPB-all";
 }
-- 
2.9.4


  parent reply	other threads:[~2018-11-21  0:42 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-21  0:08 [Patch v7 00/18] Provide task property based options to enable Spectre v2 userspace-userspace protection Tim Chen
2018-11-21  0:08 ` [Patch v7 01/18] x86/speculation: Clean up spectre_v2_parse_cmdline() Tim Chen
2018-11-21  0:08 ` [Patch v7 02/18] x86/speculation: Remove unnecessary ret variable in cpu_show_common() Tim Chen
2018-11-21  0:08 ` [Patch v7 03/18] x86/speculation: Reorganize cpu_show_common() Tim Chen
2018-11-21  0:08 ` [Patch v7 04/18] x86/speculation: Add X86_FEATURE_USE_IBRS_ENHANCED Tim Chen
2018-11-21  0:08 ` [Patch v7 05/18] x86/speculation: Disable STIBP when enhanced IBRS is in use Tim Chen
2018-11-21  0:08 ` [Patch v7 06/18] x86/speculation: Rename SSBD update functions Tim Chen
2018-11-21  0:08 ` [Patch v7 07/18] x86/speculation: Reorganize speculation control MSRs update Tim Chen
2018-11-21  0:08 ` [Patch v7 08/18] smt: Create cpu_smt_enabled static key for SMT specific code Tim Chen
2018-11-21  0:08 ` [Patch v7 09/18] x86/smt: Convert cpu_smt_control check to cpu_smt_enabled static key Tim Chen
2018-11-21 13:38   ` Thomas Gleixner
2018-11-21  0:08 ` [Patch v7 10/18] x86/speculation: Turn on or off STIBP according to a task's TIF_STIBP Tim Chen
2018-11-21 13:33   ` Thomas Gleixner
2018-11-21  0:08 ` [Patch v7 11/18] x86/speculation: Add Spectre v2 app to app protection modes Tim Chen
2018-11-21  0:08 ` [Patch v7 12/18] x86/speculation: Create PRCTL interface to restrict indirect branch speculation Tim Chen
2018-11-21  0:08 ` [Patch v7 13/18] x86/speculation: Enable IBPB for tasks with TIF_SPEC_BRANCH_SPECULATION Tim Chen
2018-11-21  0:08 ` Tim Chen [this message]
2018-11-21 13:52   ` [Patch v7 14/18] x86/speculation: Add 'seccomp' Spectre v2 app to app protection mode Thomas Gleixner
2018-11-21 18:16     ` Tim Chen
2018-11-21 22:29   ` Tim Chen
2018-11-21 22:39     ` Thomas Gleixner
2018-11-21  0:08 ` [Patch v7 15/18] security: Update speculation restriction of a process when modifying its dumpability Tim Chen
2018-11-21  0:08 ` [Patch v7 16/18] x86/speculation: Use STIBP to restrict speculation on non-dumpable task Tim Chen
2018-11-21  0:08 ` [Patch v7 17/18] sched/smt: Make sched_smt_present track topology Tim Chen
2018-11-21  0:08 ` [Patch v7 18/18] x86/smt: Allow disabling of SMT when last SMT is offlined Tim Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fc2524a59454509f505e120b0b63d60efcadfc98.1542758656.git.tim.c.chen@linux.intel.com \
    --to=tim.c.chen@linux.intel.com \
    --cc=aarcange@redhat.com \
    --cc=ak@linux.intel.com \
    --cc=arjan@linux.intel.com \
    --cc=asit.k.mallick@intel.com \
    --cc=casey.schaufler@intel.com \
    --cc=dave.hansen@intel.com \
    --cc=david.c.stewart@intel.com \
    --cc=dwmw@amazon.co.uk \
    --cc=gregkh@linuxfoundation.org \
    --cc=jcm@redhat.com \
    --cc=jikos@kernel.org \
    --cc=jkosina@suse.cz \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman9394@gmail.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=thomas.lendacky@amd.com \
    --cc=torvalds@linux-foundation.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®