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