Blame SOURCES/autofs-5.1.0-add-config-option-to-force-use-of-program-map-stdvars.patch

516ab0
autofs-5.1.0 - add config option to force use of program map stdvars
516ab0
516ab0
From: Ian Kent <ikent@redhat.com>
516ab0
516ab0
Enabling the extended environment (including $HOME, for example) for
516ab0
program maps opens automount(8) to a privilege escalation.
516ab0
516ab0
Rather than just removing the entended environment a configuration
516ab0
option is added to disable it by default so that those who wish to
516ab0
use it can do so if they wish.
516ab0
---
516ab0
 CHANGELOG                      |    1 +
516ab0
 include/defaults.h             |    2 ++
516ab0
 lib/defaults.c                 |   12 ++++++++++++
516ab0
 man/autofs.5                   |    5 +++++
516ab0
 man/autofs.conf.5.in           |    9 +++++++++
516ab0
 modules/lookup_program.c       |   14 +++++++++++++-
516ab0
 redhat/autofs.conf.default.in  |   11 +++++++++++
516ab0
 samples/autofs.conf.default.in |   11 +++++++++++
516ab0
 8 files changed, 64 insertions(+), 1 deletion(-)
516ab0
516ab0
--- autofs-5.0.7.orig/CHANGELOG
516ab0
+++ autofs-5.0.7/CHANGELOG
516ab0
@@ -163,6 +163,7 @@
516ab0
 - ensure negative cache isn't updated on remount.
516ab0
 - dont add wildcard to negative cache.
516ab0
 - add a prefix to program map stdvars.
516ab0
+- add config option to force use of program map stdvars.
516ab0
 
516ab0
 25/07/2012 autofs-5.0.7
516ab0
 =======================
516ab0
--- autofs-5.0.7.orig/include/defaults.h
516ab0
+++ autofs-5.0.7/include/defaults.h
516ab0
@@ -30,6 +30,7 @@
516ab0
 #define DEFAULT_UMOUNT_WAIT		"12"
516ab0
 #define DEFAULT_BROWSE_MODE		"1"
516ab0
 #define DEFAULT_LOGGING			"none"
516ab0
+#define DEFAULT_FORCE_STD_PROG_MAP_ENV	"0"
516ab0
 
516ab0
 #define DEFAULT_LDAP_TIMEOUT		"-1"
516ab0
 #define DEFAULT_LDAP_NETWORK_TIMEOUT	"8"
516ab0
@@ -151,6 +152,7 @@ unsigned int defaults_get_timeout(void);
516ab0
 unsigned int defaults_get_negative_timeout(void);
516ab0
 unsigned int defaults_get_browse_mode(void);
516ab0
 unsigned int defaults_get_logging(void);
516ab0
+unsigned int defaults_force_std_prog_map_env(void);
516ab0
 const char *defaults_get_ldap_server(void);
516ab0
 unsigned int defaults_get_ldap_timeout(void);
516ab0
 unsigned int defaults_get_ldap_network_timeout(void);
516ab0
--- autofs-5.0.7.orig/lib/defaults.c
516ab0
+++ autofs-5.0.7/lib/defaults.c
516ab0
@@ -50,6 +50,7 @@
516ab0
 #define NAME_NEGATIVE_TIMEOUT		"negative_timeout"
516ab0
 #define NAME_BROWSE_MODE		"browse_mode"
516ab0
 #define NAME_LOGGING			"logging"
516ab0
+#define NAME_FORCE_STD_PROG_MAP_ENV	"force_standard_program_map_env"
516ab0
 
516ab0
 #define NAME_LDAP_URI			"ldap_uri"
516ab0
 #define NAME_LDAP_TIMEOUT		"ldap_timeout"
516ab0
@@ -1589,6 +1590,17 @@ unsigned int defaults_get_logging(void)
516ab0
 	return logging;
516ab0
 }
516ab0
 
516ab0
+unsigned int defaults_force_std_prog_map_env(void)
516ab0
+{
516ab0
+	int res;
516ab0
+
516ab0
+	res = conf_get_yesno(autofs_gbl_sec, NAME_FORCE_STD_PROG_MAP_ENV);
516ab0
+	if (res < 0)
516ab0
+		res = atoi(DEFAULT_FORCE_STD_PROG_MAP_ENV);
516ab0
+
516ab0
+	return res;
516ab0
+}
516ab0
+
516ab0
 unsigned int defaults_get_ldap_timeout(void)
