|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [xen staging] x86/traps: use entry_ssp in fixup_exception_return()
commit 08b7d5cfb20319406b4606e1b4e500743bcaf533
Author: Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Tue Nov 10 09:48:00 2026 +0100
Commit: Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Tue Nov 10 09:48:00 2026 +0100
x86/traps: use entry_ssp in fixup_exception_return()
With the value recorded on entry there's no need anymore to go hunt for
the respective exception frame on the shadow stack. By deriving "ptr"
from that field (without any offset), it then ends up pointing one slot
lower than before. Therefore all array indexes need incrementing, nicely
doing away with all the negative ones.
Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
Reviewed-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
xen/arch/x86/traps.c | 74 ++++++++++++++++++----------------------------------
1 file changed, 26 insertions(+), 48 deletions(-)
diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c
index 5a702fe22c..93a69e49c2 100644
--- a/xen/arch/x86/traps.c
+++ b/xen/arch/x86/traps.c
@@ -690,19 +690,6 @@ unsigned long get_stack_trace_bottom(unsigned long sp)
}
}
-static unsigned long get_shstk_bottom(unsigned long sp)
-{
- /* SAF-11-safe */
- switch ( get_stack_page(sp) )
- {
-#ifdef CONFIG_XEN_SHSTK
- case 0: return ROUNDUP(sp, IST_SHSTK_SIZE) - sizeof(unsigned long);
- case 5: return ROUNDUP(sp, PAGE_SIZE) - sizeof(unsigned long);
-#endif
- default: return sp - sizeof(unsigned long);
- }
-}
-
unsigned long get_stack_dump_bottom(unsigned long sp)
{
switch ( get_stack_page(sp) )
@@ -1187,26 +1174,29 @@ void asmlinkage noreturn do_unhandled_trap(struct
cpu_user_regs *regs)
static void fixup_exception_return(struct cpu_user_regs *regs,
unsigned long fixup, unsigned long stub_ra)
{
- if ( IS_ENABLED(CONFIG_XEN_SHSTK) )
+#ifdef CONFIG_XEN_SHSTK
{
- unsigned long ssp, *ptr, *base;
+ unsigned long ssp = rdssp();
- if ( (ssp = rdssp()) == SSP_NO_SHSTK )
- goto shstk_done;
+ if ( ssp != SSP_NO_SHSTK )
+ {
+ unsigned long *ptr = _p(regs->entry_ssp);
+ unsigned long primary_shstk =
+ (ssp & ~(STACK_SIZE - 1)) +
+ (PRIMARY_SHSTK_SLOT + 1) * PAGE_SIZE - 8;
- ptr = _p(ssp);
- base = _p(get_shstk_bottom(ssp));
+ BUG_ON((regs->entry_ssp ^ primary_shstk) >>
+ (PAGE_SHIFT + STACK_ORDER));
- for ( ; ptr < base; ++ptr )
- {
/*
- * Search for %rip. The shstk currently looks like this:
+ * The shstk currently looks like this:
*
* tok [Supervisor token, == &tok | BUSY, only with FRED
inactive]
* ... [Pointed to by SSP for most exceptions, empty in IST
cases]
* %cs [== regs->cs]
* %rip [== regs->rip]
- * SSP [Likely points to 3 slots higher, above %cs]
+ * SSP [Pointed to by entry_ssp; Likely points to 3 slots
+ * higher, above %cs]
* ... [call tree to this function, likely 2/3 slots]
*
* and we want to overwrite %rip with fixup. There are two
@@ -1219,13 +1209,10 @@ static void fixup_exception_return(struct cpu_user_regs
*regs,
*
* Check for both regs->rip and regs->cs matching.
*/
- if ( ptr[0] == regs->rip && ptr[1] == regs->cs )
- {
- unsigned long primary_shstk =
- (ssp & ~(STACK_SIZE - 1)) +
- (PRIMARY_SHSTK_SLOT + 1) * PAGE_SIZE - 8;
+ BUG_ON(ptr[1] != regs->rip || ptr[2] != regs->cs);
- wrss(fixup, ptr);
+ {
+ wrss(fixup, &ptr[1]);
if ( !stub_ra )
goto shstk_done;
@@ -1242,7 +1229,7 @@ static void fixup_exception_return(struct cpu_user_regs
*regs,
* - if we're on an IST stack, we need to increment the
* original SSP.
*/
- BUG_ON((ptr[-1] ^ primary_shstk) >> PAGE_SHIFT);
+ BUG_ON((ptr[0] ^ primary_shstk) >> PAGE_SHIFT);
if ( (ssp ^ primary_shstk) >> PAGE_SHIFT )
{
@@ -1251,39 +1238,30 @@ static void fixup_exception_return(struct cpu_user_regs
*regs,
* addresses actually match. Then increment the
interrupted
* context's SSP.
*/
- BUG_ON(stub_ra != *(unsigned long*)ptr[-1]);
- wrss(ptr[-1] + 8, &ptr[-1]);
+ BUG_ON(stub_ra != *(unsigned long*)ptr[0]);
+ wrss(ptr[0] + 8, &ptr[0]);
goto shstk_done;
}
/* Make sure the two return addresses actually match. */
- BUG_ON(stub_ra != ptr[2]);
+ BUG_ON(stub_ra != ptr[3]);
/* Move exception frame, updating SSP there. */
- wrss(ptr[1], &ptr[2]); /* %cs */
- wrss(ptr[0], &ptr[1]); /* %rip */
- wrss(ptr[-1] + 8, &ptr[0]); /* SSP */
+ wrss(ptr[2], &ptr[3]); /* %cs */
+ wrss(ptr[1], &ptr[2]); /* %rip */
+ wrss(ptr[0] + 8, &ptr[1]); /* SSP */
/* Move all newer entries. */
- while ( --ptr != _p(ssp) )
- wrss(ptr[-1], &ptr[0]);
+ while ( ptr-- != _p(ssp) )
+ wrss(ptr[0], &ptr[1]);
/* Finally account for our own stack having shifted up. */
asm volatile ( "incsspd %0" :: "r" (2) );
-
- goto shstk_done;
}
}
-
- /*
- * We failed to locate and fix up the shadow IRET frame. This could
- * be due to shadow stack corruption, or bad logic above. We cannot
- * continue executing the interrupted context.
- */
- BUG();
-
}
shstk_done:
+#endif /* CONFIG_XEN_SHSTK */
/* Fixup the regular stack. */
regs->rip = fixup;
--
generated by git-patchbot for /home/xen/git/xen.git#staging
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |