From 1772d89c08edce9c9ec0779bcb57d05410aa8851 Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Fri, 2 Mar 2018 15:19:28 +0100 Subject: [PATCH] x86: guard more stack pages There's no reason to keep the unused pages (of which there are actually two; respective commentary also gets adjusted) mapped. Signed-off-by: Jan Beulich Reviewed-by: Andrew Cooper --- xen/arch/x86/mm.c | 14 +++++++------- xen/arch/x86/x86_64/traps.c | 4 ++-- xen/include/asm-x86/current.h | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 9d26a9d5ec..829a262950 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5563,17 +5563,17 @@ void memguard_unguard_range(void *p, unsigned long l) void memguard_guard_stack(void *p) { - BUILD_BUG_ON((PRIMARY_STACK_SIZE + PAGE_SIZE) > STACK_SIZE); - p = (void *)((unsigned long)p + STACK_SIZE - - PRIMARY_STACK_SIZE - PAGE_SIZE); - memguard_guard_range(p, PAGE_SIZE); + /* IST_MAX IST pages + at least 1 guard page + primary stack. */ + BUILD_BUG_ON((IST_MAX + 1) * PAGE_SIZE + PRIMARY_STACK_SIZE > STACK_SIZE); + + memguard_guard_range(p + IST_MAX * PAGE_SIZE, + STACK_SIZE - PRIMARY_STACK_SIZE - IST_MAX * PAGE_SIZE); } void memguard_unguard_stack(void *p) { - p = (void *)((unsigned long)p + STACK_SIZE - - PRIMARY_STACK_SIZE - PAGE_SIZE); - memguard_unguard_range(p, PAGE_SIZE); + memguard_unguard_range(p + IST_MAX * PAGE_SIZE, + STACK_SIZE - PRIMARY_STACK_SIZE - IST_MAX * PAGE_SIZE); } void arch_dump_shared_mem_info(void) diff --git a/xen/arch/x86/x86_64/traps.c b/xen/arch/x86/x86_64/traps.c index 3652f5ff21..4649ad4d10 100644 --- a/xen/arch/x86/x86_64/traps.c +++ b/xen/arch/x86/x86_64/traps.c @@ -301,8 +301,8 @@ void subarch_percpu_traps_init(void) unsigned char *stub_page; unsigned int offset; - /* IST_MAX IST pages + 1 syscall page + 1 guard page + primary stack. */ - BUILD_BUG_ON((IST_MAX + 2) * PAGE_SIZE + PRIMARY_STACK_SIZE > STACK_SIZE); + /* IST_MAX IST pages + at least 1 guard page + primary stack. */ + BUILD_BUG_ON((IST_MAX + 1) * PAGE_SIZE + PRIMARY_STACK_SIZE > STACK_SIZE); stub_page = map_domain_page(_mfn(this_cpu(stubs.mfn))); diff --git a/xen/include/asm-x86/current.h b/xen/include/asm-x86/current.h index 4678a0fcf5..3a0e1eef36 100644 --- a/xen/include/asm-x86/current.h +++ b/xen/include/asm-x86/current.h @@ -16,9 +16,9 @@ * * 7 - Primary stack (with a struct cpu_info at the top) * 6 - Primary stack - * 5 - Optionally not preset (MEMORY_GUARD) - * 4 - unused - * 3 - Syscall trampolines + * 5 - Optionally not present (MEMORY_GUARD) + * 4 - Unused; optionally not present (MEMORY_GUARD) + * 3 - Unused; optionally not present (MEMORY_GUARD) * 2 - MCE IST stack * 1 - NMI IST stack * 0 - Double Fault IST stack -- 2.30.2