Blame SOURCES/autofs-5.1.2-add-congigure-option-for-limiting-getgrgid_r-stack-usage.patch

304803
autofs-5.1.2 - add congigure option for limiting getgrgid_r() stack usage
304803
304803
From: Ian Kent <raven@themaw.net>
304803
304803
Almost all the time it isn't a problem for glibc to use stack allocation
304803
to store group information during calls to getgrgid_r().
304803
304803
But if it is a problem the --enable-limit-getgrgid-size configure option
304803
can be used to limit the buffer size passed to getgrgid_r() (which is used
304803
to decide whether to alloca() local storage for the call).
304803
304803
The check allows the call to go ahead if the increased buffer size is less
304803
than 0.9 of the thread stack size.
304803
304803
This isn't ideal because the current stack usage isn't known but should
304803
be ok much of the time.
304803
304803
Signed-off-by: Ian Kent <raven@themaw.net>
304803
---
304803
 CHANGELOG           |    1 +
304803
 configure           |   32 +++++++++++++++++++++++++-------
304803
 configure.in        |   24 +++++++++++++++++-------
304803
 include/config.h.in |    3 +++
304803
 lib/mounts.c        |    6 ++++--
304803
 5 files changed, 50 insertions(+), 16 deletions(-)
304803
304803
--- autofs-5.0.7.orig/CHANGELOG
304803
+++ autofs-5.0.7/CHANGELOG
304803
@@ -249,6 +249,7 @@
304803
 - fix invalid reference in remount_active_mount().
304803
 - increase worker thread per-thread stack size.
304803
 - limit getgrgid_r() buffer size.
304803
+- add congigure option for limiting getgrgid_r() stack usage.
304803
 
304803
 25/07/2012 autofs-5.0.7
304803
 =======================
304803
--- autofs-5.0.7.orig/configure
304803
+++ autofs-5.0.7/configure
304803
@@ -743,6 +743,7 @@ enable_ext_env
304803
 enable_mount_locking
304803
 enable_forced_shutdown
304803
 enable_ignore_busy
304803
+enable_limit_getgrgid_size
304803
 '
304803
       ac_precious_vars='build_alias
304803
 host_alias
304803
@@ -1360,13 +1361,14 @@ Optional Features:
304803
   --disable-option-checking  ignore unrecognized --enable/--with options
304803
   --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
304803
   --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
304803
-  --enable-sloppy-mount   enable the use of the -s option to mount
304803
-  --disable-ext-env	  disable search in environment for substitution variable
304803
-  --disable-mount-locking disable use of locking when spawning mount command
304803
-  --enable-force-shutdown enable USR1 signal to force unlink umount of any
304803
-			  busy mounts during shutdown
304803
-  --enable-ignore-busy	  enable exit without umounting busy mounts during
304803
-			  shutdown
304803
+  --enable-sloppy-mount         enable the use of the -s option to mount
304803
+  --disable-ext-env	        disable search in environment for substitution variable
304803
+  --disable-mount-locking       disable use of locking when spawning mount command
304803
+  --enable-force-shutdown       enable USR1 signal to force unlink umount of any
304803
+			        busy mounts during shutdown
304803
+  --enable-ignore-busy	        enable exit without umounting busy mounts during
304803
+			        shutdown
304803
+  --enable-limit-getgrgid-size	enable limit stack use of getgrgid_r()
304803
 
304803
 Optional Packages:
304803
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
304803
@@ -5662,6 +5664,22 @@ $as_echo "#define ENABLE_IGNORE_BUSY_MOU
304803
 
304803
 fi
304803
 
304803
+#
304803
+# Enable exit, ignoring busy mounts.
304803
+#
304803
+# Check whether --enable-limit-getgrgid-size was given.
304803
+if test "${enable_limit_getgrgid_size+set}" = set; then :
304803
+  enableval=$enable_limit_getgrgid_size;
304803
+else
304803
+  enableval=no
304803
+fi
304803
+
304803
+if test x$enable_limit_getgrgid_size = xyes -o x$enableval = xyes; then
304803
+
304803
+$as_echo "#define ENABLE_LIMIT_GETGRGID_SIZE 1" >>confdefs.h
304803
+
304803
+fi
304803
+
304803
 #
304803
 # Write Makefile.conf and include/config.h
304803
 #
304803
--- autofs-5.0.7.orig/configure.in
304803
+++ autofs-5.0.7/configure.in
304803
@@ -158,7 +158,7 @@ AC_SUBST(sssldir)
304803
 # good for portability
304803
 #
304803
 AC_ARG_ENABLE(sloppy-mount,
304803
-[  --enable-sloppy-mount   enable the use of the -s option to mount],,
304803
+[  --enable-sloppy-mount         enable the use of the -s option to mount],,
304803
 	enable_sloppy_mount=auto)
304803
 if test x$enable_sloppy_mount = xauto; then
304803
 	AF_SLOPPY_MOUNT()
304803
@@ -344,7 +344,7 @@ AC_SUBST(DAEMON_LDFLAGS)
304803
 # Enable ability to access value in external env variable
