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

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