From: Andrew Cooper Date: Thu, 2 Mar 2017 16:04:49 +0000 (+0000) Subject: Provide a common user_stack[] for tests X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=a2b8a3f25558792e5956b960c6fa52698da811b0;p=people%2Fandrewcoop%2Fxen-test-framework.git Provide a common user_stack[] for tests Automatically remap this frame as _PAGE_USER. Signed-off-by: Andrew Cooper --- diff --git a/arch/x86/hvm/traps.c b/arch/x86/hvm/traps.c index eb05f27..cfaa69b 100644 --- a/arch/x86/hvm/traps.c +++ b/arch/x86/hvm/traps.c @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -153,6 +154,22 @@ void arch_init_traps(void) gdt[GDTE_TSS] = (typeof(*gdt))INIT_GDTE((unsigned long)&tss, 0x67, 0x89); ltr(GDTE_TSS * 8); + + /* + * If we haven't applied blanket PAGE_USER mappings, remap the structures + * which specifically want to be user. + */ + if ( !test_wants_user_mappings ) + { + unsigned long gfn = virt_to_gfn(user_stack); + + if ( gfn >= ARRAY_SIZE(l1_identmap) ) + panic("user_stack[] outside of l1_identmap[]\n"); + + l1_identmap[gfn] |= _PAGE_USER; + + write_cr3((unsigned long)&cr3_target); + } } void __noreturn arch_crash_hard(void) diff --git a/arch/x86/include/arch/traps.h b/arch/x86/include/arch/traps.h index ae68293..a428630 100644 --- a/arch/x86/include/arch/traps.h +++ b/arch/x86/include/arch/traps.h @@ -24,6 +24,7 @@ unsigned long cpu_regs_sp(const struct cpu_regs *regs); unsigned int cpu_regs_ss(const struct cpu_regs *regs); extern uint8_t boot_stack[3 * PAGE_SIZE]; +extern uint8_t user_stack[PAGE_SIZE]; #if defined(CONFIG_PV) #include diff --git a/arch/x86/link.lds.S b/arch/x86/link.lds.S index 4f7eaf5..1f4f604 100644 --- a/arch/x86/link.lds.S +++ b/arch/x86/link.lds.S @@ -72,6 +72,7 @@ zeroptr = 0; ASSERT(IS_ALIGNED(hypercall_page, PAGE_SIZE), "hypercall_page misaligned"); ASSERT(IS_ALIGNED(boot_stack, PAGE_SIZE), "boot_stack misaligned"); +ASSERT(IS_ALIGNED(user_stack, PAGE_SIZE), "user_stack misaligned"); #ifdef CONFIG_HVM diff --git a/arch/x86/pv/traps.c b/arch/x86/pv/traps.c index 9561cba..f4a1b17 100644 --- a/arch/x86/pv/traps.c +++ b/arch/x86/pv/traps.c @@ -212,6 +212,17 @@ void arch_init_traps(void) va += 1UL << L1_PT_SHIFT; } } + else + { + /* + * If we haven't applied blanket PAGE_USER mappings, remap the + * structures which specifically want to be user. + */ + intpte_t nl1e = pte_from_virt(user_stack, PF_SYM(AD, U, RW, P)); + + if ( hypercall_update_va_mapping(user_stack, nl1e, UVMF_INVLPG) ) + panic("Unable to remap user_stack with _PAGE_USER\n"); + } #endif /* Unmap page at 0 to catch errors with NULL pointers. */ diff --git a/arch/x86/setup.c b/arch/x86/setup.c index 497c368..45fef99 100644 --- a/arch/x86/setup.c +++ b/arch/x86/setup.c @@ -17,6 +17,7 @@ * boot_stack[page 1] Top of work stack */ uint8_t boot_stack[3 * PAGE_SIZE] __aligned(PAGE_SIZE); +uint8_t user_stack[PAGE_SIZE] __aligned(PAGE_SIZE); uint32_t x86_features[FSCAPINTS]; enum x86_vendor x86_vendor; unsigned int x86_family, x86_model, x86_stepping; diff --git a/include/xtf/traps.h b/include/xtf/traps.h index 872b86f..6deb496 100644 --- a/include/xtf/traps.h +++ b/include/xtf/traps.h @@ -2,6 +2,7 @@ #define XTF_TRAPS_H #include +#include #include diff --git a/tests/xsa-183/main.c b/tests/xsa-183/main.c index b388283..12cc7b7 100644 --- a/tests/xsa-183/main.c +++ b/tests/xsa-183/main.c @@ -42,16 +42,9 @@ const char test_title[] = "XSA-183 PoC"; -uint8_t user_stack[PAGE_SIZE] __aligned(PAGE_SIZE); - void test_main(void) { unsigned long curr_stk, discard; - intpte_t nl1e = pte_from_virt(user_stack, PF_SYM(AD, U, RW, P)); - - /* Remap user_stack with _PAGE_USER. */ - if ( hypercall_update_va_mapping(user_stack, nl1e, UVMF_INVLPG) ) - panic("Unable to remap user_stack with _PAGE_USER\n"); /* Load NULL selector to guarantee a fault. */ write_fs(0);