diff --git a/scripts/selinux/mdp/mdp.c b/scripts/selinux/mdp/mdp.c
index 073fe7537f6c..4223e2fea441 100644
--- a/scripts/selinux/mdp/mdp.c
+++ b/scripts/selinux/mdp/mdp.c
@@ -33,6 +33,7 @@
#include <unistd.h>
#include <string.h>
#include <sys/socket.h>
+#include <linux/kconfig.h>
static void usage(char *name)
{
@@ -95,10 +96,31 @@ int main(int argc, char *argv[])
}
fprintf(fout, "\n");
- /* NOW PRINT OUT MLS STUFF */
+ /* print out mls declarations and constraints */
if (mls) {
- printf("MLS not yet implemented\n");
- exit(1);
+ fprintf(fout, "sensitivity s0;\n");
+ fprintf(fout, "sensitivity s1;\n");
+ fprintf(fout, "dominance { s0 s1 }\n");
+ fprintf(fout, "category c0;\n");
+ fprintf(fout, "category c1;\n");
+ fprintf(fout, "level s0:c0.c1;\n");
+ fprintf(fout, "level s1:c0.c1;\n");
+#define SYSTEMLOW "s0"
+#define SYSTEMHIGH "s1:c0.c1"
+ for (i = 0; secclass_map[i].name; i++) {
+ struct security_class_mapping *map =
&secclass_map[i];
+
+ fprintf(fout, "mlsconstrain %s {\n",
map->name);
+ for (j = 0; map->perms[j]; j++)
+ fprintf(fout, "\t%s\n", map->perms[j]);
+ /*
+ * This requires all subjects and objects to be
+ * single-level (l2 eq h2), and that the
subject
+ * level dominate the object level (h1 dom h2)
+ * in order to have any permissions to it.
+ */
+ fprintf(fout, "} (l2 eq h2 and h1 dom
h2);\n\n");
+ }
}
/* types, roles, and allows */
@@ -108,34 +130,87 @@ int main(int argc, char *argv[])
for (i = 0; secclass_map[i].name; i++)
fprintf(fout, "allow base_t base_t:%s *;\n",
secclass_map[i].name);
- fprintf(fout, "user user_u roles { base_r };\n");
- fprintf(fout, "\n");
+ fprintf(fout, "user user_u roles { base_r }");
+ if (mls)
+ fprintf(fout, " level %s range %s - %s", SYSTEMHIGH,
+ SYSTEMLOW, SYSTEMHIGH);
+ fprintf(fout, ";\n");
+
+#define USERROLETYPE "user_u:base_r:base_t"
/* default sids */
for (i = 1; i < initial_sid_to_string_len; i++)
- fprintf(fout, "sid %s user_u:base_r:base_t\n",
initial_sid_to_string[i]);
+ fprintf(fout, "sid %s " USERROLETYPE "%s\n",
+ initial_sid_to_string[i], mls ? ":"
SYSTEMHIGH : "");
fprintf(fout, "\n");
- fprintf(fout, "fs_use_xattr ext2 user_u:base_r:base_t;\n");
- fprintf(fout, "fs_use_xattr ext3 user_u:base_r:base_t;\n");
- fprintf(fout, "fs_use_xattr ext4 user_u:base_r:base_t;\n");
- fprintf(fout, "fs_use_xattr jfs user_u:base_r:base_t;\n");
- fprintf(fout, "fs_use_xattr xfs user_u:base_r:base_t;\n");
- fprintf(fout, "fs_use_xattr reiserfs user_u:base_r:base_t;\n");
- fprintf(fout, "fs_use_xattr jffs2 user_u:base_r:base_t;\n");
- fprintf(fout, "fs_use_xattr gfs2 user_u:base_r:base_t;\n");
-
- fprintf(fout, "fs_use_task eventpollfs
user_u:base_r:base_t;\n");
- fprintf(fout, "fs_use_task pipefs user_u:base_r:base_t;\n");
- fprintf(fout, "fs_use_task sockfs user_u:base_r:base_t;\n");
-
- fprintf(fout, "fs_use_trans mqueue user_u:base_r:base_t;\n");
- fprintf(fout, "fs_use_trans devpts user_u:base_r:base_t;\n");
- fprintf(fout, "fs_use_trans hugetlbfs
user_u:base_r:base_t;\n");
- fprintf(fout, "fs_use_trans tmpfs user_u:base_r:base_t;\n");
- fprintf(fout, "fs_use_trans shm user_u:base_r:base_t;\n");
-
- fprintf(fout, "genfscon proc / user_u:base_r:base_t\n");
+#define FS_USE(behavior, fstype) \
+ fprintf(fout, "fs_use_%s %s " USERROLETYPE "%s;\n", \
+ behavior, fstype, mls ? ":" SYSTEMLOW : "")
+
+ /*
+ * Filesystems whose inode labels can be fetched via getxattr.
+ */
+#ifdef CONFIG_EXT2_FS_SECURITY
+ FS_USE("xattr", "ext2");
+#endif
+#ifdef CONFIG_EXT3_FS_SECURITY
+ FS_USE("xattr", "ext3");
+#endif
+#ifdef CONFIG_EXT4_FS_SECURITY
+ FS_USE("xattr", "ext4");
+#endif
+#ifdef CONFIG_JFS_SECURITY
+ FS_USE("xattr", "jfs");
+#endif
+#ifdef CONFIG_REISERFS_FS_SECURITY
+ FS_USE("xattr", "reiserfs");
+#endif
+#ifdef CONFIG_JFFS2_FS_SECURITY
+ FS_USE("xattr", "jffs2");
+#endif
+#ifdef CONFIG_XFS_FS
+ FS_USE("xattr", "xfs");
+#endif
+#ifdef CONFIG_GFS2_FS
+ FS_USE("xattr", "gfs2");
+#endif
+
+ /*
+ * Filesystems whose inodes are labeled from allocating task.
+ */
+ FS_USE("task", "pipefs");
+ FS_USE("task", "sockfs");
+#ifdef CONFIG_POSIX_MQUEUE
+ FS_USE("task", "mqueue");
+#endif
+
+ /*
+ * Filesystems whose inode labels are computed from both
+ * the allocating task and the superblock label.
+ */
+#ifdef CONFIG_UNIX98_PTYS
+ FS_USE("trans", "devpts");
+#endif
+#ifdef CONFIG_HUGETLBFS
+ FS_USE("trans", "hugetlbfs");
+#endif
+#ifdef CONFIG_TMPFS
+ FS_USE("trans", "tmpfs");
+#endif
+
+
+#define GENFSCON(fstype, prefix) \
+ fprintf(fout, "genfscon %s %s " USERROLETYPE "%s\n", \
+ fstype, prefix, mls ? ":" SYSTEMLOW : "")
+
+ /*
+ * Filesystems whose inodes are labeled from path prefix match
+ * relative to the filesystem root. Depending on the
filesystem,
+ * only a single label for all inodes may be supported.
+ */
+ GENFSCON("proc", "/");
+ GENFSCON("selinuxfs", "/");
fclose(fout);
@@ -144,8 +219,8 @@ int main(int argc, char *argv[])
printf("Wrote policy, but cannot open %s for
writing\n", ctxout);
usage(argv[0]);
}
- fprintf(fout, "/ user_u:base_r:base_t\n");
- fprintf(fout, "/.* user_u:base_r:base_t\n");
+ fprintf(fout, "/ " USERROLETYPE "%s\n", mls ? ":" SYSTEMLOW
: "");
+ fprintf(fout, "/.* " USERROLETYPE "%s\n", mls ? ":"
SYSTEMLOW : "");
fclose(fout);
return 0;
--
2.20.1