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

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