xen: Check NX state before setting up GDT mapping
Subsystems (3)
Hi Ingo,
This is a little followup fix to the previous Xen stack-protector patches to deal with the case of a 64-bit processor without NX support (either old Intel or disabled in BIOS). Before creating the mapping for the GDT we need to make sure that NX is actually supported or the processor will fault on us.
This ends up making mm/init.o non-stack-protected. Given that this file has some fairly complex functions with local arrays, I've made an additional change to move the NX setup into its own file to limit the non-stack-protected code. I added it as a later delta so that the pure bugfix can be applied to stable, and the cleanup can go on top into mainline.
Thanks,
J
The following changes since commit 79b520e87e1214cfa107bdc8528b5d6c055a8b82:
Linus Torvalds (1):
Merge branch 'for-linus' of git://oss.sgi.com/xfs/xfs
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git bugfix
Jeremy Fitzhardinge (2):
xen: check EFER for NX before setting up GDT mapping
x86: split NX setup into separate file to limit unstack-protected code
arch/x86/include/asm/pgtable_types.h | 1 + arch/x86/mm/Makefile | 3 +- arch/x86/mm/init.c | 63 ------------------------------- arch/x86/mm/setup_nx.c | 69 ++++++++++++++++++++++++++++++++++ arch/x86/xen/enlighten.c | 10 ++-- 5 files changed, 77 insertions(+), 69 deletions(-) create mode 100644 arch/x86/mm/setup_nx.c
arch/x86/include/asm/pgtable_types.h +1 -0
@@ -277,6 +277,7 @@ static inline pteval_t pte_flags(pte_t pte)typedef struct page *pgtable_t ;extern pteval_t __supported_pte_mask; +extern void set_nx (void );extern int nx_enabled;#define pgprot_writecombine pgprot_writecombine
arch/x86/mm/Makefile +2 -1
@@ -1,9 +1,10 @@ obj-y := init.o init_$(BITS).o fault.o ioremap.o extable.o pageattr.o mmap.o \ - pat.o pgtable.o physaddr.o gup.o + pat.o pgtable.o physaddr.o gup.o setup_nx.o # Make sure __phys_addr has no stackprotector nostackp := $(call cc-option, -fno-stack-protector) CFLAGS_physaddr.o := $(nostackp) +CFLAGS_setup_nx.o := $(nostackp) obj-$(CONFIG_SMP) += tlb.o
arch/x86/mm/init.c +0 -63
69 lines not on this page · raw message
arch/x86/mm/setup_nx.c new file +69 -0
69 lines not on this page · raw message
arch/x86/xen/enlighten.c +5 -5
@@ -1083,6 +1083,11 @@ asmlinkage void __init xen_start_kernel(void) __supported_pte_mask |= _PAGE_IOMAP; +#ifdef CONFIG_X86_64 +/* Work out if we support NX */ +check_efer (); +#endif +xen_setup_features ();/* Get mfn list */
@@ -1123,11 +1128,6 @@ asmlinkage void __init xen_start_kernel(void) pgd = (pgd_t *)xen_start_info->pt_base; -#ifdef CONFIG_X86_64 -/* Work out if we support NX */ -check_efer (); -#endif -/* Don't do the full vcpu_info placement stuff until we have a possible map and a non-dummy shared_info. */ per_cpu (xen_vcpu,0 ) = &HYPERVISOR_shared_info->vcpu_info[0 ];
Quoted 30 lines · Jeremy Fitzhardinge
Hi Ingo,
This is a little followup fix to the previous Xen stack-protector patches to deal with the case of a 64-bit processor without NX support (either old Intel or disabled in BIOS). Before creating the mapping for the GDT we need to make sure that NX is actually supported or the processor will fault on us.
This ends up making
mm/init.onon-stack-protected. Given that this file has some fairly complex functions with local arrays, I've made an additional change to move the NX setup into its own file to limit the non-stack-protected code. I added it as a later delta so that the pure bugfix can be applied to stable, and the cleanup can go on top into mainline.Thanks,
JThe following changes since commit
79b520e87e1214cfa107bdc8528b5d6c055a8b82:
Linus Torvalds (1):
Merge branch 'for-linus' ofgit://oss.sgi.com/xfs/xfsare available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.gitbugfixJeremy Fitzhardinge (2):
xen: check EFER for NX before setting up GDT mapping
x86: split NX setup into separate file to limit unstack-protected code
Quoted 7 lines
arch/x86/include/asm/pgtable_types.h | 1 + arch/x86/mm/Makefile | 3 +- arch/x86/mm/init.c | 63 ------------------------------- arch/x86/mm/setup_nx.c | 69 ++++++++++++++++++++++++++++++++++ arch/x86/xen/enlighten.c | 10 ++-- 5 files changed, 77 insertions(+), 69 deletions(-) create mode 100644 arch/x86/mm/setup_nx.c
Pulled, thanks Jeremy!
Ingo
arch/x86/xen/enlighten.c asmlinkage void __init xen_start_kernel(void) · line 1090
Quoted 13 lines · Jeremy Fitzhardinge
arch/x86/xen/enlighten.c +5
-0@@ -1083,6 +1083,11 @@ asmlinkage void __init xen_start_kernel(void) __supported_pte_mask |= _PAGE_IOMAP; +#ifdef CONFIG_X86_64 +/* Work out if we support NX */ +check_efer (); +#endif +
btw., this #ifdef could sure be eliminated, right?
Ingo
Quoted 8 lines · Ingo Molnar
arch/x86/xen/enlighten.c asmlinkage void __init xen_start_kernel(void) · line 1090
Quoted 6 lines
arch/x86/xen/enlighten.c +5
-0+#ifdef CONFIG_X86_64 +/* Work out if we support NX */ +check_efer (); +#endif +btw., this #ifdef could sure be eliminated, right?
check_efer() is only defined on x86-64 and all its existing callsites have a similar #ifdef. NX setup is an area which could do with a bit of hitting with the unification stick.
J
Quoted 10 lines · Jeremy Fitzhardinge
Quoted 8 lines · Ingo Molnar
arch/x86/xen/enlighten.c asmlinkage void __init xen_start_kernel(void) · line 1090
Quoted 6 lines
arch/x86/xen/enlighten.c +5
-0+#ifdef CONFIG_X86_64 +/* Work out if we support NX */ +check_efer (); +#endif +btw., this #ifdef could sure be eliminated, right?
Quoted 2 lines
check_efer()is only defined on x86-64 and all its existing callsites have a similar #ifdef.
Yes, a familar pattern that prompted my comment.
Quoted 2 lines
[...] NX setup is an area which could do with a bit of hitting with the unification stick.
Yes.
Ingo