[Bug dynamic-link/32897] pthread_getattr_np fails with executable stack
adhemerval.zanella at linaro dot org
sourceware-bugzilla@sourceware.org
Wed Apr 23 16:10:32 GMT 2025
https://sourceware.org/bugzilla/show_bug.cgi?id=32897
--- Comment #4 from Adhemerval Zanella <adhemerval.zanella at linaro dot org> ---
(In reply to Luke Drummond from comment #2)
> git bisect is pointing its finger at
> 12a497c716f0a06be5946cabb8c3ec22a079771e. I'll see if I can understand
> what's going on there
So previously make_main_stack_executable clear the stack_endp which pointers to
a temporary variable created before the call of _dl_map_object_from_fd
_dl_map_object; while now we use the __libc_stack_end directly.
I think there is no need to clear the value and I am not sure why the original
code did (since it was always used on temporary value and it was not checked
after the _dl_map_object call anyway).
Does this fix it:
diff --git a/elf/dl-execstack-tunable.c b/elf/dl-execstack-tunable.c
index 6cef1a3036..e3b638aeaa 100644
--- a/elf/dl-execstack-tunable.c
+++ b/elf/dl-execstack-tunable.c
@@ -31,7 +31,7 @@ _dl_handle_execstack_tunable (void)
break;
case stack_tunable_mode_force:
- if (_dl_make_stack_executable (&__libc_stack_end) != 0)
+ if (_dl_make_stack_executable (__libc_stack_end) != 0)
_dl_fatal_printf (
"Fatal glibc error: cannot enable executable stack as tunable requires");
break;
diff --git a/elf/dl-execstack.c b/elf/dl-execstack.c
index e4d7dbe7f8..ceec5b2def 100644
--- a/elf/dl-execstack.c
+++ b/elf/dl-execstack.c
@@ -23,7 +23,7 @@
so as to mprotect it. */
int
-_dl_make_stack_executable (void **stack_endp)
+_dl_make_stack_executable (const void *stack_endp)
{
return ENOSYS;
}
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index b5d5b3106c..fc4a3de767 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -733,7 +733,7 @@ void _dl_handle_execstack_tunable (void) attribute_hidden;
/* This function changes the permission of the memory region pointed
by STACK_ENDP to executable and update the internal memory protection
flags for future thread stack creation. */
-int _dl_make_stack_executable (void **stack_endp) attribute_hidden;
+int _dl_make_stack_executable (const void *stack_endp) attribute_hidden;
/* Variable pointing to the end of the stack (or close to it). This value
must be constant over the runtime of the application. Some programs
diff --git a/sysdeps/mach/hurd/dl-execstack.c
b/sysdeps/mach/hurd/dl-execstack.c
index 0617d3a161..158908ff0d 100644
--- a/sysdeps/mach/hurd/dl-execstack.c
+++ b/sysdeps/mach/hurd/dl-execstack.c
@@ -26,12 +26,11 @@ extern struct hurd_startup_data *_dl_hurd_data
attribute_hidden;
so as to mprotect it. */
int
-_dl_make_stack_executable (void **stack_endp)
+_dl_make_stack_executable (const void *stack_endp)
{
/* Challenge the caller. */
- if (__builtin_expect (*stack_endp != __libc_stack_end, 0))
+ if (__builtin_expect (stack_endp != __libc_stack_end, 0))
return EPERM;
- *stack_endp = NULL;
#if IS_IN (rtld)
if (__mprotect ((void *)_dl_hurd_data->stack_base,
_dl_hurd_data->stack_size,
diff --git a/sysdeps/unix/sysv/linux/dl-execstack.c
b/sysdeps/unix/sysv/linux/dl-execstack.c
index 9791b339ca..6db9601656 100644
--- a/sysdeps/unix/sysv/linux/dl-execstack.c
+++ b/sysdeps/unix/sysv/linux/dl-execstack.c
@@ -19,10 +19,10 @@
#include <ldsodefs.h>
int
-_dl_make_stack_executable (void **stack_endp)
+_dl_make_stack_executable (const void *stack_endp)
{
/* This gives us the highest/lowest page that needs to be changed. */
- uintptr_t page = ((uintptr_t) *stack_endp
+ uintptr_t page = ((uintptr_t) stack_endp
& -(intptr_t) GLRO(dl_pagesize));
if (__mprotect ((void *) page, GLRO(dl_pagesize),
@@ -35,9 +35,6 @@ _dl_make_stack_executable (void **stack_endp)
) != 0)
return errno;
- /* Clear the address. */
- *stack_endp = NULL;
-
/* Remember that we changed the permission. */
GL(dl_stack_flags) |= PF_X;
?
--
You are receiving this mail because:
You are on the CC list for the bug.
More information about the Glibc-bugs
mailing list