Blame SOURCES/pam-1.3.1-namespace-mntopts.patch

43d219
diff --git a/modules/pam_namespace/namespace.conf.5.xml b/modules/pam_namespace/namespace.conf.5.xml
43d219
index c7698cb..a94b49e 100644
43d219
--- a/modules/pam_namespace/namespace.conf.5.xml
43d219
+++ b/modules/pam_namespace/namespace.conf.5.xml
43d219
@@ -122,9 +122,14 @@
43d219
     <para><emphasis>mntopts</emphasis>=<replaceable>value</replaceable>
43d219
       - value of this flag is passed to the mount call when the tmpfs mount is
43d219
       done. It allows for example the specification of the maximum size of the
43d219
-      tmpfs instance that is created by the mount call. See <citerefentry>
43d219
-      <refentrytitle>mount</refentrytitle><manvolnum>8</manvolnum>
43d219
-      </citerefentry> for details.
43d219
+      tmpfs instance that is created by the mount call. In addition to
43d219
+      options specified in the <citerefentry>
43d219
+      <refentrytitle>tmpfs</refentrytitle><manvolnum>5</manvolnum>
43d219
+      </citerefentry> manual the <emphasis>nosuid</emphasis>,
43d219
+      <emphasis>noexec</emphasis>, and <emphasis>nodev</emphasis> flags
43d219
+      can be used to respectively disable setuid bit effect, disable running
43d219
+      executables, and disable devices to be interpreted on the mounted
43d219
+      tmpfs filesystem.
43d219
     </para>
43d219
 
43d219
     <para>
43d219
diff --git a/modules/pam_namespace/pam_namespace.c b/modules/pam_namespace/pam_namespace.c
43d219
index f541f89..660c7a1 100644
43d219
--- a/modules/pam_namespace/pam_namespace.c
43d219
+++ b/modules/pam_namespace/pam_namespace.c
43d219
@@ -230,6 +230,73 @@ static int parse_iscript_params(char *params, struct polydir_s *poly)
43d219
     return 0;
43d219
 }
43d219
 
43d219
+struct mntflag {
43d219
+    const char *name;
43d219
+    size_t len;
43d219
+    unsigned long flag;
43d219
+};
43d219
+
43d219
+#define LITERAL_AND_LEN(x) x, sizeof(x) - 1
43d219
+
43d219
+static const struct mntflag mntflags[] = {
43d219
+	{ LITERAL_AND_LEN("noexec"), MS_NOEXEC },
43d219
+	{ LITERAL_AND_LEN("nosuid"), MS_NOSUID },
43d219
+	{ LITERAL_AND_LEN("nodev"), MS_NODEV }
43d219
+    };
43d219
+
43d219
+static int filter_mntopts(const char *opts, char **filtered,
43d219
+		unsigned long *mountflags)
43d219
+{
43d219
+    size_t origlen = strlen(opts);
43d219
+    const char *end;
43d219
+    char *dest;
43d219
+
43d219
+    dest = *filtered = NULL;
43d219
+    *mountflags = 0;
43d219
+
43d219
+    if (origlen == 0)
43d219
+	return 0;
43d219
+
43d219
+    do {
43d219
+	size_t len;
43d219
+	int i;
43d219
+
43d219
+	end = strchr(opts, ',');
43d219
+	if (end == NULL) {
43d219
+	    len = strlen(opts);
43d219
+	} else {
43d219
+	    len = end - opts;
43d219
+	}
43d219
+
43d219
+	for (i = 0; i < (int)(sizeof(mntflags)/sizeof(mntflags[0])); i++) {
43d219
+	    if (mntflags[i].len != len)
43d219
+		continue;
43d219
+	    if (memcmp(mntflags[i].name, opts, len) == 0) {
43d219
+		*mountflags |= mntflags[i].flag;
43d219
+		opts = end;
43d219
+		break;
43d219
+	    }
43d219
+	}
43d219
+
43d219
+	if (opts != end) {
43d219
+	    if (dest != NULL) {
43d219
+		*dest = ',';
43d219
+		++dest;
43d219
+	    } else {
43d219
+		dest = *filtered = calloc(1, origlen + 1);
43d219
+		if (dest == NULL)
43d219
+		    return -1;
43d219
+	    }
43d219
+	    memcpy(dest, opts, len);
43d219
+	    dest += len;
43d219
+	}
43d219
+
43d219
+	opts = end + 1;
43d219
+    } while (end != NULL);
43d219
+
43d219
+    return 0;
43d219
+}
43d219
+
43d219
 static int parse_method(char *method, struct polydir_s *poly,
43d219
 		struct instance_data *idata)
43d219
 {
43d219
@@ -289,7 +356,8 @@ static int parse_method(char *method, struct polydir_s *poly,
43d219
 					break;
43d219
 				}
43d219
 				free(poly->mount_opts); /* if duplicate mntopts specified */
43d219
-				if ((poly->mount_opts = strdup(flag+namelen+1)) == NULL) {
43d219
+				poly->mount_opts = NULL;
43d219
+				if (filter_mntopts(flag+namelen+1, &poly->mount_opts, &poly->mount_flags) != 0) {
43d219
 					pam_syslog(idata->pamh, LOG_CRIT, "Memory allocation error");
43d219
 					return -1;
43d219
 				}
43d219
@@ -1484,7 +1552,7 @@ static int ns_setup(struct polydir_s *polyptr,
43d219
     }
43d219
 
43d219
     if (polyptr->method == TMPFS) {
43d219
-	if (mount("tmpfs", polyptr->dir, "tmpfs", 0, polyptr->mount_opts) < 0) {
43d219
+	if (mount("tmpfs", polyptr->dir, "tmpfs", polyptr->mount_flags, polyptr->mount_opts) < 0) {
43d219
 	    pam_syslog(idata->pamh, LOG_ERR, "Error mounting tmpfs on %s, %m",
43d219
 		polyptr->dir);
43d219
             return PAM_SESSION_ERR;
43d219
diff --git a/modules/pam_namespace/pam_namespace.h b/modules/pam_namespace/pam_namespace.h
43d219
index 47ebcc3..1522386 100644
43d219
--- a/modules/pam_namespace/pam_namespace.h
43d219
+++ b/modules/pam_namespace/pam_namespace.h
43d219
@@ -166,6 +166,7 @@ struct polydir_s {
43d219
     unsigned int flags;			/* polydir flags */
43d219
     char *init_script;			/* path to init script */
43d219
     char *mount_opts;			/* mount options for tmpfs mount */
43d219
+    unsigned long mount_flags;		/* mount flags for tmpfs mount */
43d219
     uid_t owner;			/* user which should own the polydir */
43d219
     gid_t group;			/* group which should own the polydir */
43d219
     mode_t mode;			/* mode of the polydir */