]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
elf: early conversion of elf p_flags to mprotect flags
authorCupertino Miranda <cupertino.miranda@oracle.com>
Fri, 22 Aug 2025 10:37:00 +0000 (11:37 +0100)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 27 Aug 2025 13:45:45 +0000 (10:45 -0300)
This patch replaces _dl_stack_flags global variable by
_dl_stack_prot_flags.
The advantage is that any convertion from p_flags to final used mprotect
flags occurs at loading of p_flags. It avoids repeated spurious
convertions of _dl_stack_flags, for example in allocate_thread_stack.

This modification was suggested in:
  https://sourceware.org/pipermail/libc-alpha/2025-March/165537.html

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
30 files changed:
elf/Makefile
elf/dl-execstack-tunable.c
elf/dl-load.c
elf/dl-support.c
elf/rtld.c
include/alloca.h
include/stackinfo.h
nptl/allocatestack.c
support/support_stack_alloc.c
sysdeps/alpha/stackinfo.h
sysdeps/arm/stackinfo.h
sysdeps/generic/ldsodefs.h
sysdeps/generic/stackinfo.h
sysdeps/hppa/stackinfo.h
sysdeps/i386/stackinfo.h
sysdeps/m68k/stackinfo.h
sysdeps/mach/htl/pt-stack-alloc.c
sysdeps/mach/hurd/dl-execstack.c
sysdeps/mach/hurd/htl/pt-sysdep.c
sysdeps/microblaze/stackinfo.h
sysdeps/mips/stackinfo.h
sysdeps/or1k/stackinfo.h
sysdeps/powerpc/powerpc32/stackinfo.h
sysdeps/s390/stackinfo.h
sysdeps/sh/stackinfo.h
sysdeps/sparc/stackinfo.h
sysdeps/unix/sysv/linux/dl-execstack.c
sysdeps/unix/sysv/linux/machine-sp.h
sysdeps/unix/sysv/linux/spawni.c
sysdeps/x86_64/stackinfo.h

