Skip to content

Commit 3acae02

Browse files
keeskonradwilk
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]> (cherry picked from commit f21b53b) Orabug: 28034177 CVE: CVE-2018-3639 Signed-off-by: Konrad Rzeszutek Wilk <[email protected]> Tested-by: Mihai Carabas <[email protected]> Reviewed-by: Mihai Carabas <[email protected]> Reviewed-by: John Haxby <[email protected]> Conflicts: Documentation/admin-guide/kernel-parameters.txt arch/x86/include/asm/nospec-branch.h arch/x86/kernel/cpu/bugs.c [As we did the IBRS first]
1 parent 2bd3d9c commit 3acae02

File tree

3 files changed

+41
-16
lines changed

3 files changed

+41
-16
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3970,21 +3970,29 @@
39703970
This parameter controls whether the Speculative Store
39713971
Bypass optimization is used.
39723972

3973-
on - Unconditionally disable Speculative Store Bypass
3974-
off - Unconditionally enable Speculative Store Bypass
3975-
auto - Kernel detects whether the CPU model contains an
3976-
implementation of Speculative Store Bypass and
3977-
picks the most appropriate mitigation.
3978-
prctl - Control Speculative Store Bypass per thread
3979-
via prctl. Speculative Store Bypass is enabled
3980-
for a process by default. The state of the control
3981-
is inherited on fork.
3973+
on - Unconditionally disable Speculative Store Bypass
3974+
off - Unconditionally enable Speculative Store Bypass
3975+
auto - Kernel detects whether the CPU model contains an
3976+
implementation of Speculative Store Bypass and
3977+
picks the most appropriate mitigation. If the
3978+
CPU is not vulnerable, "off" is selected. If the
3979+
CPU is vulnerable the default mitigation is
3980+
architecture and Kconfig dependent. See below.
3981+
prctl - Control Speculative Store Bypass per thread
3982+
via prctl. Speculative Store Bypass is enabled
3983+
for a process by default. The state of the control
3984+
is inherited on fork.
3985+
seccomp - Same as "prctl" above, but all seccomp threads
3986+
will disable SSB unless they explicitly opt out.
39823987
userspace - Disable Speculative Store Bypass when entering
39833988
userspace.
39843989

39853990
Not specifying this option is equivalent to
39863991
spec_store_bypass_disable=auto.
39873992

3993+
Default mitigations:
3994+
X86: If CONFIG_SECCOMP=y "seccomp", otherwise "prctl"
3995+
39883996
spectre_v2_heuristics=
39893997
[X86] Control Spectre_v2 variant heuristics.
39903998

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
SPEC_STORE_BYPASS_USERSPACE,
237238
};
238239

arch/x86/kernel/cpu/bugs.c

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -679,24 +679,27 @@ enum ssb_mitigation_cmd {
679679
SPEC_STORE_BYPASS_CMD_AUTO,
680680
SPEC_STORE_BYPASS_CMD_ON,
681681
SPEC_STORE_BYPASS_CMD_PRCTL,
682+
SPEC_STORE_BYPASS_CMD_SECCOMP,
682683
SPEC_STORE_BYPASS_CMD_USERSPACE,
683684
};
684685

685686
static const char *ssb_strings[] = {
686687
[SPEC_STORE_BYPASS_NONE] = "Vulnerable",
687688
[SPEC_STORE_BYPASS_DISABLE] = "Mitigation: Speculative Store Bypass disabled",
688689
[SPEC_STORE_BYPASS_PRCTL] = "Mitigation: Speculative Store Bypass disabled via prctl",
690+
[SPEC_STORE_BYPASS_SECCOMP] = "Mitigation: Speculative Store Bypass disabled via prctl and seccomp",
689691
[SPEC_STORE_BYPASS_USERSPACE] = "Mitigation: Speculative Store Bypass disabled for userspace"
690692
};
691693

