scripts/selinux: modernize mdp
PATCH 1/1 scripts/selinux: modernize mdp
The MDP example no longer works on modern systems.
Add support for devtmpfs. This is required by login programs to relabel terminals.
Compile the policy with deny_unknown allow status to anticipate user space object managers in core components such as systemd. Add default seusers mapping and failsafe context for the SELinux PAM module.
--- scripts/selinux/install_policy.sh | 6 +++++- scripts/selinux/mdp/mdp.c | 1 + 2 files changed, 6 insertions(+), 1 deletion(-)
scripts/selinux/install_policy.sh +5 -1
@@ -20,14 +20,18 @@ CP=`which checkpolicy` VERS=`$CP -V | awk '{print $1}'` ./mdp policy.conf file_contexts -$CP -o policy.$VERS policy.conf +$CP -U allow -o policy.$VERS policy.conf mkdir -p /etc/selinux/dummy/policy mkdir -p /etc/selinux/dummy/contexts/files +echo "__default__:user_u" > /etc/selinux/dummy/seusers +echo "base_r:base_t" > /etc/selinux/dummy/contexts/failsafe_context + cp file_contexts /etc/selinux/dummy/contexts/files cp dbus_contexts /etc/selinux/dummy/contexts cp policy.$VERS /etc/selinux/dummy/policy + FC_FILE=/etc/selinux/dummy/contexts/files/file_contexts if [ ! -d /etc/selinux ]; then
scripts/selinux/mdp/mdp.c +1 -0
@@ -131,6 +131,7 @@ int main(int argc, char *argv[])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 devtmpfs 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" );
Signature · 1 line
2.21.0.rc1
Quoted 5 lines · Dominick Grift
The MDP example no longer works on modern systems.
Add support for devtmpfs. This is required by login programs to relabel terminals.
Compile the policy withdeny_unknownallow status to anticipate user space object managers in core components such as systemd. Add default seusers mapping and failsafe context for the SELinux PAM module.
There are a couple more possible improvements that i have identified:
Fail gracefully if checkpolicy does not exist
Run setfiles with -F. There *might* be one scenario where this might be a good idea. Where the filesystem is labeled with invalid contexts but where SELinux is disabled. In that case setfiles will reset, but only types (I suppose)
Quoted 46 lines
Signed-off-by Dominick Grift <[email protected]>--- scripts/selinux/install_policy.sh | 6 +++++- scripts/selinux/mdp/mdp.c | 1 + 2 files changed, 6 insertions(+), 1 deletion(-)scripts/selinux/install_policy.sh +5
-1@@ -20,14 +20,18 @@ CP=`which checkpolicy` VERS=`$CP -V | awk '{print $1}'` ./mdp policy.conf file_contexts -$CP -o policy.$VERS policy.conf +$CP -U allow -o policy.$VERS policy.conf mkdir -p /etc/selinux/dummy/policy mkdir -p /etc/selinux/dummy/contexts/files +echo "__default__:user_u" > /etc/selinux/dummy/seusers +echo "base_r:base_t" > /etc/selinux/dummy/contexts/failsafe_context + cp file_contexts /etc/selinux/dummy/contexts/files cp dbus_contexts /etc/selinux/dummy/contexts cp policy.$VERS /etc/selinux/dummy/policy + FC_FILE=/etc/selinux/dummy/contexts/files/file_contexts if [ ! -d /etc/selinux ]; thenscripts/selinux/mdp/mdp.c +1
-0@@ -131,6 +131,7 @@ int main(int argc, char *argv[])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 devtmpfs 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" );Signature · 1 line
2.21.0.rc1
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 7 lines · Dominick Grift
Quoted 5 lines · Dominick Grift
The MDP example no longer works on modern systems.
Add support for devtmpfs. This is required by login programs to relabel terminals.
Compile the policy withdeny_unknownallow status to anticipate user space object managers in core components such as systemd. Add default seusers mapping and failsafe context for the SELinux PAM module.
Quoted 5 lines
There are a couple more possible improvements that i have identified:
Fail gracefully if checkpolicy does not exist
Run setfiles with -F. There *might* be one scenario where this might be a good idea. Where the filesystem is labeled with invalid contexts but where SELinux is disabled. In that case setfiles will reset, but only types (I suppose)
This also does not make sense to me:
if [ -f /sbin/setfiles ]; then SF="/usr/setfiles"
I think "-f /usr/setfiles" was meant here? I suppose which setfiles only searches "PATH", and so it wouldnt find /usr/setfiles. But then, who uses /usr/setfiles?
Quoted 52 lines
Quoted 47 lines
Signed-off-by Dominick Grift <[email protected]>--- scripts/selinux/install_policy.sh | 6 +++++- scripts/selinux/mdp/mdp.c | 1 + 2 files changed, 6 insertions(+), 1 deletion(-)scripts/selinux/install_policy.sh +5
-1@@ -20,14 +20,18 @@ CP=`which checkpolicy` VERS=`$CP -V | awk '{print $1}'` ./mdp policy.conf file_contexts -$CP -o policy.$VERS policy.conf +$CP -U allow -o policy.$VERS policy.conf mkdir -p /etc/selinux/dummy/policy mkdir -p /etc/selinux/dummy/contexts/files +echo "__default__:user_u" > /etc/selinux/dummy/seusers +echo "base_r:base_t" > /etc/selinux/dummy/contexts/failsafe_context + cp file_contexts /etc/selinux/dummy/contexts/files cp dbus_contexts /etc/selinux/dummy/contexts cp policy.$VERS /etc/selinux/dummy/policy + FC_FILE=/etc/selinux/dummy/contexts/files/file_contexts if [ ! -d /etc/selinux ]; thenscripts/selinux/mdp/mdp.c +1
-0@@ -131,6 +131,7 @@ int main(int argc, char *argv[])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 devtmpfs 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" );Signature · 1 line
2.21.0.rc1Signature · 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 15 lines · Dominick Grift
Quoted 7 lines · Dominick Grift
Quoted 5 lines · Dominick Grift
The MDP example no longer works on modern systems.
Add support for devtmpfs. This is required by login programs to relabel terminals.
Compile the policy withdeny_unknownallow status to anticipate user space object managers in core components such as systemd. Add default seusers mapping and failsafe context for the SELinux PAM module.Quoted 5 lines
There are a couple more possible improvements that i have identified:
Fail gracefully if checkpolicy does not exist
Run setfiles with -F. There *might* be one scenario where this might be a good idea. Where the filesystem is labeled with invalid contexts but where SELinux is disabled. In that case setfiles will reset, but only types (I suppose)
Quoted 7 lines
This also does not make sense to me:
if [ -f
/sbin/setfiles]; then
SF="/usr/setfiles"I think "-f
/usr/setfiles" was meant here? I supposewhich setfilesonly searches "PATH", and so it wouldnt find/usr/setfiles. But then, who uses/usr/setfiles?
No one AFAIK. So I agree that this does not make sense. Might have been a broken attempt to support either /sbin/setfiles or /usr/sbin/setfiles as the install location of setfiles, since that did change at some point.
Quoted 58 lines
Quoted 39 lines
Quoted 39 lines
Signed-off-by Dominick Grift <[email protected]>--- scripts/selinux/install_policy.sh | 6 +++++- scripts/selinux/mdp/mdp.c | 1 + 2 files changed, 6 insertions(+), 1 deletion(-)scripts/selinux/install_policy.sh +5
-1@@ -20,14 +20,18 @@ CP=`which checkpolicy` VERS=`$CP -V | awk '{print $1}'` ./mdp policy.conf file_contexts -$CP -o policy.$VERS policy.conf +$CP -U allow -o policy.$VERS policy.conf mkdir -p /etc/selinux/dummy/policy mkdir -p /etc/selinux/dummy/contexts/files +echo "__default__:user_u" > /etc/selinux/dummy/seusers +echo "base_r:base_t" > /etc/selinux/dummy/contexts/failsafe_context + cp file_contexts /etc/selinux/dummy/contexts/files cp dbus_contexts /etc/selinux/dummy/contexts cp policy.$VERS /etc/selinux/dummy/policy + FC_FILE=/etc/selinux/dummy/contexts/files/file_contexts if [ ! -d /etc/selinux ]; thenscripts/selinux/mdp/mdp.c +0
-0@@ -131,6 +131,7 @@ int main(int argc, char *argv[])Quoted 14 lines
Quoted 9 lines
scripts/selinux/mdp/mdp.c +1
-1fprintf (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 devtmpfs 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" ); --2.21.0.rc1
--
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02
https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02
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 23 lines · Stephen Smalley
Quoted 20 lines · Dominick Grift
Quoted 7 lines · Dominick Grift
Quoted 5 lines · Dominick Grift
The MDP example no longer works on modern systems.
Add support for devtmpfs. This is required by login programs to relabel terminals.
Compile the policy withdeny_unknownallow status to anticipate user space object managers in core components such as systemd. Add default seusers mapping and failsafe context for the SELinux PAM module.Quoted 5 lines
There are a couple more possible improvements that i have identified:
Fail gracefully if checkpolicy does not exist
Run setfiles with -F. There *might* be one scenario where this might be a good idea. Where the filesystem is labeled with invalid contexts but where SELinux is disabled. In that case setfiles will reset, but only types (I suppose)This also does not make sense to me:
if [ -f
/sbin/setfiles]; then
SF="/usr/setfiles"
Quoted 7 lines
Quoted 2 lines
I think "-f
/usr/setfiles" was meant here? I supposewhich setfilesonly searches "PATH", and so it wouldnt find/usr/setfiles. But then, who uses/usr/setfiles?No one AFAIK. So I agree that this does not make sense. Might have been a broken attempt to support either
/sbin/setfilesor/usr/sbin/setfilesas the install location of setfiles, since that did change at some point.
Or if as you say it was just an attempt to deal with a PATH that omits /sbin, then maybe they should both be /sbin/setfiles.
Quoted 59 lines
Quoted 59 lines
Quoted 40 lines
Quoted 40 lines
Signed-off-by Dominick Grift <[email protected]>--- scripts/selinux/install_policy.sh | 6 +++++- scripts/selinux/mdp/mdp.c | 1 + 2 files changed, 6 insertions(+), 1 deletion(-)scripts/selinux/install_policy.sh +5
-1@@ -20,14 +20,18 @@ CP=`which checkpolicy` VERS=`$CP -V | awk '{print $1}'` ./mdp policy.conf file_contexts -$CP -o policy.$VERS policy.conf +$CP -U allow -o policy.$VERS policy.conf mkdir -p /etc/selinux/dummy/policy mkdir -p /etc/selinux/dummy/contexts/files +echo "__default__:user_u" > /etc/selinux/dummy/seusers +echo "base_r:base_t" > /etc/selinux/dummy/contexts/failsafe_context + cp file_contexts /etc/selinux/dummy/contexts/files cp dbus_contexts /etc/selinux/dummy/contexts cp policy.$VERS /etc/selinux/dummy/policy + FC_FILE=/etc/selinux/dummy/contexts/files/file_contexts if [ ! -d /etc/selinux ]; thenscripts/selinux/mdp/mdp.c +0
-0@@ -131,6 +131,7 @@ int main(int argc, char *argv[])Quoted 14 lines
Quoted 9 lines
scripts/selinux/mdp/mdp.c +1
-1fprintf (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 devtmpfs 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" ); --2.21.0.rc1
--
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02
https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02
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 28 lines · Stephen Smalley
Quoted 26 lines · Stephen Smalley
Quoted 22 lines · Dominick Grift
Quoted 7 lines · Dominick Grift
Quoted 5 lines · Dominick Grift
The MDP example no longer works on modern systems.
Add support for devtmpfs. This is required by login programs to relabel terminals.
Compile the policy withdeny_unknownallow status to anticipate user space object managers in core components such as systemd. Add default seusers mapping and failsafe context for the SELinux PAM module.Quoted 5 lines
There are a couple more possible improvements that i have identified:
Fail gracefully if checkpolicy does not exist
Run setfiles with -F. There *might* be one scenario where this might be a good idea. Where the filesystem is labeled with invalid contexts but where SELinux is disabled. In that case setfiles will reset, but only types (I suppose)This also does not make sense to me:
if [ -f
/sbin/setfiles]; then
SF="/usr/setfiles"I think "-f
/usr/setfiles" was meant here? I supposewhich setfilesonly searches "PATH", and so it wouldnt find/usr/setfiles. But then, who uses/usr/setfiles?
Quoted 7 lines
Quoted 4 lines
No one AFAIK. So I agree that this does not make sense. Might have been a broken attempt to support either
/sbin/setfilesor/usr/sbin/setfilesas the install location of setfiles, since that did change at some point.Or if as you say it was just an attempt to deal with a PATH that omits /sbin, then maybe they should both be
/sbin/setfiles.
We should probably remove those particular file tests altogether?
If which does not find it then you have a problem that I am not we want to support?
Not to mention that we just dont know the reason for this and what is right or what is wrong?
Quoted 60 lines
Quoted 60 lines
Quoted 60 lines
Quoted 41 lines
Quoted 41 lines
Signed-off-by Dominick Grift <[email protected]>--- scripts/selinux/install_policy.sh | 6 +++++- scripts/selinux/mdp/mdp.c | 1 + 2 files changed, 6 insertions(+), 1 deletion(-)scripts/selinux/install_policy.sh +5
-1@@ -20,14 +20,18 @@ CP=`which checkpolicy` VERS=`$CP -V | awk '{print $1}'` ./mdp policy.conf file_contexts -$CP -o policy.$VERS policy.conf +$CP -U allow -o policy.$VERS policy.conf mkdir -p /etc/selinux/dummy/policy mkdir -p /etc/selinux/dummy/contexts/files +echo "__default__:user_u" > /etc/selinux/dummy/seusers +echo "base_r:base_t" > /etc/selinux/dummy/contexts/failsafe_context + cp file_contexts /etc/selinux/dummy/contexts/files cp dbus_contexts /etc/selinux/dummy/contexts cp policy.$VERS /etc/selinux/dummy/policy + FC_FILE=/etc/selinux/dummy/contexts/files/file_contexts if [ ! -d /etc/selinux ]; thenscripts/selinux/mdp/mdp.c +0
-0@@ -131,6 +131,7 @@ int main(int argc, char *argv[])Quoted 14 lines
Quoted 9 lines
scripts/selinux/mdp/mdp.c +1
-1fprintf (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 devtmpfs 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" ); --2.21.0.rc1
--
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02
https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02
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
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
PATCH v2 1/1 scripts/selinux: modernize mdp
In reply to Dominick GriftThe MDP example no longer works on modern systems.
Add support for devtmpfs. This is required by login programs to relabel terminals.
Compile the policy with deny_unknown allow status to anticipate user space object managers in core components such as systemd. Add default seusers mapping and failsafe context for the SELinux PAM module.
V2:
Fix existing file test for setfiles.
Add a file test for checkpolicy similar to the test for setfiles for consistency.
Execute setfiles with -F to ensure that customizables are relabeled as well in scenarios where filesystems are labeled but where SELinux is disabled.
--- scripts/selinux/install_policy.sh | 21 ++++++++++++++++----- scripts/selinux/mdp/mdp.c | 1 + 2 files changed, 17 insertions(+), 5 deletions(-)
scripts/selinux/install_policy.sh +16 -5
@@ -6,7 +6,7 @@ if [ `id -u` -ne 0 ]; then fi SF=`which setfiles` if [ $? -eq 1 ]; then - if [ -f /sbin/setfiles ]; then + if [ -f /usr/setfiles ]; then SF="/usr/setfiles" else echo "no selinux tools installed: setfiles"
@@ -17,14 +17,25 @@ fi cd mdp CP=`which checkpolicy` +if [ $? -eq 1 ]; then + if [ -f /usr/checkpolicy ]; then + SF="/usr/checkpolicy" + else + echo "no selinux tools installed: checkpolicy" + exit 1 + fi +fi VERS=`$CP -V | awk '{print $1}'` ./mdp policy.conf file_contexts -$CP -o policy.$VERS policy.conf +$CP -U allow -o policy.$VERS policy.conf mkdir -p /etc/selinux/dummy/policy mkdir -p /etc/selinux/dummy/contexts/files +echo "__default__:user_u" > /etc/selinux/dummy/seusers +echo "base_r:base_t" > /etc/selinux/dummy/contexts/failsafe_context + cp file_contexts /etc/selinux/dummy/contexts/files cp dbus_contexts /etc/selinux/dummy/contexts cp policy.$VERS /etc/selinux/dummy/policy
@@ -55,15 +66,15 @@ else fi cd /etc/selinux/dummy/contexts/files -$SF file_contexts / +$SF -F file_contexts / mounts=`cat /proc/$$/mounts | egrep "ext2|ext3|xfs|jfs|ext4|ext4dev|gfs2" | awk '{ print $2 '}` -$SF file_contexts $mounts +$SF -F file_contexts $mounts dodev=`cat /proc/$$/mounts | grep "/dev "` if [ "eq$dodev" != "eq" ]; then mount --move /dev /mnt - $SF file_contexts /dev + $SF -F file_contexts /dev mount --move /mnt /dev fi
scripts/selinux/mdp/mdp.c +1 -0
@@ -131,6 +131,7 @@ int main(int argc, char *argv[])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 devtmpfs 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" );
Signature · 1 line
2.21.0.rc1
PATCH v3 1/1 scripts/selinux: modernize mdp
In reply to Dominick GriftThe MDP example no longer works on modern systems.
Add support for devtmpfs. This is required by login programs to relabel terminals.
Compile the policy with deny_unknown allow status to anticipate user space object managers in core components such as systemd. Add default seusers mapping and failsafe context for the SELinux PAM module.
V2:
Fix existing file test for setfiles.
Add a file test for checkpolicy similar to the test for setfiles for consistency.
Execute setfiles with -F to ensure that customizables are relabeled as well in scenarios where filesystems are labeled but where SELinux is disabled.
V3: Fixes file test that was introduced in V2.
--- scripts/selinux/install_policy.sh | 21 ++++++++++++++++----- scripts/selinux/mdp/mdp.c | 1 + 2 files changed, 17 insertions(+), 5 deletions(-)
scripts/selinux/install_policy.sh +16 -5
@@ -6,7 +6,7 @@ if [ `id -u` -ne 0 ]; then fi SF=`which setfiles` if [ $? -eq 1 ]; then - if [ -f /sbin/setfiles ]; then + if [ -f /usr/setfiles ]; then SF="/usr/setfiles" else echo "no selinux tools installed: setfiles"
@@ -17,14 +17,25 @@ fi cd mdp CP=`which checkpolicy` +if [ $? -eq 1 ]; then + if [ -f /usr/checkpolicy ]; then + CP="/usr/checkpolicy" + else + echo "no selinux tools installed: checkpolicy" + exit 1 + fi +fi VERS=`$CP -V | awk '{print $1}'` ./mdp policy.conf file_contexts -$CP -o policy.$VERS policy.conf +$CP -U allow -o policy.$VERS policy.conf mkdir -p /etc/selinux/dummy/policy mkdir -p /etc/selinux/dummy/contexts/files +echo "__default__:user_u" > /etc/selinux/dummy/seusers +echo "base_r:base_t" > /etc/selinux/dummy/contexts/failsafe_context + cp file_contexts /etc/selinux/dummy/contexts/files cp dbus_contexts /etc/selinux/dummy/contexts cp policy.$VERS /etc/selinux/dummy/policy
@@ -55,15 +66,15 @@ else fi cd /etc/selinux/dummy/contexts/files -$SF file_contexts / +$SF -F file_contexts / mounts=`cat /proc/$$/mounts | egrep "ext2|ext3|xfs|jfs|ext4|ext4dev|gfs2" | awk '{ print $2 '}` -$SF file_contexts $mounts +$SF -F file_contexts $mounts dodev=`cat /proc/$$/mounts | grep "/dev "` if [ "eq$dodev" != "eq" ]; then mount --move /dev /mnt - $SF file_contexts /dev + $SF -F file_contexts /dev mount --move /mnt /dev fi
scripts/selinux/mdp/mdp.c +1 -0
@@ -131,6 +131,7 @@ int main(int argc, char *argv[])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 devtmpfs 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" );
Signature · 1 line
2.21.0.rc1
Quoted 25 lines · Dominick Grift
The MDP example no longer works on modern systems.
Add support for devtmpfs. This is required by login programs to relabel terminals.
Compile the policy withdeny_unknownallow status to anticipate user space object managers in core components such as systemd. Add default seusers mapping and failsafe context for the SELinux PAM module.V2:
Fix existing file test for setfiles.
Add a file test for checkpolicy similar to the test for setfiles for consistency.
Execute setfiles with -F to ensure that customizables are relabeled as well in scenarios where filesystems are labeled but where SELinux is disabled.V3: Fixes file test that was introduced in V2.
Signed-off-by Dominick Grift <[email protected]>--- scripts/selinux/install_policy.sh | 21 ++++++++++++++++----- scripts/selinux/mdp/mdp.c | 1 + 2 files changed, 17 insertions(+), 5 deletions(-)scripts/selinux/install_policy.sh +0
-0
scripts/selinux/install_policy.sh if [ `id -u` -ne 0 ]; then · line 10
Quoted 6 lines
scripts/selinux/install_policy.sh +1
-1@@ -6,7 +6,7 @@ if [ `id -u` -ne 0 ]; then fi SF=`which setfiles` if [ $? -eq 1 ]; then - if [ -f /sbin/setfiles ]; then + if [ -f /usr/setfiles ]; then SF="/usr/setfiles"
I don't believe we've ever installed setfiles anywhere other than /sbin/setfile or /usr/sbin/setfiles so no other locations should be used. Maybe just drop the inner if statement entirely.
scripts/selinux/install_policy.sh fi · line 22
Quoted 9 lines
scripts/selinux/install_policy.sh +3
-0else echo "no selinux tools installed: setfiles"@@ -17,14 +17,25 @@ fi cd mdp CP=`which checkpolicy` +if [ $? -eq 1 ]; then + if [ -f /usr/checkpolicy ]; then + CP="/usr/checkpolicy"
Similarly for /usr/bin/checkpolicy or /bin/checkpolicy.
Quoted 25 lines
scripts/selinux/install_policy.sh +9
-2+ else + echo "no selinux tools installed: checkpolicy" + exit 1 + fi +fi VERS=`$CP -V | awk '{print $1}'` ./mdp policy.conf file_contexts -$CP -o policy.$VERS policy.conf +$CP -U allow -o policy.$VERS policy.conf mkdir -p /etc/selinux/dummy/policy mkdir -p /etc/selinux/dummy/contexts/files +echo "__default__:user_u" > /etc/selinux/dummy/seusers +echo "base_r:base_t" > /etc/selinux/dummy/contexts/failsafe_context + cp file_contexts /etc/selinux/dummy/contexts/files cp dbus_contexts /etc/selinux/dummy/contexts cp policy.$VERS /etc/selinux/dummy/policy@@ -55,15 +66,15 @@ else fi cd /etc/selinux/dummy/contexts/files -$SF file_contexts /
scripts/selinux/install_policy.sh else · line 77
Quoted 10 lines
scripts/selinux/install_policy.sh +2
-1+$SF -F file_contexts / mounts=`cat /proc/$$/mounts | egrep "ext2|ext3|xfs|jfs|ext4|ext4dev|gfs2" | awk '{ print $2 '}` -$SF file_contexts $mounts +$SF -F file_contexts $mounts dodev=`cat /proc/$$/mounts | grep "/dev "` if [ "eq$dodev" != "eq" ]; then mount --move /dev /mnt
I recall seeing errors from mount when running this script about invalid usage of mount --move?
scripts/selinux/mdp/mdp.c int main(int argc, char *argv[]) · line 134
Quoted 13 lines
scripts/selinux/install_policy.sh +1
-1- $SF file_contexts /dev + $SF -F file_contexts /dev mount --move /mnt /dev fiscripts/selinux/mdp/mdp.c +1
-0@@ -131,6 +131,7 @@ int main(int argc, char *argv[])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 devtmpfs user_u:base_r:base_t;\n" );
This will conflict with my patch but probably your patch should be applied first since it fixes current usage of mdp, and then mine can be re-based and introduce the MLS support (which hopefully can now be tested on Fedora). Ideally we'd add fs_use* and genfscon statements for all filesystems supported by the kernel but that can come later.
Quoted 6 lines
scripts/selinux/mdp/mdp.c +0
-1fprintf (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" ); --2.21.0.rc1
Quoted 22 lines · Stephen Smalley
Quoted 20 lines · Dominick Grift
The MDP example no longer works on modern systems.
Add support for devtmpfs. This is required by login programs to relabel terminals.
Compile the policy withdeny_unknownallow status to anticipate user space object managers in core components such as systemd. Add default seusers mapping and failsafe context for the SELinux PAM module.V2:
Fix existing file test for setfiles.
Add a file test for checkpolicy similar to the test for setfiles for consistency.
Execute setfiles with -F to ensure that customizables are relabeled as well in scenarios where filesystems are labeled but where SELinux is disabled.V3: Fixes file test that was introduced in V2.
Signed-off-by Dominick Grift <[email protected]>--- scripts/selinux/install_policy.sh | 21 ++++++++++++++++----- scripts/selinux/mdp/mdp.c | 1 + 2 files changed, 17 insertions(+), 5 deletions(-)
Quoted 15 lines
scripts/selinux/install_policy.sh if [ `id -u` -ne 0 ]; then · line 10
Quoted 11 lines
scripts/selinux/install_policy.sh +1
-1@@ -6,7 +6,7 @@ if [ `id -u` -ne 0 ]; then fi SF=`which setfiles` if [ $? -eq 1 ]; then - if [ -f /sbin/setfiles ]; then + if [ -f /usr/setfiles ]; then SF="/usr/setfiles"I don't believe we've ever installed setfiles anywhere other than
/sbin/setfileor/usr/sbin/setfilesso no other locations should be used. Maybe just drop the inner if statement entirely.
I agree
Quoted 78 lines
scripts/selinux/install_policy.sh fi · line 22
Quoted 10 lines
scripts/selinux/install_policy.sh +3
-0else echo "no selinux tools installed: setfiles"@@ -17,14 +17,25 @@ fi cd mdp CP=`which checkpolicy` +if [ $? -eq 1 ]; then + if [ -f /usr/checkpolicy ]; then + CP="/usr/checkpolicy"Similarly for
/usr/bin/checkpolicyor/bin/checkpolicy.Quoted 25 lines
scripts/selinux/install_policy.sh +9
-2+ else + echo "no selinux tools installed: checkpolicy" + exit 1 + fi +fi VERS=`$CP -V | awk '{print $1}'` ./mdp policy.conf file_contexts -$CP -o policy.$VERS policy.conf +$CP -U allow -o policy.$VERS policy.conf mkdir -p /etc/selinux/dummy/policy mkdir -p /etc/selinux/dummy/contexts/files +echo "__default__:user_u" > /etc/selinux/dummy/seusers +echo "base_r:base_t" > /etc/selinux/dummy/contexts/failsafe_context + cp file_contexts /etc/selinux/dummy/contexts/files cp dbus_contexts /etc/selinux/dummy/contexts cp policy.$VERS /etc/selinux/dummy/policy@@ -55,15 +66,15 @@ else fi cd /etc/selinux/dummy/contexts/files -$SF file_contexts /scripts/selinux/install_policy.sh else · line 77
Quoted 10 lines
scripts/selinux/install_policy.sh +2
-1+$SF -F file_contexts / mounts=`cat /proc/$$/mounts | egrep "ext2|ext3|xfs|jfs|ext4|ext4dev|gfs2" | awk '{ print $2 '}` -$SF file_contexts $mounts +$SF -F file_contexts $mounts dodev=`cat /proc/$$/mounts | grep "/dev "` if [ "eq$dodev" != "eq" ]; then mount --move /dev /mntI recall seeing errors from mount when running this script about invalid usage of mount --move?
scripts/selinux/mdp/mdp.c int main(int argc, char *argv[]) · line 134
Quoted 13 lines
scripts/selinux/install_policy.sh +1
-1- $SF file_contexts /dev + $SF -F file_contexts /dev mount --move /mnt /dev fiscripts/selinux/mdp/mdp.c +1
-0@@ -131,6 +131,7 @@ int main(int argc, char *argv[])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 devtmpfs user_u:base_r:base_t;\n" );This will conflict with my patch but probably your patch should be applied first since it fixes current usage of mdp, and then mine can be re-based and introduce the MLS support (which hopefully can now be tested on Fedora). Ideally we'd add fs_use* and genfscon statements for all filesystems supported by the kernel but that can come later.
Quoted 6 lines
scripts/selinux/mdp/mdp.c +0
-1fprintf (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" ); --2.21.0.rc1
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 82 lines · Stephen Smalley
Quoted 25 lines · Dominick Grift
The MDP example no longer works on modern systems.
Add support for devtmpfs. This is required by login programs to relabel terminals.
Compile the policy withdeny_unknownallow status to anticipate user space object managers in core components such as systemd. Add default seusers mapping and failsafe context for the SELinux PAM module.V2:
Fix existing file test for setfiles.
Add a file test for checkpolicy similar to the test for setfiles for consistency.
Execute setfiles with -F to ensure that customizables are relabeled as well in scenarios where filesystems are labeled but where SELinux is disabled.V3: Fixes file test that was introduced in V2.
Signed-off-by Dominick Grift <[email protected]>--- scripts/selinux/install_policy.sh | 21 ++++++++++++++++----- scripts/selinux/mdp/mdp.c | 1 + 2 files changed, 17 insertions(+), 5 deletions(-)scripts/selinux/install_policy.sh +0
-0scripts/selinux/install_policy.sh if [ `id -u` -ne 0 ]; then · line 10
Quoted 6 lines
scripts/selinux/install_policy.sh +1
-1@@ -6,7 +6,7 @@ if [ `id -u` -ne 0 ]; then fi SF=`which setfiles` if [ $? -eq 1 ]; then - if [ -f /sbin/setfiles ]; then + if [ -f /usr/setfiles ]; then SF="/usr/setfiles"I don't believe we've ever installed setfiles anywhere other than
/sbin/setfileor/usr/sbin/setfilesso no other locations should be used. Maybe just drop the inner if statement entirely.scripts/selinux/install_policy.sh fi · line 22
Quoted 9 lines
scripts/selinux/install_policy.sh +3
-0else echo "no selinux tools installed: setfiles"@@ -17,14 +17,25 @@ fi cd mdp CP=`which checkpolicy` +if [ $? -eq 1 ]; then + if [ -f /usr/checkpolicy ]; then + CP="/usr/checkpolicy"Similarly for
/usr/bin/checkpolicyor/bin/checkpolicy.Quoted 32 lines
scripts/selinux/install_policy.sh +11
-3+ else + echo "no selinux tools installed: checkpolicy" + exit 1 + fi +fi VERS=`$CP -V | awk '{print $1}'` ./mdp policy.conf file_contexts -$CP -o policy.$VERS policy.conf +$CP -U allow -o policy.$VERS policy.conf mkdir -p /etc/selinux/dummy/policy mkdir -p /etc/selinux/dummy/contexts/files +echo "__default__:user_u" > /etc/selinux/dummy/seusers +echo "base_r:base_t" > /etc/selinux/dummy/contexts/failsafe_context + cp file_contexts /etc/selinux/dummy/contexts/files cp dbus_contexts /etc/selinux/dummy/contexts cp policy.$VERS /etc/selinux/dummy/policy@@ -55,15 +66,15 @@ else fi cd /etc/selinux/dummy/contexts/files -$SF file_contexts / +$SF -F file_contexts / mounts=`cat /proc/$$/mounts | egrep "ext2|ext3|xfs|jfs|ext4|ext4dev|gfs2" | awk '{ print $2 '}` -$SF file_contexts $mounts +$SF -F file_contexts $mounts
Quoted 6 lines
scripts/selinux/install_policy.sh else · line 77
Quoted 3 lines
scripts/selinux/install_policy.sh +0
-0dodev=`cat /proc/$$/mounts | grep "/dev "` if [ "eq$dodev" != "eq" ]; then mount --move /dev /mntI recall seeing errors from mount when running this script about invalid usage of mount --move?
Yes but we may want this for (backwards) compatibility? I suspect that this might work in some scenario's (just not ours)
Quoted 11 lines
Quoted 11 lines
scripts/selinux/install_policy.sh +1
-1- $SF file_contexts /dev + $SF -F file_contexts /dev mount --move /mnt /dev fiscripts/selinux/mdp/mdp.c +0
-0@@ -131,6 +131,7 @@ int main(int argc, char *argv[])
Quoted 9 lines
scripts/selinux/mdp/mdp.c int main(int argc, char *argv[]) · line 134
Quoted 3 lines
scripts/selinux/mdp/mdp.c +1
-0fprintf (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 devtmpfs user_u:base_r:base_t;\n" );This will conflict with my patch but probably your patch should be applied first since it fixes current usage of mdp, and then mine can be re-based and introduce the MLS support (which hopefully can now be tested on Fedora). Ideally we'd add fs_use* and genfscon statements for all filesystems supported by the kernel but that can come later.
Probably yes, but you can also just take my changes and add them to your patch.
BTW: we also might want to use object_r instead of base_r for object contexts for consistency?
Quoted 7 lines
Quoted 7 lines
scripts/selinux/mdp/mdp.c +0
-1fprintf (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" ); --2.21.0.rc1
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