@@ -2525,16 +2525,8 @@ static void update_mds_branch_idle(void)
25252525#undef pr_fmt
25262526#define pr_fmt (fmt ) "Speculative Store Bypass: " fmt
25272527
2528- static enum ssb_mitigation ssb_mode __ro_after_init = SPEC_STORE_BYPASS_NONE ;
2529-
2530- /* The kernel command line selection */
2531- enum ssb_mitigation_cmd {
2532- SPEC_STORE_BYPASS_CMD_NONE ,
2533- SPEC_STORE_BYPASS_CMD_AUTO ,
2534- SPEC_STORE_BYPASS_CMD_ON ,
2535- SPEC_STORE_BYPASS_CMD_PRCTL ,
2536- SPEC_STORE_BYPASS_CMD_SECCOMP ,
2537- };
2528+ static enum ssb_mitigation ssb_mode __ro_after_init =
2529+ IS_ENABLED (CONFIG_MITIGATION_SSB ) ? SPEC_STORE_BYPASS_AUTO : SPEC_STORE_BYPASS_NONE ;
25382530
25392531static const char * const ssb_strings [] = {
25402532 [SPEC_STORE_BYPASS_NONE ] = "Vulnerable" ,
@@ -2543,94 +2535,61 @@ static const char * const ssb_strings[] = {
25432535 [SPEC_STORE_BYPASS_SECCOMP ] = "Mitigation: Speculative Store Bypass disabled via prctl and seccomp" ,
25442536};
25452537
2546- static const struct {
2547- const char * option ;
2548- enum ssb_mitigation_cmd cmd ;
2549- } ssb_mitigation_options [] __initconst = {
2550- { "auto" , SPEC_STORE_BYPASS_CMD_AUTO }, /* Platform decides */
2551- { "on" , SPEC_STORE_BYPASS_CMD_ON }, /* Disable Speculative Store Bypass */
2552- { "off" , SPEC_STORE_BYPASS_CMD_NONE }, /* Don't touch Speculative Store Bypass */
2553- { "prctl" , SPEC_STORE_BYPASS_CMD_PRCTL }, /* Disable Speculative Store Bypass via prctl */
2554- { "seccomp" , SPEC_STORE_BYPASS_CMD_SECCOMP }, /* Disable Speculative Store Bypass via prctl and seccomp */
2555- };
2538+ static bool nossb __ro_after_init ;
25562539
2557- static enum ssb_mitigation_cmd __init ssb_parse_cmdline ( void )
2540+ static int __init nossb_parse_cmdline ( char * str )
25582541{
2559- enum ssb_mitigation_cmd cmd ;
2560- char arg [20 ];
2561- int ret , i ;
2562-
2563- cmd = IS_ENABLED (CONFIG_MITIGATION_SSB ) ?
2564- SPEC_STORE_BYPASS_CMD_AUTO : SPEC_STORE_BYPASS_CMD_NONE ;
2565- if (cmdline_find_option_bool (boot_command_line , "nospec_store_bypass_disable" ) ||
2566- cpu_mitigations_off ()) {
2567- return SPEC_STORE_BYPASS_CMD_NONE ;
2568- } else {
2569- ret = cmdline_find_option (boot_command_line , "spec_store_bypass_disable" ,
2570- arg , sizeof (arg ));
2571- if (ret < 0 )
2572- return cmd ;
2542+ nossb = true;
2543+ ssb_mode = SPEC_STORE_BYPASS_NONE ;
2544+ return 0 ;
2545+ }
2546+ early_param ("nospec_store_bypass_disable" , nossb_parse_cmdline );
25732547
2574- for (i = 0 ; i < ARRAY_SIZE (ssb_mitigation_options ); i ++ ) {
2575- if (!match_option (arg , ret , ssb_mitigation_options [i ].option ))
2576- continue ;
2548+ static int __init ssb_parse_cmdline (char * str )
2549+ {
2550+ if (!str )
2551+ return - EINVAL ;
25772552
2578- cmd = ssb_mitigation_options [i ].cmd ;
2579- break ;
2580- }
2553+ if (nossb )
2554+ return 0 ;
25812555
2582- if (i >= ARRAY_SIZE (ssb_mitigation_options )) {
2583- pr_err ("unknown option (%s). Switching to default mode\n" , arg );
2584- return cmd ;
2585- }
2586- }
2556+ if (!strcmp (str , "auto" ))
2557+ ssb_mode = SPEC_STORE_BYPASS_AUTO ;
2558+ else if (!strcmp (str , "on" ))
2559+ ssb_mode = SPEC_STORE_BYPASS_DISABLE ;
2560+ else if (!strcmp (str , "off" ))
2561+ ssb_mode = SPEC_STORE_BYPASS_NONE ;
2562+ else if (!strcmp (str , "prctl" ))
2563+ ssb_mode = SPEC_STORE_BYPASS_PRCTL ;
2564+ else if (!strcmp (str , "seccomp" ))
2565+ ssb_mode = IS_ENABLED (CONFIG_SECCOMP ) ?
2566+ SPEC_STORE_BYPASS_SECCOMP : SPEC_STORE_BYPASS_PRCTL ;
2567+ else
2568+ pr_err ("Ignoring unknown spec_store_bypass_disable option (%s).\n" ,
2569+ str );
25872570
2588- return cmd ;
2571+ return 0 ;
25892572}
2573+ early_param ("spec_store_bypass_disable" , ssb_parse_cmdline );
25902574
25912575static void __init ssb_select_mitigation (void )
25922576{
2593- enum ssb_mitigation_cmd cmd ;
2594-
2595- if (!boot_cpu_has (X86_FEATURE_SSBD ))
2596- goto out ;
2597-
2598- cmd = ssb_parse_cmdline ();
2599- if (!boot_cpu_has_bug (X86_BUG_SPEC_STORE_BYPASS ) &&
2600- (cmd == SPEC_STORE_BYPASS_CMD_NONE ||
2601- cmd == SPEC_STORE_BYPASS_CMD_AUTO ))
2577+ if (!boot_cpu_has_bug (X86_BUG_SPEC_STORE_BYPASS )) {
2578+ ssb_mode = SPEC_STORE_BYPASS_NONE ;
26022579 return ;
2580+ }
26032581
2604- switch (cmd ) {
2605- case SPEC_STORE_BYPASS_CMD_SECCOMP :
2606- /*
2607- * Choose prctl+seccomp as the default mode if seccomp is
2608- * enabled.
2609- */
2610- if (IS_ENABLED (CONFIG_SECCOMP ))
2611- ssb_mode = SPEC_STORE_BYPASS_SECCOMP ;
2612- else
2613- ssb_mode = SPEC_STORE_BYPASS_PRCTL ;
2614- break ;
2615- case SPEC_STORE_BYPASS_CMD_ON :
2616- ssb_mode = SPEC_STORE_BYPASS_DISABLE ;
2617- break ;
2618- case SPEC_STORE_BYPASS_CMD_AUTO :
2582+ if (ssb_mode == SPEC_STORE_BYPASS_AUTO ) {
26192583 if (should_mitigate_vuln (X86_BUG_SPEC_STORE_BYPASS ))
26202584 ssb_mode = SPEC_STORE_BYPASS_PRCTL ;
26212585 else
26222586 ssb_mode = SPEC_STORE_BYPASS_NONE ;
2623- break ;
2624- case SPEC_STORE_BYPASS_CMD_PRCTL :
2625- ssb_mode = SPEC_STORE_BYPASS_PRCTL ;
2626- break ;
2627- case SPEC_STORE_BYPASS_CMD_NONE :
2628- break ;
26292587 }
26302588
2631- out :
2632- if (boot_cpu_has_bug (X86_BUG_SPEC_STORE_BYPASS ))
2633- pr_info ("%s\n" , ssb_strings [ssb_mode ]);
2589+ if (!boot_cpu_has (X86_FEATURE_SSBD ))
2590+ ssb_mode = SPEC_STORE_BYPASS_NONE ;
2591+
2592+ pr_info ("%s\n" , ssb_strings [ssb_mode ]);
26342593}
26352594
26362595static void __init ssb_apply_mitigation (void )
@@ -2846,6 +2805,7 @@ static int ssb_prctl_get(struct task_struct *task)
28462805 return PR_SPEC_DISABLE ;
28472806 case SPEC_STORE_BYPASS_SECCOMP :
28482807 case SPEC_STORE_BYPASS_PRCTL :
2808+ case SPEC_STORE_BYPASS_AUTO :
28492809 if (task_spec_ssb_force_disable (task ))
28502810 return PR_SPEC_PRCTL | PR_SPEC_FORCE_DISABLE ;
28512811 if (task_spec_ssb_noexec (task ))
0 commit comments