Skip to contentSkip to conversation

scripts/selinux: modernize mdp

PATCH In review Dominick Grift 1 participant 2 messages Feb 20, 2019 1 message not in the archive SELinux security module

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH v4 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.

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.

V4: Remove file tests and instead rely on which

---
 scripts/selinux/install_policy.sh | 23 +++++++++++++----------
 scripts/selinux/mdp/mdp.c         |  1 +
 2 files changed, 14 insertions(+), 10 deletions(-)
scripts/selinux/install_policy.sh +13 -10
index 0b86c47baf7d..773377838670 100755
@@ -6,25 +6,28 @@ if [ `id -u` -ne 0 ]; then
 fi
 SF=`which setfiles`
 if [ $? -eq 1 ]; then
-	if [ -f /sbin/setfiles ]; then
-		SF="/usr/setfiles"
-	else
-		echo "no selinux tools installed: setfiles"
-		exit 1
-	fi
+	echo "no selinux tools installed: setfiles"
+	exit 1
 fi
 
 cd mdp
 
 CP=`which checkpolicy`
+if [ $? -eq 1 ]; then
+	echo "no selinux tools installed: checkpolicy"
+	exit 1
+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 +58,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
index 073fe7537f6c..cf06d5694cbc 100644
@@ -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
#2 lore raw
Quoted 1 line · Dominick Grift

The MDP example no longer works on modern systems.

I would prefer that my changes would just be addressed in Stephen's patch instead. In that case this patch can be ignored.

Quoted 94 lines

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.

V4: Remove file tests and instead rely on which

---
 scripts/selinux/install_policy.sh | 23 +++++++++++++----------
 scripts/selinux/mdp/mdp.c         |  1 +
 2 files changed, 14 insertions(+), 10 deletions(-)
scripts/selinux/install_policy.sh +13 -10
index 0b86c47baf7d..773377838670 100755
@@ -6,25 +6,28 @@ if [ `id -u` -ne 0 ]; then
 fi
 SF=`which setfiles`
 if [ $? -eq 1 ]; then
-	if [ -f /sbin/setfiles ]; then
-		SF="/usr/setfiles"
-	else
-		echo "no selinux tools installed: setfiles"
-		exit 1
-	fi
+	echo "no selinux tools installed: setfiles"
+	exit 1
 fi
 
 cd mdp
 
 CP=`which checkpolicy`
+if [ $? -eq 1 ]; then
+	echo "no selinux tools installed: checkpolicy"
+	exit 1
+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 +58,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
index 073fe7537f6c..cf06d5694cbc 100644
@@ -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