aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Kosina <jkosina@suse.cz>2018-07-26 07:14:55 -0400
committerThomas Gleixner <tglx@linutronix.de>2018-07-30 18:45:15 -0400
commitfdf82a7856b32d905c39afc85e34364491e46346 (patch)
tree9aaead977f0e8179b929ee98ca2b2914fc119b7d
parentca38dc8f2724d101038b1205122c93a1c7f38f11 (diff)
x86/speculation: Protect against userspace-userspace spectreRSB
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 <jkosina@suse.cz> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Josh Poimboeuf <jpoimboe@redhat.com> Acked-by: Tim Chen <tim.c.chen@linux.intel.com> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Cc: Borislav Petkov <bp@suse.de> Cc: David Woodhouse <dwmw@amazon.co.uk> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/nycvar.YFH.7.76.1807261308190.997@cbobk.fhfr.pm
-rw-r--r--arch/x86/kernel/cpu/bugs.c38
1 files changed, 7 insertions, 31 deletions
diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index 5c0ea39311fe..bc8c43b22460 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -313,23 +313,6 @@ static enum spectre_v2_mitigation_cmd __init spectre_v2_parse_cmdline(void)
313 return cmd; 313 return cmd;
314} 314}
315 315
316/* Check for Skylake-like CPUs (for RSB handling) */
317static bool __init is_skylake_era(void)
318{
319 if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
320 boot_cpu_data.x86 == 6) {
321 switch (boot_cpu_data.x86_model) {
322 case INTEL_FAM6_SKYLAKE_MOBILE:
323 case INTEL_FAM6_SKYLAKE_DESKTOP:
324 case INTEL_FAM6_SKYLAKE_X:
325 case INTEL_FAM6_KABYLAKE_MOBILE:
326 case INTEL_FAM6_KABYLAKE_DESKTOP:
327 return true;
328 }
329 }
330 return false;
331}
332
333static void __init spectre_v2_select_mitigation(void) 316static void __init spectre_v2_select_mitigation(void)
334{ 317{
335 enum spectre_v2_mitigation_cmd cmd = spectre_v2_parse_cmdline(); 318 enum spectre_v2_mitigation_cmd cmd = spectre_v2_parse_cmdline();
@@ -390,22 +373,15 @@ retpoline_auto:
390 pr_info("%s\n", spectre_v2_strings[mode]); 373 pr_info("%s\n", spectre_v2_strings[mode]);
391 374
392 /* 375 /*
393 * If neither SMEP nor PTI are available, there is a risk of 376 * If spectre v2 protection has been enabled, unconditionally fill
394 * hitting userspace addresses in the RSB after a context switch 377 * RSB during a context switch; this protects against two independent
395 * from a shallow call stack to a deeper one. To prevent this fill 378 * issues:
396 * the entire RSB, even when using IBRS.
397 * 379 *
398 * Skylake era CPUs have a separate issue with *underflow* of the 380 * - RSB underflow (and switch to BTB) on Skylake+
399 * RSB, when they will predict 'ret' targets from the generic BTB. 381 * - SpectreRSB variant of spectre v2 on X86_BUG_SPECTRE_V2 CPUs
400 * The proper mitigation for this is IBRS. If IBRS is not supported
401 * or deactivated in favour of retpolines the RSB fill on context
402 * switch is required.
403 */ 382 */
404 if ((!boot_cpu_has(X86_FEATURE_PTI) && 383 setup_force_cpu_cap(X86_FEATURE_RSB_CTXSW);
405 !boot_cpu_has(X86_FEATURE_SMEP)) || is_skylake_era()) { 384 pr_info("Spectre v2 / SpectreRSB mitigation: Filling RSB on context switch\n");
406 setup_force_cpu_cap(X86_FEATURE_RSB_CTXSW);
407 pr_info("Spectre v2 mitigation: Filling RSB on context switch\n");
408 }
409 385
410 /* Initialize Indirect Branch Prediction Barrier if supported */ 386 /* Initialize Indirect Branch Prediction Barrier if supported */
411 if (boot_cpu_has(X86_FEATURE_IBPB)) { 387 if (boot_cpu_has(X86_FEATURE_IBPB)) {