Skip to content

Commit 98fdaeb

Browse files
leitaoIngo Molnar
authored andcommitted
x86/bugs: Make spectre user default depend on MITIGATION_SPECTRE_V2
Change the default value of spectre v2 in user mode to respect the CONFIG_MITIGATION_SPECTRE_V2 config option. Currently, user mode spectre v2 is set to auto (SPECTRE_V2_USER_CMD_AUTO) by default, even if CONFIG_MITIGATION_SPECTRE_V2 is disabled. Set the spectre_v2 value to auto (SPECTRE_V2_USER_CMD_AUTO) if the Spectre v2 config (CONFIG_MITIGATION_SPECTRE_V2) is enabled, otherwise set the value to none (SPECTRE_V2_USER_CMD_NONE). Important to say the command line argument "spectre_v2_user" overwrites the default value in both cases. When CONFIG_MITIGATION_SPECTRE_V2 is not set, users have the flexibility to opt-in for specific mitigations independently. In this scenario, setting spectre_v2= will not enable spectre_v2_user=, and command line options spectre_v2_user and spectre_v2 are independent when CONFIG_MITIGATION_SPECTRE_V2=n. Signed-off-by: Breno Leitao <leitao@debian.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Reviewed-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com> Acked-by: Josh Poimboeuf <jpoimboe@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: David Kaplan <David.Kaplan@amd.com> Link: https://lore.kernel.org/r/20241031-x86_bugs_last_v2-v2-2-b7ff1dab840e@debian.org
1 parent 2a08b83 commit 98fdaeb

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6582,6 +6582,8 @@
65826582

65836583
Selecting 'on' will also enable the mitigation
65846584
against user space to user space task attacks.
6585+
Selecting specific mitigation does not force enable
6586+
user mitigations.
65856587

65866588
Selecting 'off' will disable both the kernel and
65876589
the user space protections.

arch/x86/kernel/cpu/bugs.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,9 +1308,13 @@ static __ro_after_init enum spectre_v2_mitigation_cmd spectre_v2_cmd;
13081308
static enum spectre_v2_user_cmd __init
13091309
spectre_v2_parse_user_cmdline(void)
13101310
{
1311+
enum spectre_v2_user_cmd mode;
13111312
char arg[20];
13121313
int ret, i;
13131314

1315+
mode = IS_ENABLED(CONFIG_MITIGATION_SPECTRE_V2) ?
1316+
SPECTRE_V2_USER_CMD_AUTO : SPECTRE_V2_USER_CMD_NONE;
1317+
13141318
switch (spectre_v2_cmd) {
13151319
case SPECTRE_V2_CMD_NONE:
13161320
return SPECTRE_V2_USER_CMD_NONE;
@@ -1323,7 +1327,7 @@ spectre_v2_parse_user_cmdline(void)
13231327
ret = cmdline_find_option(boot_command_line, "spectre_v2_user",
13241328
arg, sizeof(arg));
13251329
if (ret < 0)
1326-
return SPECTRE_V2_USER_CMD_AUTO;
1330+
return mode;
13271331

13281332
for (i = 0; i < ARRAY_SIZE(v2_user_options); i++) {
13291333
if (match_option(arg, ret, v2_user_options[i].option)) {
@@ -1333,8 +1337,8 @@ spectre_v2_parse_user_cmdline(void)
13331337
}
13341338
}
13351339

1336-
pr_err("Unknown user space protection option (%s). Switching to AUTO select\n", arg);
1337-
return SPECTRE_V2_USER_CMD_AUTO;
1340+
pr_err("Unknown user space protection option (%s). Switching to default\n", arg);
1341+
return mode;
13381342
}
13391343

13401344
static inline bool spectre_v2_in_ibrs_mode(enum spectre_v2_mitigation mode)

0 commit comments

Comments
 (0)