304803
 #
304803
 AC_ARG_ENABLE(ext-env,
304803
-[  --disable-ext-env	  disable search in environment for substitution variable],,
304803
+[  --disable-ext-env	        disable search in environment for substitution variable],,
304803
 	enableval=yes)
304803
 if test x$enable_ext_env = xyes -o x$enableval = xyes; then
304803
         AC_DEFINE(ENABLE_EXT_ENV, 1, [leave this alone])
304803
@@ -354,7 +354,7 @@ fi
304803
 # Disable use of locking when spawning mount command
304803
 #
304803
 AC_ARG_ENABLE(mount-locking,
304803
-[  --disable-mount-locking disable use of locking when spawning mount command],,
304803
+[  --disable-mount-locking       disable use of locking when spawning mount command],,
304803
 	enableval=yes)
304803
 if test x$enable_mount_locking = xyes -o x$enableval = xyes; then
304803
 	AC_DEFINE(ENABLE_MOUNT_LOCKING, 1, [Disable use of locking when spawning mount command])
304803
@@ -364,8 +364,8 @@ fi
304803
 # Enable forced shutdown on USR1 signal (unlink umounts all mounts).
304803
 #
304803
 AC_ARG_ENABLE(forced-shutdown,
304803
-[  --enable-force-shutdown enable USR1 signal to force unlink umount of any
304803
-			  busy mounts during shutdown],,
304803
+[  --enable-force-shutdown       enable USR1 signal to force unlink umount of any
304803
+			        busy mounts during shutdown],,
304803
 	enableval=no)
304803
 if test x$enable_forced_shutdown = xyes -o x$enableval = xyes; then
304803
 	AC_DEFINE(ENABLE_FORCED_SHUTDOWN, 1, [Enable forced shutdown on USR1 signal])
304803
@@ -375,14 +375,24 @@ fi
304803
 # Enable exit, ignoring busy mounts.
304803
 #
304803
 AC_ARG_ENABLE(ignore-busy,
304803
-[  --enable-ignore-busy	  enable exit without umounting busy mounts during
304803
-			  shutdown],,
304803
+[  --enable-ignore-busy	        enable exit without umounting busy mounts during
304803
+			        shutdown],,
304803
 	enableval=no)
304803
 if test x$enable_ignore_busy_mounts = xyes -o x$enableval = xyes; then
304803
 	AC_DEFINE(ENABLE_IGNORE_BUSY_MOUNTS, 1, [Enable exit, ignoring busy mounts])
304803
 fi
304803
 
304803
 #
304803
+# Enable exit, ignoring busy mounts.
304803
+#
304803
+AC_ARG_ENABLE(limit-getgrgid-size,
304803
+[  --enable-limit-getgrgid-size	enable limit stack use of getgrgid_r()],,
304803
+	enableval=no)
304803
+if test x$enable_limit_getgrgid_size = xyes -o x$enableval = xyes; then
304803
+	AC_DEFINE(ENABLE_LIMIT_GETGRGID_SIZE, 1, [Enable limit stack use of getgrgid_r()])
304803
+fi
304803
+
304803
+#
304803
 # Write Makefile.conf and include/config.h
304803
 #
304803
 AC_CONFIG_HEADER(include/config.h)
304803
--- autofs-5.0.7.orig/include/config.h.in
304803
+++ autofs-5.0.7/include/config.h.in
304803
@@ -9,6 +9,9 @@
304803
 /* Enable exit, ignoring busy mounts */
304803
 #undef ENABLE_IGNORE_BUSY_MOUNTS
304803
 
304803
+/* Enable limit stack use of getgrgid_r() */
304803
+#undef ENABLE_LIMIT_GETGRGID_SIZE
304803
+
304803
 /* Disable use of locking when spawning mount command */
304803
 #undef ENABLE_MOUNT_LOCKING
304803
 
304803
--- autofs-5.0.7.orig/lib/mounts.c
304803
+++ autofs-5.0.7/lib/mounts.c
304803
@@ -1507,8 +1507,10 @@ void set_tsd_user_vars(unsigned int logo
304803
 
304803
 	gr_tmp = NULL;
304803
 	status = ERANGE;
304803
+#ifdef ENABLE_LIMIT_GETGRGID_SIZE
304803
 	if (!maxgrpbuf)
304803
 		maxgrpbuf = detached_thread_stack_size * 0.9;
304803
+#endif
304803
 
304803
 	/* If getting the group name fails go on without it. It's
304803
 	 * used to set an environment variable for program maps
304803
@@ -1532,9 +1534,9 @@ void set_tsd_user_vars(unsigned int logo
304803
 		tmplen += grplen;
304803
 
304803
 		/* Don't tempt glibc to alloca() larger than is (likely)
304803
-		 * available on the stack.
304803
+		 * available on the stack if limit-getgrgid-size is enabled.
304803
 		 */
304803
-		if (tmplen < maxgrpbuf)
304803
+		if (!maxgrpbuf || (tmplen < maxgrpbuf))
304803
 			continue;
304803
 
304803
 		/* Add a message so we know this happened */