x86/bugs: Add force_cpu_bug= cmdline param
Subsystems (2)
PATCH 1/1 x86/bugs: Add force_cpu_bug= cmdline param
Sometimes it can be very useful to run CPU vulnerability mitigations on systems where they aren't known to mitigate any real-world vulnerabilities. This can be handy for mundane reasons like "I wanna debug this on the machine that quickly", but also for research reasons:
while some mitigations are focussed on individual vulns and uarches, others are fairly general, and it's strategically useful to have an idea how they'd perform on systems where we don't currently need them.
As evidence for this being useful, a flag specifically for Retbleed was added in commit 5c9a92dec323 ("x86/bugs: Add retbleed=force").
It's a bit unfortunate that we have to do this by bug instead of by mitigation. However, we don't have clear identifiers for the mitigations that we do, so I don't think it's practical to do better here than "you can pretend you're on a vulnerable CPU - now go and read the docs for the per-vuln cmdline params to figure out how to run the mitigation you want".
Being an early_param() means we get to do this before identify_cpu() and cpu_select_mitigations(). But it's possible there's still other types of bugs that get setup earlier and might miss this override...
I've only tested this by booting a QEMU guest and checking /proc/cpuinfo.
--- Documentation/admin-guide/kernel-parameters.txt | 6 ++++ arch/x86/kernel/cpu/common.c | 40 +++++++++++++++++++++++++ 2 files changed, 46 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +6 -0
@@ -1559,6 +1559,12 @@ floppy= [HW] See Documentation/admin-guide/blockdev/floppy.rst. + force_cpu_bug= [X86,EARLY] + Force the kernel to assume the CPU is affected by the + given bug, regardless of its built-in information about + individual models. Comma-separated list of the names of + vulnerabilities that would appear in /proc/cpuinfo. + forcepae [X86-32] Forcefully enable Physical Address Extension (PAE). Many Pentium M systems disable PAE but may have a
arch/x86/kernel/cpu/common.c +40 -0
@@ -1318,6 +1318,10 @@ static bool __init vulnerable_to_rfds(u64 x86_arch_cap_msr)return cpu_matches (cpu_vuln_blacklist,RFDS ); } +/* +* This sets up what we _really_ think the CPU has. The user might override this +* later via force_cpu_bug. +*/ static void __init cpu_set_bug_bits (struct cpuinfo_x86 *c) {u64 x86_arch_cap_msr =x86_read_arch_cap_msr ();
@@ -1462,6 +1466,42 @@ static void __init cpu_set_bug_bits(struct cpuinfo_x86 *c)setup_force_cpu_bug (X86_BUG_L1TF ); } +static int __init force_cpu_bug_parse_cmdline (char *str) +{ +if (!str) +return -EINVAL ; + +while (str) { +char *next =strchr (str,',' ); +int i; + +if (next) { + *next =0 ; + next++; + } + +/* +* Linear search because there aren't many bugs (well, at least +* not for the definition of "many" that is relevant here...). +* +* Some configs have no gaps so we could stop at the first NULL, +* but it isn't worth the ifdeffery. +*/ +for (i =0 ; i <ARRAY_SIZE (x86_bug_flags); i++) { +if (x86_bug_flags[i] && !strcmp (str, x86_bug_flags[i])) { +setup_force_cpu_bug (X86_BUG (i)); + goto found; + } + } +pr_err ("Ignoring unknown force_cpu_bug= option (%s)." , str); +found: + str = next; + } + +return 0 ; +} +early_param ("force_cpu_bug" , force_cpu_bug_parse_cmdline); +/* * The NOPL instruction is supposed to exist on all CPUs of family >= 6; * unfortunately, that's not true in practice because of early VIA
---
base-commit: adc218676eef25575469234709c2d87185ca223a
change-id: 20241119-force-cpu-bug-94a08ab0239f
Best regards,
Signature · 1 line
Brendan Jackman <[email protected]>
Hi all, any thoughts on this?
Borislav Petkov
maintainerQuoted 5 lines · Brendan Jackman
Sometimes it can be very useful to run CPU vulnerability mitigations on systems where they aren't known to mitigate any real-world vulnerabilities. This can be handy for mundane reasons like "I wanna debug this on the machine that quickly", but also for research reasons:
while some mitigations are focussed on individual vulns and uarches,
Unknown word [focussed] in commit message.
Suggestions: ['focused', 'focuses', 'cussed', 'fussed', 'foxed', "focus's", 'flossed', 'coursed', 'focus', 'fused', 'cursed', 'fessed', 'refocused', "ficus's"]
Spellchecker pls.
Quoted 2 lines
others are fairly general, and it's strategically useful to have an idea how they'd perform on systems where we don't currently need them.
Please use passive voice in your commit message: no "we" or "I", etc, and describe your changes in imperative mood.
Also, pls read section "2) Describe your changes" in Documentation/process/submitting-patches.rst for more details.
Also, see section "Changelog" inDocumentation/process/maintainer-tip.rst
Bottom line is: personal pronouns are ambiguous in text, especially with so many parties/companies/etc developing the kernel so let's avoid them please.
Also check your comments in the code pls.
Quoted 10 lines
As evidence for this being useful, a flag specifically for Retbleed was added in commit
5c9a92dec323("x86/bugs: Add retbleed=force").It's a bit unfortunate that we have to do this by bug instead of by mitigation. However, we don't have clear identifiers for the mitigations that we do, so I don't think it's practical to do better here than "you can pretend you're on a vulnerable CPU - now go and read the docs for the per-vuln cmdline params to figure out how to run the mitigation you want".
Quoted 5 lines
Being an
early_param()means we get to do this beforeidentify_cpu()andcpu_select_mitigations(). But it's possible there's still other types of bugs that get setup earlier and might miss this override...I've only tested this by booting a QEMU guest and checking
/proc/cpuinfo.
Right, I don't mind this - question is, how do we make it such that people do not use it in production and then come complaining to us why their CPU is affected.
Yeah, sure, they better know what they're doing but I've seen pretty evil perversions so far and us giving them enough rope just to shoot themselves is fine.
What I don't think is fine is for *us* to shoot ourselves in the foot by giving the users such a thing.
Btw, there's a clearcpuid= cmdline option which has the same potential and that thing taints the kernel. Yours should probably do the same.
And it probably should be called "setcpuid=" as a counterpart to what we have now...
Dunno, this is just my 2¢ opinion, don't have a clear idea yet what we wanna do here...
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 22 lines · Borislav Petkov
Quoted 5 lines · Brendan Jackman
Sometimes it can be very useful to run CPU vulnerability mitigations on systems where they aren't known to mitigate any real-world vulnerabilities. This can be handy for mundane reasons like "I wanna debug this on the machine that quickly", but also for research reasons:
while some mitigations are focussed on individual vulns and uarches,Unknown word [focussed] in commit message.
Suggestions: ['focused', 'focuses', 'cussed', 'fussed', 'foxed', "focus's", 'flossed', 'coursed', 'focus', 'fused', 'cursed', 'fessed', 'refocused', "ficus's"]Spellchecker pls.
Quoted 2 lines
others are fairly general, and it's strategically useful to have an idea how they'd perform on systems where we don't currently need them.
Please use passive voice in your commit message: no "we" or "I", etc, and describe your changes in imperative mood.
Also, pls read section "2) Describe your changes" in
Documentation/process/submitting-patches.rstfor more details.
Quoted 8 lines
Also, see section "Changelog" in
Documentation/process/maintainer-tip.rstBottom line is: personal pronouns are ambiguous in text, especially with so many parties/companies/etc developing the kernel so let's avoid them please.
Also check your comments in the code pls.
Ack.
Quoted 24 lines
Quoted 10 lines
As evidence for this being useful, a flag specifically for Retbleed was added in commit
5c9a92dec323("x86/bugs: Add retbleed=force").It's a bit unfortunate that we have to do this by bug instead of by mitigation. However, we don't have clear identifiers for the mitigations that we do, so I don't think it's practical to do better here than "you can pretend you're on a vulnerable CPU - now go and read the docs for the per-vuln cmdline params to figure out how to run the mitigation you want".
Quoted 5 lines
Being an
early_param()means we get to do this beforeidentify_cpu()andcpu_select_mitigations(). But it's possible there's still other types of bugs that get setup earlier and might miss this override...I've only tested this by booting a QEMU guest and checking
/proc/cpuinfo.Right, I don't mind this - question is, how do we make it such that people do not use it in production and then come complaining to us why their CPU is affected.
Yeah, sure, they better know what they're doing but I've seen pretty evil perversions so far and us giving them enough rope just to shoot themselves is fine.
Quoted 5 lines
What I don't think is fine is for *us* to shoot ourselves in the foot by giving the users such a thing.
Btw, there's a clearcpuid= cmdline option which has the same potential and that thing taints the kernel. Yours should probably do the same.
OK yeah, tainting definitely makes sense, I think that goes quite a long way to avoid bogus bug reports? I will also update the docs to sound scarier.
Quoted 2 lines
And it probably should be called "setcpuid=" as a counterpart to what we have now...
So do you think we should allow setting arbitrary cpu features? That seems like a much bigger footgun. But then again, the difference between "big footgun" and "very big footgun" is not that important, either way it needs to be clear to users that this is a scary red button.
Borislav Petkov
maintainerQuoted 2 lines · Brendan Jackman
OK yeah, tainting definitely makes sense, I think that goes quite a long way to avoid bogus bug reports?
It was my feeble attempt back then to leave enough breadcrumbs so that when I see a bug report, I can say: "well, then don't do that then" and mark it as invalid. :)
Quoted 1 line
I will also update the docs to sound scarier.
Right.
Quoted 5 lines
So do you think we should allow setting arbitrary cpu features? That seems like a much bigger footgun. But then again, the difference between "big footgun" and "very big footgun" is not that important, either way it needs to be clear to users that this is a scary red button.
Yeah, with your patch we're half-way there. Might as well do the whole thing but again, this is only my opinion. Probably should hear what others have to say first...
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 11 lines · Borislav Petkov
Quoted 2 lines · Brendan Jackman
OK yeah, tainting definitely makes sense, I think that goes quite a long way to avoid bogus bug reports?
It was my feeble attempt back then to leave enough breadcrumbs so that when I see a bug report, I can say: "well, then don't do that then" and mark it as invalid. :)
Quoted 1 line
I will also update the docs to sound scarier.
Right.
Perhaps issue a pr_warn() for every bit set? People tend to not like WARN/ERR in their production logs much :-)
Quoted 9 lines
Quoted 5 lines
So do you think we should allow setting arbitrary cpu features? That seems like a much bigger footgun. But then again, the difference between "big footgun" and "very big footgun" is not that important, either way it needs to be clear to users that this is a scary red button.
Yeah, with your patch we're half-way there. Might as well do the whole thing but again, this is only my opinion. Probably should hear what others have to say first...
Given I'm the one that did the retbleed=force thing (and other force options), I'm in favour.