index 3a5596e2bbc9f8ff77cb30401d203b351c7bc28c..5a676f858d63a408d08d77a1cffe9aa1c947f6e2 100644 (file)
@@ -2167,7 +2167,7 @@ $(objpfx)execstack-default: $(first-word $(wildcard $(sysdirs:%=%/stackinfo.h)))
        $(make-target-directory)
        { echo '#include <elf.h>'; \
          echo '#include <stackinfo.h>'; \
-         echo '#if (DEFAULT_STACK_PERMS & PF_X) == 0'; \
+         echo '#if (DEFAULT_STACK_PROT_PERMS & PROT_EXEC) == 0'; \
          echo '@@@execstack-no@@@'; \
          echo '#else'; \
          echo '@@@execstack-yes@@@'; \
index e3b638aeaaad467c487be8e958181c350a72a7db..b2511ea0312dcdb5d901d57a61f5c70327feddb8 100644 (file)
@@ -25,7 +25,7 @@ _dl_handle_execstack_tunable (void)
   switch (TUNABLE_GET (glibc, rtld, execstack, int32_t, NULL))
     {
     case stack_tunable_mode_disable:
-      if ((__glibc_unlikely (GL(dl_stack_flags)) & PF_X))
+      if ((__glibc_unlikely (GL(dl_stack_prot_flags)) & PROT_EXEC))
        _dl_fatal_printf (
 "Fatal glibc error: executable stack is not allowed\n");
       break;
index 00b9da9ec741bef32cadb2c5d168eaafdef95ac4..891b44966c524b7f8cd1c14e3f8abab15bba1fa8 100644 (file)
@@ -1095,7 +1095,7 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
    /* On most platforms presume that PT_GNU_STACK is absent and the stack is
     * executable.  Other platforms default to a nonexecutable stack and don't
     * need PT_GNU_STACK to do so.  */
-   unsigned int stack_flags = DEFAULT_STACK_PERMS;
+   unsigned int stack_flags = DEFAULT_STACK_PROT_PERMS;
 
   {
     /* Scan the program header table, collecting its load commands.  */
@@ -1170,18 +1170,7 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
          DIAG_POP_NEEDS_COMMENT;
 
          /* Optimize a common case.  */
-#if (PF_R | PF_W | PF_X) == 7 && (PROT_READ | PROT_WRITE | PROT_EXEC) == 7
-         c->prot = (PF_TO_PROT
-                    >> ((ph->p_flags & (PF_R | PF_W | PF_X)) * 4)) & 0xf;
-#else
-         c->prot = 0;
-         if (ph->p_flags & PF_R)
-           c->prot |= PROT_READ;
-         if (ph->p_flags & PF_W)
-           c->prot |= PROT_WRITE;
-         if (ph->p_flags & PF_X)
-           c->prot |= PROT_EXEC;
-#endif
+         c->prot = pf_to_prot (ph->p_flags);
          break;
 
        case PT_TLS:
@@ -1218,7 +1207,7 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
          break;
 
        case PT_GNU_STACK:
-         stack_flags = ph->p_flags;
+         stack_flags = pf_to_prot (ph->p_flags);
          break;
 
        case PT_GNU_RELRO:
@@ -1318,7 +1307,7 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
     /* Adjust the PT_PHDR value by the runtime load address.  */
     l->l_phdr = (ElfW(Phdr) *) ((ElfW(Addr)) l->l_phdr + l->l_addr);
 
-  if (__glibc_unlikely ((stack_flags &~ GL(dl_stack_flags)) & PF_X))
+  if (__glibc_unlikely ((stack_flags &~ GL(dl_stack_prot_flags)) & PROT_EXEC))
     {
       /* The stack is presently not executable, but this module
         requires that it be executable.  Only tries to change the
index 7b2a1c35d53786f57bf4b432e3e2bca1e850fe6b..bbef3ab6b6462caab38d592e6f2e55fe105840d3 100644 (file)
@@ -166,9 +166,8 @@ enum dso_sort_algorithm _dl_dso_sort_algo;
 /* The value of the FPU control word the kernel will preset in hardware.  */
 fpu_control_t _dl_fpu_control = _FPU_DEFAULT;
 
-/* Prevailing state of the stack.  Generally this includes PF_X, indicating it's
- * executable but this isn't true for all platforms.  */
-ElfW(Word) _dl_stack_flags = DEFAULT_STACK_PERMS;
+/* Required flags used for stack allocation.  */
+int _dl_stack_prot_flags = DEFAULT_STACK_PROT_PERMS;
 
 #if PTHREAD_IN_LIBC
 list_t _dl_stack_used;
@@ -322,7 +321,7 @@ _dl_non_dynamic_init (void)
       {
       /* Check if the stack is nonexecutable.  */
       case PT_GNU_STACK:
-       _dl_stack_flags = ph->p_flags;
+       _dl_stack_prot_flags = pf_to_prot (ph->p_flags);
        break;
 
       case PT_GNU_RELRO:
index ef4d96c053f5e75b3e727fb36063370fa66829e7..753ce6690ba5f0bfaa87308ae342ac6703d9abed 100644 (file)
@@ -322,7 +322,7 @@ struct rtld_global _rtld_global =
 #include <dl-procruntime.c>
     /* Generally the default presumption without further information is an
      * executable stack but this is not true for all platforms.  */
-    ._dl_stack_flags = DEFAULT_STACK_PERMS,
+    ._dl_stack_prot_flags = DEFAULT_STACK_PROT_PERMS,
 #ifdef _LIBC_REENTRANT
     ._dl_load_lock = _RTLD_LOCK_RECURSIVE_INITIALIZER,
     ._dl_load_write_lock = _RTLD_LOCK_RECURSIVE_INITIALIZER,
@@ -1197,7 +1197,7 @@ rtld_setup_main_map (struct link_map *main_map)
        break;
 
       case PT_GNU_STACK:
-       GL(dl_stack_flags) = ph->p_flags;
+       GL(dl_stack_prot_flags) = pf_to_prot (ph->p_flags);
        break;
 
       case PT_GNU_RELRO:
@@ -1541,12 +1541,12 @@ dl_main (const ElfW(Phdr) *phdr,
       --_dl_argc;
       ++_dl_argv;
 
-      /* The initialization of _dl_stack_flags done below assumes the
+      /* The initialization of dl_stack_prot_flags done below assumes the
         executable's PT_GNU_STACK may have been honored by the kernel, and
         so a PT_GNU_STACK with PF_X set means the stack started out with
         execute permission.  However, this is not really true if the
         dynamic linker is the executable the kernel loaded.  For this
-        case, we must reinitialize _dl_stack_flags to match the dynamic
+        case, we must reinitialize dl_stack_prot_flags to match the dynamic
         linker itself.  If the dynamic linker was built with a
         PT_GNU_STACK, then the kernel may have loaded us with a
         nonexecutable stack that we will have to make executable when we
@@ -1556,7 +1556,7 @@ dl_main (const ElfW(Phdr) *phdr,
       for (const ElfW(Phdr) *ph = phdr; ph < &phdr[phnum]; ++ph)
        if (ph->p_type == PT_GNU_STACK)
          {
-           GL(dl_stack_flags) = ph->p_flags;
+           GL(dl_stack_prot_flags) = pf_to_prot (ph->p_flags);
            break;
          }
 
@@ -1677,8 +1677,6 @@ dl_main (const ElfW(Phdr) *phdr,
 
   bool has_interp = rtld_setup_main_map (main_map);
 
-  /* Handle this after PT_GNU_STACK parse, because it updates dl_stack_flags
-     if required.  */
   _dl_handle_execstack_tunable ();
 
   /* If the current libname is different from the SONAME, add the
index c0b83954436ed4c1e7c3246e914bc36ac1606dd9..5f2df32b46252a4fb33f2b7800889733b001e502 100644 (file)
@@ -4,7 +4,7 @@
 
 # ifndef _ISOMAC
 
-#include <stackinfo.h>
+#include <elf.h>
 
 #undef __alloca
 
index 3c1541b42d39f6fe429ec39fc8477559ce155c90..3cf36c9b1d881ff7470b43ac0b57582628be7372 100644 (file)
 # error "stackinfo.h must define _STACK_GROWS_UP or _STACK_GROWS_DOWN!"
 #endif
 
+#include <sys/mman.h>
+#include <link.h>
+
+/* ELF uses the PF_x macros to specify the segment permissions, mmap
+   uses PROT_xxx.  In most cases the three macros have the values 1, 2,
+   and 4 but not in a matching order.  The following macros allows
+   converting from the PF_x values to PROT_xxx values.  */
+#define PF_TO_PROT \
+  ((PROT_READ << (PF_R * 4))                                                 \
+   | (PROT_WRITE << (PF_W * 4))                                                      \
+   | (PROT_EXEC << (PF_X * 4))                                               \
+   | ((PROT_READ | PROT_WRITE) << ((PF_R | PF_W) * 4))                       \
+   | ((PROT_READ | PROT_EXEC) << ((PF_R | PF_X) * 4))                        \
+   | ((PROT_WRITE | PROT_EXEC) << (PF_W | PF_X) * 4)                         \
+   | ((PROT_READ | PROT_WRITE | PROT_EXEC) << ((PF_R | PF_W | PF_X) * 4)))
+
+static inline int
+pf_to_prot (ElfW(Word) value)
+{
+#if (PF_R | PF_W | PF_X) == 7 && (PROT_READ | PROT_WRITE | PROT_EXEC) == 7
+  return (PF_TO_PROT >> ((value & (PF_R | PF_W | PF_X)) * 4)) & 0xf;
+#else
+  ElfW(Word) ret = 0;
+  if (value & PF_R)
+    ret |= PROT_READ;
+  if (value & PF_W)
+    ret |= PROT_WRITE;
+  if (value & PF_X)
+    ret |= PROT_EXEC;
+  return ret;
+#endif
+
+}
+
 #endif  /* include/stackinfo.h */
index 800ca89720d6278c3fd2f27d1dc6fc907d5b6f03..4c2aacdd10153e8a1728c98687e40b09722c445d 100644 (file)
@@ -150,17 +150,11 @@ get_cached_stack (size_t *sizep, void **memp)
    and fallback to ALLOCATE_GUARD_PROT_NONE if the madvise call fails.  */
 static int allocate_stack_mode = ALLOCATE_GUARD_MADV_GUARD;
 
-static inline int stack_prot (void)
-{
-  return (PROT_READ | PROT_WRITE
-         | ((GL(dl_stack_flags) & PF_X) ? PROT_EXEC : 0));
-}
-
 static void *
 allocate_thread_stack (size_t size, size_t guardsize)
 {
   /* MADV_ADVISE_GUARD does not require an additional PROT_NONE mapping.  */
-  int prot = stack_prot ();
+  int prot = GL(dl_stack_prot_flags);
 
   if (atomic_load_relaxed (&allocate_stack_mode) == ALLOCATE_GUARD_PROT_NONE)
     /* If a guard page is required, avoid committing memory by first allocate
@@ -216,7 +210,7 @@ setup_stack_prot (char *mem, size_t size, struct pthread *pd,
     }
   else
     {
-      const int prot = stack_prot ();
+      const int prot = GL(dl_stack_prot_flags);
       char *guardend = guard + guardsize;
 #if _STACK_GROWS_DOWN
       /* As defined at guard_position, for architectures with downward stack
@@ -294,7 +288,7 @@ adjust_stack_prot (char *mem, size_t size, const struct pthread *pd,
        }
       else if (pd->stack_mode == ALLOCATE_GUARD_PROT_NONE)
        {
-         const int prot = stack_prot ();
+         const int prot = GL(dl_stack_prot_flags);
 #if _STACK_GROWS_DOWN
          return __mprotect (mem + guardsize, slacksize, prot) == 0;
 #else
index 5e576bea74cd28d614f19f5af6627560cb498efe..132e7b4f70cf7158c9fcd24f80c0abd8fbce0193 100644 (file)
@@ -64,11 +64,10 @@ support_stack_alloc (size_t size)
                             MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE|MAP_STACK,
                             -1);
   /* Some architecture still requires executable stack for the signal return
-     trampoline, although PF_X could be overridden if PT_GNU_STACK is present.
-     However since glibc does not export such information with a proper ABI,
-     it uses the historical permissions.  */
-  int prot = PROT_READ | PROT_WRITE
-            | (DEFAULT_STACK_PERMS & PF_X ? PROT_EXEC : 0);
+     trampoline, although PROT_EXEC could be overridden if PT_GNU_STACK is
+     present.  However since glibc does not export such information with a
+     proper ABI, it uses the historical permissions.  */
+  int prot = DEFAULT_STACK_PROT_PERMS;
   xmprotect (alloc_base + guardsize, stacksize, prot);
   memset (alloc_base + guardsize, 0xA5, stacksize);
   return (struct support_stack) { alloc_base + guardsize, stacksize, guardsize };
index a469964c1079b50086b5e12c4b9ee860127bc669..d69647756b50439801956d165ec1faa11e370d18 100644 (file)
@@ -26,8 +26,8 @@
 /* On Alpha the stack grows down.  */
 #define _STACK_GROWS_DOWN      1
 
-/* Default to an executable stack.  PF_X can be overridden if PT_GNU_STACK is
- * present, but it is presumed absent.  */
-#define DEFAULT_STACK_PERMS (PF_R|PF_W|PF_X)
+/* Default to an executable stack.  PROT_EXEC can be overridden if PT_GNU_STACK
+ * is present, but it is presumed absent.  */
+#define DEFAULT_STACK_PROT_PERMS (PROT_READ|PROT_WRITE|PROT_EXEC)
 
 #endif /* stackinfo.h */
index 3068352eabe62c145d800ed156c1cc1f0bc1ae68..30608f706259eda3095c594bbb4d0da4f2c113bf 100644 (file)
@@ -26,8 +26,8 @@
 /* On Arm the stack grows down.  */
 #define _STACK_GROWS_DOWN      1
 
-/* Default to an executable stack.  PF_X can be overridden if PT_GNU_STACK is
- * present, but it is presumed absent.  */
-#define DEFAULT_STACK_PERMS (PF_R|PF_W|PF_X)
+/* Default to an executable stack.  PROT_EXEC can be overridden if PT_GNU_STACK
+ * is present, but it is presumed absent.  */
+#define DEFAULT_STACK_PROT_PERMS (PROT_READ|PROT_WRITE|PROT_EXEC)
 
 #endif /* stackinfo.h */
index 74025f1f93ff934ee3eaae8e87e4d509f76f30d1..31e9a6b60079394d477a4e1a45ab636738a14807 100644 (file)
@@ -171,19 +171,6 @@ dl_symbol_visibility_binds_local_p (const ElfW(Sym) *sym)
 # define ELF_RTYPE_CLASS_COPY 0
 #endif
 
-/* ELF uses the PF_x macros to specify the segment permissions, mmap
-   uses PROT_xxx.  In most cases the three macros have the values 1, 2,
-   and 3 but not in a matching order.  The following macros allows
-   converting from the PF_x values to PROT_xxx values.  */
-#define PF_TO_PROT \
-  ((PROT_READ << (PF_R * 4))                                                 \
-   | (PROT_WRITE << (PF_W * 4))                                                      \
-   | (PROT_EXEC << (PF_X * 4))                                               \
-   | ((PROT_READ | PROT_WRITE) << ((PF_R | PF_W) * 4))                       \
-   | ((PROT_READ | PROT_EXEC) << ((PF_R | PF_X) * 4))                        \
-   | ((PROT_WRITE | PROT_EXEC) << (PF_W | PF_X) * 4)                         \
-   | ((PROT_READ | PROT_WRITE | PROT_EXEC) << ((PF_R | PF_W | PF_X) * 4)))
-
 /* The filename itself, or the main program name, if available.  */
 #define DSO_FILENAME(name) ((name)[0] ? (name)                               \
                            : (rtld_progname ?: "<main program>"))
@@ -416,7 +403,7 @@ struct rtld_global
 #include <dl-procruntime.c>
 
   /* Prevailing state of the stack, PF_X indicating it's executable.  */
-  EXTERN ElfW(Word) _dl_stack_flags;
+  EXTERN int _dl_stack_prot_flags;
 
   /* Flag signalling whether there are gaps in the module ID allocation.  */
   EXTERN bool _dl_tls_dtv_gaps;
index 8abbb3dff755defbd073eb6e720033aa1069f501..ab3e72e5c252d7ffe63448736025e0a898a194d8 100644 (file)
@@ -24,6 +24,6 @@
 #include <elf.h>
 
 #define _STACK_GROWS_DOWN      1
-#define DEFAULT_STACK_PERMS    (PF_R|PF_W)
+#define DEFAULT_STACK_PROT_PERMS (PROT_READ|PROT_WRITE)
 
 #endif
index 53bb11fde07b4e3ff342265b3da025bfafcaabb1..22920d20a90675a72521072ec2bbef95e7e099b6 100644 (file)
@@ -23,9 +23,9 @@
 
 #include <elf.h>
 
-/* Default to an executable stack.  PF_X can be overridden if PT_GNU_STACK is
- * present, but it is presumed absent.  */
-#define DEFAULT_STACK_PERMS (PF_R|PF_W|PF_X)
+/* Default to an executable stack.  PROT_EXEC can be overridden if PT_GNU_STACK
+ * is present, but it is presumed absent.  */
+#define DEFAULT_STACK_PROT_PERMS (PROT_READ|PROT_WRITE|PROT_EXEC)
 
 /* On PA the stack grows up.  */
 #define _STACK_GROWS_UP        1
index 74e82278d3f92a79bc9a30dc8a59bfa2fdff8dea..8d7a46c405467acd42a2de9d22225da6848b95d5 100644 (file)
@@ -26,9 +26,9 @@
 /* On x86 the stack grows down.  */
 #define _STACK_GROWS_DOWN      1
 
-/* Default to an executable stack.  PF_X can be overridden if PT_GNU_STACK is
- * present, but it is presumed absent.  */
-#define DEFAULT_STACK_PERMS (PF_R|PF_W|PF_X)
+/* Default to an executable stack.  PROT_EXEC can be overridden if PT_GNU_STACK
+ * is present, but it is presumed absent.  */
+#define DEFAULT_STACK_PROT_PERMS (PROT_READ|PROT_WRITE|PROT_EXEC)
 
 /* Access to the stack pointer.  The macros are used in alloca_account
    for which they need to act as barriers as well, hence the additional
index 7a757df14782d65f453534260267a3f13c5afbc4..74c0af55636a25a73435ededb5778448e256f850 100644 (file)
@@ -26,9 +26,9 @@
 /* On m68k the stack grows down.  */
 #define _STACK_GROWS_DOWN      1
 
-/* Default to an executable stack.  PF_X can be overridden if PT_GNU_STACK
+/* Default to an executable stack.  PROT_EXEC can be overridden if PT_GNU_STACK
    is present, but it is presumed absent.  */
-#define DEFAULT_STACK_PERMS (PF_R|PF_W|PF_X)
+#define DEFAULT_STACK_PROT_PERMS (PROT_READ|PROT_WRITE|PROT_EXEC)
 
 /* Access to the stack pointer.  */
 #define stackinfo_get_sp() \
index 64cc18657ef569e828723d6ea3d98a844611e0a9..d9f3e24ca12bf0a6ddaa9d179cd784ca7a4f02ef 100644 (file)
@@ -34,7 +34,7 @@ __pthread_stack_alloc (void **stackaddr, size_t stacksize)
   error_t err;
   vm_prot_t prot = VM_PROT_READ | VM_PROT_WRITE;
 
-  if (GL(dl_stack_flags) & PF_X)
+  if (GL(dl_stack_prot_flags) & PROT_EXEC)
     prot |= VM_PROT_EXECUTE;
 
   err = __vm_map (__mach_task_self (), (vm_offset_t *) stackaddr,
index dc4719bd38b9b0f56c546c6fbb83e7c3d809878e..9e691693678dce40f8360074aab3f4d8c0d4681a 100644 (file)
@@ -38,7 +38,7 @@ _dl_make_stack_executable (const void *stack_endp)
     return errno;
 
   /* Remember that we changed the permission.  */
-  GL(dl_stack_flags) |= PF_X;
+  GL(dl_stack_prot_flags) |= PROT_EXEC;
 
   return 0;
 #else
index 3505d31beeeda9d0bdeedacf4fc19076b63f3c3f..735dc5b68dd68d958be61f481594c1a64308278d 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <pt-internal.h>
 #include <pthreadP.h>
+#include <stackinfo.h>
 
 static void
 reset_pthread_total (void)
index 8960bd3d25bd508977092139db9e14717269bc09..51d40a773219a27bf559624e2f3ac74dfd3f8b3c 100644 (file)
@@ -27,8 +27,8 @@
 /* On MicroBlaze the stack grows down.  */
 # define _STACK_GROWS_DOWN     1
 
-/* Default to an executable stack.  PF_X can be overridden if PT_GNU_STACK is
- * present, but it is presumed absent.  */
-# define DEFAULT_STACK_PERMS (PF_R|PF_W|PF_X)
+/* Default to an executable stack.  PROT_EXEC can be overridden if PT_GNU_STACK
+ * is present, but it is presumed absent.  */
+#define DEFAULT_STACK_PROT_PERMS (PROT_READ|PROT_WRITE|PROT_EXEC)
 
 #endif /* stackinfo.h.  */
index 6cce9386d6defdab0623af1ccc4db7adadd92873..107a8ea7c97a98280ae2d015734e1518c8ae11a8 100644 (file)
@@ -26,8 +26,8 @@
 /* On MIPS the stack grows down.  */
 #define _STACK_GROWS_DOWN      1
 
-/* Default to an executable stack.  PF_X can be overridden if PT_GNU_STACK is
- * present, but it is presumed absent.  */
-#define DEFAULT_STACK_PERMS (PF_R|PF_W|PF_X)
+/* Default to an executable stack.  PROT_EXEC can be overridden if PT_GNU_STACK
+ * is present, but it is presumed absent.  */
+#define DEFAULT_STACK_PROT_PERMS (PROT_READ|PROT_WRITE|PROT_EXEC)
 
 #endif /* stackinfo.h */
index 39cf5c245601bfbc5a60e4680ecf754bf9929310..10a56c57f7d5e5e5631aa20d0c0d66cbcf9eeee1 100644 (file)
@@ -27,8 +27,8 @@
 /* On or1k the stack grows down.  */
 #define _STACK_GROWS_DOWN      1
 
-/* Default to an executable stack.  PF_X can be overridden if PT_GNU_STACK is
-   present, but it is presumed absent.  */
-#define DEFAULT_STACK_PERMS (PF_R | PF_W | PF_X)
+/* Default to an executable stack.  PROT_EXEC can be overridden if PT_GNU_STACK
+   is present, but it is presumed absent.  */
+#define DEFAULT_STACK_PROT_PERMS (PROT_READ|PROT_WRITE|PROT_EXEC)
 
 #endif /* stackinfo.h */
index 31cba55805b430156529495ab4914986131cd856..327e61444587c6f1a352a763ea77ff97c1f85957 100644 (file)
@@ -26,7 +26,8 @@
 /* On PPC the stack grows down.  */
 #define _STACK_GROWS_DOWN      1
 
-/* PF_X can be overridden if PT_GNU_STACK is present but is presumed absent.  */
-#define DEFAULT_STACK_PERMS (PF_R|PF_W|PF_X)
+/* PROT_EXEC can be overridden if PT_GNU_STACK is present but is presumed
+   absent.  */
+#define DEFAULT_STACK_PROT_PERMS (PROT_READ|PROT_WRITE|PROT_EXEC)
 
 #endif /* stackinfo.h */
index 657ab3487fb9ea21c2e7cc78d40ca5dbaee6b8b9..9be764495a9b55b0ecc145dde523f0c9107dd73c 100644 (file)
@@ -26,8 +26,8 @@
 /* On s390 the stack grows down.  */
 #define _STACK_GROWS_DOWN      1
 
-/* Default to an executable stack.  PF_X can be overridden if PT_GNU_STACK is
- * present, but it is presumed absent.  */
-#define DEFAULT_STACK_PERMS (PF_R|PF_W|PF_X)
+/* Default to an executable stack.  PROT_EXEC can be overridden if PT_GNU_STACK
+ * is present, but it is presumed absent.  */
+#define DEFAULT_STACK_PROT_PERMS (PROT_READ|PROT_WRITE|PROT_EXEC)
 
 #endif /* stackinfo.h */
index 8f7bf163be25f7ef190138bf1899a1dafd354967..e502993d244669278a848e4f39d0054dcc1a2bb5 100644 (file)
@@ -26,8 +26,8 @@
 /* On SH the stack grows down.  */
 #define _STACK_GROWS_DOWN      1
 
-/* Default to an executable stack.  PF_X can be overridden if PT_GNU_STACK is
- * present, but it is presumed absent.  */
-#define DEFAULT_STACK_PERMS (PF_R|PF_W|PF_X)
+/* Default to an executable stack.  PROT_EXEC can be overridden if PT_GNU_STACK
+ * is present, but it is presumed absent.  */
+#define DEFAULT_STACK_PROT_PERMS (PROT_READ|PROT_WRITE|PROT_EXEC)
 
 #endif /* stackinfo.h */
index 23a74ed7fe78a5f97ee12289d1f765735b1941e6..a4a0eb15c9f1e3ec847c6dd2541cea68f957af00 100644 (file)
@@ -26,8 +26,8 @@
 /* On sparc the stack grows down.  */
 #define _STACK_GROWS_DOWN      1
 
-/* Default to an executable stack.  PF_X can be overridden if PT_GNU_STACK is
- * present, but it is presumed absent.  */
-#define DEFAULT_STACK_PERMS (PF_R|PF_W|PF_X)
+/* Default to an executable stack.  PROT_EXEC can be overridden if PT_GNU_STACK
+ * is present, but it is presumed absent.  */
+#define DEFAULT_STACK_PROT_PERMS (PROT_READ|PROT_WRITE|PROT_EXEC)
 
 #endif /* stackinfo.h */
index 6db96016568520ceeedfd0366a1002e9c59551fa..a59bd5632a5cf70acaa8348c8d836033fe629fbd 100644 (file)
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <ldsodefs.h>
+#include <stackinfo.h>
 
 int
 _dl_make_stack_executable (const void *stack_endp)
@@ -36,7 +37,7 @@ _dl_make_stack_executable (const void *stack_endp)
     return errno;
 
   /* Remember that we changed the permission.  */
-  GL(dl_stack_flags) |= PF_X;
+  GL(dl_stack_prot_flags) |= PROT_EXEC;
 
   return 0;
 }
index 6ab3ca6d50e1790838234d4e4e3d04f552a329a8..bda90fe801e930250ae78be41f295ed2b8c64b0d 100644 (file)
@@ -19,6 +19,8 @@
 #ifndef _MACHINE_SP_H
 #define _MACHINE_SP_H
 
+#include <stackinfo.h>
+
 /* Return the current stack pointer.  */
 static inline uintptr_t
 __thread_stack_pointer (void)
index eca1a84254fa2ffa48478bc2ffd3e63542fa4da8..bc8476ff116f6030665383829a9c51facca72c73 100644 (file)
@@ -348,9 +348,6 @@ __spawnix (int *pid, const char *file,
        return errno;
       }
 
-  int prot = (PROT_READ | PROT_WRITE
-            | ((GL (dl_stack_flags) & PF_X) ? PROT_EXEC : 0));
-
   /* Add a slack area for child's stack.  */
   size_t argv_size = (argc * sizeof (void *)) + 512;
   /* We need at least a few pages in case the compiler's stack checking is
@@ -361,7 +358,7 @@ __spawnix (int *pid, const char *file,
      where it might use about 1k extra stack space).  */
   argv_size += (32 * 1024);
   size_t stack_size = ALIGN_UP (argv_size, GLRO(dl_pagesize));
-  void *stack = __mmap (NULL, stack_size, prot,
+  void *stack = __mmap (NULL, stack_size, GL (dl_stack_prot_flags),
                        MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0);
   if (__glibc_unlikely (stack == MAP_FAILED))
     return errno;
index 416d687869942f067c46187b3ea422f94ed0b586..0e88e6d94e773be0500ad3945e26d7a37078962a 100644 (file)
@@ -32,9 +32,9 @@
 /* On x86_64 the stack grows down.  */
 #define _STACK_GROWS_DOWN      1
 
-/* Default to an executable stack.  PF_X can be overridden if PT_GNU_STACK is
- * present, but it is presumed absent.  */
-#define DEFAULT_STACK_PERMS (PF_R|PF_W|PF_X)
+/* Default to an executable stack.  PROT_EXEC can be overridden if PT_GNU_STACK
+ * is present, but it is presumed absent.  */
+#define DEFAULT_STACK_PROT_PERMS (PROT_READ|PROT_WRITE|PROT_EXEC)
 
 /* Access to the stack pointer.  The macros are used in alloca_account
    for which they need to act as barriers as well, hence the additional