Skip to content

Commit 24f7fc8

Browse files
konradwilkKAGA-KOKO
authored andcommitted
x86/bugs: Provide boot parameters for the spec_store_bypass_disable mitigation
Contemporary high performance processors use a common industry-wide optimization known as "Speculative Store Bypass" in which loads from addresses to which a recent store has occurred may (speculatively) see an older value. Intel refers to this feature as "Memory Disambiguation" which is part of their "Smart Memory Access" capability. Memory Disambiguation can expose a cache side-channel attack against such speculatively read values. An attacker can create exploit code that allows them to read memory outside of a sandbox environment (for example, malicious JavaScript in a web page), or to perform more complex attacks against code running within the same privilege level, e.g. via the stack. As a first step to mitigate against such attacks, provide two boot command line control knobs: nospec_store_bypass_disable spec_store_bypass_disable=[off,auto,on] By default affected x86 processors will power on with Speculative Store Bypass enabled. Hence the provided kernel parameters are written from the point of view of whether to enable a mitigation or not. The parameters are as follows: - auto - Kernel detects whether your CPU model contains an implementation of Speculative Store Bypass and picks the most appropriate mitigation. - on - disable Speculative Store Bypass - off - enable Speculative Store Bypass [ tglx: Reordered the checks so that the whole evaluation is not done when the CPU does not support RDS ] Signed-off-by: Konrad Rzeszutek Wilk <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Borislav Petkov <[email protected]> Reviewed-by: Ingo Molnar <[email protected]>
1 parent 0cc5fa0 commit 24f7fc8

File tree

4 files changed

+143
-0
lines changed

4 files changed

+143
-0
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2680,6 +2680,9 @@
26802680
allow data leaks with this option, which is equivalent
26812681
to spectre_v2=off.
26822682

2683+
nospec_store_bypass_disable
2684+
[HW] Disable all mitigations for the Speculative Store Bypass vulnerability
2685+
26832686
noxsave [BUGS=X86] Disables x86 extended register state save
26842687
and restore using xsave. The kernel will fallback to
26852688
enabling legacy floating-point and sse state.
@@ -4025,6 +4028,36 @@
40254028
Not specifying this option is equivalent to
40264029
spectre_v2=auto.
40274030

4031+
spec_store_bypass_disable=
4032+
[HW] Control Speculative Store Bypass (SSB) Disable mitigation
4033+
(Speculative Store Bypass vulnerability)
4034+
4035+
Certain CPUs are vulnerable to an exploit against a
4036+
a common industry wide performance optimization known
4037+
as "Speculative Store Bypass" in which recent stores
4038+
to the same memory location may not be observed by
4039+
later loads during speculative execution. The idea
4040+
is that such stores are unlikely and that they can
4041+
be detected prior to instruction retirement at the
4042+
end of a particular speculation execution window.
4043+
4044+
In vulnerable processors, the speculatively forwarded
4045+
store can be used in a cache side channel attack, for
4046+
example to read memory to which the attacker does not
4047+
directly have access (e.g. inside sandboxed code).
4048+
4049+
This parameter controls whether the Speculative Store
4050+
Bypass optimization is used.
4051+
4052+
on - Unconditionally disable Speculative Store Bypass
4053+
off - Unconditionally enable Speculative Store Bypass
4054+
auto - Kernel detects whether the CPU model contains an
4055+
implementation of Speculative Store Bypass and
4056+
picks the most appropriate mitigation
4057+
4058+
Not specifying this option is equivalent to
4059+
spec_store_bypass_disable=auto.
4060+
40284061
spia_io_base= [HW,MTD]
40294062
spia_fio_base=
40304063
spia_pedr=

arch/x86/include/asm/cpufeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@
214214

215215
#define X86_FEATURE_USE_IBPB ( 7*32+21) /* "" Indirect Branch Prediction Barrier enabled */
216216
#define X86_FEATURE_USE_IBRS_FW ( 7*32+22) /* "" Use IBRS during runtime firmware calls */
217+
#define X86_FEATURE_SPEC_STORE_BYPASS_DISABLE ( 7*32+23) /* "" Disable Speculative Store Bypass. */
217218

218219
/* Virtualization flags: Linux defined, word 8 */
219220
#define X86_FEATURE_TPR_SHADOW ( 8*32+ 0) /* Intel TPR Shadow */

arch/x86/include/asm/nospec-branch.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ extern u64 x86_spec_ctrl_get_default(void);
238238
extern void x86_spec_ctrl_set_guest(u64);
239239
extern void x86_spec_ctrl_restore_host(u64);
240240

241+
/* The Speculative Store Bypass disable variants */
242+
enum ssb_mitigation {
243+
SPEC_STORE_BYPASS_NONE,
244+
SPEC_STORE_BYPASS_DISABLE,
245+
};
246+
241247
extern char __indirect_thunk_start[];
242248
extern char __indirect_thunk_end[];
243249

arch/x86/kernel/cpu/bugs.c

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <asm/intel-family.h>
2828

2929
static void __init spectre_v2_select_mitigation(void);
30+
static void __init ssb_select_mitigation(void);
3031

3132
/*
3233
* Our boot-time value of the SPEC_CTRL MSR. We read it once so that any
@@ -53,6 +54,12 @@ void __init check_bugs(void)
5354
/* Select the proper spectre mitigation before patching alternatives */
5455
spectre_v2_select_mitigation();
5556