516ab0
 {
516ab0
 	int res;
516ab0
--- autofs-5.0.7.orig/man/autofs.5
516ab0
+++ autofs-5.0.7/man/autofs.5
516ab0
@@ -190,6 +190,11 @@ SHOST	Short hostname (domain part remove
516ab0
 .fi
516ab0
 .RE
516ab0
 .sp
516ab0
+If a program map is used these standard environment variables will have
516ab0
+a prefix of "AUTOFS_" to prevent interpreted languages like python from
516ab0
+being able to load and execute arbitray code from a user home directory.
516ab0
+.RE
516ab0
+.sp
516ab0
 Additional entries can be defined with the -Dvariable=Value map-option to
516ab0
 .BR automount (8).
516ab0
 .SS Executable Maps
516ab0
--- autofs-5.0.7.orig/man/autofs.conf.5.in
516ab0
+++ autofs-5.0.7/man/autofs.conf.5.in
516ab0
@@ -71,6 +71,15 @@ options replace the global options (prog
516ab0
 .B logging
516ab0
 .br
516ab0
 set default log level "none", "verbose" or "debug" (program default "none").
516ab0
+.TP
516ab0
+.B force_standard_program_map_env
516ab0
+.br
516ab0
+override the use of a prefix with standard environment variables when a
516ab0
+program map is executed. Since program maps are run as the privileded
516ab0
+user setting these standard environment variables opens automount(8) to
516ab0
+potential user privilege escalation when the program map is written in a
516ab0
+language that can load components from, for example, a user home directory
516ab0
+(program default "no").
516ab0
 .SS LDAP Configuration
516ab0
 .P
516ab0
 Configuration settings available are:
516ab0
--- autofs-5.0.7.orig/modules/lookup_program.c
516ab0
+++ autofs-5.0.7/modules/lookup_program.c
516ab0
@@ -129,6 +129,7 @@ static char *lookup_one(struct autofs_po
516ab0
 	int distance;
516ab0
 	int alloci = 1;
516ab0
 	int status;
516ab0
+	char *prefix;
516ab0
 
516ab0
 	mapent = (char *) malloc(MAPENT_MAX_LEN + 1);
516ab0
 	if (!mapent) {
516ab0
@@ -174,6 +175,17 @@ static char *lookup_one(struct autofs_po
516ab0
 			warn(ap->logopt,
516ab0
 			     MODPREFIX "failed to set PWD to %s for map %s",
516ab0
 			     ap->path, ctxt->mapname);
516ab0
+
516ab0
+		/*
516ab0
+		 * By default use a prefix with standard environment
516ab0
+		 * variables to prevent system subversion by interpreted
516ab0
+		 * languages.
516ab0
+		 */
516ab0
+		if (defaults_force_std_prog_map_env())
516ab0
+			prefix = NULL;
516ab0
+		else
516ab0
+			prefix = "AUTOFS_";
516ab0
+
516ab0
 		/*
516ab0
 		 * MAPFMT_DEFAULT must be "sun" for ->parse_init() to have setup
516ab0
 		 * the macro table.
516ab0
@@ -181,7 +193,7 @@ static char *lookup_one(struct autofs_po
516ab0
 		if (ctxt->mapfmt && strcmp(ctxt->mapfmt, "MAPFMT_DEFAULT")) {
516ab0
 			struct parse_context *pctxt = (struct parse_context *) ctxt->parse->context;
516ab0
 			/* Add standard environment as seen by sun map parser */
516ab0
-			pctxt->subst = addstdenv(pctxt->subst, "AUTOFS_");
516ab0
+			pctxt->subst = addstdenv(pctxt->subst, prefix);
516ab0
 			macro_setenv(pctxt->subst);
516ab0
 		}
516ab0
 		execl(ctxt->mapname, ctxt->mapname, name, NULL);
516ab0
--- autofs-5.0.7.orig/redhat/autofs.conf.default.in
516ab0
+++ autofs-5.0.7/redhat/autofs.conf.default.in
516ab0
@@ -53,6 +53,17 @@ mount_nfs_default_protocol = 4
516ab0
 #
516ab0
 #logging = none
516ab0
 #
516ab0
+# force_standard_program_map_env - disable the use of the "AUTOFS_"
516ab0
+#			prefix for standard environemt variables when
516ab0
+#			executing a program map. Since program maps
516ab0
+#			are run as the privileded user this opens
516ab0
+#			automount(8) to potential user privilege
516ab0
+#			escalation when the program map is written
516ab0
+#			in a language that  can load components from,
516ab0
+#			for example, a user home directory.
516ab0
+#
516ab0
+# force_standard_program_map_env = no
516ab0
+#
516ab0
 # Define base dn for map dn lookup.
516ab0
 #
516ab0
 # Define server URIs
516ab0
--- autofs-5.0.7.orig/samples/autofs.conf.default.in
516ab0
+++ autofs-5.0.7/samples/autofs.conf.default.in
516ab0
@@ -52,6 +52,17 @@ browse_mode = no
516ab0
 #
516ab0
 #logging = none
516ab0
 #
516ab0
+# force_standard_program_map_env - disable the use of the "AUTOFS_"
516ab0
+#			prefix for standard environemt variables when
516ab0
+#			executing a program map. Since program maps
516ab0
+#			are run as the privileded user this opens
516ab0
+#			automount(8) to potential user privilege
516ab0
+#			escalation when the program map is written
516ab0
+#			in a language that  can load components from,
516ab0
+#			for example, a user home directory.
516ab0
+#
516ab0
+# force_standard_program_map_env = no
516ab0
+#
516ab0
 # Define base dn for map dn lookup.
516ab0
 #
516ab0
 # Define server URIs