x86/shstk: Fix possible crash while enabling Shadow Stacks
PATCH 1/1 x86/shstk: Fix possible crash while enabling Shadow Stacks
Between writing MSR_S_CET.SHSTK_EN and establishing SSP using RSTORSSP or SETSSBSY, there must not be any CALL or RET instructions.
Building Xen with -fno-early-inlining causes wrmsr() to become out-of-line, and thus suffers #DF during boot.
Make the MSR and shstk helpers always_inline. They ought to have been this way all along.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>
No change in the compiled binary at -O2, except for the line numbers embedded into *_param() names.
With -fno-early-inlining, the resulting delta is:
add/remove: 8/9 grow/shrink: 13/50 up/down: 360/-736 (-376)
--- xen/arch/x86/include/asm/msr.h | 8 ++++---- xen/arch/x86/include/asm/shstk.h | 4 ++-- xen/arch/x86/setup.c | 5 +++++ 3 files changed, 11 insertions(+), 6 deletions(-)
xen/arch/x86/include/asm/msr.h +4 -4
@@ -47,7 +47,7 @@ static always_inline uint64_t rdmsr(unsigned int msr) val = a__ | ((u64 )b__<<32 ); \ }while (0 ) -static inline void wrmsr(unsigned int msr, uint64_t val) +static always_inline void wrmsr(unsigned int msr, uint64_t val) {uint32_t lo = val, hi = val >>32 ;
@@ -56,7 +56,7 @@ static inline void wrmsr(unsigned int msr, uint64_t val)#define wrmsrl (msr, val) wrmsr(msr, val)/* Non-serialising WRMSR, when available. Falls back to a serialising WRMSR. */ -static inline void wrmsrns (uint32_t msr,uint64_t val) +static always_inline void wrmsrns(uint32_t msr, uint64_t val) {uint32_t lo = val, hi = val >>32 ;
@@ -72,7 +72,7 @@ static inline void wrmsrns(uint32_t msr, uint64_t val) }/* rdmsr with exception handling */ -static inline int rdmsr_safe (unsigned int msr,uint64_t *val) +static always_inline int rdmsr_safe(unsigned int msr, uint64_t *val) {uint64_t lo, hi;
@@ -113,7 +113,7 @@ static inline int rdmsr_safe(unsigned int msr, uint64_t *val) }/* wrmsr with exception handling */ -static inline int wrmsr_safe (unsigned int msr,uint64_t val) +static always_inline int wrmsr_safe(unsigned int msr, uint64_t val) {uint32_t lo = val, hi = val >>32 ;
xen/arch/x86/include/asm/shstk.h +2 -2
@@ -15,7 +15,7 @@*/ #define SSP_NO_SHSTK 1 -static inline unsigned long rdssp (void ) +static always_inline unsigned long rdssp (void ) {unsigned long ssp;
@@ -24,7 +24,7 @@ static inline unsigned long rdssp(void)return ssp; } -static inline void wrss (unsigned long val,unsigned long *ptr) +static always_inline void wrss(unsigned long val, unsigned long *ptr) { asm ("wrssq %[val], %[ptr]" : [ptr] "=m" (*ptr)
xen/arch/x86/setup.c +5 -0
@@ -915,6 +915,11 @@ static void __init noreturn reinit_bsp_stack(void)*/ local_irq_disable (); +/* +* There must be no CALL or RET instructions between writing +* MSR_S_CET.SHSTK_EN and establishing SSP with RSTORSSP or SETSSBSY +* below. All helpers must be forced inline. +*/ wrmsrl (MSR_S_CET ,xen_msr_s_cet_value ());/*
base-commit: 7e020a4dd6ed30eb6c91a9abe2767034e2bb270a
Signature · 1 line
2.39.5
Le 19/10/2026 à 18:00, Andrew Cooper a écrit :
Quoted 11 lines
Between writing MSR_S_CET.SHSTK_EN and establishing SSP using RSTORSSP or SETSSBSY, there must not be any CALL or RET instructions.
Building Xen with -fno-early-inlining causes
wrmsr()to become out-of-line, and thus suffers #DF during boot.Make the MSR and shstk helpers
always_inline. They ought to have been this way all along.Reported-by Roger Pau Monné <[email protected]>Signed-off-by Andrew Cooper <[email protected]>
Teddy
Quoted 11 lines · Andrew Cooper
Between writing MSR_S_CET.SHSTK_EN and establishing SSP using RSTORSSP or SETSSBSY, there must not be any CALL or RET instructions.
Building Xen with -fno-early-inlining causes
wrmsr()to become out-of-line, and thus suffers #DF during boot.Make the MSR and shstk helpers
always_inline. They ought to have been this way all along.Reported-by Roger Pau Monné <[email protected]>Signed-off-by Andrew Cooper <[email protected]>
Originally this was reported by Stefano, so it should likely have his reported-by tag also.
Thanks, Roger.
Quoted 10 lines · Roger Pau Monné
Quoted 9 lines · Andrew Cooper
Between writing MSR_S_CET.SHSTK_EN and establishing SSP using RSTORSSP or SETSSBSY, there must not be any CALL or RET instructions.
Building Xen with -fno-early-inlining causes
wrmsr()to become out-of-line, and thus suffers #DF during boot.Make the MSR and shstk helpers
always_inline. They ought to have been this way all along.
Quoted 6 lines
Quoted 2 lines
Reported-by Roger Pau Monné <[email protected]>Signed-off-by Andrew Cooper <[email protected]>Reviewed-by Roger Pau Monné <[email protected]>Originally this was reported by Stefano, so it should likely have his reported-by tag also.
Fine. I can adjust on commit.
Thanks,
~Andrew
Quoted 11 lines · Andrew Cooper
Between writing MSR_S_CET.SHSTK_EN and establishing SSP using RSTORSSP or SETSSBSY, there must not be any CALL or RET instructions.
Building Xen with -fno-early-inlining causes
wrmsr()to become out-of-line, and thus suffers #DF during boot.Make the MSR and shstk helpers
always_inline. They ought to have been this way all along.Reported-by Roger Pau Monné <[email protected]>Signed-off-by Andrew Cooper <[email protected]>
Sorry seems like I'm a bit slow today. Also worth adding:
Thanks, Roger.
Quoted 7 lines · Roger Pau Monné
Quoted 6 lines · Andrew Cooper
Between writing MSR_S_CET.SHSTK_EN and establishing SSP using RSTORSSP or SETSSBSY, there must not be any CALL or RET instructions.
Building Xen with -fno-early-inlining causes
wrmsr()to become out-of-line, and thus suffers #DF during boot.
Quoted 8 lines
Quoted 5 lines
Make the MSR and shstk helpers
always_inline. They ought to have been this way all along.Reported-by Roger Pau Monné <[email protected]>Signed-off-by Andrew Cooper <[email protected]>Sorry seems like I'm a bit slow today. Also worth adding:
Fixes b60ab42db2f0 ("x86/shstk: Activate Supervisor Shadow Stacks").
If we're doing that, we need
too.
~Andrew
Quoted 13 lines · Andrew Cooper
Quoted 12 lines · Roger Pau Monné
Quoted 11 lines · Andrew Cooper
Between writing MSR_S_CET.SHSTK_EN and establishing SSP using RSTORSSP or SETSSBSY, there must not be any CALL or RET instructions.
Building Xen with -fno-early-inlining causes
wrmsr()to become out-of-line, and thus suffers #DF during boot.Make the MSR and shstk helpers
always_inline. They ought to have been this way all along.Reported-by Roger Pau Monné <[email protected]>Signed-off-by Andrew Cooper <[email protected]>
Quoted 7 lines
Quoted 3 lines
Sorry seems like I'm a bit slow today. Also worth adding:
Fixes b60ab42db2f0 ("x86/shstk: Activate Supervisor Shadow Stacks").If we're doing that, we need
Fixes 3037d8b7eb3e ("x86/boot: Use RSTORSSP to establish SSP")
Fine with me, I just went for the first instance, and didn't care for the FRED one.
Thanks, Roger.