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

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