From cb38d4941c45e3c72c4b5b3fad87d297d950cf53 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Tue, 25 Jan 2011 21:12:31 +0000 Subject: [PATCH] When loading dso without PT_GNU_STACK phdr, only call __pthread_map_stacks_exec() on architectures that allow executable stacks. Reported and tested by: marcel (ia64) --- libexec/rtld-elf/amd64/rtld_machdep.h | 3 +++ libexec/rtld-elf/arm/rtld_machdep.h | 3 +++ libexec/rtld-elf/i386/rtld_machdep.h | 3 +++ libexec/rtld-elf/ia64/rtld_machdep.h | 3 +++ libexec/rtld-elf/map_object.c | 2 +- libexec/rtld-elf/mips/rtld_machdep.h | 3 +++ libexec/rtld-elf/powerpc/rtld_machdep.h | 3 +++ libexec/rtld-elf/powerpc64/rtld_machdep.h | 3 +++ libexec/rtld-elf/rtld.c | 2 +- libexec/rtld-elf/sparc64/rtld_machdep.h | 3 +++ 10 files changed, 26 insertions(+), 2 deletions(-) diff --git a/libexec/rtld-elf/amd64/rtld_machdep.h b/libexec/rtld-elf/amd64/rtld_machdep.h index 301eb0c59e1..48d225f3e6e 100644 --- a/libexec/rtld-elf/amd64/rtld_machdep.h +++ b/libexec/rtld-elf/amd64/rtld_machdep.h @@ -73,4 +73,7 @@ typedef struct { extern void *__tls_get_addr(tls_index *ti); +#define RTLD_DEFAULT_STACK_PF_EXEC PF_X +#define RTLD_DEFAULT_STACK_EXEC PROT_EXEC + #endif diff --git a/libexec/rtld-elf/arm/rtld_machdep.h b/libexec/rtld-elf/arm/rtld_machdep.h index 8364afa2e71..8a1b7869e3f 100644 --- a/libexec/rtld-elf/arm/rtld_machdep.h +++ b/libexec/rtld-elf/arm/rtld_machdep.h @@ -69,4 +69,7 @@ void _rtld_bind_start(void); extern void *__tls_get_addr(tls_index *ti); +#define RTLD_DEFAULT_STACK_PF_EXEC PF_X +#define RTLD_DEFAULT_STACK_EXEC PROT_EXEC + #endif diff --git a/libexec/rtld-elf/i386/rtld_machdep.h b/libexec/rtld-elf/i386/rtld_machdep.h index 9b3dcdf209d..7d121e4ca44 100644 --- a/libexec/rtld-elf/i386/rtld_machdep.h +++ b/libexec/rtld-elf/i386/rtld_machdep.h @@ -74,4 +74,7 @@ typedef struct { extern void *___tls_get_addr(tls_index *ti) __attribute__((__regparm__(1))); extern void *__tls_get_addr(tls_index *ti); +#define RTLD_DEFAULT_STACK_PF_EXEC PF_X +#define RTLD_DEFAULT_STACK_EXEC PROT_EXEC + #endif diff --git a/libexec/rtld-elf/ia64/rtld_machdep.h b/libexec/rtld-elf/ia64/rtld_machdep.h index 5af9602f764..c47b3090b8f 100644 --- a/libexec/rtld-elf/ia64/rtld_machdep.h +++ b/libexec/rtld-elf/ia64/rtld_machdep.h @@ -65,4 +65,7 @@ void call_initfini_pointer(const struct Struct_Obj_Entry *, Elf_Addr); extern void *__tls_get_addr(unsigned long module, unsigned long offset); +#define RTLD_DEFAULT_STACK_PF_EXEC 0 +#define RTLD_DEFAULT_STACK_EXEC 0 + #endif diff --git a/libexec/rtld-elf/map_object.c b/libexec/rtld-elf/map_object.c index 3f69e9b5d52..2b33862bc7f 100644 --- a/libexec/rtld-elf/map_object.c +++ b/libexec/rtld-elf/map_object.c @@ -101,7 +101,7 @@ map_object(int fd, const char *path, const struct stat *sb) phdyn = phinterp = phtls = NULL; phdr_vaddr = 0; segs = alloca(sizeof(segs[0]) * hdr->e_phnum); - stack_flags = PF_X | PF_R | PF_W; + stack_flags = RTLD_DEFAULT_STACK_PF_EXEC | PF_R | PF_W; while (phdr < phlimit) { switch (phdr->p_type) { diff --git a/libexec/rtld-elf/mips/rtld_machdep.h b/libexec/rtld-elf/mips/rtld_machdep.h index 8364afa2e71..8a1b7869e3f 100644 --- a/libexec/rtld-elf/mips/rtld_machdep.h +++ b/libexec/rtld-elf/mips/rtld_machdep.h @@ -69,4 +69,7 @@ void _rtld_bind_start(void); extern void *__tls_get_addr(tls_index *ti); +#define RTLD_DEFAULT_STACK_PF_EXEC PF_X +#define RTLD_DEFAULT_STACK_EXEC PROT_EXEC + #endif diff --git a/libexec/rtld-elf/powerpc/rtld_machdep.h b/libexec/rtld-elf/powerpc/rtld_machdep.h index bf589c5728f..4d0dad4ac4c 100644 --- a/libexec/rtld-elf/powerpc/rtld_machdep.h +++ b/libexec/rtld-elf/powerpc/rtld_machdep.h @@ -84,4 +84,7 @@ typedef struct { extern void *__tls_get_addr(tls_index* ti); +#define RTLD_DEFAULT_STACK_PF_EXEC PF_X +#define RTLD_DEFAULT_STACK_EXEC PROT_EXEC + #endif diff --git a/libexec/rtld-elf/powerpc64/rtld_machdep.h b/libexec/rtld-elf/powerpc64/rtld_machdep.h index 3c08ea59945..041efe09937 100644 --- a/libexec/rtld-elf/powerpc64/rtld_machdep.h +++ b/libexec/rtld-elf/powerpc64/rtld_machdep.h @@ -76,4 +76,7 @@ typedef struct { extern void *__tls_get_addr(tls_index* ti); +#define RTLD_DEFAULT_STACK_PF_EXEC PF_X +#define RTLD_DEFAULT_STACK_EXEC PROT_EXEC + #endif diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c index 8acbdc5a7fc..2ed7ea4a9d7 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -191,7 +191,7 @@ extern Elf_Dyn _DYNAMIC; int osreldate, pagesize; -static int stack_prot = PROT_READ | PROT_WRITE | PROT_EXEC; +static int stack_prot = PROT_READ | PROT_WRITE | RTLD_DEFAULT_STACK_EXEC; static int max_stack_flags; /* diff --git a/libexec/rtld-elf/sparc64/rtld_machdep.h b/libexec/rtld-elf/sparc64/rtld_machdep.h index a1610718ba1..3160391424b 100644 --- a/libexec/rtld-elf/sparc64/rtld_machdep.h +++ b/libexec/rtld-elf/sparc64/rtld_machdep.h @@ -65,4 +65,7 @@ typedef struct { extern void *__tls_get_addr(tls_index *ti); +#define RTLD_DEFAULT_STACK_PF_EXEC 0 +#define RTLD_DEFAULT_STACK_EXEC 0 + #endif