x86/cpufeatures: Make X86_FEATURE_SHSTK clearcpuid-able
Subsystems (2)
PATCH v3 1/1 x86/cpufeatures: Make X86_FEATURE_SHSTK clearcpuid-able
Allow X86_FEATURE_SHST to be disabled through the kernel commandline via 'clearcpuid=shstk' as 'nousershstk' would still enable CR4.CET even if no CET features are in use.
This, in combination with disabling IBT as well, e.g. via 'clearcpuid=shstk,ibt' allows to fully disable CR4.CET enabling on capable hardware, which in turn allows debugging CET-related issues during early boot.
---
v3:
- switch to clearcpuid-based approach
v2: https://lore.kernel.org/lkml/[email protected]/
arch/x86/include/asm/cpufeatures.h | 2 +- tools/arch/x86/include/asm/cpufeatures.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/cpufeatures.h +1 -1
@@ -393,7 +393,7 @@#define X86_FEATURE_OSPKE (16*32+ 4)/* "ospke" OS Protection Keys Enable */ #define X86_FEATURE_WAITPKG (16*32+ 5)/* "waitpkg" UMONITOR/UMWAIT/TPAUSE Instructions */ #define X86_FEATURE_AVX512_VBMI2 (16*32+ 6)/* "avx512_vbmi2" Additional AVX512 Vector Bit Manipulation Instructions */ -#define X86_FEATURE_SHSTK (16*32+ 7)/* Shadow stack */ +#define X86_FEATURE_SHSTK (16*32+ 7)/* "shstk" CET Shadow Stack */ #define X86_FEATURE_GFNI (16*32+ 8)/* "gfni" Galois Field New Instructions */ #define X86_FEATURE_VAES (16*32+ 9)/* "vaes" Vector AES */ #define X86_FEATURE_VPCLMULQDQ (16*32+10)/* "vpclmulqdq" Carry-Less Multiplication Double Quadword */
tools/arch/x86/include/asm/cpufeatures.h +1 -1
@@ -393,7 +393,7 @@#define X86_FEATURE_OSPKE (16*32+ 4)/* "ospke" OS Protection Keys Enable */ #define X86_FEATURE_WAITPKG (16*32+ 5)/* "waitpkg" UMONITOR/UMWAIT/TPAUSE Instructions */ #define X86_FEATURE_AVX512_VBMI2 (16*32+ 6)/* "avx512_vbmi2" Additional AVX512 Vector Bit Manipulation Instructions */ -#define X86_FEATURE_SHSTK (16*32+ 7)/* Shadow stack */ +#define X86_FEATURE_SHSTK (16*32+ 7)/* "shstk" CET Shadow Stack */ #define X86_FEATURE_GFNI (16*32+ 8)/* "gfni" Galois Field New Instructions */ #define X86_FEATURE_VAES (16*32+ 9)/* "vaes" Vector AES */ #define X86_FEATURE_VPCLMULQDQ (16*32+10)/* "vpclmulqdq" Carry-Less Multiplication Double Quadword */
Signature · 1 line
2.47.3
Borislav Petkov
maintainerQuoted 3 lines · Mathias Krause
Allow
X86_FEATURE_SHSTto be disabled through the kernel commandline via 'clearcpuid=shstk' as 'nousershstk' would still enable CR4.CET even if no CET features are in use.
clearcpuid= taints the kernel because that cmdline option is not supposed to be used except for debugging crap... and alas people are still using it. No wonder... :-\
Anyway, "nousershstk" should disable the CR4 bit too.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 8 lines · Borislav Petkov
Quoted 3 lines · Mathias Krause
Allow
X86_FEATURE_SHSTto be disabled through the kernel commandline via 'clearcpuid=shstk' as 'nousershstk' would still enable CR4.CET even if no CET features are in use.clearcpuid= taints the kernel because that cmdline option is not supposed to be used except for debugging crap... and alas people are still using it. No wonder... :-\
Do we want a non-taint version of this capability? That was Mathias' original approach, but his use was just debugging. So hence, this.
Also, have you ever thought about keeping a list of approved clearcpuid values that are supported for normal runtime. People could use it to turn off features without picking up a taint? Like maybe people want to turn off something for performance reasons or something. Then we can have one interface for it all, instead of various nousershstk-like flags. Not sure if it's a good.
Quoted 2 lines
Anyway, "nousershstk" should disable the CR4 bit too.
Mathias, I can send a patch for this if you want to be done with this.
Borislav Petkov
maintainerQuoted 2 lines · Rick P
Do we want a non-taint version of this capability? That was Mathias' original approach, but his use was just debugging. So hence, this.
No, we don't:
Also note that user programs calling CPUID directly or using the feature without checking anything will still see it. This just prevents it from being used by the kernel or shown in /proc/cpuinfo. Also note the kernel might malfunction if you disable some critical bits.
Do you want to debug issues because someone decided to shoot our representation of a CPUID flag and something is not being detected because of this and you're scratching your head why TF it happens?
Quoted 5 lines
Also, have you ever thought about keeping a list of approved clearcpuid values that are supported for normal runtime. People could use it to turn off features without picking up a taint? Like maybe people want to turn off something for performance reasons or something. Then we can have one interface for it all, instead of various nousershstk-like flags. Not sure if it's a good.
No, we have "no..." cmdline arguments for things where disabling the feature makes sense. And we support those.
The other "no..." switches we add usually as part of a chicken bit when adding a new feature. Subsequently, we delete them after it turns out the implementation is fine and there's no need for any chicken bit anymore.
If "nousershstk" has a good use case like being able to disable CET issues, then by all means, that justifies supporting it fully.
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteBorislav Petkov
maintainerI would even want to do that.
Just so that people don't get silly ideas...
Documentation/admin-guide/kernel-parameters.txt +0 -18
@@ -789,24 +789,6 @@ Kernel parameters cio_ignore= [S390] See Documentation/arch/s390/common_io.rst for details. - clearcpuid=X[,X...] [X86] - Disable CPUID feature X for the kernel. See - arch/x86/include/asm/cpufeatures.h for the valid bit - numbers X. Note the Linux-specific bits are not necessarily - stable over kernel options, but the vendor-specific - ones should be. - X can also be a string as appearing in the flags: line - in /proc/cpuinfo which does not have the above - instability issue. However, not all features have names - in /proc/cpuinfo. - Note that using this option will taint your kernel. - Also note that user programs calling CPUID directly - or using the feature without checking anything - will still see it. This just prevents it from - being used by the kernel or shown in /proc/cpuinfo. - Also note the kernel might malfunction if you disable - some critical bits. - clk_ignore_unused [CLK] Prevents the clock framework from automatically gating
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 13 lines · Borislav Petkov
Quoted 2 lines · Rick P
Do we want a non-taint version of this capability? That was Mathias' original approach, but his use was just debugging. So hence, this.
No, we don't:
Also note that user programs calling CPUID directly or using the feature without checking anything will still see it. This just prevents it from being used by the kernel or shown in
/proc/cpuinfo. Also note the kernel might malfunction if you disable some critical bits.
Quoted 3 lines
Do you want to debug issues because someone decided to shoot our representation of a CPUID flag and something is not being detected because of this and you're scratching your head why TF it happens?
I didn't mean to support disabling them all. I meant have a thing with the same format as clearcpuid, but only works for features we want to support. So maybe like disable=usershstk. And then have just less code to have to cover all the nofoo cases. It would only support limited bits that were intentionally added.
This is not a well thought out idea though.
Quoted 7 lines
Quoted 6 lines
Also, have you ever thought about keeping a list of approved clearcpuid values that are supported for normal runtime. People could use it to turn off features without picking up a taint? Like maybe people want to turn off something for performance reasons or something. Then we can have one interface for it all, instead of various nousershstk-like flags. Not sure if it's a good.
Quoted 6 lines
No, we have "no..." cmdline arguments for things where disabling the feature makes sense. And we support those.
The other "no..." switches we add usually as part of a chicken bit when adding a new feature. Subsequently, we delete them after it turns out the implementation is fine and there's no need for any chicken bit anymore.
Oh, I didn't realize they were intended to be short term things.
Quoted 3 lines
If "nousershstk" has a good use case like being able to disable CET issues, then by all means, that justifies supporting it fully.
Fair enough, thanks for the consideration.
Borislav Petkov
maintainerQuoted 6 lines · Rick P
I didn't mean to support disabling them all. I meant have a thing with the same format as clearcpuid, but only works for features we want to support. So maybe like disable=usershstk. And then have just less code to have to cover all the nofoo cases. It would only support limited bits that were intentionally added.
This is not a well thought out idea though.
I can see that...
If you want to disable things, then you need to disable them properly. Like turn off CR4 bits in this case or disable dependent features in other cases. Or whatever else is needed.
Whatever you do, it needs to have a use case and be properly done.
clearcpuid= is simply shooting down X86_FEATURE flags. Not really well thought out but a wholesale quick'n'dirty method of toggling feature bits (yah, there's the setcpuid= counterpart too). And that's why it should not really exist but that ship has sailed...
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 11 lines · Borislav Petkov
If you want to disable things, then you need to disable them properly. Like turn off CR4 bits in this case or disable dependent features in other cases. Or whatever else is needed.
Whatever you do, it needs to have a use case and be properly done.
clearcpuid= is simply shooting down
X86_FEATUREflags. Not really well thought out but a wholesale quick'n'dirty method of toggling feature bits (yah, there's the setcpuid= counterpart too). And that's why it should not really exist but that ship has sailed...
So a "nocet" for that very use case of disabling CR4.CET, which would simply disable X86_FEATURE_IBT and X86_FEATURE_SHSTK?
Thanks,
Mathias
Quoted 3 lines · Rick P
Also, have you ever thought about keeping a list of approved clearcpuid values that are supported for normal runtime. People could use it to turn off features without picking up a taint?
What's wrong with taint?
"I got a bug report from Joe who has a system with feature $FOO and not feature $BAR. I don't have that CPU, so I used clearcpuid=$BAR to help reproduce the bug. Here's the oops I saw..."
We're not going to ignore that bug report. We're going to look at it a bit closer and make sure the taint does appear to be from clearcpuid=$BAR. But the taint is *FINE*.
Quoted 7 lines · Dave Hansen
Quoted 3 lines · Rick P
Also, have you ever thought about keeping a list of approved clearcpuid values that are supported for normal runtime. People could use it to turn off features without picking up a taint?
What's wrong with taint?
Quoted 7 lines
"I got a bug report from Joe who has a system with feature $FOO and not feature $BAR. I don't have that CPU, so I used clearcpuid=$BAR to help reproduce the bug. Here's the oops I saw..."
We're not going to ignore that bug report. We're going to look at it a bit closer and make sure the taint does appear to be from clearcpuid=$BAR. But the taint is *FINE*.
For debugging I don't see a problem with the taint. But I meant instead of nofoo for the cases where there is some other purpose. I just thought the clearcpuid solution was kind of slick compared to nofoo.
Quoted 8 lines · Borislav Petkov
Quoted 3 lines · Mathias Krause
Allow
X86_FEATURE_SHSTto be disabled through the kernel commandline via 'clearcpuid=shstk' as 'nousershstk' would still enable CR4.CET even if no CET features are in use.clearcpuid= taints the kernel because that cmdline option is not supposed to be used except for debugging crap... and alas people are still using it. No wonder... :-\
Funny to see how x86 maintainer options completely disagree on this, see
https://lore.kernel.org/lkml/[email protected]/
Quoted 3 lines
Anyway, "nousershstk" should disable the CR4 bit too.
No, it should not, as that's only for the user portion (X86_FEATURE_USER_SHSTK != X86_FEATURE_SHSTK).
Even though there is (currently) no kernel level shadow stack support, KVM may still want to pass it down to guests for their usage -- even if the host *userland* shouldn't make use of it because of "nousershstk".
Thanks,
Mathias
Quoted 10 lines · Mathias Krause
Quoted 3 lines
Anyway, "nousershstk" should disable the CR4 bit too.
No, it should not, as that's only for the user portion (
X86_FEATURE_USER_SHSTK!=X86_FEATURE_SHSTK).Even though there is (currently) no kernel level shadow stack support, KVM may still want to pass it down to guests for their usage -- even if the host *userland* shouldn't make use of it because of "nousershstk".
Yea, I was thinking on how we would implement this and wondering along these same lines. We would need to set CR4.CET if we have kernel ibt, user shadow stack or KVM configured (and also with HW support).
Borislav Petkov
maintainerQuoted 2 lines · Mathias Krause
Funny to see how x86 maintainer options completely disagree on this, see
https://lore.kernel.org/lkml/[email protected]/
You mean we should have an internal meeting first to agree on maintainer policy so that we can have a common, unified messaging to the rest of the community...?
Or are we allowed to disagree and find the most optimal solution in the process?
Pfff.
Quoted 6 lines
No, it should not, as that's only for the user portion (
X86_FEATURE_USER_SHSTK!=X86_FEATURE_SHSTK).Even though there is (currently) no kernel level shadow stack support, KVM may still want to pass it down to guests for their usage -- even if the host *userland* shouldn't make use of it because of "nousershstk".
So do a global "disable control-flow enforcement" thing which disables all related features, as Rick points out.
That one should dump a warning saying what also it disables and that it should be a debugging option. And I'm thinking it probably should taint the kernel too because we don't want people left'n'right to turn off shadow stacks and then complain...
Btw, this is my own opinion and just a suggestion - not a x86 maintainer stance. I'm throwing this out so that someone else can propose a better one and we arrive at the proper solution eventually. I.e., as we have always done it on the mailing list...
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 7 lines · Borislav Petkov
Quoted 2 lines · Mathias Krause
Funny to see how x86 maintainer options completely disagree on this, see
https://lore.kernel.org/lkml/[email protected]/You mean we should have an internal meeting first to agree on maintainer policy so that we can have a common, unified messaging to the rest of the community...?
?!?
Quoted 3 lines
Or are we allowed to disagree and find the most optimal solution in the process?
Of course you are. However, it would be nice to object in time and not make a contributor implement N iterations, each being different, just because the next maintainer didn't like the previous version. Or, at least, other maintainers chiming in and commenting to the direction change from their proposal. Neither happened here.
I mean, it's a stupid debugging feature, how perfect does it need to be?
Quoted 6 lines
Pfff.
Quoted 3 lines
No, it should not, as that's only for the user portion (
X86_FEATURE_USER_SHSTK!=X86_FEATURE_SHSTK).
Quoted 6 lines
Quoted 3 lines
Even though there is (currently) no kernel level shadow stack support, KVM may still want to pass it down to guests for their usage -- even if the host *userland* shouldn't make use of it because of "nousershstk".
So do a global "disable control-flow enforcement" thing which disables all related features, as Rick points out.
Sorry, I can't figure which suggestion of Rick you are referring to but maybe you're mixing it up with that?:
https://lore.kernel.org/lkml/[email protected]/
Quoted 5 lines
That one should dump a warning saying what also it disables and that it should be a debugging option. And I'm thinking it probably should taint the kernel too because we don't want people left'n'right to turn off shadow stacks and then complain...
This is getting ridiculous. It's a debug feature by nature and it feels like clearcpuid=shstk would almost perfectly match above requirements.
Quoted 6 lines
Btw, this is my own opinion and just a suggestion - not a x86 maintainer stance. I'm throwing this out so that someone else can propose a better one and we arrive at the proper solution eventually. I.e., as we have always done it on the mailing list...
Yeah, I'm out. We just handle this downstream.
Thanks,
Mathias
Quoted 9 lines · Mathias Krause
Allow
X86_FEATURE_SHSTto be disabled through the kernel commandline via 'clearcpuid=shstk' as 'nousershstk' would still enable CR4.CET even if no CET features are in use.This, in combination with disabling IBT as well, e.g. via 'clearcpuid=shstk,ibt' allows to fully disable CR4.CET enabling on capable hardware, which in turn allows debugging CET-related issues during early boot.
Quoted 7 lines
Signed-off-by Mathias Krause <[email protected]>---
v3:
- switch to clearcpuid-based approach
v2: https://lore.kernel.org/lkml/[email protected]/arch/x86/include/asm/cpufeatures.h | 2 +-
To the general approach:
arch/x86/include/asm/cpufeatures.h line 396
Quoted 13 lines
tools/arch/x86/include/asm/cpufeatures.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)arch/x86/include/asm/cpufeatures.h +1
-1@@ -393,7 +393,7 @@#define X86_FEATURE_OSPKE (16*32+ 4)/* "ospke" OS Protection Keys Enable */ #define X86_FEATURE_WAITPKG (16*32+ 5)/* "waitpkg" UMONITOR/UMWAIT/TPAUSE Instructions */ #define X86_FEATURE_AVX512_VBMI2 (16*32+ 6)/* "avx512_vbmi2" Additional AVX512 Vector Bit Manipulation Instructions */ -#define X86_FEATURE_SHSTK (16*32+ 7)/* Shadow stack */ +#define X86_FEATURE_SHSTK (16*32+ 7)/* "shstk" CET Shadow Stack */
I hate to generate another version but adding CET here is an unnecessary change. IBT doesn't match then.
Quoted 16 lines
arch/x86/include/asm/cpufeatures.h +0
-0#define X86_FEATURE_GFNI (16*32+ 8)/* "gfni" Galois Field New Instructions */ #define X86_FEATURE_VAES (16*32+ 9)/* "vaes" Vector AES */ #define X86_FEATURE_VPCLMULQDQ (16*32+10)/* "vpclmulqdq" Carry-Less Multiplication Double Quadword */ tools/arch/x86/include/asm/cpufeatures.h +1
-1@@ -393,7 +393,7 @@#define X86_FEATURE_OSPKE (16*32+ 4)/* "ospke" OS Protection Keys Enable */ #define X86_FEATURE_WAITPKG (16*32+ 5)/* "waitpkg" UMONITOR/UMWAIT/TPAUSE Instructions */ #define X86_FEATURE_AVX512_VBMI2 (16*32+ 6)/* "avx512_vbmi2" Additional AVX512 Vector Bit Manipulation Instructions */ -#define X86_FEATURE_SHSTK (16*32+ 7)/* Shadow stack */ +#define X86_FEATURE_SHSTK (16*32+ 7)/* "shstk" CET Shadow Stack */ #define X86_FEATURE_GFNI (16*32+ 8)/* "gfni" Galois Field New Instructions */ #define X86_FEATURE_VAES (16*32+ 9)/* "vaes" Vector AES */ #define X86_FEATURE_VPCLMULQDQ (16*32+10)/* "vpclmulqdq" Carry-Less Multiplication Double Quadword */