x86/bugs: Make spectre user default depend on MITIGATION_SPECTRE_V2
authorBreno Leitao <leitao@debian.org>
Thu, 31 Oct 2024 11:06:17 +0000 (04:06 -0700)
committerIngo Molnar <mingo@kernel.org>
Mon, 3 Mar 2025 11:48:41 +0000 (12:48 +0100)
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
Documentation/admin-guide/kernel-parameters.txt
arch/x86/kernel/cpu/bugs.c

index fb8752b42ec8582b8750d7e014c4d76166fa2fc1..274b71a6fcf9bc9e594b80cffff2a878e2e9cf5c 100644 (file)
 
                        Selecting 'on' will also enable the mitigation
                        against user space to user space task attacks.
+                       Selecting specific mitigation does not force enable
+                       user mitigations.
 
                        Selecting 'off' will disable both the kernel and
                        the user space protections.
index 346bebff3f6cb8a88afc856fa95cd46e205a1684..4386aa6c69e12c9a8d66758e9f7cfff816ccbbe3 100644 (file)
@@ -1308,9 +1308,13 @@ static __ro_after_init enum spectre_v2_mitigation_cmd spectre_v2_cmd;
 static enum spectre_v2_user_cmd __init
 spectre_v2_parse_user_cmdline(void)
 {
+       enum spectre_v2_user_cmd mode;
        char arg[20];
        int ret, i;
 
+       mode = IS_ENABLED(CONFIG_MITIGATION_SPECTRE_V2) ?
+               SPECTRE_V2_USER_CMD_AUTO : SPECTRE_V2_USER_CMD_NONE;
+
        switch (spectre_v2_cmd) {
        case SPECTRE_V2_CMD_NONE:
                return SPECTRE_V2_USER_CMD_NONE;
@@ -1323,7 +1327,7 @@ spectre_v2_parse_user_cmdline(void)
        ret = cmdline_find_option(boot_command_line, "spectre_v2_user",
                                  arg, sizeof(arg));
        if (ret < 0)
-               return SPECTRE_V2_USER_CMD_AUTO;
+               return mode;
 
        for (i = 0; i < ARRAY_SIZE(v2_user_options); i++) {
                if (match_option(arg, ret, v2_user_options[i].option)) {
@@ -1333,8 +1337,8 @@ spectre_v2_parse_user_cmdline(void)
                }
        }
 
-       pr_err("Unknown user space protection option (%s). Switching to AUTO select\n", arg);
-       return SPECTRE_V2_USER_CMD_AUTO;
+       pr_err("Unknown user space protection option (%s). Switching to default\n", arg);
+       return mode;
 }
 
 static inline bool spectre_v2_in_ibrs_mode(enum spectre_v2_mitigation mode)