From 62c625fdd2ac776887c48af9cc758f6cc5e97699 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Mon, 30 Jan 2012 07:56:00 +0000 Subject: [PATCH] Finally, try to enable the nxstacks on amd64 and powerpc64 for both 64bit and 32bit ABIs. Also try to enable nxstacks for PAE/i386 when supported, and some variants of powerpc32. MFC after: 2 months (if ever) --- sys/i386/i386/initcpu.c | 3 +++ sys/kern/imgact_elf.c | 7 ++++++- sys/powerpc/aim/mmu_oea64.c | 4 ++++ sys/powerpc/booke/machdep.c | 5 +++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/sys/i386/i386/initcpu.c b/sys/i386/i386/initcpu.c index c2daf54371f..ec77adbea91 100644 --- a/sys/i386/i386/initcpu.c +++ b/sys/i386/i386/initcpu.c @@ -650,6 +650,8 @@ enable_sse(void) #endif } +extern int elf32_nxstack; + void initializecpu(void) { @@ -739,6 +741,7 @@ initializecpu(void) msr = rdmsr(MSR_EFER) | EFER_NXE; wrmsr(MSR_EFER, msr); pg_nx = PG_NX; + elf32_nxstack = 1; } #endif break; diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c index 4da2ad785a4..bde590cda8a 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -118,7 +118,12 @@ static int elf_legacy_coredump = 0; SYSCTL_INT(_debug, OID_AUTO, __elfN(legacy_coredump), CTLFLAG_RW, &elf_legacy_coredump, 0, ""); -static int __elfN(nxstack) = 0; +int __elfN(nxstack) = +#if defined(__amd64__) || defined(__powerpc64__) /* both 64 and 32 bit */ + 1; +#else + 0; +#endif SYSCTL_INT(__CONCAT(_kern_elf, __ELF_WORD_SIZE), OID_AUTO, nxstack, CTLFLAG_RW, &__elfN(nxstack), 0, __XSTRING(__CONCAT(ELF, __ELF_WORD_SIZE)) ": enable non-executable stack"); diff --git a/sys/powerpc/aim/mmu_oea64.c b/sys/powerpc/aim/mmu_oea64.c index d58e8dee164..efe091f6ccc 100644 --- a/sys/powerpc/aim/mmu_oea64.c +++ b/sys/powerpc/aim/mmu_oea64.c @@ -1445,6 +1445,8 @@ moea64_uma_page_alloc(uma_zone_t zone, int bytes, u_int8_t *flags, int wait) return (void *)va; } +extern int elf32_nxstack; + void moea64_init(mmu_t mmu) { @@ -1464,6 +1466,8 @@ moea64_init(mmu_t mmu) uma_zone_set_allocf(moea64_mpvo_zone,moea64_uma_page_alloc); } + elf32_nxstack = 1; + moea64_initialized = TRUE; } diff --git a/sys/powerpc/booke/machdep.c b/sys/powerpc/booke/machdep.c index c2b5e6fa626..82a37e14100 100644 --- a/sys/powerpc/booke/machdep.c +++ b/sys/powerpc/booke/machdep.c @@ -192,6 +192,8 @@ void print_kernel_section_addr(void); void print_kenv(void); u_int booke_init(uint32_t, uint32_t); +extern int elf32_nxstack; + static void cpu_e500_startup(void *dummy) { @@ -227,6 +229,9 @@ cpu_e500_startup(void *dummy) /* Set up buffers, so they can be used to read disk labels. */ bufinit(); vm_pager_bufferinit(); + + /* Cpu supports execution permissions on the pages. */ + elf32_nxstack = 1; } static char *