692694
static const struct {
693695
const char *option;
694696
enum ssb_mitigation_cmd cmd;
695697
} ssb_mitigation_options[] = {
696-
{ "auto", SPEC_STORE_BYPASS_CMD_AUTO }, /* Platform decides */
697-
{ "on", SPEC_STORE_BYPASS_CMD_ON }, /* Disable Speculative Store Bypass */
698-
{ "off", SPEC_STORE_BYPASS_CMD_NONE }, /* Don't touch Speculative Store Bypass */
699-
{ "prctl", SPEC_STORE_BYPASS_CMD_PRCTL }, /* Disable Speculative Store Bypass via prctl */
698+
{ "auto", SPEC_STORE_BYPASS_CMD_AUTO }, /* Platform decides */
699+
{ "on", SPEC_STORE_BYPASS_CMD_ON }, /* Disable Speculative Store Bypass */
700+
{ "off", SPEC_STORE_BYPASS_CMD_NONE }, /* Don't touch Speculative Store Bypass */
701+
{ "prctl", SPEC_STORE_BYPASS_CMD_PRCTL }, /* Disable Speculative Store Bypass via prctl */
702+
{ "seccomp", SPEC_STORE_BYPASS_CMD_SECCOMP }, /* Disable Speculative Store Bypass via prctl and seccomp */
700703
{ "userspace", SPEC_STORE_BYPASS_CMD_USERSPACE }, /* Disable Speculative Store Bypass for userspace */
701704
};
702705

@@ -748,8 +751,17 @@ static enum ssb_mitigation_cmd __init __ssb_select_mitigation(void)
748751
switch (cmd) {
749752
case SPEC_STORE_BYPASS_CMD_AUTO:
750753
/* Choose prctl as the default mode unless IBRS is enabled. */
751-
if (spectre_v2_enabled == SPECTRE_V2_IBRS)
754+
if (spectre_v2_enabled == SPECTRE_V2_IBRS) {
752755
mode = SPEC_STORE_BYPASS_USERSPACE;
756+
break;
757+
}
758+
case SPEC_STORE_BYPASS_CMD_SECCOMP:
759+
/*
760+
* Choose prctl+seccomp as the default mode if seccomp is
761+
* enabled.
762+
*/
763+
if (IS_ENABLED(CONFIG_SECCOMP))
764+
mode = SPEC_STORE_BYPASS_SECCOMP;
753765
else
754766
mode = SPEC_STORE_BYPASS_PRCTL;
755767
break;
@@ -811,12 +823,14 @@ static void ssb_select_mitigation()
811823
}
812824

813825
#undef pr_fmt
826+
#define pr_fmt(fmt) "Speculation prctl: " fmt
814827

815828
static int ssb_prctl_set(struct task_struct *task, unsigned long ctrl)
816829
{
817830
bool update;
818831

819-
if (ssb_mode != SPEC_STORE_BYPASS_PRCTL)
832+
if (ssb_mode != SPEC_STORE_BYPASS_PRCTL &&
833+
ssb_mode != SPEC_STORE_BYPASS_SECCOMP)
820834
return -ENXIO;
821835

822836
switch (ctrl) {
@@ -864,7 +878,8 @@ int arch_prctl_spec_ctrl_set(struct task_struct *task, unsigned long which,
864878
#ifdef CONFIG_SECCOMP
865879
void arch_seccomp_spec_mitigate(struct task_struct *task)
866880
{
867-
ssb_prctl_set(task, PR_SPEC_FORCE_DISABLE);
881+
if (ssb_mode == SPEC_STORE_BYPASS_SECCOMP)
882+
ssb_prctl_set(task, PR_SPEC_FORCE_DISABLE);
868883
}
869884
#endif
870885

@@ -874,6 +889,7 @@ static int ssb_prctl_get(struct task_struct *task)
874889
case SPEC_STORE_BYPASS_USERSPACE:
875890
case SPEC_STORE_BYPASS_DISABLE:
876891
return PR_SPEC_DISABLE;
892+
case SPEC_STORE_BYPASS_SECCOMP:
877893
case SPEC_STORE_BYPASS_PRCTL:
878894
if (task_spec_ssb_force_disable(task))
879895
return PR_SPEC_PRCTL | PR_SPEC_FORCE_DISABLE;

0 commit comments

Comments
 (0)