Submitted By: Robert Connolly <robert at linuxfromscratch dot org> (ashes)
Date: 2004-10-16
Initial Package Version: 2.3.4
Upstream Status: Rejected Upstream
Origin: http://csociety-ftp.ecn.purdue.edu/pub/gentoo-portage/ \
        sys-libs/glibc/files/2.3.3/glibc-2.3.3-dl_execstack-PaX-support.patch
Description: This is needed for Pax. http://pax.grsecurity.net/
This works on glibc-2.3.3 too.
Also see:
http://www.linuxfromscratch.org/hlfs/

diff -Nru glibc-2.3.3.old/sysdeps/unix/sysv/linux/dl-execstack.c glibc-2.3.3/sysdeps/unix/sysv/linux/dl-execstack.c
--- glibc-2.3.3.old/sysdeps/unix/sysv/linux/dl-execstack.c	2004-09-24 01:40:02.663710000 -0400
+++ glibc-2.3.3/sysdeps/unix/sysv/linux/dl-execstack.c	2004-09-24 01:54:55.883919888 -0400
@@ -56,11 +56,17 @@
 					__stack_prot) == 0, 1))
 	goto return_success;
 # if __ASSUME_PROT_GROWSUPDOWN == 0
-      if (errno == EINVAL)
+      if (errno == EINVAL) {
 	no_growsupdown = true;
-      else
+      } else {
+#  endif
+	if (errno == EACCES)		/* PAX is enabled */
+	  return 0;
+	else
+	  return errno;
+#  if __ASSUME_PROT_GROWSUPDOWN == 0
+      }
 # endif
-	return errno;
     }
 #endif
 
@@ -84,8 +90,11 @@
 	page -= size;
       else
 	{
-	  if (errno != ENOMEM)	/* Unexpected failure mode.  */
+	  if (errno == EACCES) {	/* PAX is enabled */
+	    return 0;
+	  } else if (errno != ENOMEM) {	/* Unexpected failure mode.  */
 	    return errno;
+	  }
 
 	  if (size == GLRO(dl_pagesize))
 	    /* We just tried to mprotect the top hole page and failed.
@@ -107,8 +116,11 @@
 	page += size;
       else
 	{
-	  if (errno != ENOMEM)	/* Unexpected failure mode.  */
+	  if (errno == EACCES) {	/* PAX is enabled */
+	    return 0;
+	  } else if (errno != ENOMEM) {	/* Unexpected failure mode.  */
 	    return errno;
+	  }
 
 	  if (size == GLRO(dl_pagesize))
 	    /* We just tried to mprotect the lowest hole page and failed.
