scripts/selinux: add basic mls support to mdp
PATCH v3 1/1 scripts/selinux: add basic mls support to mdp
Add basic MLS policy support to mdp. Declares two sensitivities and two categories, defines mls constraints for all permissions requiring dominance (ala MCS), assigns the system-high level to initial SID contexts and the default user level, and assigns system-low level to filesystems.
Also reworks the fs_use and genfscon rules to only generate rules for filesystems that are configured in the kernel. In some cases this depends on a specific config option for security xattrs, in other cases security xattrs are unconditionally supported by a given filesystem if the filesystem is enabled, and in some cases the filesystem is always enabled in the kernel. Dropped obsolete pseudo filesystems.
NB The list of fs_use_* and genfscon rules emitted by mdp is very incomplete compared to refpolicy or Android sepolicy. We should probably expand it.
Usage:scripts/selinux/mdp/mdp -m policy.conf file_contexts checkpolicy -M -o policy policy.conf
Then install the resulting policy and file_contexts as usual.
---
v3 fixes up the file contexts generation code to also use SYSTEMLOW and collapse down to a single fprintf call per line.
scripts/selinux/mdp/mdp.c | 131 ++++++++++++++++++++++++++++++-------- 1 file changed, 103 insertions(+), 28 deletions(-)
scripts/selinux/mdp/mdp.c +103 -28
@@ -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 ;
Signature · 1 line
2.20.1
Paul Moore
maintainerQuoted 24 lines · Stephen Smalley
Add basic MLS policy support to mdp. Declares two sensitivities and two categories, defines mls constraints for all permissions requiring dominance (ala MCS), assigns the system-high level to initial SID contexts and the default user level, and assigns system-low level to filesystems.
Also reworks the
fs_useand genfscon rules to only generate rules for filesystems that are configured in the kernel. In some cases this depends on a specific config option for security xattrs, in other cases security xattrs are unconditionally supported by a given filesystem if the filesystem is enabled, and in some cases the filesystem is always enabled in the kernel. Dropped obsolete pseudo filesystems.NB The list of fs_use_* and genfscon rules emitted by mdp is very incomplete compared to refpolicy or Android sepolicy. We should probably expand it.
Usage:
scripts/selinux/mdp/mdp-m policy.conffile_contextscheckpolicy -M -o policy policy.conf
Quoted 8 lines
Then install the resulting policy and
file_contextsas usual.Signed-off-by Stephen Smalley <[email protected]>---
v3 fixes up the file contexts generation code to also use SYSTEMLOW and collapse down to a single fprintf call per line.scripts/selinux/mdp/mdp.c | 131 ++++++++++++++++++++++++++++++-------- 1 file changed, 103 insertions(+), 28 deletions(-)
This is great Stephen, thanks for working on this - and rather quickly too! For those who don't follow the GitHub issues, I just opened an issue yesterday mentioning it would be nice to add MLS support to the mdp tool.
Are you planning to keep playing with this? I'm asking not because I think it needs more work to be worthwhile, but rather I don't want to merge something that you want to continue working on. If you are happy with this latest patch I think it is okay to merge this into selinux/next, even at this late stage, simply because it is not part of a built kernel, but rather a developer's tool.
Quoted 172 lines
scripts/selinux/mdp/mdp.c +103
-29@@ -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
Signature · 2 lines
paul moore www.paul-moore.com
Quoted 39 lines · Paul Moore
Quoted 24 lines · Stephen Smalley
Add basic MLS policy support to mdp. Declares two sensitivities and two categories, defines mls constraints for all permissions requiring dominance (ala MCS), assigns the system-high level to initial SID contexts and the default user level, and assigns system-low level to filesystems.
Also reworks the
fs_useand genfscon rules to only generate rules for filesystems that are configured in the kernel. In some cases this depends on a specific config option for security xattrs, in other cases security xattrs are unconditionally supported by a given filesystem if the filesystem is enabled, and in some cases the filesystem is always enabled in the kernel. Dropped obsolete pseudo filesystems.NB The list of fs_use_* and genfscon rules emitted by mdp is very incomplete compared to refpolicy or Android sepolicy. We should probably expand it.
Usage:
scripts/selinux/mdp/mdp-m policy.conffile_contextscheckpolicy -M -o policy policy.confQuoted 8 lines
Then install the resulting policy and
file_contextsas usual.Signed-off-by Stephen Smalley <[email protected]>---
v3 fixes up the file contexts generation code to also use SYSTEMLOW and collapse down to a single fprintf call per line.scripts/selinux/mdp/mdp.c | 131 ++++++++++++++++++++++++++++++-------- 1 file changed, 103 insertions(+), 28 deletions(-)This is great Stephen, thanks for working on this - and rather quickly too! For those who don't follow the GitHub issues, I just opened an issue yesterday mentioning it would be nice to add MLS support to the mdp tool.
Quoted 6 lines
Are you planning to keep playing with this? I'm asking not because I think it needs more work to be worthwhile, but rather I don't want to merge something that you want to continue working on. If you are happy with this latest patch I think it is okay to merge this into selinux/next, even at this late stage, simply because it is not part of a built kernel, but rather a developer's tool.
No, I think I'm done for now unless you find a problem with it. Absent some compelling use case for mdp it is hard to justify spending any more time on it.
Quoted 175 lines
Quoted 173 lines
scripts/selinux/mdp/mdp.c +103
-29@@ -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
Quoted 40 lines · Stephen Smalley
Quoted 39 lines · Paul Moore
Quoted 24 lines · Stephen Smalley
Add basic MLS policy support to mdp. Declares two sensitivities and two categories, defines mls constraints for all permissions requiring dominance (ala MCS), assigns the system-high level to initial SID contexts and the default user level, and assigns system-low level to filesystems.
Also reworks the
fs_useand genfscon rules to only generate rules for filesystems that are configured in the kernel. In some cases this depends on a specific config option for security xattrs, in other cases security xattrs are unconditionally supported by a given filesystem if the filesystem is enabled, and in some cases the filesystem is always enabled in the kernel. Dropped obsolete pseudo filesystems.NB The list of fs_use_* and genfscon rules emitted by mdp is very incomplete compared to refpolicy or Android sepolicy. We should probably expand it.
Usage:
scripts/selinux/mdp/mdp-m policy.conffile_contextscheckpolicy -M -o policy policy.confQuoted 8 lines
Then install the resulting policy and
file_contextsas usual.Signed-off-by Stephen Smalley <[email protected]>---
v3 fixes up the file contexts generation code to also use SYSTEMLOW and collapse down to a single fprintf call per line.scripts/selinux/mdp/mdp.c| 131 ++++++++++++++++++++++++++++++--------1 file changed, 103 insertions(+), 28 deletions(-)This is great Stephen, thanks for working on this - and rather quickly too! For those who don't follow the GitHub issues, I just opened an issue yesterday mentioning it would be nice to add MLS support to the mdp tool.
Quoted 8 lines
Quoted 6 lines
Are you planning to keep playing with this? I'm asking not because I think it needs more work to be worthwhile, but rather I don't want to merge something that you want to continue working on. If you are happy with this latest patch I think it is okay to merge this into selinux/next, even at this late stage, simply because it is not part of a built kernel, but rather a developer's tool.
No, I think I'm done for now unless you find a problem with it. Absent some compelling use case for mdp it is hard to justify spending any more time on it.
Note however that the instructions in Documentation/admin-guide/LSM/SELinux.rst just say to run scripts/selinux/install_policy.sh and since that doesn't pass -m to mdp or -M to checkpolicy, no one will use this support unless they do it all by hand.
Quoted 185 lines
Quoted 184 lines
Quoted 182 lines
scripts/selinux/mdp/mdp.c +25
-3@@ -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 */
scripts/selinux/mdp/mdp.c +72
-23@@ -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);
scripts/selinux/mdp/mdp.c +2
-2@@ -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;
Signature · 1 line
2.20.1
Paul Moore
maintainerQuoted 53 lines · Stephen Smalley
Quoted 48 lines · Stephen Smalley
Quoted 40 lines · Paul Moore
Quoted 24 lines · Stephen Smalley
Add basic MLS policy support to mdp. Declares two sensitivities and two categories, defines mls constraints for all permissions requiring dominance (ala MCS), assigns the system-high level to initial SID contexts and the default user level, and assigns system-low level to filesystems.
Also reworks the
fs_useand genfscon rules to only generate rules for filesystems that are configured in the kernel. In some cases this depends on a specific config option for security xattrs, in other cases security xattrs are unconditionally supported by a given filesystem if the filesystem is enabled, and in some cases the filesystem is always enabled in the kernel. Dropped obsolete pseudo filesystems.NB The list of fs_use_* and genfscon rules emitted by mdp is very incomplete compared to refpolicy or Android sepolicy. We should probably expand it.
Usage:
scripts/selinux/mdp/mdp-m policy.conffile_contextscheckpolicy -M -o policy policy.confQuoted 8 lines
Then install the resulting policy and
file_contextsas usual.Signed-off-by Stephen Smalley <[email protected]>---
v3 fixes up the file contexts generation code to also use SYSTEMLOW and collapse down to a single fprintf call per line.scripts/selinux/mdp/mdp.c | 131 ++++++++++++++++++++++++++++++-------- 1 file changed, 103 insertions(+), 28 deletions(-)This is great Stephen, thanks for working on this - and rather quickly too! For those who don't follow the GitHub issues, I just opened an issue yesterday mentioning it would be nice to add MLS support to the mdp tool.
Quoted 6 lines
Are you planning to keep playing with this? I'm asking not because I think it needs more work to be worthwhile, but rather I don't want to merge something that you want to continue working on. If you are happy with this latest patch I think it is okay to merge this into selinux/next, even at this late stage, simply because it is not part of a built kernel, but rather a developer's tool.
Quoted 3 lines
No, I think I'm done for now unless you find a problem with it. Absent some compelling use case for mdp it is hard to justify spending any more time on it.
Quoted 5 lines
Note however that the instructions in
Documentation/admin-guide/LSM/SELinux.rstjust say to runscripts/selinux/install_policy.shand since that doesn't pass -m to mdp or -M to checkpolicy, no one will use this support unless they do it all by hand.
Good point.
I tend to think that modifying the script to build MLS support by default is probably a good thing, after all why go to the trouble of adding MLS support to mdp? Anyone have a strong opinion against this?
Stephen, please feel free to submit a second patch adding support to the install_policy.sh script, but if you don't have time I'll get to that over the weekend.
Signature · 2 lines
paul moore www.paul-moore.com
Quoted 49 lines · Stephen Smalley
Quoted 48 lines · Stephen Smalley
Quoted 46 lines · Paul Moore
Quoted 26 lines · Stephen Smalley
Add basic MLS policy support to mdp. Declares two sensitivities and two categories, defines mls constraints for all permissions requiring dominance (ala MCS), assigns the system-high level to initial SID contexts and the default user level, and assigns system-low level to filesystems.
Also reworks the
fs_useand genfscon rules to only generate rules for filesystems that are configured in the kernel. In some cases this depends on a specific config option for security xattrs, in other cases security xattrs are unconditionally supported by a given filesystem if the filesystem is enabled, and in some cases the filesystem is always enabled in the kernel. Dropped obsolete pseudo filesystems.NB The list of fs_use_* and genfscon rules emitted by mdp is very incomplete compared to refpolicy or Android sepolicy. We should probably expand it.
Usage:
scripts/selinux/mdp/mdp-m policy.conffile_contextscheckpolicy -M -o policy policy.confThen install the resulting policy and
file_contextsas usual.Quoted 7 lines
Signed-off-by Stephen Smalley <[email protected]>---
v3 fixes up the file contexts generation code to also use SYSTEMLOW and collapse down to a single fprintf call per line.scripts/selinux/mdp/mdp.c| 131
++++++++++++++++++++++++++++++--------1 file changed, 103 insertions(+), 28 deletions(-)This is great Stephen, thanks for working on this - and rather quickly too! For those who don't follow the GitHub issues, I just opened an issue yesterday mentioning it would be nice to add MLS support to the mdp tool.
Are you planning to keep playing with this? I'm asking not because I think it needs more work to be worthwhile, but rather I don't want to merge something that you want to continue working on. If you are happy with this latest patch I think it is okay to merge this into selinux/next, even at this late stage, simply because it is not part of a built kernel, but rather a developer's tool.
Quoted 3 lines
Quoted 1 line
No, I think I'm done for now unless you find a problem with it. Absent some compelling use case for mdp it is hard to justify spending any more time on it.
Note however that the instructions in
Documentation/admin-guide/LSM/SELinux.rstjust say to runscripts/selinux/install_policy.shand since that doesn't pass -m to mdp or -M to checkpolicy, no one will use this support unless they do it all by hand.
FWIW, a Fedora system wouldn't come up cleanly with this policy. Partly appears to be due to systemd having embedded security contexts specific to Fedora/refpolicy into its own configurations and partly due to MLS denials. I don't even know if it would work before this change though...
Quoted 190 lines
Quoted 189 lines
Quoted 188 lines
Quoted 186 lines
scripts/selinux/mdp/mdp.c +20
-3@@ -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 */
scripts/selinux/mdp/mdp.c +72
-23@@ -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);
scripts/selinux/mdp/mdp.c +2
-2@@ -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;
Signature · 1 line
2.20.1
Paul Moore
maintainerQuoted 61 lines · Stephen Smalley
Quoted 54 lines · Stephen Smalley
Quoted 49 lines · Stephen Smalley
Quoted 41 lines · Paul Moore
Quoted 26 lines · Stephen Smalley
Add basic MLS policy support to mdp. Declares two sensitivities and two categories, defines mls constraints for all permissions requiring dominance (ala MCS), assigns the system-high level to initial SID contexts and the default user level, and assigns system-low level to filesystems.
Also reworks the
fs_useand genfscon rules to only generate rules for filesystems that are configured in the kernel. In some cases this depends on a specific config option for security xattrs, in other cases security xattrs are unconditionally supported by a given filesystem if the filesystem is enabled, and in some cases the filesystem is always enabled in the kernel. Dropped obsolete pseudo filesystems.NB The list of fs_use_* and genfscon rules emitted by mdp is very incomplete compared to refpolicy or Android sepolicy. We should probably expand it.
Usage:
scripts/selinux/mdp/mdp-m policy.conffile_contextscheckpolicy -M -o policy policy.confThen install the resulting policy and
file_contextsas usual.Quoted 7 lines
Signed-off-by Stephen Smalley <[email protected]>---
v3 fixes up the file contexts generation code to also use SYSTEMLOW and collapse down to a single fprintf call per line.scripts/selinux/mdp/mdp.c | 131 ++++++++++++++++++++++++++++++-------- 1 file changed, 103 insertions(+), 28 deletions(-)This is great Stephen, thanks for working on this - and rather quickly too! For those who don't follow the GitHub issues, I just opened an issue yesterday mentioning it would be nice to add MLS support to the mdp tool.
Quoted 6 lines
Are you planning to keep playing with this? I'm asking not because I think it needs more work to be worthwhile, but rather I don't want to merge something that you want to continue working on. If you are happy with this latest patch I think it is okay to merge this into selinux/next, even at this late stage, simply because it is not part of a built kernel, but rather a developer's tool.
Quoted 3 lines
No, I think I'm done for now unless you find a problem with it. Absent some compelling use case for mdp it is hard to justify spending any more time on it.
Quoted 5 lines
Note however that the instructions in
Documentation/admin-guide/LSM/SELinux.rstjust say to runscripts/selinux/install_policy.shand since that doesn't pass -m to mdp or -M to checkpolicy, no one will use this support unless they do it all by hand.
Quoted 4 lines
FWIW, a Fedora system wouldn't come up cleanly with this policy. Partly appears to be due to systemd having embedded security contexts specific to Fedora/refpolicy into its own configurations and partly due to MLS denials. I don't even know if it would work before this change though...
Providing a usable policy for Fedora via mdp, while nice, isn't really the main goal with mdp as far as I'm concerned (see my other response). As you pointed out, I'd be surprised if the current, unpatched mdp policy would work on Fedora.
Regardless, it might be nice to add a warning about that in the SELinux.rst file, along with changes to the install_policy.sh script to enable MLS.
Signature · 2 lines
paul moore www.paul-moore.com
Quoted 50 lines · Stephen Smalley
Quoted 49 lines · Stephen Smalley
Quoted 48 lines · Stephen Smalley
Quoted 46 lines · Paul Moore
Quoted 26 lines · Stephen Smalley
Add basic MLS policy support to mdp. Declares two sensitivities and two categories, defines mls constraints for all permissions requiring dominance (ala MCS), assigns the system-high level to initial SID contexts and the default user level, and assigns system-low level to filesystems.
Also reworks the
fs_useand genfscon rules to only generate rules for filesystems that are configured in the kernel. In some cases this depends on a specific config option for security xattrs, in other cases security xattrs are unconditionally supported by a given filesystem if the filesystem is enabled, and in some cases the filesystem is always enabled in the kernel. Dropped obsolete pseudo filesystems.NB The list of fs_use_* and genfscon rules emitted by mdp is very incomplete compared to refpolicy or Android sepolicy. We should probably expand it.
Usage:
scripts/selinux/mdp/mdp-m policy.conffile_contextscheckpolicy -M -o policy policy.confThen install the resulting policy and
file_contextsas usual.Quoted 7 lines
Signed-off-by Stephen Smalley <[email protected]>---
v3 fixes up the file contexts generation code to also use SYSTEMLOW and collapse down to a single fprintf call per line.scripts/selinux/mdp/mdp.c| 131
++++++++++++++++++++++++++++++--------1 file changed, 103 insertions(+), 28 deletions(-)This is great Stephen, thanks for working on this - and rather quickly too! For those who don't follow the GitHub issues, I just opened an issue yesterday mentioning it would be nice to add MLS support to the mdp tool.
Are you planning to keep playing with this? I'm asking not because I think it needs more work to be worthwhile, but rather I don't want to merge something that you want to continue working on. If you are happy with this latest patch I think it is okay to merge this into selinux/next, even at this late stage, simply because it is not part of a built kernel, but rather a developer's tool.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
No, I think I'm done for now unless you find a problem with it. Absent some compelling use case for mdp it is hard to justify spending any more time on it.
Note however that the instructions in
Documentation/admin-guide/LSM/SELinux.rstjust say to runscripts/selinux/install_policy.shand since that doesn't pass -m to mdp or -M to checkpolicy, no one will use this support unless they do it all by hand.FWIW, a Fedora system wouldn't come up cleanly with this policy. Partly appears to be due to systemd having embedded security contexts specific to Fedora/refpolicy into its own configurations and partly due to MLS denials. I don't even know if it would work before this change though...
Couldn't seem to get a mdp-generated policy to boot on Fedora even in permissive, before or after this change. I assume it has to do with leaking of contexts outside of the policy and/or missing config files from the dummy policy (e.g. /etc/selinux/targeted/contexts/ has systemd_contexts and other userspace config files that don't exist in the mdp policy). More evidence of the irrelevance of mdp...
Quoted 195 lines
Quoted 194 lines
Quoted 193 lines
Quoted 192 lines
Quoted 190 lines
scripts/selinux/mdp/mdp.c +19
-3@@ -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 */
scripts/selinux/mdp/mdp.c +72
-23@@ -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);
scripts/selinux/mdp/mdp.c +2
-2@@ -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;
Signature · 1 line
2.20.1
Quoted 69 lines · Stephen Smalley
Quoted 62 lines · Stephen Smalley
Quoted 55 lines · Stephen Smalley
Quoted 50 lines · Stephen Smalley
Quoted 42 lines · Paul Moore
Quoted 26 lines · Stephen Smalley
Add basic MLS policy support to mdp. Declares two sensitivities and two categories, defines mls constraints for all permissions requiring dominance (ala MCS), assigns the system-high level to initial SID contexts and the default user level, and assigns system-low level to filesystems.
Also reworks the
fs_useand genfscon rules to only generate rules for filesystems that are configured in the kernel. In some cases this depends on a specific config option for security xattrs, in other cases security xattrs are unconditionally supported by a given filesystem if the filesystem is enabled, and in some cases the filesystem is always enabled in the kernel. Dropped obsolete pseudo filesystems.NB The list of fs_use_* and genfscon rules emitted by mdp is very incomplete compared to refpolicy or Android sepolicy. We should probably expand it.
Usage:
scripts/selinux/mdp/mdp-m policy.conffile_contextscheckpolicy -M -o policy policy.confThen install the resulting policy and
file_contextsas usual.Quoted 8 lines
Signed-off-by Stephen Smalley <[email protected]>---
v3 fixes up the file contexts generation code to also use SYSTEMLOW and
collapse down to a single fprintf call per line.scripts/selinux/mdp/mdp.c| 131
++++++++++++++++++++++++++++++--------1 file changed, 103 insertions(+), 28 deletions(-)This is great Stephen, thanks for working on this - and rather quickly too! For those who don't follow the GitHub issues, I just opened an issue yesterday mentioning it would be nice to add MLS support to the mdp tool.
Quoted 6 lines
Are you planning to keep playing with this? I'm asking not because I think it needs more work to be worthwhile, but rather I don't want to merge something that you want to continue working on. If you are happy with this latest patch I think it is okay to merge this into selinux/next, even at this late stage, simply because it is not part of a built kernel, but rather a developer's tool.
Quoted 3 lines
No, I think I'm done for now unless you find a problem with it. Absent some compelling use case for mdp it is hard to justify spending any more time on it.
Quoted 5 lines
Note however that the instructions in
Documentation/admin-guide/LSM/SELinux.rstjust say to runscripts/selinux/install_policy.shand since that doesn't pass -m to mdp or -M to checkpolicy, no one will use this support unless they do it all by hand.Quoted 5 lines
FWIW, a Fedora system wouldn't come up cleanly with this policy. Partly appears to be due to systemd having embedded security contexts specific to Fedora/refpolicy into its own configurations and partly due to MLS denials. I don't even know if it would work before this change though...
Quoted 6 lines
Couldn't seem to get a mdp-generated policy to boot on Fedora even in permissive, before or after this change. I assume it has to do with leaking of contexts outside of the policy and/or missing config files from the dummy policy (e.g.
/etc/selinux/targeted/contexts/hassystemd_contextsand other userspace config files that don't exist in the mdp policy). More evidence of the irrelevance of mdp...
Oh, right you need a "dbus_contexts" file probably. DBUS refuses to start without it, and these day's without dbus no system
Quoted 198 lines
Quoted 197 lines
Quoted 196 lines
Quoted 195 lines
Quoted 194 lines
Quoted 192 lines
scripts/selinux/mdp/mdp.c +19
-3@@ -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 */
scripts/selinux/mdp/mdp.c +72
-23@@ -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);
scripts/selinux/mdp/mdp.c +0
-0@@ -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;
Signature · 1 line
2.20.1
Signature · 3 lines
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02 https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02 Dominick Grift
Quoted 78 lines · Dominick Grift
Quoted 69 lines · Stephen Smalley
Quoted 62 lines · Stephen Smalley
Quoted 55 lines · Stephen Smalley
Quoted 50 lines · Stephen Smalley
Quoted 42 lines · Paul Moore
Quoted 26 lines · Stephen Smalley
Add basic MLS policy support to mdp. Declares two sensitivities and two categories, defines mls constraints for all permissions requiring dominance (ala MCS), assigns the system-high level to initial SID contexts and the default user level, and assigns system-low level to filesystems.
Also reworks the
fs_useand genfscon rules to only generate rules for filesystems that are configured in the kernel. In some cases this depends on a specific config option for security xattrs, in other cases security xattrs are unconditionally supported by a given filesystem if the filesystem is enabled, and in some cases the filesystem is always enabled in the kernel. Dropped obsolete pseudo filesystems.NB The list of fs_use_* and genfscon rules emitted by mdp is very incomplete compared to refpolicy or Android sepolicy. We should probably expand it.
Usage:
scripts/selinux/mdp/mdp-m policy.conffile_contextscheckpolicy -M -o policy policy.confThen install the resulting policy and
file_contextsas usual.Quoted 8 lines
Signed-off-by Stephen Smalley <[email protected]>---
v3 fixes up the file contexts generation code to also use SYSTEMLOW and
collapse down to a single fprintf call per line.scripts/selinux/mdp/mdp.c | 131 ++++++++++++++++++++++++++++++-------- 1 file changed, 103 insertions(+), 28 deletions(-)This is great Stephen, thanks for working on this - and rather quickly too! For those who don't follow the GitHub issues, I just opened an issue yesterday mentioning it would be nice to add MLS support to the mdp tool.
Quoted 6 lines
Are you planning to keep playing with this? I'm asking not because I think it needs more work to be worthwhile, but rather I don't want to merge something that you want to continue working on. If you are happy with this latest patch I think it is okay to merge this into selinux/next, even at this late stage, simply because it is not part of a built kernel, but rather a developer's tool.
Quoted 3 lines
No, I think I'm done for now unless you find a problem with it. Absent some compelling use case for mdp it is hard to justify spending any more time on it.
Quoted 5 lines
Note however that the instructions in
Documentation/admin-guide/LSM/SELinux.rstjust say to runscripts/selinux/install_policy.shand since that doesn't pass -m to mdp or -M to checkpolicy, no one will use this support unless they do it all by hand.Quoted 5 lines
FWIW, a Fedora system wouldn't come up cleanly with this policy. Partly appears to be due to systemd having embedded security contexts specific to Fedora/refpolicy into its own configurations and partly due to MLS denials. I don't even know if it would work before this change though...
Quoted 6 lines
Couldn't seem to get a mdp-generated policy to boot on Fedora even in permissive, before or after this change. I assume it has to do with leaking of contexts outside of the policy and/or missing config files from the dummy policy (e.g.
/etc/selinux/targeted/contexts/hassystemd_contextsand other userspace config files that don't exist in the mdp policy). More evidence of the irrelevance of mdp...
Quoted 2 lines
Oh, right you need a "
dbus_contexts" file probably. DBUS refuses to start without it, and these day's without dbus no system
There is actually a dbus_contexts file provided for mdp (scripts/selinux/mdp/dbus_contexts) but not a systemd_contexts or any other *_contexts files besides file_contexts.
Quoted 200 lines
Quoted 199 lines
Quoted 198 lines
Quoted 197 lines
Quoted 196 lines
Quoted 195 lines
Quoted 193 lines
scripts/selinux/mdp/mdp.c +19
-3@@ -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 */
scripts/selinux/mdp/mdp.c +72
-23@@ -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);
scripts/selinux/mdp/mdp.c +2
-2@@ -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;
Signature · 1 line
2.20.1
Quoted 79 lines · Stephen Smalley
Quoted 78 lines · Dominick Grift
Quoted 75 lines · Stephen Smalley
Quoted 62 lines · Stephen Smalley
Quoted 55 lines · Stephen Smalley
Quoted 50 lines · Stephen Smalley
Quoted 42 lines · Paul Moore
Quoted 26 lines · Stephen Smalley
Add basic MLS policy support to mdp. Declares two sensitivities and two categories, defines mls constraints for all permissions requiring dominance (ala MCS), assigns the system-high level to initial SID contexts and the default user level, and assigns system-low level to filesystems.
Also reworks the
fs_useand genfscon rules to only generate rules for filesystems that are configured in the kernel. In some cases this depends on a specific config option for security xattrs, in other cases security xattrs are unconditionally supported by a given filesystem if the filesystem is enabled, and in some cases the filesystem is always enabled in the kernel. Dropped obsolete pseudo filesystems.NB The list of fs_use_* and genfscon rules emitted by mdp is very incomplete compared to refpolicy or Android sepolicy. We should probably expand it.
Usage:
scripts/selinux/mdp/mdp-m policy.conffile_contextscheckpolicy -M -o policy policy.confThen install the resulting policy and
file_contextsas usual.Quoted 8 lines
Signed-off-by Stephen Smalley <[email protected]>---
v3 fixes up the file contexts generation code to also use SYSTEMLOW and
collapse down to a single fprintf call per line.scripts/selinux/mdp/mdp.c | 131 ++++++++++++++++++++++++++++++-------- 1 file changed, 103 insertions(+), 28 deletions(-)This is great Stephen, thanks for working on this - and rather quickly too! For those who don't follow the GitHub issues, I just opened an issue yesterday mentioning it would be nice to add MLS support to the mdp tool.
Quoted 6 lines
Are you planning to keep playing with this? I'm asking not because I think it needs more work to be worthwhile, but rather I don't want to merge something that you want to continue working on. If you are happy with this latest patch I think it is okay to merge this into selinux/next, even at this late stage, simply because it is not part of a built kernel, but rather a developer's tool.
Quoted 3 lines
No, I think I'm done for now unless you find a problem with it. Absent some compelling use case for mdp it is hard to justify spending any more time on it.
Quoted 5 lines
Note however that the instructions in
Documentation/admin-guide/LSM/SELinux.rstjust say to runscripts/selinux/install_policy.shand since that doesn't pass -m to mdp or -M to checkpolicy, no one will use this support unless they do it all by hand.Quoted 5 lines
FWIW, a Fedora system wouldn't come up cleanly with this policy. Partly appears to be due to systemd having embedded security contexts specific to Fedora/refpolicy into its own configurations and partly due to MLS denials. I don't even know if it would work before this change though...
Couldn't seem to get a mdp-generated policy to boot on Fedora even in permissive, before or after this change. I assume it has to do with leaking of contexts outside of the policy and/or missing config files from the dummy policy (e.g.
/etc/selinux/targeted/contexts/hassystemd_contextsand other userspace config files that don't exist in the mdp policy). More evidence of the irrelevance of mdp...
Quoted 6 lines
Quoted 2 lines
Oh, right you need a "
dbus_contexts" file probably. DBUS refuses to start without it, and these day's without dbus no systemThere is actually a
dbus_contextsfile provided for mdp (scripts/selinux/mdp/dbus_contexts) but not asystemd_contextsor any other*_contextsfiles besidesfile_contexts.
There is no systemd_contexts, that never made it through. any references to that in libsemanage can be removed.
I suppose it might be related to no dbus and systemd access vector support. maybe that upsets dbus and/or systemd
Quoted 202 lines
Quoted 201 lines
Quoted 200 lines
Quoted 199 lines
Quoted 198 lines
Quoted 197 lines
Quoted 196 lines
Quoted 194 lines
scripts/selinux/mdp/mdp.c +19
-3@@ -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 */
scripts/selinux/mdp/mdp.c +72
-23@@ -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);
scripts/selinux/mdp/mdp.c +2
-2@@ -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;
Signature · 1 line
2.20.1
Signature · 3 lines
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02 https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02 Dominick Grift
Quoted 78 lines · Dominick Grift
Quoted 69 lines · Stephen Smalley
Quoted 62 lines · Stephen Smalley
Quoted 55 lines · Stephen Smalley
Quoted 50 lines · Stephen Smalley
Quoted 42 lines · Paul Moore
Quoted 26 lines · Stephen Smalley
Add basic MLS policy support to mdp. Declares two sensitivities and two categories, defines mls constraints for all permissions requiring dominance (ala MCS), assigns the system-high level to initial SID contexts and the default user level, and assigns system-low level to filesystems.
Also reworks the
fs_useand genfscon rules to only generate rules for filesystems that are configured in the kernel. In some cases this depends on a specific config option for security xattrs, in other cases security xattrs are unconditionally supported by a given filesystem if the filesystem is enabled, and in some cases the filesystem is always enabled in the kernel. Dropped obsolete pseudo filesystems.NB The list of fs_use_* and genfscon rules emitted by mdp is very incomplete compared to refpolicy or Android sepolicy. We should probably expand it.
Usage:
scripts/selinux/mdp/mdp-m policy.conffile_contextscheckpolicy -M -o policy policy.confThen install the resulting policy and
file_contextsas usual.Quoted 8 lines
Signed-off-by Stephen Smalley <[email protected]>---
v3 fixes up the file contexts generation code to also use SYSTEMLOW and
collapse down to a single fprintf call per line.scripts/selinux/mdp/mdp.c| 131
++++++++++++++++++++++++++++++--------1 file changed, 103 insertions(+), 28 deletions(-)This is great Stephen, thanks for working on this - and rather quickly too! For those who don't follow the GitHub issues, I just opened an issue yesterday mentioning it would be nice to add MLS support to the mdp tool.
Quoted 6 lines
Are you planning to keep playing with this? I'm asking not because I think it needs more work to be worthwhile, but rather I don't want to merge something that you want to continue working on. If you are happy with this latest patch I think it is okay to merge this into selinux/next, even at this late stage, simply because it is not part of a built kernel, but rather a developer's tool.
Quoted 3 lines
No, I think I'm done for now unless you find a problem with it. Absent some compelling use case for mdp it is hard to justify spending any more time on it.
Quoted 5 lines
Note however that the instructions in
Documentation/admin-guide/LSM/SELinux.rstjust say to runscripts/selinux/install_policy.shand since that doesn't pass -m to mdp or -M to checkpolicy, no one will use this support unless they do it all by hand.Quoted 5 lines
FWIW, a Fedora system wouldn't come up cleanly with this policy. Partly appears to be due to systemd having embedded security contexts specific to Fedora/refpolicy into its own configurations and partly due to MLS denials. I don't even know if it would work before this change though...
Quoted 6 lines
Couldn't seem to get a mdp-generated policy to boot on Fedora even in permissive, before or after this change. I assume it has to do with leaking of contexts outside of the policy and/or missing config files from the dummy policy (e.g.
/etc/selinux/targeted/contexts/hassystemd_contextsand other userspace config files that don't exist in the mdp policy). More evidence of the irrelevance of mdp...
Quoted 2 lines
Oh, right you need a "
dbus_contexts" file probably. DBUS refuses to start without it, and these day's without dbus no system
My dssp2-minimal [1] policy is my alternative to mdp.
https://github.com/DefenSec/dssp2-minimal
It is not quite as simple as mpd but it think it is decent balance between having something useful and still easy to read.
Quoted 199 lines
Quoted 199 lines
Quoted 198 lines
Quoted 197 lines
Quoted 196 lines
Quoted 195 lines
Quoted 193 lines
scripts/selinux/mdp/mdp.c +19
-3@@ -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 */
scripts/selinux/mdp/mdp.c +72
-23@@ -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);
scripts/selinux/mdp/mdp.c +0
-0@@ -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;
Signature · 1 line
2.20.1
Signature · 3 lines
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02 https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02 Dominick Grift
Paul Moore
maintainerQuoted 82 lines · Dominick Grift
Quoted 78 lines · Dominick Grift
Quoted 69 lines · Stephen Smalley
Quoted 62 lines · Stephen Smalley
Quoted 55 lines · Stephen Smalley
Quoted 50 lines · Stephen Smalley
Quoted 42 lines · Paul Moore
Quoted 26 lines · Stephen Smalley
Add basic MLS policy support to mdp. Declares two sensitivities and two categories, defines mls constraints for all permissions requiring dominance (ala MCS), assigns the system-high level to initial SID contexts and the default user level, and assigns system-low level to filesystems.
Also reworks the
fs_useand genfscon rules to only generate rules for filesystems that are configured in the kernel. In some cases this depends on a specific config option for security xattrs, in other cases security xattrs are unconditionally supported by a given filesystem if the filesystem is enabled, and in some cases the filesystem is always enabled in the kernel. Dropped obsolete pseudo filesystems.NB The list of fs_use_* and genfscon rules emitted by mdp is very incomplete compared to refpolicy or Android sepolicy. We should probably expand it.
Usage:
scripts/selinux/mdp/mdp-m policy.conffile_contextscheckpolicy -M -o policy policy.confThen install the resulting policy and
file_contextsas usual.Quoted 8 lines
Signed-off-by Stephen Smalley <[email protected]>---
v3 fixes up the file contexts generation code to also use SYSTEMLOW and
collapse down to a single fprintf call per line.scripts/selinux/mdp/mdp.c | 131 ++++++++++++++++++++++++++++++-------- 1 file changed, 103 insertions(+), 28 deletions(-)This is great Stephen, thanks for working on this - and rather quickly too! For those who don't follow the GitHub issues, I just opened an issue yesterday mentioning it would be nice to add MLS support to the mdp tool.
Quoted 6 lines
Are you planning to keep playing with this? I'm asking not because I think it needs more work to be worthwhile, but rather I don't want to merge something that you want to continue working on. If you are happy with this latest patch I think it is okay to merge this into selinux/next, even at this late stage, simply because it is not part of a built kernel, but rather a developer's tool.
Quoted 3 lines
No, I think I'm done for now unless you find a problem with it. Absent some compelling use case for mdp it is hard to justify spending any more time on it.
Quoted 5 lines
Note however that the instructions in
Documentation/admin-guide/LSM/SELinux.rstjust say to runscripts/selinux/install_policy.shand since that doesn't pass -m to mdp or -M to checkpolicy, no one will use this support unless they do it all by hand.Quoted 5 lines
FWIW, a Fedora system wouldn't come up cleanly with this policy. Partly appears to be due to systemd having embedded security contexts specific to Fedora/refpolicy into its own configurations and partly due to MLS denials. I don't even know if it would work before this change though...
Quoted 6 lines
Couldn't seem to get a mdp-generated policy to boot on Fedora even in permissive, before or after this change. I assume it has to do with leaking of contexts outside of the policy and/or missing config files from the dummy policy (e.g.
/etc/selinux/targeted/contexts/hassystemd_contextsand other userspace config files that don't exist in the mdp policy). More evidence of the irrelevance of mdp...Quoted 2 lines
Oh, right you need a "
dbus_contexts" file probably. DBUS refuses to start without it, and these day's without dbus no system
Quoted 6 lines
My dssp2-minimal [1] policy is my alternative to mdp.
https://github.com/DefenSec/dssp2-minimal
It is not quite as simple as mpd but it think it is decent balance between having something useful and still easy to read.
While dssp2-minimal is much smaller than reference policy, it's still an order of magnitude larger than the mdp generated policy. I'm not sure if this is something you care about, but if you wanted to work on getting mdp to the point where it would allow a Fedora system (or any modern SELinux based system for that matter) to boot, that could be useful, even if I'm not convinced it needs to be a priority at the moment.
Besides, haven't you always wanted to get a patch accepted into the kernel Dominick? ;)
Signature · 2 lines
paul moore www.paul-moore.com
Quoted 90 lines · Paul Moore
Quoted 82 lines · Dominick Grift
Quoted 78 lines · Dominick Grift
Quoted 69 lines · Stephen Smalley
Quoted 62 lines · Stephen Smalley
Quoted 55 lines · Stephen Smalley
Quoted 50 lines · Stephen Smalley
Quoted 42 lines · Paul Moore
Quoted 26 lines · Stephen Smalley
Add basic MLS policy support to mdp. Declares two sensitivities and two categories, defines mls constraints for all permissions requiring dominance (ala MCS), assigns the system-high level to initial SID contexts and the default user level, and assigns system-low level to filesystems.
Also reworks the
fs_useand genfscon rules to only generate rules for filesystems that are configured in the kernel. In some cases this depends on a specific config option for security xattrs, in other cases security xattrs are unconditionally supported by a given filesystem if the filesystem is enabled, and in some cases the filesystem is always enabled in the kernel. Dropped obsolete pseudo filesystems.NB The list of fs_use_* and genfscon rules emitted by mdp is very incomplete compared to refpolicy or Android sepolicy. We should probably expand it.
Usage:
scripts/selinux/mdp/mdp-m policy.conffile_contextscheckpolicy -M -o policy policy.confThen install the resulting policy and
file_contextsas usual.Quoted 8 lines
Signed-off-by Stephen Smalley <[email protected]>---
v3 fixes up the file contexts generation code to also use SYSTEMLOW and
collapse down to a single fprintf call per line.scripts/selinux/mdp/mdp.c | 131 ++++++++++++++++++++++++++++++-------- 1 file changed, 103 insertions(+), 28 deletions(-)This is great Stephen, thanks for working on this - and rather quickly too! For those who don't follow the GitHub issues, I just opened an issue yesterday mentioning it would be nice to add MLS support to the mdp tool.
Quoted 6 lines
Are you planning to keep playing with this? I'm asking not because I think it needs more work to be worthwhile, but rather I don't want to merge something that you want to continue working on. If you are happy with this latest patch I think it is okay to merge this into selinux/next, even at this late stage, simply because it is not part of a built kernel, but rather a developer's tool.
Quoted 3 lines
No, I think I'm done for now unless you find a problem with it. Absent some compelling use case for mdp it is hard to justify spending any more time on it.
Quoted 5 lines
Note however that the instructions in
Documentation/admin-guide/LSM/SELinux.rstjust say to runscripts/selinux/install_policy.shand since that doesn't pass -m to mdp or -M to checkpolicy, no one will use this support unless they do it all by hand.Quoted 5 lines
FWIW, a Fedora system wouldn't come up cleanly with this policy. Partly appears to be due to systemd having embedded security contexts specific to Fedora/refpolicy into its own configurations and partly due to MLS denials. I don't even know if it would work before this change though...
Quoted 6 lines
Couldn't seem to get a mdp-generated policy to boot on Fedora even in permissive, before or after this change. I assume it has to do with leaking of contexts outside of the policy and/or missing config files from the dummy policy (e.g.
/etc/selinux/targeted/contexts/hassystemd_contextsand other userspace config files that don't exist in the mdp policy). More evidence of the irrelevance of mdp...Quoted 2 lines
Oh, right you need a "
dbus_contexts" file probably. DBUS refuses to start without it, and these day's without dbus no systemQuoted 6 lines
My dssp2-minimal [1] policy is my alternative to mdp.
https://github.com/DefenSec/dssp2-minimal
It is not quite as simple as mpd but it think it is decent balance between having something useful and still easy to read.
Quoted 7 lines
While dssp2-minimal is much smaller than reference policy, it's still an order of magnitude larger than the mdp generated policy. I'm not sure if this is something you care about, but if you wanted to work on getting mdp to the point where it would allow a Fedora system (or any modern SELinux based system for that matter) to boot, that could be useful, even if I'm not convinced it needs to be a priority at the moment.
It is also an order of magnitude more useful than mdp.
I suppose I could look at what it would take to get it to boot on some rainy afternoon. Should not be hard, but i hesitate to polute mdp with user space access vectors. It feels like setting a precendent somehow.
Quoted 3 lines
Besides, haven't you always wanted to get a patch accepted into the kernel Dominick? ;)
Not particularly, no.
Signature · 3 lines
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02 https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02 Dominick Grift
Quoted 100 lines · Dominick Grift
Quoted 90 lines · Paul Moore
Quoted 82 lines · Dominick Grift
Quoted 78 lines · Dominick Grift
Quoted 69 lines · Stephen Smalley
Quoted 62 lines · Stephen Smalley
Quoted 55 lines · Stephen Smalley
Quoted 50 lines · Stephen Smalley
Quoted 42 lines · Paul Moore
Quoted 26 lines · Stephen Smalley
Add basic MLS policy support to mdp. Declares two sensitivities and two categories, defines mls constraints for all permissions requiring dominance (ala MCS), assigns the system-high level to initial SID contexts and the default user level, and assigns system-low level to filesystems.
Also reworks the
fs_useand genfscon rules to only generate rules for filesystems that are configured in the kernel. In some cases this depends on a specific config option for security xattrs, in other cases security xattrs are unconditionally supported by a given filesystem if the filesystem is enabled, and in some cases the filesystem is always enabled in the kernel. Dropped obsolete pseudo filesystems.NB The list of fs_use_* and genfscon rules emitted by mdp is very incomplete compared to refpolicy or Android sepolicy. We should probably expand it.
Usage:
scripts/selinux/mdp/mdp-m policy.conffile_contextscheckpolicy -M -o policy policy.confThen install the resulting policy and
file_contextsas usual.Quoted 8 lines
Signed-off-by Stephen Smalley <[email protected]>---
v3 fixes up the file contexts generation code to also use SYSTEMLOW and
collapse down to a single fprintf call per line.scripts/selinux/mdp/mdp.c | 131 ++++++++++++++++++++++++++++++-------- 1 file changed, 103 insertions(+), 28 deletions(-)This is great Stephen, thanks for working on this - and rather quickly too! For those who don't follow the GitHub issues, I just opened an issue yesterday mentioning it would be nice to add MLS support to the mdp tool.
Quoted 6 lines
Are you planning to keep playing with this? I'm asking not because I think it needs more work to be worthwhile, but rather I don't want to merge something that you want to continue working on. If you are happy with this latest patch I think it is okay to merge this into selinux/next, even at this late stage, simply because it is not part of a built kernel, but rather a developer's tool.
Quoted 3 lines
No, I think I'm done for now unless you find a problem with it. Absent some compelling use case for mdp it is hard to justify spending any more time on it.
Quoted 5 lines
Note however that the instructions in
Documentation/admin-guide/LSM/SELinux.rstjust say to runscripts/selinux/install_policy.shand since that doesn't pass -m to mdp or -M to checkpolicy, no one will use this support unless they do it all by hand.Quoted 5 lines
FWIW, a Fedora system wouldn't come up cleanly with this policy. Partly appears to be due to systemd having embedded security contexts specific to Fedora/refpolicy into its own configurations and partly due to MLS denials. I don't even know if it would work before this change though...
Quoted 6 lines
Couldn't seem to get a mdp-generated policy to boot on Fedora even in permissive, before or after this change. I assume it has to do with leaking of contexts outside of the policy and/or missing config files from the dummy policy (e.g.
/etc/selinux/targeted/contexts/hassystemd_contextsand other userspace config files that don't exist in the mdp policy). More evidence of the irrelevance of mdp...Quoted 2 lines
Oh, right you need a "
dbus_contexts" file probably. DBUS refuses to start without it, and these day's without dbus no systemQuoted 6 lines
My dssp2-minimal [1] policy is my alternative to mdp.
https://github.com/DefenSec/dssp2-minimal
It is not quite as simple as mpd but it think it is decent balance between having something useful and still easy to read.
Quoted 7 lines
While dssp2-minimal is much smaller than reference policy, it's still an order of magnitude larger than the mdp generated policy. I'm not sure if this is something you care about, but if you wanted to work on getting mdp to the point where it would allow a Fedora system (or any modern SELinux based system for that matter) to boot, that could be useful, even if I'm not convinced it needs to be a priority at the moment.
Quoted 5 lines
It is also an order of magnitude more useful than mdp.
I suppose I could look at what it would take to get it to boot on some rainy afternoon. Should not be hard, but i hesitate to polute mdp with user space access vectors. It feels like setting a precendent somehow.
In theory, if using selinux_check_access() to check permissions and if the policy sets allow_unknown=true, then the absence of the userspace classes and access vectors should just cause all userspace permission checks to pass.
Of course, not all userspace object managers use selinux_check_access(), and may not check security_deny_unknown() directly.
Quoted 7 lines
Quoted 4 lines
Besides, haven't you always wanted to get a patch accepted into the kernel Dominick? ;)
Not particularly, no.
Quoted 107 lines · Stephen Smalley
Quoted 100 lines · Dominick Grift
Quoted 90 lines · Paul Moore
Quoted 82 lines · Dominick Grift
Quoted 78 lines · Dominick Grift
Quoted 69 lines · Stephen Smalley
Quoted 62 lines · Stephen Smalley
Quoted 55 lines · Stephen Smalley
Quoted 50 lines · Stephen Smalley
Quoted 42 lines · Paul Moore
Quoted 26 lines · Stephen Smalley
Add basic MLS policy support to mdp. Declares two sensitivities and two categories, defines mls constraints for all permissions requiring dominance (ala MCS), assigns the system-high level to initial SID contexts and the default user level, and assigns system-low level to filesystems.
Also reworks the
fs_useand genfscon rules to only generate rules for filesystems that are configured in the kernel. In some cases this depends on a specific config option for security xattrs, in other cases security xattrs are unconditionally supported by a given filesystem if the filesystem is enabled, and in some cases the filesystem is always enabled in the kernel. Dropped obsolete pseudo filesystems.NB The list of fs_use_* and genfscon rules emitted by mdp is very incomplete compared to refpolicy or Android sepolicy. We should probably expand it.
Usage:
scripts/selinux/mdp/mdp-m policy.conffile_contextscheckpolicy -M -o policy policy.confThen install the resulting policy and
file_contextsas usual.Quoted 8 lines
Signed-off-by Stephen Smalley <[email protected]>---
v3 fixes up the file contexts generation code to also use SYSTEMLOW and
collapse down to a single fprintf call per line.scripts/selinux/mdp/mdp.c | 131 ++++++++++++++++++++++++++++++-------- 1 file changed, 103 insertions(+), 28 deletions(-)This is great Stephen, thanks for working on this - and rather quickly too! For those who don't follow the GitHub issues, I just opened an issue yesterday mentioning it would be nice to add MLS support to the mdp tool.
Quoted 6 lines
Are you planning to keep playing with this? I'm asking not because I think it needs more work to be worthwhile, but rather I don't want to merge something that you want to continue working on. If you are happy with this latest patch I think it is okay to merge this into selinux/next, even at this late stage, simply because it is not part of a built kernel, but rather a developer's tool.
Quoted 3 lines
No, I think I'm done for now unless you find a problem with it. Absent some compelling use case for mdp it is hard to justify spending any more time on it.
Quoted 5 lines
Note however that the instructions in
Documentation/admin-guide/LSM/SELinux.rstjust say to runscripts/selinux/install_policy.shand since that doesn't pass -m to mdp or -M to checkpolicy, no one will use this support unless they do it all by hand.Quoted 5 lines
FWIW, a Fedora system wouldn't come up cleanly with this policy. Partly appears to be due to systemd having embedded security contexts specific to Fedora/refpolicy into its own configurations and partly due to MLS denials. I don't even know if it would work before this change though...
Quoted 6 lines
Couldn't seem to get a mdp-generated policy to boot on Fedora even in permissive, before or after this change. I assume it has to do with leaking of contexts outside of the policy and/or missing config files from the dummy policy (e.g.
/etc/selinux/targeted/contexts/hassystemd_contextsand other userspace config files that don't exist in the mdp policy). More evidence of the irrelevance of mdp...Quoted 2 lines
Oh, right you need a "
dbus_contexts" file probably. DBUS refuses to start without it, and these day's without dbus no systemQuoted 6 lines
My dssp2-minimal [1] policy is my alternative to mdp.
https://github.com/DefenSec/dssp2-minimal
It is not quite as simple as mpd but it think it is decent balance between having something useful and still easy to read.
Quoted 7 lines
While dssp2-minimal is much smaller than reference policy, it's still an order of magnitude larger than the mdp generated policy. I'm not sure if this is something you care about, but if you wanted to work on getting mdp to the point where it would allow a Fedora system (or any modern SELinux based system for that matter) to boot, that could be useful, even if I'm not convinced it needs to be a priority at the moment.
Quoted 5 lines
It is also an order of magnitude more useful than mdp.
I suppose I could look at what it would take to get it to boot on some rainy afternoon. Should not be hard, but i hesitate to polute mdp with user space access vectors. It feels like setting a precendent somehow.
Quoted 8 lines
In theory, if using
selinux_check_access()to check permissions and if the policy sets allow_unknown=true, then the absence of the userspace classes and access vectors should just cause all userspace permission checks to pass.Of course, not all userspace object managers use
selinux_check_access(), and may not checksecurity_deny_unknown()directly.
The two object managers that matter do use selinux_access_check()
I admit that I got a little curious to find out what the issue is.
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
Besides, haven't you always wanted to get a patch accepted into the kernel Dominick? ;)
Not particularly, no.
Signature · 3 lines
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02 https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02 Dominick Grift
Quoted 114 lines · Dominick Grift
Quoted 112 lines · Stephen Smalley
Quoted 100 lines · Dominick Grift
Quoted 90 lines · Paul Moore
Quoted 82 lines · Dominick Grift
Quoted 78 lines · Dominick Grift
Quoted 69 lines · Stephen Smalley
Quoted 62 lines · Stephen Smalley
Quoted 55 lines · Stephen Smalley
Quoted 50 lines · Stephen Smalley
Quoted 42 lines · Paul Moore
Quoted 26 lines · Stephen Smalley
Add basic MLS policy support to mdp. Declares two sensitivities and two categories, defines mls constraints for all permissions requiring dominance (ala MCS), assigns the system-high level to initial SID contexts and the default user level, and assigns system-low level to filesystems.
Also reworks the
fs_useand genfscon rules to only generate rules for filesystems that are configured in the kernel. In some cases this depends on a specific config option for security xattrs, in other cases security xattrs are unconditionally supported by a given filesystem if the filesystem is enabled, and in some cases the filesystem is always enabled in the kernel. Dropped obsolete pseudo filesystems.NB The list of fs_use_* and genfscon rules emitted by mdp is very incomplete compared to refpolicy or Android sepolicy. We should probably expand it.
Usage:
scripts/selinux/mdp/mdp-m policy.conffile_contextscheckpolicy -M -o policy policy.confThen install the resulting policy and
file_contextsas usual.Quoted 8 lines
Signed-off-by Stephen Smalley <[email protected]>---
v3 fixes up the file contexts generation code to also use SYSTEMLOW and
collapse down to a single fprintf call per line.scripts/selinux/mdp/mdp.c | 131 ++++++++++++++++++++++++++++++-------- 1 file changed, 103 insertions(+), 28 deletions(-)This is great Stephen, thanks for working on this - and rather quickly too! For those who don't follow the GitHub issues, I just opened an issue yesterday mentioning it would be nice to add MLS support to the mdp tool.
Quoted 6 lines
Are you planning to keep playing with this? I'm asking not because I think it needs more work to be worthwhile, but rather I don't want to merge something that you want to continue working on. If you are happy with this latest patch I think it is okay to merge this into selinux/next, even at this late stage, simply because it is not part of a built kernel, but rather a developer's tool.
Quoted 3 lines
No, I think I'm done for now unless you find a problem with it. Absent some compelling use case for mdp it is hard to justify spending any more time on it.
Quoted 5 lines
Note however that the instructions in
Documentation/admin-guide/LSM/SELinux.rstjust say to runscripts/selinux/install_policy.shand since that doesn't pass -m to mdp or -M to checkpolicy, no one will use this support unless they do it all by hand.Quoted 5 lines
FWIW, a Fedora system wouldn't come up cleanly with this policy. Partly appears to be due to systemd having embedded security contexts specific to Fedora/refpolicy into its own configurations and partly due to MLS denials. I don't even know if it would work before this change though...
Quoted 6 lines
Couldn't seem to get a mdp-generated policy to boot on Fedora even in permissive, before or after this change. I assume it has to do with leaking of contexts outside of the policy and/or missing config files from the dummy policy (e.g.
/etc/selinux/targeted/contexts/hassystemd_contextsand other userspace config files that don't exist in the mdp policy). More evidence of the irrelevance of mdp...Quoted 2 lines
Oh, right you need a "
dbus_contexts" file probably. DBUS refuses to start without it, and these day's without dbus no systemQuoted 6 lines
My dssp2-minimal [1] policy is my alternative to mdp.
https://github.com/DefenSec/dssp2-minimal
It is not quite as simple as mpd but it think it is decent balance between having something useful and still easy to read.
Quoted 7 lines
While dssp2-minimal is much smaller than reference policy, it's still an order of magnitude larger than the mdp generated policy. I'm not sure if this is something you care about, but if you wanted to work on getting mdp to the point where it would allow a Fedora system (or any modern SELinux based system for that matter) to boot, that could be useful, even if I'm not convinced it needs to be a priority at the moment.
Quoted 5 lines
It is also an order of magnitude more useful than mdp.
I suppose I could look at what it would take to get it to boot on some rainy afternoon. Should not be hard, but i hesitate to polute mdp with user space access vectors. It feels like setting a precendent somehow.
In theory, if using
selinux_check_access()to check permissions and if the policy sets allow_unknown=true, then the absence of the userspace classes and access vectors should just cause all userspace permission checks to pass.
Quoted 7 lines
Quoted 3 lines
Of course, not all userspace object managers use
selinux_check_access(), and may not checksecurity_deny_unknown()directly.The two object managers that matter do use
selinux_access_check()I admit that I got a little curious to find out what the issue is.
Oh, I see: scripts/selinux/install_policy.sh just invokes checkpolicy without specifying -U / --handle-unknown, so the policy defaults to deny, and that would indeed render dbus-daemon and systemd broken with that policy. Might be as simple to fix as passing -U allow.
Quoted 11 lines
Quoted 10 lines
Quoted 9 lines
Quoted 6 lines
Besides, haven't you always wanted to get a patch accepted into the kernel Dominick? ;)
Not particularly, no.
On Fri, Feb 15, 2019 at 02:48:45PM -0500, Stephen Smalley wrote:
<snip>
Quoted 5 lines
Oh, I see:
scripts/selinux/install_policy.shjust invokes checkpolicy without specifying -U / --handle-unknown, so the policy defaults to deny, and that would indeed render dbus-daemon and systemd broken with that policy. Might be as simple to fix as passing -U allow.
I have looked a litte into this and here are some observations:
1. You can boot mdp as-is in permissive mode if you use checkpolicy with -U allow
2. You need *at least* an /etc/selinux/dummy/seusers with __default__:user_u and an accompanying /etc/selinux/dummy/contexts/failsafe_context with base_r:base_t to boot mdp in enforcing
3. There is an issue with checkpolicy and object_r:
PAM libselinux clients such as login try to associate object_r with the tty and fail.
if you try to append: role object_r; role object_r types base_t; to policy.conf and compile that with checkpolicy then the roletype-rule does *not* end up in the compiled policy for some reason.
thus, you cannot log in because object_r:base_t is not valid.
To hack around this add default_role * source rules to policy.conf and recompile.
This will allow you to log into the system locally in enforcing mode.
4. I also noticed that fedoras' ssh seems to hardcode sshd_net_t for its "privsep" functionality so, while untested, you probably need an openssh_contexts with privsep_preauth=base_t
Quoted 13 lines
Quoted 12 lines
Quoted 11 lines
Quoted 10 lines
Quoted 7 lines
Besides, haven't you always wanted to get a patch accepted into the kernel Dominick? ;)
Not particularly, no.
Signature · 3 lines
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02 https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02 Dominick Grift
Quoted 21 lines · Dominick Grift
On Fri, Feb 15, 2019 at 02:48:45PM -0500, Stephen Smalley wrote:
<snip>Quoted 5 lines
Oh, I see:
scripts/selinux/install_policy.shjust invokes checkpolicy without specifying -U / --handle-unknown, so the policy defaults to deny, and that would indeed render dbus-daemon and systemd broken with that policy. Might be as simple to fix as passing -U allow.I have looked a litte into this and here are some observations:
1. You can boot mdp as-is in permissive mode if you use
checkpolicywith-U allow2. You need *at least* an
/etc/selinux/dummy/seuserswith__default__:user_uand an accompanying/etc/selinux/dummy/contexts/failsafe_contextwithbase_r:base_tto boot mdp in enforcing3. There is an issue with checkpolicy and
object_r:PAM libselinux clients such as
logintry to associateobject_rwith the tty and fail.if you try to append:
role object_r; role object_r types base_t;to policy.conf and compile that withcheckpolicythen theroletype-ruledoes *not* end up in the compiled policy for some reason.
Quoted 8 lines
thus, you cannot log in because object_r:base_t is not valid.
To hack around this add
default_role * sourcerules to policy.conf and recompile.This will allow you to log into the system locally in enforcing mode.
4. I also noticed that fedoras' ssh seems to hardcode
sshd_net_tfor its "privsep" functionality so, while untested, you probably need anopenssh_contextswithprivsep_preauth=base_t
The install_policy.sh script should probably also do a bash file test for checkpolicy and fail gracefully if its not found
Signature · 3 lines
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02 https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02 Dominick Grift
Paul Moore
maintainerQuoted 11 lines · Dominick Grift
Quoted 9 lines · Dominick Grift
On Fri, Feb 15, 2019 at 02:48:45PM -0500, Stephen Smalley wrote:
<snip>Quoted 5 lines
Oh, I see:
scripts/selinux/install_policy.shjust invokes checkpolicy without specifying -U / --handle-unknown, so the policy defaults to deny, and that would indeed render dbus-daemon and systemd broken with that policy. Might be as simple to fix as passing -U allow.
Quoted 5 lines
Quoted 5 lines
I have looked a litte into this and here are some observations:
1. You can boot mdp as-is in permissive mode if you use
checkpolicywith-U allow2. You need *at least* an
/etc/selinux/dummy/seuserswith__default__:user_uand an accompanying/etc/selinux/dummy/contexts/failsafe_contextwithbase_r:base_tto boot mdp in enforcing
Wow. I didn't expect we would get to this point so quickly.
Originally my plan had been to just merge the mdp changes that Stephen submitted, and leave the rest for some other time. Although based on everything in this thread, it looks like we are really close to having something that you can build and boot without too many hacks.
Quoted 5 lines
Quoted 5 lines
3. There is an issue with checkpolicy and
object_r:PAM libselinux clients such as
logintry to associateobject_rwith the tty and fail.if you try to append:
role object_r; role object_r types base_t;to policy.conf and compile that withcheckpolicythen theroletype-ruledoes *not* end up in the compiled policy for some reason.
This sounds like a bug in checkpolicy ... ?
Quoted 7 lines
Quoted 7 lines
thus, you cannot log in because object_r:base_t is not valid.
To hack around this add
default_role * sourcerules to policy.conf and recompile.This will allow you to log into the system locally in enforcing mode.
4. I also noticed that fedoras' ssh seems to hardcode
sshd_net_tfor its "privsep" functionality so, while untested, you probably need anopenssh_contextswithprivsep_preauth=base_t
Petr, what's the deal with ssh on Fedora?
Quoted 1 line
The
install_policy.shscript should probably also do a bash file test forcheckpolicyand fail gracefully if its not found
Signature · 2 lines
paul moore www.paul-moore.com
Quoted 30 lines · Paul Moore
Quoted 11 lines · Dominick Grift
Quoted 9 lines · Dominick Grift
On Fri, Feb 15, 2019 at 02:48:45PM -0500, Stephen Smalley wrote:
<snip>Quoted 5 lines
Oh, I see:
scripts/selinux/install_policy.shjust invokes checkpolicy without specifying -U / --handle-unknown, so the policy defaults to deny, and that would indeed render dbus-daemon and systemd broken with that policy. Might be as simple to fix as passing -U allow.Quoted 8 lines
Quoted 8 lines
I have looked a litte into this and here are some observations:
1. You can boot mdp as-is in permissive mode if you use
checkpolicywith-U allow2. You need *at least* an
/etc/selinux/dummy/seuserswith__default__:user_uand an accompanying/etc/selinux/dummy/contexts/failsafe_contextwithbase_r:base_tto boot mdp in enforcingWow. I didn't expect we would get to this point so quickly.
Originally my plan had been to just merge the mdp changes that Stephen submitted, and leave the rest for some other time. Although based on everything in this thread, it looks like we are really close to having something that you can build and boot without too many hacks.
Quoted 2 lines
Quoted 2 lines
3. There is an issue with checkpolicy and
object_r:
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
PAM libselinux clients such as
logintry to associateobject_rwith the tty and fail.if you try to append:
role object_r; role object_r types base_t;to policy.conf and compile that withcheckpolicythen theroletype-ruledoes *not* end up in the compiled policy for some reason.This sounds like a bug in checkpolicy ... ?
Yes, looks like it
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
thus, you cannot log in because object_r:base_t is not valid.
To hack around this add
default_role * sourcerules to policy.conf and recompile.
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
This will allow you to log into the system locally in enforcing mode.
4. I also noticed that fedoras' ssh seems to hardcode
sshd_net_tfor its "privsep" functionality so, while untested, you probably need anopenssh_contextswithprivsep_preauth=base_tPetr, what's the deal with ssh on Fedora?
I wonder whether it would be possible (and feasible) to not transition on privsep_preauth at all *unless* a privsep preauth type is specified in openssh_context.
Currently it falls back to a hardcoded type to transition to if openssh_contexts does not exist.
Then again, i would not want to risk breaking or regressing some of the nice functionality openssh in fedora has for selinux. It's state is currently very good even compared to RHEL.
Quoted 2 lines
Quoted 2 lines
The
install_policy.shscript should probably also do a bash file test forcheckpolicyand fail gracefully if its not found
Signature · 3 lines
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02 https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02 Dominick Grift
A message that is not in the archive (sent off-list or not yet received): CAB9W1A3f1jxJQPrU-o=gEKzgjRGmbThoqPvzbK7QNqprdE-LAw@mail.gmail.com
Quoted 41 lines · Stephen Smalley
On Mon, Feb 18, 2019, 2:09 AM Dominick Grift <[email protected] wrote:
Quoted 37 lines · Paul Moore
Quoted 11 lines · Dominick Grift
Quoted 9 lines · Dominick Grift
On Fri, Feb 15, 2019 at 02:48:45PM -0500, Stephen Smalley wrote:
<snip>Quoted 5 lines
Oh, I see:
scripts/selinux/install_policy.shjust invokes checkpolicy without specifying -U / --handle-unknown, so the policy defaults to deny, and that would indeed render dbus-daemon and systemd broken with that policy. Might be as simple to fix as passing -U allow.Quoted 8 lines
Quoted 8 lines
I have looked a litte into this and here are some observations:
1. You can boot mdp as-is in permissive mode if you use
checkpolicywith-U allow2. You need *at least* an
/etc/selinux/dummy/seuserswith__default__:user_uand an accompanying/etc/selinux/dummy/contexts/failsafe_contextwithbase_r:base_tto boot mdp in enforcingWow. I didn't expect we would get to this point so quickly.
Originally my plan had been to just merge the mdp changes that Stephen submitted, and leave the rest for some other time. Although based on everything in this thread, it looks like we are really close to having something that you can build and boot without too many hacks.
Quoted 8 lines
Quoted 8 lines
3. There is an issue with checkpolicy and
object_r:PAM libselinux clients such as
logintry to associateobject_rwith the tty and fail.if you try to append:
role object_r; role object_r types base_t;to policy.conf and compile that withcheckpolicythen theroletype-ruledoes *not* end up in the compiled policy for some reason.
Quoted 8 lines
Quoted 1 line
This sounds like a bug in checkpolicy ... ?
Yes, looks like it
I don't think so.
object_rhas always been handled specially. The kernel ignores the role-type definition for it and always exempts contexts that contain it from user-role, role-type, and user-range restrictions. We didn't use to include it in the policy at all; I think CIL does but we only generate a stub in the kernel policy with the role name and value but no types and the kernel ignores it. What exactly breaks withpam_selinux?
The login program (pam_selinux) is not able to relabel the login user tty
(/dev/ttys0: user_u:base_r:base_t -> user_u:object_r:base_t) and so the user cannot log into the system in enforcing mode.
Maybe a missing contexts config file? I suppose I should look at it again since you sound confident that this is not a bug. I also suppose Android uses checkpolicy so they would have noticed?
Quoted 33 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
thus, you cannot log in because object_r:base_t is not valid.
To hack around this add
default_role * sourcerules to policy.conf and recompile.Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
This will allow you to log into the system locally in enforcing mode.
4. I also noticed that fedoras' ssh seems to hardcode
sshd_net_tfor its "privsep" functionality so, while untested, you probably need anopenssh_contextswithprivsep_preauth=base_tPetr, what's the deal with ssh on Fedora?
I wonder whether it would be possible (and feasible) to not transition on
privsep_preauthat all *unless* a privsep preauth type is specified inopenssh_context.Currently it falls back to a hardcoded type to transition to if
openssh_contextsdoes not exist.Then again, i would not want to risk breaking or regressing some of the nice functionality openssh in fedora has for selinux. It's state is currently very good even compared to RHEL.
Quoted 2 lines
Quoted 2 lines
The
install_policy.shscript should probably also do a bash file test forcheckpolicyand fail gracefully if its not found--
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02
https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02
Dominick Grift
Signature · 3 lines
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02 https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02 Dominick Grift
Quoted 52 lines · Stephen Smalley
Quoted 40 lines · On Mon, Feb 18, 2019, 2:09 AM Dominick Grift <[email protected] wrote:
Quoted 1 line · Paul Moore
On Sat, Feb 16, 2019 at 7:12 AM Dominick Grift <[email protected]>
Quoted 7 lines · wrote:
Quoted 7 lines · Dominick Grift
Quoted 5 lines · Stephen Smalley
<snip>
Quoted 2 lines
Oh, I see:
scripts/selinux/install_policy.shjust invokescheckpolicy
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
without specifying -U / --handle-unknown, so the policy defaults to
deny,
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
and that would indeed render dbus-daemon and systemd broken with
that
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
policy. Might be as simple to fix as passing -U allow.
I have looked a litte into this and here are some observations:
1. You can boot mdp as-is in permissive mode if you use
checkpolicywith
-U allowQuoted 6 lines
Quoted 5 lines
Quoted 5 lines
2. You need *at least* an
/etc/selinux/dummy/seuserswith__default__:user_uand an accompanying/etc/selinux/dummy/contexts/failsafe_contextwithbase_r:base_tto boot mdp in enforcingQuoted 10 lines
Wow. I didn't expect we would get to this point so quickly.
Originally my plan had been to just merge the mdp changes that Stephen submitted, and leave the rest for some other time. Although based on everything in this thread, it looks like we are really close to having something that you can build and boot without too many hacks.
Quoted 3 lines
Quoted 3 lines
3. There is an issue with checkpolicy and
object_r:PAM libselinux clients such as
logintry to associateobject_rwith the tty and fail.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
if you try to append:
role object_r; role object_r types base_t;to policy.conf and compile that withcheckpolicythen theroletype-ruledoes *not* end up in the compiled policy for some reason.This sounds like a bug in checkpolicy ... ?
Yes, looks like it
Quoted 7 lines
I don't think so.
object_rhas always been handled specially. The kernel ignores the role-type definition for it and always exempts contexts that contain it from user-role, role-type, and user-range restrictions. We didn't use to include it in the policy at all; I think CIL does but we only generate a stub in the kernel policy with the role name and value but no types and the kernel ignores it. What exactly breaks withpam_selinux?
Tried it again and this time I tried to run install_selinux.sh with selinux disabled (previously i did not bother to boot with selinux disabled)
Now I think I see what you were seeing:
1. setfiles is called in install_selinux.sh but it does not relabel when selinux is disabled
2. the system is misabeled and when you boot, that prompts an autorelabel (don't what does that but maybe systemd) which ,for some reason, does not work either even though it looks like its doing something
3. system does not start properly (even in permissive mode) because it looks like systemd can't compute a valid context using the mislabeled /sbin/init
This, i think, would address that:
1. dont try to run setfiles in install_selinux.sh because it does not work in the scenario where you run install_selinux.sh when selinux is disabled (audit actually prints an FS_RELABEL event but nothing is relabeled)
2. in /etc/selinux/config use SELINUX=permissive instead of SELINUX=enforcing (it needs to relabel in permissive mode in the next step)
3. echo '-F' > /.autorelabel
When all is said and done I still hit the issue where I am not able to log into the system in enforcing mode:
Feb 19 12:05:04 myguest login[1175]: pam_selinux(login:session): Setting file context "user_u:object_r:base_t" failed for /dev/ttyS0: Operation not supported
Quoted 36 lines
Quoted 36 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
thus, you cannot log in because object_r:base_t is not valid.
To hack around this add
default_role * sourcerules to policy.confand recompile.
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
This will allow you to log into the system locally in enforcing mode.
4. I also noticed that fedoras' ssh seems to hardcode
sshd_net_tfor its "privsep" functionality so, while untested, you probably need anopenssh_contextswithprivsep_preauth=base_tPetr, what's the deal with ssh on Fedora?
I wonder whether it would be possible (and feasible) to not transition on
privsep_preauthat all *unless* a privsep preauth type is specified inopenssh_context.Currently it falls back to a hardcoded type to transition to if
openssh_contextsdoes not exist.Then again, i would not want to risk breaking or regressing some of the nice
functionality openssh in fedora has for selinux. It's state is currently very good even compared to RHEL.Quoted 2 lines
Quoted 2 lines
The
install_policy.shscript should probably also do a bash file testfor
checkpolicyand fail gracefully if its not found--
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02
https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02
Dominick Grift
Signature · 3 lines
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02 https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02 Dominick Grift
A message that is not in the archive (sent off-list or not yet received): CAB9W1A2s+PcrC=fPXA9AYRm1oVYArsRCGKihM5mjUqnQtuLe3w@mail.gmail.com
A message that is not in the archive (sent off-list or not yet received): CAB9W1A3Pef5pfAZ8UEvSQYvWA9oZTRNPvWFCHw8e9eqZsGvGWA@mail.gmail.com
Quoted 87 lines · Stephen Smalley
Quoted 84 lines · On Tue, Feb 19, 2019, 8:21 AM Stephen Smalley <[email protected] wrote:
Quoted 80 lines · On Tue, Feb 19, 2019, 6:08 AM Dominick Grift <[email protected] wrote:
Quoted 1 line · Stephen Smalley
On Mon, Feb 18, 2019, 2:09 AM Dominick Grift <[email protected]
Quoted 4 lines · wrote:
Quoted 4 lines
Quoted 1 line · Paul Moore
On Sat, Feb 16, 2019 at 7:12 AM Dominick Grift <
Quoted 10 lines
Quoted 10 lines
Quoted 7 lines · wrote:
Quoted 7 lines · Dominick Grift
Quoted 5 lines · Stephen Smalley
<snip>
Quoted 2 lines
Oh, I see:
scripts/selinux/install_policy.shjust invokescheckpolicy
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
without specifying -U / --handle-unknown, so the policy
defaults to
Quoted 2 lines
Quoted 2 lines
deny,
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
and that would indeed render dbus-daemon and systemd broken
with
Quoted 6 lines
Quoted 6 lines
that
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
policy. Might be as simple to fix as passing -U allow.
I have looked a litte into this and here are some observations:
1. You can boot mdp as-is in permissive mode if you use
checkpolicyQuoted 10 lines
Quoted 10 lines
with
-U allowQuoted 9 lines
Quoted 5 lines
Quoted 5 lines
2. You need *at least* an
/etc/selinux/dummy/seuserswith__default__:user_uand an accompanying/etc/selinux/dummy/contexts/failsafe_contextwithbase_r:base_tto boot mdp in enforcingWow. I didn't expect we would get to this point so quickly.
Originally my plan had been to just merge the mdp changes that
Stephen
Quoted 1 line
Quoted 1 line
Quoted 1 line
submitted, and leave the rest for some other time. Although based
on
Quoted 1 line
Quoted 1 line
Quoted 1 line
everything in this thread, it looks like we are really close to
having
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
something that you can build and boot without too many hacks.
Quoted 3 lines
Quoted 3 lines
3. There is an issue with checkpolicy and
object_r:PAM libselinux clients such as
logintry to associate
object_rQuoted 3 lines
Quoted 3 lines
with the tty and fail.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
if you try to append: `role
object_r; roleobject_rtypesbase_t;`
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
to policy.conf and compile that with
checkpolicythen theroletype-ruledoes *not* end up in the compiled policy for some reason.This sounds like a bug in checkpolicy ... ?
Quoted 7 lines
Quoted 2 lines
Yes, looks like it
I don't think so.
object_rhas always been handled specially. The kernel ignores the role-type definition for it and always exempts contexts that contain it from user-role, role-type, and user-range restrictions. We didn't use to include it in the policy at all; I think CIL does but weonly
Quoted 3 lines
generate a stub in the kernel policy with the role name and value but no types and the kernel ignores it. What exactly breaks with
pam_selinux?Tried it again and this time I tried to run
install_selinux.shwith selinux disabled (previously i did not bother to boot with selinux disabled)Now I think I see what you were seeing:
1. setfiles is called in
install_selinux.shbut it does not relabel when selinux is disabled
Quoted 7 lines
Quoted 4 lines
That's a bug in setfiles / libselinux
selinux_restorecon. I thought that was fixed recently. If selinux is disabled, we should not exclude filesystem based on seclabel.Was it never merged?
https://lore.kernel.org/selinux/[email protected]/
Apparently it was not merged. Since there was no objection, only a LGTM comment I've just merged it.
Quoted 83 lines
Quoted 83 lines
2. the system is misabeled and when you boot, that prompts an autorelabel
Quoted 16 lines
(don't what does that but maybe systemd) which ,for some reason, does not work either even though it looks like its doing something
3. system does not start properly (even in permissive mode) because it looks like systemd can't compute a valid context using the mislabeled/sbin/initThis, i think, would address that:
1. dont try to run setfiles in
install_selinux.shbecause it does not work in the scenario where you runinstall_selinux.shwhen selinux is disabled (audit actually prints anFS_RELABELevent but nothing is relabeled)
2. in/etc/selinux/configuse SELINUX=permissive instead of SELINUX=enforcing (it needs to relabel in permissive mode in the next step)
3. echo '-F' > /.autorelabelQuoted 7 lines
When all is said and done I still hit the issue where I am not able to log into the system in enforcing mode:
Feb 19 12:05:04 myguest login[1175]: pam_selinux(login:session): Settingfile context "user_u:object_r:base_t" failed for
/dev/ttyS0: Operation not supportedOperation not supported means that the filesystem type isn't configured for labeling. Looks like mdp was never updated to include devtmpfs among other filesystems.
Quoted 50 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
thus, you cannot log in because object_r:base_t is not valid.
To hack around this add
default_role * sourcerules topolicy.conf
Quoted 3 lines
Quoted 3 lines
and recompile.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
This will allow you to log into the system locally in enforcing
mode.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
4. I also noticed that fedoras' ssh seems to hardcode
sshd_net_tQuoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
for its "privsep" functionality so, while untested, you probably need an
openssh_contextswithprivsep_preauth=base_tPetr, what's the deal with ssh on Fedora?
I wonder whether it would be possible (and feasible) to not
transition on
Quoted 7 lines
Quoted 7 lines
privsep_preauthat all *unless* a privsep preauth type is specified inopenssh_context.Currently it falls back to a hardcoded type to transition to if
openssh_contextsdoes not exist.Then again, i would not want to risk breaking or regressing some of
the
Quoted 2 lines
Quoted 2 lines
nice
functionality openssh in fedora has for selinux. It's state iscurrently
Quoted 4 lines
Quoted 4 lines
very good even compared to RHEL.
Quoted 2 lines
Quoted 2 lines
The
install_policy.shscript should probably also do a bash filetest
Quoted 5 lines
Quoted 5 lines
for
checkpolicyand fail gracefully if its not found--
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02
Quoted 2 lines
Quoted 2 lines
Dominick Grift
--
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02
https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02
Dominick Grift
Quoted 34 lines · Dominick Grift
Quoted 32 lines · Paul Moore
Quoted 11 lines · Dominick Grift
Quoted 9 lines · Dominick Grift
On Fri, Feb 15, 2019 at 02:48:45PM -0500, Stephen Smalley wrote:
<snip>Quoted 5 lines
Oh, I see:
scripts/selinux/install_policy.shjust invokes checkpolicy without specifying -U / --handle-unknown, so the policy defaults to deny, and that would indeed render dbus-daemon and systemd broken with that policy. Might be as simple to fix as passing -U allow.Quoted 8 lines
Quoted 8 lines
I have looked a litte into this and here are some observations:
1. You can boot mdp as-is in permissive mode if you use
checkpolicywith-U allow2. You need *at least* an
/etc/selinux/dummy/seuserswith__default__:user_uand an accompanying/etc/selinux/dummy/contexts/failsafe_contextwithbase_r:base_tto boot mdp in enforcingWow. I didn't expect we would get to this point so quickly.
Originally my plan had been to just merge the mdp changes that Stephen submitted, and leave the rest for some other time. Although based on everything in this thread, it looks like we are really close to having something that you can build and boot without too many hacks.
Quoted 4 lines
Quoted 4 lines
3. There is an issue with checkpolicy and
object_r:PAM libselinux clients such as
logintry to associateobject_rwith the tty and fail.
Quoted 19 lines
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
if you try to append:
role object_r; role object_r types base_t;to policy.conf and compile that withcheckpolicythen theroletype-ruledoes *not* end up in the compiled policy for some reason.This sounds like a bug in checkpolicy ... ?
Yes, looks like it
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
thus, you cannot log in because object_r:base_t is not valid.
To hack around this add
default_role * sourcerules to policy.conf and recompile.This will allow you to log into the system locally in enforcing mode.
4. I also noticed that fedoras' ssh seems to hardcode
sshd_net_tfor its "privsep" functionality so, while untested, you probably need anopenssh_contextswithprivsep_preauth=base_t
"sshd_net_t" is really hardcoded as a fallback but ssh_selinux_change_context("sshd_net_t"); is not a fatal operation. If it fails it just logs a debug message and the type of the process stays unaffected - by default it's sshd_t
I believe that openssh_context is not necessary if you don't mind or want to use different type for privsep preauth sshd processes.
Quoted 6 lines
Quoted 1 line
Petr, what's the deal with ssh on Fedora?
I wonder whether it would be possible (and feasible) to not transition on
privsep_preauthat all *unless* a privsep preauth type is specified inopenssh_context.
Quoted 6 lines
Currently it falls back to a hardcoded type to transition to if
openssh_contextsdoes not exist.Then again, i would not want to risk breaking or regressing some of the nice functionality openssh in fedora has for selinux. It's state is currently very good even compared to RHEL.
I think it's feasible without a big risk.
https://bugzilla.redhat.com/show_bug.cgi?id=1678695
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
The
install_policy.shscript should probably also do a bash file test forcheckpolicyand fail gracefully if its not found
Quoted 73 lines · Petr Lautrbach
Quoted 47 lines · Dominick Grift
Quoted 45 lines · Paul Moore
Quoted 12 lines · Dominick Grift
Quoted 1 line · Dominick Grift
On Fri, Feb 15, 2019 at 02:48:45PM -0500, Stephen Smalley >
Quoted 4 lines · wrote:
<snip>
Quoted 2 lines
Oh, I see:
scripts/selinux/install_policy.shjust invokes > >checkpolicy
Quoted 1 line
Quoted 1 line
without specifying -U / --handle-unknown, so the policy > >
defaults to deny,
Quoted 1 line
Quoted 1 line
and that would indeed render dbus-daemon and systemd > >
Quoted 13 lines
broken with that
Quoted 3 lines
Quoted 1 line
policy. Might be as simple to fix as passing -U allow.
I have looked a litte into this and here are some >
observations:
Quoted 2 lines
1. You can boot mdp as-is in permissive mode if you use >
checkpolicywith-U allowQuoted 5 lines
2. You need *at least* an
/etc/selinux/dummy/seuserswith__default__:user_uand an accompanying/etc/selinux/dummy/contexts/failsafe_contextwithbase_r:base_tto boot mdp in enforcingWow. I didn't expect we would get to this point so quickly.
Originally my plan had been to just merge the mdp changes that Stephen
submitted, and leave the rest for some other time. Although based on
everything in this thread, it looks like we are really close to having
something that you can build and boot without too many hacks.Quoted 7 lines
Quoted 3 lines
3. There is an issue with checkpolicy and
object_r:PAM libselinux clients such as
logintry to associate >
object_rwith the tty and fail.Quoted 2 lines
if you try to append: `role
object_r; roleobject_rtypes >base_t;`
Quoted 23 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
to policy.conf and compile that with
checkpolicythen theroletype-ruledoes *not* end up in the compiled policy for >some
Quoted 1 line
reason.
This sounds like a bug in checkpolicy ... ?
Yes, looks like it
Quoted 14 lines
Quoted 14 lines
Quoted 4 lines
thus, you cannot log in because object_r:base_t is not > valid.
To hack around this add
default_role * sourcerules to >policy.conf and recompile.
Quoted 2 lines
This will allow you to log into the system locally in >
enforcing mode.
Quoted 2 lines
4. I also noticed that fedoras' ssh seems to hardcode >
sshd_net_tQuoted 1 line
for its "privsep" functionality so, while untested, you >
probably
Quoted 1 line
need an
openssh_contextswithprivsep_preauth=base_t
Quoted 7 lines
"
sshd_net_t" is really hardcoded as a fallback butssh_selinux_change_context("sshd_net_t"); is not a fatal operation. If it fails it just logs a debug message and the type of the process stays unaffected - by default it'ssshd_tI believe that
openssh_contextis not necessary if you don't mind or want to use different type for privsep preauth sshd processes.
Thanks. So just a warning message. Might be possible to only log it if debug is enabled?
Quoted 27 lines
Quoted 10 lines
Quoted 3 lines
Petr, what's the deal with ssh on Fedora?
I wonder whether it would be possible (and feasible) to not transition on
privsep_preauthat all *unless* a privsep preauth type is specified inopenssh_context.Quoted 8 lines
Currently it falls back to a hardcoded type to transition to if
openssh_contextsdoes not exist.Then again, i would not want to risk breaking or regressing some of the nice
functionality openssh in fedora has for selinux. It's state is currently
very good even compared to RHEL.I think it's feasible without a big risk.
https://bugzilla.redhat.com/show_bug.cgi?id=1678695
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
The
install_policy.shscript should probably also do a bash file test forcheckpolicyand fail gracefully if its not found
Signature · 3 lines
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02 https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02 Dominick Grift
Quoted 80 lines · Dominick Grift
Quoted 78 lines · Petr Lautrbach
Quoted 47 lines · Dominick Grift
Quoted 45 lines · Paul Moore
Quoted 12 lines · Dominick Grift
Quoted 1 line · Dominick Grift
On Fri, Feb 15, 2019 at 02:48:45PM -0500, Stephen Smalley >
Quoted 4 lines · wrote:
<snip>
Quoted 2 lines
Oh, I see:
scripts/selinux/install_policy.shjust invokes > >checkpolicy
Quoted 1 line
Quoted 1 line
without specifying -U / --handle-unknown, so the policy > >
defaults to deny,
Quoted 1 line
Quoted 1 line
and that would indeed render dbus-daemon and systemd > >
Quoted 13 lines
broken with that
Quoted 3 lines
Quoted 1 line
policy. Might be as simple to fix as passing -U allow.
I have looked a litte into this and here are some >
observations:
Quoted 2 lines
1. You can boot mdp as-is in permissive mode if you use >
checkpolicywith-U allowQuoted 5 lines
2. You need *at least* an
/etc/selinux/dummy/seuserswith__default__:user_uand an accompanying/etc/selinux/dummy/contexts/failsafe_contextwithbase_r:base_tto boot mdp in enforcingWow. I didn't expect we would get to this point so quickly.
Originally my plan had been to just merge the mdp changes that Stephen
submitted, and leave the rest for some other time. Although based on
everything in this thread, it looks like we are really close to having
something that you can build and boot without too many hacks.Quoted 7 lines
Quoted 3 lines
3. There is an issue with checkpolicy and
object_r:PAM libselinux clients such as
logintry to associate >
object_rwith the tty and fail.Quoted 2 lines
if you try to append: `role
object_r; roleobject_rtypes >base_t;`
Quoted 23 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
to policy.conf and compile that with
checkpolicythen theroletype-ruledoes *not* end up in the compiled policy for >some
Quoted 1 line
reason.
This sounds like a bug in checkpolicy ... ?
Yes, looks like it
Quoted 14 lines
Quoted 14 lines
Quoted 4 lines
thus, you cannot log in because object_r:base_t is not > valid.
To hack around this add
default_role * sourcerules to >policy.conf and recompile.
Quoted 2 lines
This will allow you to log into the system locally in >
enforcing mode.
Quoted 2 lines
4. I also noticed that fedoras' ssh seems to hardcode >
sshd_net_tQuoted 1 line
for its "privsep" functionality so, while untested, you >
probably
Quoted 1 line
need an
openssh_contextswithprivsep_preauth=base_t"
sshd_net_t" is really hardcoded as a fallback butssh_selinux_change_context("sshd_net_t"); is not a fatal operation. If it fails it just logs a debug message and the type of the process stays unaffected - by default it'ssshd_t
Quoted 5 lines
Quoted 2 lines
I believe that
openssh_contextis not necessary if you don't mind or want to use different type for privsep preauth sshd processes.Thanks. So just a warning message. Might be possible to only log it if debug is enabled?
Whoops sorry. I overlooked the remainder of your reply. Thanks for addressing.
Quoted 33 lines
Quoted 28 lines
Quoted 11 lines
Quoted 4 lines
Petr, what's the deal with ssh on Fedora?
I wonder whether it would be possible (and feasible) to not transition on
privsep_preauthat all *unless* a privsep preauth type is specified inopenssh_context.Quoted 8 lines
Currently it falls back to a hardcoded type to transition to if
openssh_contextsdoes not exist.Then again, i would not want to risk breaking or regressing some of the nice
functionality openssh in fedora has for selinux. It's state is currently
very good even compared to RHEL.I think it's feasible without a big risk.
https://bugzilla.redhat.com/show_bug.cgi?id=1678695
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
The
install_policy.shscript should probably also do a bash file test forcheckpolicyand fail gracefully if its not foundSignature · 3 lines
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02 https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02 Dominick Grift
Signature · 3 lines
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02 https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02 Dominick Grift
Quoted 61 lines · Stephen Smalley
Quoted 54 lines · Stephen Smalley
Quoted 49 lines · Stephen Smalley
Quoted 41 lines · Paul Moore
Quoted 26 lines · Stephen Smalley
Add basic MLS policy support to mdp. Declares two sensitivities and two categories, defines mls constraints for all permissions requiring dominance (ala MCS), assigns the system-high level to initial SID contexts and the default user level, and assigns system-low level to filesystems.
Also reworks the
fs_useand genfscon rules to only generate rules for filesystems that are configured in the kernel. In some cases this depends on a specific config option for security xattrs, in other cases security xattrs are unconditionally supported by a given filesystem if the filesystem is enabled, and in some cases the filesystem is always enabled in the kernel. Dropped obsolete pseudo filesystems.NB The list of fs_use_* and genfscon rules emitted by mdp is very incomplete compared to refpolicy or Android sepolicy. We should probably expand it.
Usage:
scripts/selinux/mdp/mdp-m policy.conffile_contextscheckpolicy -M -o policy policy.confThen install the resulting policy and
file_contextsas usual.Quoted 7 lines
Signed-off-by Stephen Smalley <[email protected]>---
v3 fixes up the file contexts generation code to also use SYSTEMLOW and collapse down to a single fprintf call per line.scripts/selinux/mdp/mdp.c| 131
++++++++++++++++++++++++++++++--------1 file changed, 103 insertions(+), 28 deletions(-)This is great Stephen, thanks for working on this - and rather quickly too! For those who don't follow the GitHub issues, I just opened an issue yesterday mentioning it would be nice to add MLS support to the mdp tool.
Quoted 6 lines
Are you planning to keep playing with this? I'm asking not because I think it needs more work to be worthwhile, but rather I don't want to merge something that you want to continue working on. If you are happy with this latest patch I think it is okay to merge this into selinux/next, even at this late stage, simply because it is not part of a built kernel, but rather a developer's tool.
Quoted 3 lines
No, I think I'm done for now unless you find a problem with it. Absent some compelling use case for mdp it is hard to justify spending any more time on it.
Quoted 5 lines
Note however that the instructions in
Documentation/admin-guide/LSM/SELinux.rstjust say to runscripts/selinux/install_policy.shand since that doesn't pass -m to mdp or -M to checkpolicy, no one will use this support unless they do it all by hand.
Quoted 5 lines
FWIW, a Fedora system wouldn't come up cleanly with this policy. Partly appears to be due to systemd having embedded security contexts specific to Fedora/refpolicy into its own configurations and partly due to MLS denials. I don't even know if it would work before this change though...
Interesting. Can you be more specific? I can boot my dssp2 policy on fedora just fine.
The only thing you might want to do is relabeling the underlying mountpoints. Beccause if you install mdp and then relabel the filesystem, there are a lot of filesystems mounted over mislabeled mountpoints
you'd do a bind --mount / /mnt
And then label those there. Example from dssp2:
When installing dssp2-standard on an existing fedora installation some contexts of directories in the root filesystem become invalid
mount --bind / /mnt
chcon -u sys.id -r sys.role -t fs.sysfs.fs /mnt/sys
chcon -u sys.id -r sys.role -t files.generic_runtime.runtime_file /mnt/run chcon -u sys.id -r sys.role -t files.home.file /mnt/home
chcon -u sys.id -r sys.role -t fs.proc.fs /mnt/proc
chcon -u sys.id -r sys.role -t fs.devtmpfs.fs /mnt/dev
chcon -u sys.id -r sys.role -t files.generic_boot.boot_file /mnt/boot chcon -R -u sys.id -r sys.role -t fs.tmpfs.fs /mnt/tmp setenforce 0
rm -f /mnt/tmp/ks-script-*
setenforce 1
umount /mnt
umount /boot/efi
restorecon -RF /boot/efi
mount /dev/sda1 /boot/efi
setsebool -P sys.mounton_invalid_dir off
Quoted 193 lines
Quoted 192 lines
Quoted 191 lines
Quoted 190 lines
Quoted 188 lines
scripts/selinux/mdp/mdp.c +20
-3@@ -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 */
scripts/selinux/mdp/mdp.c +72
-23@@ -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);
scripts/selinux/mdp/mdp.c +0
-0@@ -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;
Signature · 1 line
2.20.1
Signature · 3 lines
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02 https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02 Dominick Grift
Paul Moore
maintainerQuoted 47 lines · Stephen Smalley
Quoted 39 lines · Paul Moore
Quoted 24 lines · Stephen Smalley
Add basic MLS policy support to mdp. Declares two sensitivities and two categories, defines mls constraints for all permissions requiring dominance (ala MCS), assigns the system-high level to initial SID contexts and the default user level, and assigns system-low level to filesystems.
Also reworks the
fs_useand genfscon rules to only generate rules for filesystems that are configured in the kernel. In some cases this depends on a specific config option for security xattrs, in other cases security xattrs are unconditionally supported by a given filesystem if the filesystem is enabled, and in some cases the filesystem is always enabled in the kernel. Dropped obsolete pseudo filesystems.NB The list of fs_use_* and genfscon rules emitted by mdp is very incomplete compared to refpolicy or Android sepolicy. We should probably expand it.
Usage:
scripts/selinux/mdp/mdp-m policy.conffile_contextscheckpolicy -M -o policy policy.confQuoted 8 lines
Then install the resulting policy and
file_contextsas usual.Signed-off-by Stephen Smalley <[email protected]>---
v3 fixes up the file contexts generation code to also use SYSTEMLOW and collapse down to a single fprintf call per line.scripts/selinux/mdp/mdp.c | 131 ++++++++++++++++++++++++++++++-------- 1 file changed, 103 insertions(+), 28 deletions(-)This is great Stephen, thanks for working on this - and rather quickly too! For those who don't follow the GitHub issues, I just opened an issue yesterday mentioning it would be nice to add MLS support to the mdp tool.
Quoted 6 lines
Are you planning to keep playing with this? I'm asking not because I think it needs more work to be worthwhile, but rather I don't want to merge something that you want to continue working on. If you are happy with this latest patch I think it is okay to merge this into selinux/next, even at this late stage, simply because it is not part of a built kernel, but rather a developer's tool.
Quoted 3 lines
No, I think I'm done for now unless you find a problem with it. Absent some compelling use case for mdp it is hard to justify spending any more time on it.
For the record, I think having something like mdp is important as a simple, quick to parse (by human eyes) demonstration of a "complete" SELinux policy. I recognize we could have a lot of good arguments about what constitutes a "complete" SELinux policy, but for mdp let's try to keep it as simple as possible for now.
Signature · 2 lines
paul moore www.paul-moore.com