[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commits] r18717 - in /fsf/trunk/libc: ChangeLog NEWS elf/tst-execstack.c nptl/ChangeLog nptl/pthread_getattr_np.c



Author: eglibc
Date: Sat May 26 10:54:22 2012
New Revision: 18717

Log:
Import glibc-mainline for 2012-05-26

Modified:
    fsf/trunk/libc/ChangeLog
    fsf/trunk/libc/NEWS
    fsf/trunk/libc/elf/tst-execstack.c
    fsf/trunk/libc/nptl/ChangeLog
    fsf/trunk/libc/nptl/pthread_getattr_np.c

Modified: fsf/trunk/libc/ChangeLog
==============================================================================
--- fsf/trunk/libc/ChangeLog (original)
+++ fsf/trunk/libc/ChangeLog Sat May 26 10:54:22 2012
@@ -1,3 +1,10 @@
+2012-05-26  Siddhesh Poyarekar  <siddhesh@xxxxxxxxxx>
+
+	[BZ #12416]
+	* elf/tst-execstack.c: Include stackinfo.h.
+	(do_test): Adjust test case to ensure that pthread_getattr_np
+	behaviour remains the same after marking stack executable.
+
 2012-05-25  Joseph Myers  <joseph@xxxxxxxxxxxxxxxx>
 
 	* sysdeps/unix/sysv/linux/kernel-features.h

Modified: fsf/trunk/libc/NEWS
==============================================================================
--- fsf/trunk/libc/NEWS (original)
+++ fsf/trunk/libc/NEWS Sat May 26 10:54:22 2012
@@ -16,19 +16,19 @@
   6884, 6890, 6894, 6895, 6907, 6911, 6959, 7064, 9739, 9902, 10110, 10135,
   10140, 10153, 10210, 10254, 10346, 10375, 10545, 10716, 10846, 11174,
   11322, 11365, 11451, 11494, 11521, 11677, 11837, 11959, 12047, 12097,
-  12193, 12297, 12298, 12301, 12340, 12354, 12495, 13058, 13361, 13525,
-  13526, 13527, 13528, 13529, 13530, 13531, 13532, 13533, 13547, 13551,
-  13552, 13553, 13555, 13556, 13559, 13563, 13566, 13576, 13583, 13592,
-  13594, 13613, 13618, 13637, 13656, 13658, 13673, 13691, 13695, 13704,
-  13705, 13706, 13726, 13738, 13739, 13750, 13758, 13760, 13761, 13775,
-  13786, 13787, 13792, 13806, 13824, 13840, 13841, 13844, 13846, 13851,
-  13852, 13854, 13871, 13872, 13873, 13879, 13883, 13884, 13885, 13886,
-  13892, 13895, 13908, 13910, 13911, 13912, 13913, 13914, 13915, 13916,
-  13917, 13918, 13919, 13920, 13921, 13922, 13923, 13924, 13926, 13927,
-  13928, 13938, 13941, 13942, 13954, 13955, 13956, 13963, 13967, 13968,
-  13970, 13973, 13979, 13983, 13986, 14012, 14027, 14033, 14034, 14036,
-  14040, 14043, 14044, 14049, 14053, 14055, 14059, 14064, 14080, 14083,
-  14103, 14104, 14109, 14122, 14123, 14153
+  12193, 12297, 12298, 12301, 12340, 12354, 12416, 12495, 13058, 13361,
+  13525, 13526, 13527, 13528, 13529, 13530, 13531, 13532, 13533, 13547,
+  13551, 13552, 13553, 13555, 13556, 13559, 13563, 13566, 13576, 13583,
+  13592, 13594, 13613, 13618, 13637, 13656, 13658, 13673, 13691, 13695,
+  13704, 13705, 13706, 13726, 13738, 13739, 13750, 13758, 13760, 13761,
+  13775, 13786, 13787, 13792, 13806, 13824, 13840, 13841, 13844, 13846,
+  13851, 13852, 13854, 13871, 13872, 13873, 13879, 13883, 13884, 13885,
+  13886, 13892, 13895, 13908, 13910, 13911, 13912, 13913, 13914, 13915,
+  13916, 13917, 13918, 13919, 13920, 13921, 13922, 13923, 13924, 13926,
+  13927, 13928, 13938, 13941, 13942, 13954, 13955, 13956, 13963, 13967,
+  13968, 13970, 13973, 13979, 13983, 13986, 14012, 14027, 14033, 14034,
+  14036, 14040, 14043, 14044, 14049, 14053, 14055, 14059, 14064, 14080,
+  14083, 14103, 14104, 14109, 14122, 14123, 14153
 
 * ISO C11 support:
 

Modified: fsf/trunk/libc/elf/tst-execstack.c
==============================================================================
--- fsf/trunk/libc/elf/tst-execstack.c (original)
+++ fsf/trunk/libc/elf/tst-execstack.c Sat May 26 10:54:22 2012
@@ -7,6 +7,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <error.h>
+#include <stackinfo.h>
 
 static void
 print_maps (void)
@@ -45,7 +46,6 @@
   return 0;
 }
 #endif
-
 
 static bool allow_execstack = true;
 
@@ -107,6 +107,35 @@
 
   print_maps ();
 
