Skip to content

Commit f21b53b

Browse files
keesKAGA-KOKO
authored andcommitted
x86/speculation: Make "seccomp" the default mode for Speculative Store Bypass
Unless explicitly opted out of, anything running under seccomp will have SSB mitigations enabled. Choosing the "prctl" mode will disable this. [ tglx: Adjusted it to the new arch_seccomp_spec_mitigate() mechanism ] Signed-off-by: Kees Cook <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]>
1 parent 8bf37d8 commit f21b53b

File tree

3 files changed

+41
-18
lines changed

3 files changed

+41
-18
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4049,19 +4049,27 @@
40494049
This parameter controls whether the Speculative Store
40504050
Bypass optimization is used.
40514051

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-
prctl - Control Speculative Store Bypass per thread
4058-
via prctl. Speculative Store Bypass is enabled
4059-
for a process by default. The state of the control
4060-
is inherited on fork.
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. If the
4057+
CPU is not vulnerable, "off" is selected. If the
4058+
CPU is vulnerable the default mitigation is
4059+
architecture and Kconfig dependent. See below.
4060+
prctl - Control Speculative Store Bypass per thread
4061+
via prctl. Speculative Store Bypass is enabled
4062+
for a process by default. The state of the control
4063+
is inherited on fork.
4064+
seccomp - Same as "prctl" above, but all seccomp threads
4065+
will disable SSB unless they explicitly opt out.
40614066

40624067
Not specifying this option is equivalent to
40634068
spec_store_bypass_disable=auto.
40644069

4070+
Default mitigations:
4071+
X86: If CONFIG_SECCOMP=y "seccomp", otherwise "prctl"
4072+
40654073
spia_io_base= [HW,MTD]
40664074
spia_fio_base=
40674075
spia_pedr=

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ enum ssb_mitigation {
233233
SPEC_STORE_BYPASS_NONE,
234234
SPEC_STORE_BYPASS_DISABLE,
235235
SPEC_STORE_BYPASS_PRCTL,
236+
SPEC_STORE_BYPASS_SECCOMP,
236237
};
237238

238239
extern char __indirect_thunk_start[];

arch/x86/kernel/cpu/bugs.c

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -416,22 +416,25 @@ enum ssb_mitigation_cmd {
416416
SPEC_STORE_BYPASS_CMD_AUTO,
417417
SPEC_STORE_BYPASS_CMD_ON,
418418
SPEC_STORE_BYPASS_CMD_PRCTL,
419+
SPEC_STORE_BYPASS_CMD_SECCOMP,
419420
};
420421

421422
static const char *ssb_strings[] = {
422423
[SPEC_STORE_BYPASS_NONE] = "Vulnerable",
423424
[SPEC_STORE_BYPASS_DISABLE] = "Mitigation: Speculative Store Bypass disabled",
424-
[SPEC_STORE_BYPASS_PRCTL] = "Mitigation: Speculative Store Bypass disabled via prctl"
425+
[SPEC_STORE_BYPASS_PRCTL] = "Mitigation: Speculative Store Bypass disabled via prctl",
426+
[SPEC_STORE_BYPASS_SECCOMP] = "Mitigation: Speculative Store Bypass disabled via prctl and seccomp",
425427
};
426428

427429
static const struct {
428430
const char *option;
429431
enum ssb_mitigation_cmd cmd;
430432
} ssb_mitigation_options[] = {
431-
{ "auto", SPEC_STORE_BYPASS_CMD_AUTO }, /* Platform decides */
432-
{ "on", SPEC_STORE_BYPASS_CMD_ON }, /* Disable Speculative Store Bypass */
433-
{ "off", SPEC_STORE_BYPASS_CMD_NONE }, /* Don't touch Speculative Store Bypass */
434-
{ "prctl", SPEC_STORE_BYPASS_CMD_PRCTL }, /* Disable Speculative Store Bypass via prctl */
433+
{ "auto", SPEC_STORE_BYPASS_CMD_AUTO }, /* Platform decides */
434+
{ "on", SPEC_STORE_BYPASS_CMD_ON }, /* Disable Speculative Store Bypass */
435+
{ "off", SPEC_STORE_BYPASS_CMD_NONE }, /* Don't touch Speculative Store Bypass */
436+
{ "prctl", SPEC_STORE_BYPASS_CMD_PRCTL }, /* Disable Speculative Store Bypass via prctl */
437+
{ "seccomp", SPEC_STORE_BYPASS_CMD_SECCOMP }, /* Disable Speculative Store Bypass via prctl and seccomp */
435438
};
436439

437440
static enum ssb_mitigation_cmd __init ssb_parse_cmdline(void)
@@ -481,8 +484,15 @@ static enum ssb_mitigation_cmd __init __ssb_select_mitigation(void)
481484

482485
switch (cmd) {
483486
case SPEC_STORE_BYPASS_CMD_AUTO:
484-
/* Choose prctl as the default mode */
485-
mode = SPEC_STORE_BYPASS_PRCTL;
487+
case SPEC_STORE_BYPASS_CMD_SECCOMP:
488+
/*
489+
* Choose prctl+seccomp as the default mode if seccomp is
490+
* enabled.
491+
*/
492+
if (IS_ENABLED(CONFIG_SECCOMP))
493+
mode = SPEC_STORE_BYPASS_SECCOMP;
494+
else
495+
mode = SPEC_STORE_BYPASS_PRCTL;
486496
break;
487497
case SPEC_STORE_BYPASS_CMD_ON:
488498
mode = SPEC_STORE_BYPASS_DISABLE;
@@ -530,12 +540,14 @@ static void ssb_select_mitigation()
530540
}
531541

532542
#undef pr_fmt
543+
#define pr_fmt(fmt) "Speculation prctl: " fmt
533544

534545
static int ssb_prctl_set(struct task_struct *task, unsigned long ctrl)
535546
{
536547
bool update;
537548

538-
if (ssb_mode != SPEC_STORE_BYPASS_PRCTL)
549+
if (ssb_mode != SPEC_STORE_BYPASS_PRCTL &&
550+
ssb_mode != SPEC_STORE_BYPASS_SECCOMP)
539551
return -ENXIO;
540552

541553
switch (ctrl) {
@@ -583,7 +595,8 @@ int arch_prctl_spec_ctrl_set(struct task_struct *task, unsigned long which,
583595
#ifdef CONFIG_SECCOMP
584596
void arch_seccomp_spec_mitigate(struct task_struct *task)
585597
{
586-
ssb_prctl_set(task, PR_SPEC_FORCE_DISABLE);
598+
if (ssb_mode == SPEC_STORE_BYPASS_SECCOMP)
599+
ssb_prctl_set(task, PR_SPEC_FORCE_DISABLE);
587600
}
588601
#endif
589602

@@ -592,6 +605,7 @@ static int ssb_prctl_get(struct task_struct *task)
592605
switch (ssb_mode) {
593606
case SPEC_STORE_BYPASS_DISABLE:
594607
return PR_SPEC_DISABLE;
608+
case SPEC_STORE_BYPASS_SECCOMP:
595609
case SPEC_STORE_BYPASS_PRCTL:
596610
if (task_spec_ssb_force_disable(task))
597611
return PR_SPEC_PRCTL | PR_SPEC_FORCE_DISABLE;

0 commit comments

Comments
 (0)