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