57+
/*
58+
* Select proper mitigation for any exposure to the Speculative Store
59+
* Bypass vulnerability.
60+
*/
61+
ssb_select_mitigation();
62+
5663
#ifdef CONFIG_X86_32
5764
/*
5865
* Check whether we are able to run this kernel safely on SMP.
@@ -357,6 +364,99 @@ static void __init spectre_v2_select_mitigation(void)
357364
}
358365
}
359366

367+
#undef pr_fmt
368+
#define pr_fmt(fmt) "Speculative Store Bypass: " fmt
369+
370+
static enum ssb_mitigation ssb_mode = SPEC_STORE_BYPASS_NONE;
371+
372+
/* The kernel command line selection */
373+
enum ssb_mitigation_cmd {
374+
SPEC_STORE_BYPASS_CMD_NONE,
375+
SPEC_STORE_BYPASS_CMD_AUTO,
376+
SPEC_STORE_BYPASS_CMD_ON,
377+
};
378+
379+
static const char *ssb_strings[] = {
380+
[SPEC_STORE_BYPASS_NONE] = "Vulnerable",
381+
[SPEC_STORE_BYPASS_DISABLE] = "Mitigation: Speculative Store Bypass disabled"
382+
};
383+
384+
static const struct {
385+
const char *option;
386+
enum ssb_mitigation_cmd cmd;
387+
} ssb_mitigation_options[] = {
388+
{ "auto", SPEC_STORE_BYPASS_CMD_AUTO }, /* Platform decides */
389+
{ "on", SPEC_STORE_BYPASS_CMD_ON }, /* Disable Speculative Store Bypass */
390+
{ "off", SPEC_STORE_BYPASS_CMD_NONE }, /* Don't touch Speculative Store Bypass */
391+
};
392+
393+
static enum ssb_mitigation_cmd __init ssb_parse_cmdline(void)
394+
{
395+
enum ssb_mitigation_cmd cmd = SPEC_STORE_BYPASS_CMD_AUTO;
396+
char arg[20];
397+
int ret, i;
398+
399+
if (cmdline_find_option_bool(boot_command_line, "nospec_store_bypass_disable")) {
400+
return SPEC_STORE_BYPASS_CMD_NONE;
401+
} else {
402+
ret = cmdline_find_option(boot_command_line, "spec_store_bypass_disable",
403+
arg, sizeof(arg));
404+
if (ret < 0)
405+
return SPEC_STORE_BYPASS_CMD_AUTO;
406+
407+
for (i = 0; i < ARRAY_SIZE(ssb_mitigation_options); i++) {
408+
if (!match_option(arg, ret, ssb_mitigation_options[i].option))
409+
continue;
410+
411+
cmd = ssb_mitigation_options[i].cmd;
412+
break;
413+
}
414+
415+
if (i >= ARRAY_SIZE(ssb_mitigation_options)) {
416+
pr_err("unknown option (%s). Switching to AUTO select\n", arg);
417+
return SPEC_STORE_BYPASS_CMD_AUTO;
418+
}
419+
}
420+
421+
return cmd;
422+
}
423+
424+
static enum ssb_mitigation_cmd __init __ssb_select_mitigation(void)
425+
{
426+
enum ssb_mitigation mode = SPEC_STORE_BYPASS_NONE;
427+
enum ssb_mitigation_cmd cmd;
428+
429+
if (!boot_cpu_has(X86_FEATURE_RDS))
430+
return mode;
431+
432+
cmd = ssb_parse_cmdline();
433+
if (!boot_cpu_has_bug(X86_BUG_SPEC_STORE_BYPASS) &&
434+
(cmd == SPEC_STORE_BYPASS_CMD_NONE ||
435+
cmd == SPEC_STORE_BYPASS_CMD_AUTO))
436+
return mode;
437+
438+
switch (cmd) {
439+
case SPEC_STORE_BYPASS_CMD_AUTO:
440+
case SPEC_STORE_BYPASS_CMD_ON:
441+
mode = SPEC_STORE_BYPASS_DISABLE;
442+
break;
443+
case SPEC_STORE_BYPASS_CMD_NONE:
444+
break;
445+
}
446+
447+
if (mode != SPEC_STORE_BYPASS_NONE)
448+
setup_force_cpu_cap(X86_FEATURE_SPEC_STORE_BYPASS_DISABLE);
449+
return mode;
450+
}
451+
452+
static void ssb_select_mitigation()
453+
{
454+
ssb_mode = __ssb_select_mitigation();
455+
456+
if (boot_cpu_has_bug(X86_BUG_SPEC_STORE_BYPASS))
457+
pr_info("%s\n", ssb_strings[ssb_mode]);
458+
}
459+
360460
#undef pr_fmt
361461

362462
#ifdef CONFIG_SYSFS
@@ -383,6 +483,9 @@ ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr,
383483
boot_cpu_has(X86_FEATURE_USE_IBRS_FW) ? ", IBRS_FW" : "",
384484
spectre_v2_module_string());
385485

486+
case X86_BUG_SPEC_STORE_BYPASS:
487+
return sprintf(buf, "%s\n", ssb_strings[ssb_mode]);
488+
386489
default:
387490
break;
388491
}

0 commit comments

Comments
 (0)