Skip to content

Commit

Permalink
x86/shstk: Fix use of shadow stacks with XPTI active
Browse files Browse the repository at this point in the history
The call to setup_cpu_root_pgt(0) in smp_prepare_cpus() is too early.  It
clones the BSP's stack while the .data mapping is still in use, causing all
mappings to be fully read read/write (and with no guard pages either).  This
ultimately causes #DF when trying to enter the dom0 kernel for the first time.

Defer setting up BSPs XPTI pagetable until reinit_bsp_stack() after we've set
up proper shadow stack permissions.

Fixes: 6001660 ("x86/shstk: Rework the stack layout to support shadow stacks")
Fixes: b60ab42 ("x86/shstk: Activate Supervisor Shadow Stacks")
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Release-Acked-by: Ian Jackson <iwj@xenproject.org>
  • Loading branch information
andyhhp committed Nov 3, 2021
1 parent ce30994 commit b285158
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
5 changes: 5 additions & 0 deletions xen/arch/x86/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ static void noreturn init_done(void)
static void __init noreturn reinit_bsp_stack(void)
{
unsigned long *stack = (void*)(get_stack_bottom() & ~(STACK_SIZE - 1));
int rc;

/* Update TSS and ISTs */
load_system_tables();
Expand All @@ -676,6 +677,10 @@ static void __init noreturn reinit_bsp_stack(void)
stack_base[0] = stack;
memguard_guard_stack(stack);

rc = setup_cpu_root_pgt(0);
if ( rc )
panic("Error %d setting up PV root page table\n", rc);

if ( IS_ENABLED(CONFIG_XEN_SHSTK) && cpu_has_xen_shstk )
{
wrmsrl(MSR_PL0_SSP,
Expand Down
9 changes: 2 additions & 7 deletions xen/arch/x86/smpboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ static root_pgentry_t common_pgt;

extern const char _stextentry[], _etextentry[];

static int setup_cpu_root_pgt(unsigned int cpu)
int setup_cpu_root_pgt(unsigned int cpu)
{
root_pgentry_t *rpt;
unsigned int off;
Expand Down Expand Up @@ -1138,8 +1138,6 @@ static struct notifier_block cpu_smpboot_nfb = {

void __init smp_prepare_cpus(void)
{
int rc;

register_cpu_notifier(&cpu_smpboot_nfb);

mtrr_aps_sync_begin();
Expand All @@ -1153,10 +1151,7 @@ void __init smp_prepare_cpus(void)

stack_base[0] = (void *)((unsigned long)stack_start & ~(STACK_SIZE - 1));

rc = setup_cpu_root_pgt(0);
if ( rc )
panic("Error %d setting up PV root page table\n", rc);
if ( per_cpu(root_pgt, 0) )
if ( opt_xpti_hwdom || opt_xpti_domu )
{
get_cpu_info()->pv_cr3 = 0;

Expand Down
1 change: 1 addition & 0 deletions xen/include/xen/smp.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,6 @@ int alloc_cpu_id(void);
extern void *stack_base[NR_CPUS];

void initialize_cpu_data(unsigned int cpu);
int setup_cpu_root_pgt(unsigned int cpu);

#endif /* __XEN_SMP_H__ */

0 comments on commit b285158

Please sign in to comment.