|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v8 56/65] x86/mm: write shadow stack tokens for the address the stack is used at
From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
A supervisor shadow stack token holds the linear address it is used at.
On entry to Xen from a guest, and when an IST vector switches stacks,
the CPU takes SSP from MSR_PL0_SSP or from the interrupt SSP table, and
before it uses the shadow stack there, checks that the token at that
address contains the address itself, with the busy bit clear. SETSSBSY,
on the SYSCALL and SYSENTER paths, checks it the same way. So a token
must name the address its stack is used at, which need not be the
address memguard_guard_stack() writes it through.
The two are the same today: a stack is used at its directmap address.
But soon we'll want to make it possible for these to differ.
Give write_sss_token() the address the token is used at, separately
from the pointer it writes through. No functional change.
Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
Assisted-by: Claude Code:claude-fable-5, Claude Code:claude-opus-4-8, Claude
Code:claude-opus-5-5
Signed-off-by: George Dunlap <gwd@xxxxxxxxxxxxxx>
---
Changes in v8:
- New in this version.
Changes since previously posted version ("x86: adventures in Address Space
Isolation", v2):
- Split out of "x86/mm: switch to a per-CPU mapped stack when using
ASI" (now "x86/mm: run every CPU on a per-CPU stack address"):
write_sss_token()'s separate address alone, without
memguard_guard_stack() taking a CPU.
---
xen/arch/x86/mm.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index be429a174f..51f11d8a39 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -6797,17 +6797,20 @@ void free_pervcpu_mappings(struct vcpu *v)
free_perdomain_l3(l3pg);
}
-static void write_sss_token(unsigned long *ptr)
+static void write_sss_token(unsigned long *ptr, unsigned long va)
{
/*
* A supervisor shadow stack token is its own linear address, with the
- * busy bit (0) clear.
+ * busy bit (0) clear: @va is the address the token is used at.
*/
- *ptr = (unsigned long)ptr;
+ *ptr = va;
}
+/* Guard a xenheap stack, at @p, which is also the address it is used at. */
void memguard_guard_stack(void *p)
{
+ unsigned long va = (unsigned long)p;
+
ASSERT(opt_fred >= 0); /* Confirm that FRED-ness has been resolved */
/*
@@ -6818,17 +6821,22 @@ void memguard_guard_stack(void *p)
*/
if ( IS_ENABLED(CONFIG_XEN_SHSTK) && !opt_fred )
{
- write_sss_token(p + (IST_MCE * IST_SHSTK_SIZE) - 8);
- write_sss_token(p + (IST_NMI * IST_SHSTK_SIZE) - 8);
- write_sss_token(p + (IST_DB * IST_SHSTK_SIZE) - 8);
- write_sss_token(p + (IST_DF * IST_SHSTK_SIZE) - 8);
+ write_sss_token(p + (IST_MCE * IST_SHSTK_SIZE) - 8,
+ va + (IST_MCE * IST_SHSTK_SIZE) - 8);
+ write_sss_token(p + (IST_NMI * IST_SHSTK_SIZE) - 8,
+ va + (IST_NMI * IST_SHSTK_SIZE) - 8);
+ write_sss_token(p + (IST_DB * IST_SHSTK_SIZE) - 8,
+ va + (IST_DB * IST_SHSTK_SIZE) - 8);
+ write_sss_token(p + (IST_DF * IST_SHSTK_SIZE) - 8,
+ va + (IST_DF * IST_SHSTK_SIZE) - 8);
}
map_pages_to_xen((unsigned long)p, virt_to_mfn(p), 1,
PAGE_HYPERVISOR_SHSTK);
/* Primary Shadow Stack. 1x 4k in stack page 5. */
p += PRIMARY_SHSTK_SLOT * PAGE_SIZE;
+ va += PRIMARY_SHSTK_SLOT * PAGE_SIZE;
if ( IS_ENABLED(CONFIG_XEN_SHSTK) && !opt_fred )
- write_sss_token(p + PAGE_SIZE - 8);
+ write_sss_token(p + PAGE_SIZE - 8, va + PAGE_SIZE - 8);
map_pages_to_xen((unsigned long)p, virt_to_mfn(p), 1,
PAGE_HYPERVISOR_SHSTK);
}
--
2.56.0
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |