Patch to fix the ELF loader to ensure executable regions of memory are mprotected with PROT_EXEC, to ensure the server will function correctly under a non-executable-stack/heap/etc. environment such as exec-shield. Original patch by John Dennis for XFree86 4.3.0, ported to Xorg X11 by Mike A. Harris --- xc/programs/Xserver/hw/xfree86/loader/elfloader.c.redhat-elfloader-linux-non-exec-stack 2004-03-04 12:48:07.000000000 -0500 +++ xc/programs/Xserver/hw/xfree86/loader/elfloader.c 2004-03-09 18:51:43.000000000 -0500 @@ -921,7 +921,7 @@ ErrorF("ELFCreateGOT() Unable to reallocate memory!!!!\n"); return FALSE; } -# if defined(linux) && defined(__ia64__) || defined(__OpenBSD__) +# if defined(linux) || defined(__OpenBSD__) { unsigned long page_size = getpagesize(); unsigned long round; @@ -2760,10 +2760,16 @@ elffile->lsection[j].size = SecSize(i); elffile->lsection[j].flags = flags; switch (SecType(i)) { -#ifdef __OpenBSD__ +#if defined(linux) || defined(__OpenBSD__) case SHT_PROGBITS: - mprotect(elffile->lsection[j].saddr, SecSize(i), - PROT_READ | PROT_WRITE | PROT_EXEC); + { + unsigned long page_size = getpagesize(); + unsigned long round; + + round = (unsigned long)elffile->lsection[j].saddr & (page_size -1); + mprotect( (char *)elffile->lsection[j].saddr - round, + SecSize(i) + round, PROT_READ | PROT_WRITE | PROT_EXEC); + } break; #endif case SHT_SYMTAB: @@ -2958,7 +2964,7 @@ ErrorF("Unable to allocate ELF sections\n"); return NULL; } -# if defined(linux) && defined(__ia64__) || defined(__OpenBSD__) +# if defined(linux) || defined(__OpenBSD__) { unsigned long page_size = getpagesize(); unsigned long round;