Skip to content

Commit ce0abef

Browse files
sean-jcbp3tk0v
authored andcommitted
cpu: Ignore "mitigations" kernel parameter if CPU_MITIGATIONS=n
Explicitly disallow enabling mitigations at runtime for kernels that were built with CONFIG_CPU_MITIGATIONS=n, as some architectures may omit code entirely if mitigations are disabled at compile time. E.g. on x86, a large pile of Kconfigs are buried behind CPU_MITIGATIONS, and trying to provide sane behavior for retroactively enabling mitigations is extremely difficult, bordering on impossible. E.g. page table isolation and call depth tracking require build-time support, BHI mitigations will still be off without additional kernel parameters, etc. [ bp: Touchups. ] Signed-off-by: Sean Christopherson <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Acked-by: Borislav Petkov (AMD) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent fe42754 commit ce0abef

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3423,6 +3423,9 @@
34233423
arch-independent options, each of which is an
34243424
aggregation of existing arch-specific options.
34253425

3426+
Note, "mitigations" is supported if and only if the
3427+
kernel was built with CPU_MITIGATIONS=y.
3428+
34263429
off
34273430
Disable all optional CPU mitigations. This
34283431
improves system performance, but it may also

arch/x86/Kconfig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,9 +2495,13 @@ menuconfig CPU_MITIGATIONS
24952495
help
24962496
Say Y here to enable options which enable mitigations for hardware
24972497
vulnerabilities (usually related to speculative execution).
2498+
Mitigations can be disabled or restricted to SMT systems at runtime
2499+
via the "mitigations" kernel parameter.
24982500

2499-
If you say N, all mitigations will be disabled. You really
2500-
should know what you are doing to say so.
2501+
If you say N, all mitigations will be disabled. This CANNOT be
2502+
overridden at runtime.
2503+
2504+
Say 'Y', unless you really know what you are doing.
25012505

25022506
if CPU_MITIGATIONS
25032507

include/linux/cpu.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,18 @@ void cpuhp_report_idle_dead(void);
221221
static inline void cpuhp_report_idle_dead(void) { }
222222
#endif /* #ifdef CONFIG_HOTPLUG_CPU */
223223

224+
#ifdef CONFIG_CPU_MITIGATIONS
224225
extern bool cpu_mitigations_off(void);
225226
extern bool cpu_mitigations_auto_nosmt(void);
227+
#else
228+
static inline bool cpu_mitigations_off(void)
229+
{
230+
return true;
231+
}
232+
static inline bool cpu_mitigations_auto_nosmt(void)
233+
{
234+
return false;
235+
}
236+
#endif
226237

227238
#endif /* _LINUX_CPU_H_ */

kernel/cpu.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3196,6 +3196,7 @@ void __init boot_cpu_hotplug_init(void)
31963196
this_cpu_write(cpuhp_state.target, CPUHP_ONLINE);
31973197
}
31983198

3199+
#ifdef CONFIG_CPU_MITIGATIONS
31993200
/*
32003201
* These are used for a global "mitigations=" cmdline option for toggling
32013202
* optional CPU mitigations.
@@ -3206,9 +3207,7 @@ enum cpu_mitigations {
32063207
CPU_MITIGATIONS_AUTO_NOSMT,
32073208
};
32083209

3209-
static enum cpu_mitigations cpu_mitigations __ro_after_init =
3210-
IS_ENABLED(CONFIG_CPU_MITIGATIONS) ? CPU_MITIGATIONS_AUTO :
3211-
CPU_MITIGATIONS_OFF;
3210+
static enum cpu_mitigations cpu_mitigations __ro_after_init = CPU_MITIGATIONS_AUTO;
32123211

32133212
static int __init mitigations_parse_cmdline(char *arg)
32143213
{
@@ -3224,7 +3223,6 @@ static int __init mitigations_parse_cmdline(char *arg)
32243223

32253224
return 0;
32263225
}
3227-
early_param("mitigations", mitigations_parse_cmdline);
32283226

32293227
/* mitigations=off */
32303228
bool cpu_mitigations_off(void)
@@ -3239,3 +3237,11 @@ bool cpu_mitigations_auto_nosmt(void)
32393237
return cpu_mitigations == CPU_MITIGATIONS_AUTO_NOSMT;
32403238
}
32413239
EXPORT_SYMBOL_GPL(cpu_mitigations_auto_nosmt);
3240+
#else
3241+
static int __init mitigations_parse_cmdline(char *arg)
3242+
{
3243+
pr_crit("Kernel compiled without mitigations, ignoring 'mitigations'; system may still be vulnerable\n");
3244+
return 0;
3245+
}
3246+
#endif
3247+
early_param("mitigations", mitigations_parse_cmdline);

0 commit comments

Comments
 (0)