cpu/bugs: Disable CPU mitigations at compilation time
Subsystems (2)
PATCH 1/1 cpu/bugs: Disable CPU mitigations at compilation time
Right now it is not possible to disable CPU vulnerabilities mitigations at build time. Mitigation needs to be disabled passing kernel parameters, such as 'mitigations=off'.
Create a new config option (CONFIG_CPU_MITIGATIONS_DEFAULT_OFF) that sets the global variable cpu_mitigations to OFF, instead of AUTO. This allows the creation of kernel binaries that boots with the CPU mitigations turned off by default, and does not require dealing kernel parameters.
--- kernel/cpu.c | 7 +++++-- security/Kconfig | 11 +++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-)
kernel/cpu.c +5 -2
@@ -2727,8 +2727,11 @@ enum cpu_mitigations { CPU_MITIGATIONS_AUTO_NOSMT, }; -static enum cpu_mitigations cpu_mitigations__ro_after_init = -CPU_MITIGATIONS_AUTO ; +#ifdef CONFIG_CPU_MITIGATIONS_DEFAULT_OFF +static enum cpu_mitigations cpu_mitigations__ro_after_init =CPU_MITIGATIONS_OFF ; +#else +static enum cpu_mitigations cpu_mitigations__ro_after_init =CPU_MITIGATIONS_AUTO ; +#endif static int __init mitigations_parse_cmdline (char *arg) {
security/Kconfig +11 -0
@@ -258,6 +258,17 @@ config LSM If unsure, leave this as the default. +config CPU_MITIGATIONS_DEFAULT_OFF + bool "Disable mitigations for CPU vulnerabilities by default" + default n + help + This option disables mitigations for CPU vulnerabilities by default. + Disabling CPU mitigations improves system performance, + but it may also expose users to several CPU vulnerabilities. + This option has the same effect of passing `mitigations=off` kernel + parameter. The CPU mitigations could be enabled back using the + 'mitigations' parameter. + source "security/Kconfig.hardening" endmenu
Signature · 1 line
2.30.2
Quoted 9 lines · Breno Leitao
Right now it is not possible to disable CPU vulnerabilities mitigations at build time. Mitigation needs to be disabled passing kernel parameters, such as 'mitigations=off'.
Create a new config option (
CONFIG_CPU_MITIGATIONS_DEFAULT_OFF) that sets the global variablecpu_mitigationsto OFF, instead of AUTO. This allows the creation of kernel binaries that boots with the CPU mitigations turned off by default, and does not require dealing kernel parameters.
What's the real-life use case for this?
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteFrom: Borislav Petkov
Quoted 7 lines
Sent: 09 June 2023 18:34
Quoted 4 lines · Breno Leitao
Right now it is not possible to disable CPU vulnerabilities mitigations at build time. Mitigation needs to be disabled passing kernel parameters, such as 'mitigations=off'.
Quoted 7 lines
Quoted 5 lines
Create a new config option (
CONFIG_CPU_MITIGATIONS_DEFAULT_OFF) that sets the global variablecpu_mitigationsto OFF, instead of AUTO. This allows the creation of kernel binaries that boots with the CPU mitigations turned off by default, and does not require dealing kernel parameters.What's the real-life use case for this?
I can definitely justify compiling them all out. For instance embedded systems with limited userspace and (pretty much) everything running as root.
Compiling them out gives better code than patching them out during boot.
I've stopped updating an LTS kernel because I really don't want/need any of the mitigations - especially the ones associated with 'ret' instructions.
They are far more pervasive than the ones for indirect jumps.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Quoted 3 lines · David Laight
I can definitely justify compiling them all out. For instance embedded systems with limited userspace and (pretty much) everything running as root.
Nothing's stopping you from adding "mitigations=off" to your grub config.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteFrom: Borislav Petkov
Quoted 9 lines
Sent: 12 June 2023 12:52
Quoted 3 lines · David Laight
I can definitely justify compiling them all out. For instance embedded systems with limited userspace and (pretty much) everything running as root.
Nothing's stopping you from adding "mitigations=off" to your grub config.
I do (and I compile without page table separation), but some of the run-time patched versions are not as 'good' as compiling the code out.
It might just be some nops, but maybe it is worse. This can be particularly true for new mitigations.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Quoted 4 lines · David Laight
I do (and I compile without page table separation), but some of the run-time patched versions are not as 'good' as compiling the code out.
It might just be some nops, but maybe it is worse.
"might", schmight, ... other statements without proof...
If you want me to take you seriously, explain in detail the problem. Otherwise, I can keep on ignoring you.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 9 lines · Breno Leitao
Right now it is not possible to disable CPU vulnerabilities mitigations at build time. Mitigation needs to be disabled passing kernel parameters, such as 'mitigations=off'.
Create a new config option (
CONFIG_CPU_MITIGATIONS_DEFAULT_OFF) that sets the global variablecpu_mitigationsto OFF, instead of AUTO. This allows the creation of kernel binaries that boots with the CPU mitigations turned off by default, and does not require dealing kernel parameters.
Why? What's the justification
Just because we do not have not enough kernel config items yet, does not count.
Thanks,
tglx
Quoted 5 lines · Thomas Gleixner
Quoted 4 lines · Breno Leitao
Right now it is not possible to disable CPU vulnerabilities mitigations at build time. Mitigation needs to be disabled passing kernel parameters, such as 'mitigations=off'.
Quoted 7 lines
Quoted 5 lines
Create a new config option (
CONFIG_CPU_MITIGATIONS_DEFAULT_OFF) that sets the global variablecpu_mitigationsto OFF, instead of AUTO. This allows the creation of kernel binaries that boots with the CPU mitigations turned off by default, and does not require dealing kernel parameters.Why? What's the justification
There are two major justification from my point of view:
1) We keep consistency with other CONFIG options. Linux already has a CONFIG option to enable/disable mitigations for speculations (CONFIG_SPECULATION_MITIGATIONS), so, this will be a similar one.
2) There are companies that have different kernel flavours (different CONFIG options basically), for different type of workloads, and a machine can change their kernel flavors a few times a day. I.e, for a specifically workload, boots in flavor X since it works the best. Mitigation enabled/disabled is key to some of these flavors.
I would like to see a flavor as self-contained in a binary that I can mix and match. Right not they are not, since for some kernel flavours, you need to add kernel command lines (mitigations=off), which requires some hard logic, mainly when you are dealing with kexec and grub.
Quoted 3 lines · Breno Leitao
1) We keep consistency with other CONFIG options. Linux already has a CONFIG option to enable/disable mitigations for speculations (
CONFIG_SPECULATION_MITIGATIONS), so, this will be a similar one.
So you can get what you want by disabling all those options there, right?
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 7 lines · Borislav Petkov
Quoted 3 lines · Breno Leitao
1) We keep consistency with other CONFIG options. Linux already has a CONFIG option to enable/disable mitigations for speculations (
CONFIG_SPECULATION_MITIGATIONS), so, this will be a similar one.So you can get what you want by disabling all those options there, right?
This patch proposes creating CONFIG_CPU_MITIGATIONS_DEFAULT_OFF that will turn all the mitigations off in a binary, which is the same as passing mitigations=off in the command line when the kernel boots.
Setting CONFIG_SPECULATION_MITIGATIONS=n does *not* disable all the mitigations, as, there are some mitigations that are *not* disabled when you pass CONFIG_SPECULATION_MITIGATIONS=n. As an example (from my memory - need to double check in 6.4), MDS and TAA mitigations are not disabled when CONFIG_SPECULATION_MITIGATIONS=n. MDS and TAA mitigations are disabled when mitigations=off parameter is passed, tho.
Quoted 2 lines · Breno Leitao
MDS and TAA mitigations are disabled when
mitigations=offparameter is passed, tho.
So add them to that menu.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 5 lines · Borislav Petkov
Quoted 2 lines · Breno Leitao
MDS and TAA mitigations are disabled when
mitigations=offparameter is passed, tho.So add them to that menu.
Sorry, to waht menu specifically?
Quoted 1 line · Breno Leitao
Sorry, to waht menu specifically?
CONFIG_SPECULATION_MITIGATIONS
It even has the proper text in there, warning people.
menuconfig SPECULATION_MITIGATIONS
bool "Mitigations for speculative execution vulnerabilities" default y
help
Say Y here to enable options which enable mitigations for speculative execution hardware vulnerabilities.
If you say N, all mitigations will be disabled. You really should know what you are doing to say so.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 5 lines · Borislav Petkov
Quoted 1 line · Breno Leitao
Sorry, to waht menu specifically?
CONFIG_SPECULATION_MITIGATIONS
Quoted 8 lines
It even has the proper text in there, warning people.
menuconfig
SPECULATION_MITIGATIONS
bool "Mitigations for speculative execution vulnerabilities" default y
help
Say Y here to enable options which enable mitigations for speculative execution hardware vulnerabilities.
I am not sure if these bugs (MDS, TAA) are speculations related. Pawan could help us here.
Quoted 2 lines · Breno Leitao
I am not sure if these bugs (MDS, TAA) are speculations related. Pawan could help us here.
"Microarchitectural Data Sampling is a hardware vulnerability which allows unprivileged speculative access..."
"TAA is a hardware vulnerability that allows unprivileged speculative access to data which is available in various CPU..."
That's all in the tree.
Your grep no workie?
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 9 lines · Borislav Petkov
Quoted 2 lines · Breno Leitao
I am not sure if these bugs (MDS, TAA) are speculations related. Pawan could help us here.
"Microarchitectural Data Sampling is a hardware vulnerability which allows unprivileged speculative access..."
"TAA is a hardware vulnerability that allows unprivileged speculative access to data which is available in various CPU..."
Is it OK if I send a patch that would disable these mitigations ifCONFIG_SPECULATION_MITIGATIONS is set to "no"?
Thank you!
Quoted 2 lines · Breno Leitao
Is it OK if I send a patch that would disable these mitigations if
CONFIG_SPECULATION_MITIGATIONSis set to "no"?
Isn't this the direction we're going to?
So yes, I was suggesting exactly that - add those mitigations to that submenu so that they can be controlled with config options too, like the others.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 15 lines · Breno Leitao
Quoted 5 lines · Borislav Petkov
Quoted 1 line · Breno Leitao
Sorry, to waht menu specifically?
CONFIG_SPECULATION_MITIGATIONSQuoted 8 lines
It even has the proper text in there, warning people.
menuconfig
SPECULATION_MITIGATIONS
bool "Mitigations for speculative execution vulnerabilities" default y
help
Say Y here to enable options which enable mitigations for speculative execution hardware vulnerabilities.
Quoted 2 lines
I am not sure if these bugs (MDS, TAA) are speculations related. Pawan could help us here.
https://www.kernel.org/doc/html/latest/admin-guide/hw-vuln/index.html
might answer your question.
Quoted 14 lines · Borislav Petkov
Quoted 1 line · Breno Leitao
Sorry, to waht menu specifically?
CONFIG_SPECULATION_MITIGATIONSIt even has the proper text in there, warning people.
menuconfig
SPECULATION_MITIGATIONS
bool "Mitigations for speculative execution vulnerabilities" default y
help
Say Y here to enable options which enable mitigations for speculative execution hardware vulnerabilities.
Quoted 2 lines
If you say N, all mitigations will be disabled. You really should know what you are doing to say so.
I would say: doing to say No.
Was there a typo there?
thanks.
Signature · 1 line
~Randy
Quoted 6 lines · Randy Dunlap
Quoted 2 lines
If you say N, all mitigations will be disabled. You really should know what you are doing to say so.
I would say: doing to say No.
Was there a typo there?
I don't think so - it reads right to me this way too. Yours would simply make it more explicit but the "so" is the "N" at the beginning of the sentence:
"You really should know what you're doing to say so, i.e., the N".
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette