x86/shstk: shadow stack enabling write return code change
PATCH v2 1/1 x86/shstk: shadow stack enabling write return code change
The WRSS instruction (the special instruction that writes to shadow stacks) cannot be used in userspace unless IA32_U_CET.SH_STK_EN=1 (user shadow stack is enabled). So the kernel *should* return -EINVAL to userspace if it tries to enable it when shadow stack is disabled. However, currently, it will return -EPERM. But, that error code doesn't fit the condition as the failure is due to an invalid state change request not a permission issue.
Investigating userspace call sites, like glibc and criu (checkpoint code), they do not rely on this specific error message, nor could a userspace effectively utilize this specific return error code to indicate a difference in "I cannot enable write because of invalid permissions" versus "I cannot enable write because the shadow stack is disabled".
--- arch/x86/kernel/shstk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/shstk.c +1 -1
@@ -490,7 +490,7 @@ static int wrss_control(bool enable)* when disabling. */ if (!features_enabled (ARCH_SHSTK_SHSTK )) -return -EPERM ; +return -EINVAL ;/* Already enabled/disabled? */ if (features_enabled (ARCH_SHSTK_WRSS ) == enable)
Signature · 1 line
2.54.0
Quoted 8 lines · Bill Roberts
The WRSS instruction (the special instruction that writes to shadow stacks) cannot be used in userspace unless IA32_U_CET.SH_STK_EN=1 (user shadow stack is enabled). So the kernel *should* return
-EINVALto userspace if it tries to enable it when shadow stack is disabled. However, currently, it will return-EPERM. But, that error code doesn't fit the condition as the failure is due to an invalid state change request not a permission issue.
Quoted 7 lines
Investigating userspace call sites, like glibc and criu (checkpoint code), they do not rely on this specific error message, nor could a userspace effectively utilize this specific return error code to indicate a difference in "I cannot enable write because of invalid permissions" versus "I cannot enable write because the shadow stack is disabled".
Signed-off-by Bill Roberts <[email protected]>
Quoted 17 lines
--- arch/x86/kernel/shstk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kernel/shstk.c +1
-1@@ -490,7 +490,7 @@ static int wrss_control(bool enable)* when disabling. */ if (!features_enabled (ARCH_SHSTK_SHSTK )) -return -EPERM ; +return -EINVAL ;/* Already enabled/disabled? */ if (features_enabled (ARCH_SHSTK_WRSS ) == enable)
Quoted 8 lines · Bill Roberts
The WRSS instruction (the special instruction that writes to shadow stacks) cannot be used in userspace unless IA32_U_CET.SH_STK_EN=1 (user shadow stack is enabled). So the kernel *should* return
-EINVALto userspace if it tries to enable it when shadow stack is disabled. However, currently, it will return-EPERM. But, that error code doesn't fit the condition as the failure is due to an invalid state change request not a permission issue.
Quoted 5 lines
Investigating userspace call sites, like glibc and criu (checkpoint code), they do not rely on this specific error message, nor could a userspace effectively utilize this specific return error code to indicate a difference in "I cannot enable write because of invalid permissions" versus "I cannot enable write because the shadow stack is disabled".
Hi Bill,
Thanks for the patch. One bit of context I'd appreciate: why do you care? Were you just auditing the code and something seemed wrong? Were you doing some ARM code and noticed a mismatch?
What motivated the change?
Quoted 14 lines · Dave Hansen
Quoted 8 lines · Bill Roberts
The WRSS instruction (the special instruction that writes to shadow stacks) cannot be used in userspace unless IA32_U_CET.SH_STK_EN=1 (user shadow stack is enabled). So the kernel *should* return
-EINVALto userspace if it tries to enable it when shadow stack is disabled. However, currently, it will return-EPERM. But, that error code doesn't fit the condition as the failure is due to an invalid state change request not a permission issue.Quoted 5 lines
Investigating userspace call sites, like glibc and criu (checkpoint code), they do not rely on this specific error message, nor could a userspace effectively utilize this specific return error code to indicate a difference in "I cannot enable write because of invalid permissions" versus "I cannot enable write because the shadow stack is disabled".
Quoted 7 lines
Hi Bill,
Thanks for the patch. One bit of context I'd appreciate: why do you care? Were you just auditing the code and something seemed wrong? Were you doing some ARM code and noticed a mismatch?
What motivated the change?
Hi Dave, long time no see. So the motivation for the patches is around adding LSM controls on disabling or making the shadow stack writable.
So, as part of that work, which will be forthcoming very soon, is supporting the prctl interface for x86 shadow stack controls, so that the LSMs are arch agnostic. This also provides a common userspace shadow stack API for all archs currently supporting this feature (x86, arm64, riscv). This would also let things, like glibc, have a common UAPI.
It's important to note that this work I describe, leaves the arch_prctl interface intact, and it will need an lsm hook for controls via arch_prctl. This way both paths behave the same way.
Now for this patch. I noticed this issue when I was doing negative testing from userspace via prctl and the return value didn't match what was in the pcrtl man page.
Thanks,
Bill
Quoted 3 lines · Bill Roberts
Now for this patch. I noticed this issue when I was doing negative testing from userspace via prctl and the return value didn't match what was in the pcrtl man page.
Ahh, that's the bit of background I was looking for. Thanks for that, and thanks for the patch!
Quoted 6 lines · Dave Hansen
Quoted 3 lines · Bill Roberts
Now for this patch. I noticed this issue when I was doing negative testing from userspace via prctl and the return value didn't match what was in the pcrtl man page.
Ahh, that's the bit of background I was looking for. Thanks for that, and thanks for the patch!
Hey Dave, just to clarify, is there anything else here I need to do for an ack, or can I consider this staged? I also sent out the prctl changes this am, so you can see more of the context.
Quoted 10 lines · Bill Roberts
Quoted 6 lines · Dave Hansen
Quoted 3 lines · Bill Roberts
Now for this patch. I noticed this issue when I was doing negative testing from userspace via prctl and the return value didn't match what was in the pcrtl man page.
Ahh, that's the bit of background I was looking for. Thanks for that, and thanks for the patch!
Hey Dave, just to clarify, is there anything else here I need to do for an ack, or can I consider this staged? I also sent out the prctl changes this am, so you can see more of the context.
It's in my list of things to queue. I'll probably push it out in a day or two.
Quoted 6 lines · Dave Hansen
Quoted 5 lines · Bill Roberts
Quoted 4 lines · Dave Hansen
Quoted 3 lines · Bill Roberts
Now for this patch. I noticed this issue when I was doing negative testing from userspace via prctl and the return value didn't match what was in the pcrtl man page.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Ahh, that's the bit of background I was looking for. Thanks for that, and thanks for the patch!
Hey Dave, just to clarify, is there anything else here I need to do for an ack, or can I consider this staged? I also sent out the prctl changes this am, so you can see more of the context.
It's in my list of things to queue. I'll probably push it out in a day or two.
I didn't see this queued, did I miss something? Thanks folks.
Quoted 1 line · Bill Roberts
I didn't see this queued, did I miss something? Thanks folks.
I got tip bot mail, and I see it:
https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/log/?h=x86/cpu
[tip: x86/cpu] x86/shstk: Shadow stack enabling write return code change
In reply to Bill RobertsThe following commit has been merged into the x86/cpu branch of tip:
The following commit has been merged into the x86/cpu branch of tip:
Commit-ID: f4cadf2d1ee3a24f259495309b76f98af467004b Gitweb: https://git.kernel.org/tip/f4cadf2d1ee3a24f259495309b76f98af467004b Author: Bill Roberts <[email protected]> AuthorDate: Tue, 07 Jul 2026 13:45:42 -05:00 Committer: Dave Hansen <[email protected]> CommitterDate: Wed, 02 Sep 2026 14:06:27 -07:00
x86/shstk: Shadow stack enabling write return code change
The WRSS instruction (the special instruction that writes to shadow stacks) cannot be used in userspace unless IA32_U_CET.SH_STK_EN=1 (user shadow stack is enabled). So the kernel *should* return -EINVAL to userspace if it tries to enable it when shadow stack is disabled. However, currently, it will return -EPERM. But, that error code doesn't fit the condition as the failure is due to an invalid state change request not a permission issue.
Investigating userspace call sites, like glibc and criu (checkpoint code), they do not rely on this specific error message, nor could a userspace effectively utilize this specific return error code to indicate a difference in "I cannot enable write because of invalid permissions" versus "I cannot enable write because the shadow stack is disabled".
--- arch/x86/kernel/shstk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/shstk.c +1 -1
@@ -490,7 +490,7 @@ static int wrss_control(bool enable)* when disabling. */ if (!features_enabled (ARCH_SHSTK_SHSTK )) -return -EPERM ; +return -EINVAL ;/* Already enabled/disabled? */ if (features_enabled (ARCH_SHSTK_WRSS ) == enable)
Borislav Petkov
maintainerRe: [tip: x86/cpu] x86/shstk: Shadow stack enabling write return code change
Quoted 10 lines · On Wed, Sep 02, 2026 at 09:11:03PM -0000, tip-bot2 for Bill Roberts wrote:
The following commit has been merged into the x86/cpu branch of tip:
Commit-ID: f4cadf2d1ee3a24f259495309b76f98af467004b Gitweb: https://git.kernel.org/tip/f4cadf2d1ee3a24f259495309b76f98af467004b Author: Bill Roberts <[email protected]> AuthorDate: Tue, 07 Jul 2026 13:45:42 -05:00 Committer: Dave Hansen <[email protected]> CommitterDate: Wed, 02 Sep 2026 14:06:27 -07:00x86/shstk: Shadow stack enabling write return code change
https://docs.kernel.org/process/maintainer-tip.html#patch-subject
"The condensed patch description in the subject line ... should be written in imperative tone."
And that title doesn't really say what this fixes.
Lemme fix it up.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette[tip: x86/cpu] x86/shstk: Return the correct error value when user shadow stacks are disabled
In reply to Bill RobertsThe following commit has been merged into the x86/cpu branch of tip:
The following commit has been merged into the x86/cpu branch of tip:
Commit-ID: 9025f3bf73f0565eaa271ecc15f468b1d1e4cbaa Gitweb: https://git.kernel.org/tip/9025f3bf73f0565eaa271ecc15f468b1d1e4cbaa Author: Bill Roberts <[email protected]> AuthorDate: Tue, 07 Jul 2026 13:45:42 -05:00 Committer: Borislav Petkov (AMD) <[email protected]> CommitterDate: Mon, 14 Sep 2026 18:57:04 -07:00
x86/shstk: Return the correct error value when user shadow stacks are disabled
The WRSS instruction (the special instruction that writes to shadow stacks) cannot be used in userspace unless IA32_U_CET.SH_STK_EN=1 (user shadow stack is enabled). So the kernel *should* return -EINVAL to userspace if it tries to enable it when shadow stack is disabled. However, currently, it will return -EPERM. But, that error code doesn't fit the condition as the failure is due to an invalid state change request not a permission issue.
Investigating userspace call sites, like glibc and criu (checkpoint code), they do not rely on this specific error message, nor could a userspace effectively utilize this specific return error code to indicate a difference in "I cannot enable write because of invalid permissions" versus "I cannot enable write because the shadow stack is disabled".
[ bp: Fixup commit title. ]
--- arch/x86/kernel/shstk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/shstk.c +1 -1
@@ -490,7 +490,7 @@ static int wrss_control(bool enable)* when disabling. */ if (!features_enabled (ARCH_SHSTK_SHSTK )) -return -EPERM ; +return -EINVAL ;/* Already enabled/disabled? */ if (features_enabled (ARCH_SHSTK_WRSS ) == enable)