From 2dd87703d4386f2776c5b5f375a494c91d7f9fe4 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Mon, 10 May 2021 10:31:41 +0200 Subject: nptl: Move changing of stack permissions into ld.so All the stack lists are now in _rtld_global, so it is possible to change stack permissions directly from there, instead of calling into libpthread to do the change. Tested-by: Carlos O'Donell Reviewed-by: Carlos O'Donell --- elf/dl-load.c | 4 ++++ elf/dl-support.c | 10 ++++------ elf/rtld.c | 2 ++ 3 files changed, 10 insertions(+), 6 deletions(-) (limited to 'elf') diff --git a/elf/dl-load.c b/elf/dl-load.c index 2832ab3540..918ec7546c 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -1368,7 +1368,11 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd, check_consistency (); #endif +#if PTHREAD_IN_LIBC + errval = _dl_make_stacks_executable (stack_endp); +#else errval = (*GL(dl_make_stack_executable_hook)) (stack_endp); +#endif if (errval) { errstring = N_("\ diff --git a/elf/dl-support.c b/elf/dl-support.c index 580b0202ad..dfc9ab760e 100644 --- a/elf/dl-support.c +++ b/elf/dl-support.c @@ -183,12 +183,6 @@ uint64_t _dl_hwcap_mask __attribute__ ((nocommon)); * executable but this isn't true for all platforms. */ ElfW(Word) _dl_stack_flags = DEFAULT_STACK_PERMS; -/* If loading a shared object requires that we make the stack executable - when it was not, we do it by calling this function. - It returns an errno code or zero on success. */ -int (*_dl_make_stack_executable_hook) (void **) = _dl_make_stack_executable; - - #if THREAD_GSCOPE_IN_TCB list_t _dl_stack_used; list_t _dl_stack_user; @@ -197,6 +191,10 @@ size_t _dl_stack_cache_actsize; uintptr_t _dl_in_flight_stack; int _dl_stack_cache_lock; #else +/* If loading a shared object requires that we make the stack executable + when it was not, we do it by calling this function. + It returns an errno code or zero on success. */ +int (*_dl_make_stack_executable_hook) (void **) = _dl_make_stack_executable; int _dl_thread_gscope_count; void (*_dl_init_static_tls) (struct link_map *) = &_dl_nothread_init_static_tls; #endif diff --git a/elf/rtld.c b/elf/rtld.c index 1255d5cc7d..fbbd60b446 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -1125,9 +1125,11 @@ dl_main (const ElfW(Phdr) *phdr, __tls_pre_init_tp (); +#if !PTHREAD_IN_LIBC /* The explicit initialization here is cheaper than processing the reloc in the _rtld_local definition's initializer. */ GL(dl_make_stack_executable_hook) = &_dl_make_stack_executable; +#endif /* Process the environment variable which control the behaviour. */ process_envvars (&state); -- cgit 1.4.1