+#if USE_PTHREADS
+  void *old_stack_addr, *new_stack_addr;
+  size_t stack_size;
+  pthread_t me = pthread_self ();
+  pthread_attr_t attr;
+  int ret = 0;
+
+  ret = pthread_getattr_np (me, &attr);
+  if (ret)
+    {
+      printf ("before execstack: pthread_getattr_np returned error: %s\n",
+	      strerror (ret));
+      return 1;
+    }
+
+  ret = pthread_attr_getstack (&attr, &old_stack_addr, &stack_size);
+  if (ret)
+    {
+      printf ("before execstack: pthread_attr_getstack returned error: %s\n",
+	      strerror (ret));
+      return 1;
+    }
+# if _STACK_GROWS_DOWN
+    old_stack_addr += stack_size;
+# else
+    old_stack_addr -= stack_size;
+# endif
+#endif
+
   /* Loading this module should force stacks to become executable.  */
   void *h = dlopen ("tst-execstack-mod.so", RTLD_LAZY);
   if (h == NULL)
@@ -128,6 +157,46 @@
   (*((void (*) (void)) f)) ();
 
   print_maps ();
+
+#if USE_PTHREADS
+  ret = pthread_getattr_np (me, &attr);
+  if (ret)
+    {
+      printf ("after execstack: pthread_getattr_np returned error: %s\n",
+	      strerror (ret));
+      return 1;
+    }
+
+  ret = pthread_attr_getstack (&attr, &new_stack_addr, &stack_size);
+  if (ret)
+    {
+      printf ("after execstack: pthread_attr_getstack returned error: %s\n",
+	      strerror (ret));
+      return 1;
+    }
+
+# if _STACK_GROWS_DOWN
+    new_stack_addr += stack_size;
+# else
+    new_stack_addr -= stack_size;
+# endif
+
+  /* It is possible that the dlopen'd module may have been mmapped just below
+     the stack.  The stack size is taken as MIN(stack rlimit size, end of last
+     vma) in pthread_getattr_np.  If rlimit is set high enough, it is possible
+     that the size may have changed.  A subsequent call to
+     pthread_attr_getstack returns the size and (bottom - size) as the
+     stacksize and stackaddr respectively.  If the size changes due to the
+     above, then both stacksize and stackaddr can change, but the stack bottom
+     should remain the same, which is computed as stackaddr + stacksize.  */
+  if (old_stack_addr != new_stack_addr)
+    {
+      printf ("Stack end changed, old: %p, new: %p\n",
+	      old_stack_addr, new_stack_addr);
+      return 1;
+    }
+  printf ("Stack address remains the same: %p\n", old_stack_addr);
+#endif
 
   /* Test that growing the stack region gets new executable pages too.  */
   deeper ((void (*) (void)) f);

Modified: fsf/trunk/libc/nptl/ChangeLog
==============================================================================
--- fsf/trunk/libc/nptl/ChangeLog (original)
+++ fsf/trunk/libc/nptl/ChangeLog Sat May 26 10:54:22 2012
@@ -1,3 +1,10 @@
+2012-05-26  Siddhesh Poyarekar  <siddhesh@xxxxxxxxxx>
+
+	[BZ #12416]
+	* nptl/pthread_getattr_np.c (pthread_getattr_np): Use
+	__libc_stack_end rounded to the end of containing page as the
+	real stack end.
+
 2012-05-25  Rayson Ho  <rho@xxxxxxxxxx>
 
 	* sysdeps/unix/sysv/linux/i386/lowlevellock.h: Low-level SystemTap

Modified: fsf/trunk/libc/nptl/pthread_getattr_np.c
==============================================================================
--- fsf/trunk/libc/nptl/pthread_getattr_np.c (original)
+++ fsf/trunk/libc/nptl/pthread_getattr_np.c Sat May 26 10:54:22 2012
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002-2004, 2006, 2007, 2011 Free Software Foundation, Inc.
+/* Copyright (C) 2002-2012 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@xxxxxxxxxx>, 2002.
 
@@ -84,6 +84,18 @@
 	    ret = errno;
 	  else
 	    {
+	      /* We consider the main process stack to have ended with
+	         the page containing __libc_stack_end.  There is stuff below
+		 it in the stack too, like the program arguments, environment
+		 variables and auxv info, but we ignore those pages when
+		 returning size so that the output is consistent when the
+		 stack is marked executable due to a loaded DSO requiring
+		 it.  */
+	      void *stack_end = (void *) ((uintptr_t) __libc_stack_end
+					  & -(uintptr_t) GLRO(dl_pagesize));
+#if _STACK_GROWS_DOWN
+	      stack_end += GLRO(dl_pagesize);
+#endif
 	      /* We need no locking.  */
 	      __fsetlocking (fp, FSETLOCKING_BYCALLER);
 
@@ -109,7 +121,7 @@
 		    {
 		      /* Found the entry.  Now we have the info we need.  */
 		      iattr->stacksize = rl.rlim_cur;
-		      iattr->stackaddr = (void *) to;
+		      iattr->stackaddr = stack_end;
 
 		      /* The limit might be too high.  */
 		      if ((size_t) iattr->stacksize

_______________________________________________
Commits mailing list
Commits@xxxxxxxxxx
http://eglibc.org/cgi-bin/mailman/listinfo/commits