SELinux MLS Policies
First, apologies if this is the wrong SELinux list to post such questions; as you can guess I'm new to SELinux development.
I'm looking at getting a base MLS policy running on a fully patched CentOS 7.2 build which I will then customise; currently as a learning exercise.
Unfortunately I'm having a few problems (usually it works out-of-the-box on distros I've used, but not in this case), so I hope someone on the list can give me a push in the right direction.
Bottom line is that if I try to use the vendor supplied version the system is unusable if set to enforcing (I've used MLS before, so I do mean unusable in this case).
I've now downloaded the latest reference policy, compiled it for mls and systemd including updating the broken labelling due to /bin and /sbin being symlinks. Things look better but there are still many errors.
One group in particular puzzles me (hopefully due to some misunderstanding on my part).
I get AVC's for a number of critical files relating to systemd sockets and /dev/log, for example. e.g.
-- snip --
type=AVC msg=audit(1472476843.913:1124): avc: denied { sendto } for pid=11015 comm="sshd" path="/dev/log" scontext=system_u:system_r:sshd_t:s0-s15:c0.c1023 tcontext=system_u:system_r:kernel_t:s15:c0.c1023 tclass=unix_dgram_socket
Was caused by:
#Constraint rule:
mlsconstrain unix_dgram_socket { sendto } ((l1 eq l2 -Fail-) or
(t1=sshd_t eq TYPE_ENTRY -Fail-) { POLICY_SOURCE: mlsnetwriteranged } and (l1 dom l2 -Fail-) and (l1 domby h2 -Pass-) or (t1=sshd_t eq TYPE_ENTRY -Fail-) { POLICY_SOURCE: mlsnetwritetoclr } and (h1 dom L2 -Pass-) and (l1 domby l2 -Pass-) or (t1=sshd_t eq TYPE_ENTRY -Fail-) { POLICY_SOURCE:
mlsnetwrite } or (t2=kernel_t eq TYPE_ENTRY -Fail-) { POLICY_SOURCE:
mlstrustedobject } ); Constraint DENIED
# Possible cause is the source level (s0-s15:c0.c1023) and target
level (s15:c0.c1023) are different.
-- snip --
Now, given that /dev/log is labelled as a devlog_t:
# ls -lZ /dev/log
srw-rw-rw-. root root system_u:object_r:devlog_t:s15:c0.c1023 /dev/log
And according to logging.te, this is a trusted object:
mls_trusted_object(devlog_t)
Why is the target context for evaluation kernel_t and not devlog_t? Surely it should be devlog_t and therefore pass the constraint rule as a trusted object?
Paul
----
http://blog.m0noc.com/ | https://keybase.io/m0noc
4329 E4C5 71F3 58B2 2246 D04D 25DA 39C2 3876 FE3D
Quoted 87 lines · Paul Bolton
First, apologies if this is the wrong SELinux list to post such questions; as you can guess I’m new to SELinux development.
I’m looking at getting a base MLS policy running on a fully patched CentOS 7.2 build which I will then customise; currently as a learning exercise.
Unfortunately I’m having a few problems (usually it works out-of-the-box on distros I’ve used, but not in this case), so I hope someone on the list can give me a push in the right direction.
Bottom line is that if I try to use the vendor supplied version the system is unusable if set to enforcing (I’ve used MLS before, so I do mean unusable in this case).
I’ve now downloaded the latest reference policy, compiled it for mls and systemd including updating the broken labelling due to /bin and /sbin being symlinks. Things look better but there are still many errors.
One group in particular puzzles me (hopefully due to some misunderstanding on my part).
I get AVC’s for a number of critical files relating to systemd sockets and
/dev/log, for example. e.g.-- snip --
type=AVC msg=audit(1472476843.913:1124): avc: denied { sendto } for pid=11015 comm="sshd" path="/dev/log" scontext=system_u:system_r:sshd_t:s0-s15:c0.c1023 tcontext=system_u:system_r:kernel_t:s15:c0.c1023 tclass=unix_dgram_socket
Was caused by:
#Constraint rule:
mlsconstrain
unix_dgram_socket{ sendto } ((l1 eq l2 -Fail-) or
(t1=sshd_t eqTYPE_ENTRY-Fail-) {POLICY_SOURCE: mlsnetwriteranged } and (l1 dom l2 -Fail-) and (l1 domby h2 -Pass-) or (t1=sshd_t eqTYPE_ENTRY-Fail-) {POLICY_SOURCE: mlsnetwritetoclr } and (h1 dom L2 -Pass-) and (l1 domby l2 -Pass-) or (t1=sshd_t eqTYPE_ENTRY-Fail-) {POLICY_SOURCE: mlsnetwrite } or (t2=kernel_t eqTYPE_ENTRY-Fail-) {POLICY_SOURCE: mlstrustedobject } ); Constraint DENIED# Possible cause is the source level (s0-s15:c0.c1023) and target
level (s15:c0.c1023) are different.-- snip --
Now, given that
/dev/logis labelled as adevlog_t:# ls -lZ /dev/logsrw-rw-rw-. root root system_u:object_r:devlog_t:s15:c0.c1023
/dev/logAnd according to logging.te, this is a trusted object:
Quoted 7 lines
mls_trusted_object(devlog_t)Why is the target context for evaluation
kernel_tand notdevlog_t? Surely it should bedevlog_tand therefore pass the constraint rule as a trusted object?
sendto is a permission check between the two socket labels, not to be confused with the file label. When you send on a local/Unix socket, you need write permission to the socket file (if using the file namespace; if using the abstract namespace, there is no equivalent check) and you need sendto to the peer socket (which typically will be labeled the same as the receiving process). So the receiving process is running in kernel_t, or was at the time it created the socket.
There are two separate kernel objects when dealing with Unix sockets - the file and the socket itself.
Quoted 14 lines · Stephen Smalley
Quoted 4 lines · Paul Bolton
Why is the target context for evaluation
kernel_tand notdevlog_t? Surely it should bedevlog_tand therefore pass the constraint rule as a trusted object?sendto is a permission check between the two socket labels, not to be confused with the file label. When you send on a local/Unix socket, you need write permission to the socket file (if using the file namespace; if using the abstract namespace, there is no equivalent check) and you need sendto to the peer socket (which typically will be labeled the same as the receiving process). So the receiving process is running in
kernel_t, or was at the time it created the socket.
Quoted 4 lines
There are two separate kernel objects when dealing with Unix sockets - the file and the socket itself.
Thanks for the explanation.
So, I guess in my example AVC, after a bit of digging to get the CentOS src patches, where we have the following added to sshd.te, it is the mls_process_write_all_levels() that clears that AVC.
policy-rhel-7.2-base.patch:
-- snip --
+mls_trusted_object(sshd_t)
+mls_process_write_all_levels(sshd_t)
+mls_dbus_send_all_levels(sshd_t)
-- snip --
Signature · 4 lines
Paul ---- http://blog.m0noc.com/ | https://keybase.io/m0noc 4329 E4C5 71F3 58B2 2246 D04D 25DA 39C2 3876 FE3D
Quoted 47 lines · Paul Bolton
Quoted 18 lines · Stephen Smalley
Quoted 5 lines · Paul Bolton
Why is the target context for evaluation
kernel_tand notdevlog_t? Surely it should bedevlog_tand therefore pass the constraint rule as a trusted object?sendto is a permission check between the two socket labels, not to be confused with the file label. When you send on a local/Unix socket, you need write permission to the socket file (if using the file namespace; if using the abstract namespace, there is no equivalent check) and you need sendto to the peer socket (which typically will be labeled the same as the receiving process). So the receiving process is running in
kernel_t, or was at the time it created the socket.Quoted 2 lines
There are two separate kernel objects when dealing with Unix sockets - the file and the socket itself.
Thanks for the explanation.
So, I guess in my example AVC, after a bit of digging to get the CentOS src patches, where we have the following added to sshd.te, it is the
mls_process_write_all_levels()that clears that AVC.policy-rhel-7.2-base.patch:
-- snip --(quoted diff) +3
-1+mls_trusted_object(sshd_t) +mls_process_write_all_levels(sshd_t) +mls_dbus_send_all_levels(sshd_t) -- snip --Signature · 10 lines
-- Paul ---- http://blog.m0noc.com/ | https://keybase.io/m0noc 4329 E4C5 71F3 58B2 2246 D04D 25DA 39C2 3876 FE3D _______________________________________________ Selinux mailing list [email protected] To unsubscribe, send email to [email protected]. To get help, send an email containing "help" to [email protected].
Have you managed to correct the incorrect labelling of /etc? When I've tried to use the MLS policy on RHEL/CentOS 7-7.2, that has stopped logins from working when running in enforcing mode.
Quoted 3 lines · ileyd
Have you managed to correct the incorrect labelling of /etc? When I've tried to use the MLS policy on RHEL/CentOS 7-7.2, that has stopped logins from working when running in enforcing mode.
So if I turn off the dontaudit rules that issue shows up with unix_chkpwd and mls_constrain AVCs. Admittedly I did notice it was at s15 but thought that was intentional. Though, as most of the files in /etc are at s0 that doesn't sound right.
Anyway, changing /etc to s0 allows logins to work; and looks more like what I would expect an out-of-the-box MLS system to look like.
Thanks for the advice.
Signature · 4 lines
Paul ---- http://blog.m0noc.com/ | https://keybase.io/m0noc 4329 E4C5 71F3 58B2 2246 D04D 25DA 39C2 3876 FE3D
Quoted 12 lines · Paul Bolton
Quoted 3 lines · ileyd
Have you managed to correct the incorrect labelling of /etc? When I've tried to use the MLS policy on RHEL/CentOS 7-7.2, that has stopped logins from working when running in enforcing mode.
So if I turn off the dontaudit rules that issue shows up with
unix_chkpwdandmls_constrainAVCs. Admittedly I did notice it was at s15 but thought that was intentional. Though, as most of the files in /etc are at s0 that doesn't sound right.
Quoted 6 lines
Anyway, changing /etc to s0 allows logins to work; and looks more like what I would expect an out-of-the-box MLS system to look like.
Thanks for the advice.
This is a bug in initscripts.
/usr/lib/systemd/rhel-import-state copies files from initrd to a filesystem during boot but doesn't reset level on the copied files. Since dracut is running as ks15, copied files inherits s15 level. The fix is quite easy:
--- /usr/lib/systemd/rhel-import-state.bug 2016-09-07
04:44:45.413231227 -0400
+++ /usr/lib/systemd/rhel-import-state 2016-09-07 04:44:51.645274588 -0400 @@ -7,5 +7,5 @@
# run restorecon on the copied files
if [ -e /sys/fs/selinux/enforce -a -x /usr/sbin/restorecon ]; then
- find . -mindepth 1 -print0 | { cd / && xargs --null restorecon -i; }
+ find . -mindepth 1 -print0 | { cd / && xargs --null restorecon -i -F; }
fiPetr
Signature · 1 line
Petr Lautrbach
Quoted 39 lines · Petr Lautrbach
Quoted 13 lines · Paul Bolton
Quoted 5 lines · ileyd
Have you managed to correct the incorrect labelling of /etc? When I've tried to use the MLS policy on RHEL/CentOS 7-7.2, that has stopped logins from working when running in enforcing mode.
So if I turn off the dontaudit rules that issue shows up with
unix_chkpwdandmls_constrainAVCs. Admittedly I did notice it was at s15 but thought that was intentional. Though, as most of the files in /etc are at s0 that doesn't sound right.Quoted 4 lines
Anyway, changing /etc to s0 allows logins to work; and looks more like what I would expect an out-of-the-box MLS system to look like.
Thanks for the advice.
This is a bug in initscripts.
/usr/lib/systemd/rhel-import-statecopies files from initrd to a filesystem during boot but doesn't reset level on the copied files. Since dracut is running as ks15, copied files inherits s15 level. The fix is quite easy:---
/usr/lib/systemd/rhel-import-state.bug2016-09-07
04:44:45.413231227 -0400
+++/usr/lib/systemd/rhel-import-state2016-09-07 04:44:51.645274588 -0400(quoted diff) +0
-0@@ -7,5 +7,5 @@ # run restorecon on the copied filesif [ -e
/sys/fs/selinux/enforce-a -x/usr/sbin/restorecon]; then(quoted diff) +1
-1- find . -mindepth 1 -print0 | { cd / && xargs --null restorecon -i; } + find . -mindepth 1 -print0 | { cd / && xargs --null restorecon -i -F; }fi
Quoted 5 lines
Petr
Signature · 1 line
Petr Lautrbach
Thanks for sharing that!
Quoted 5 lines · Paul Bolton
First, apologies if this is the wrong SELinux list to post such questions; as you can guess I'm new to SELinux development.
Quoted 9 lines
I'm looking at getting a base MLS policy running on a fully patched CentOS 7.2 build which I will then customise; currently as a learning exercise.
Unfortunately I'm having a few problems (usually it works out-of-the-box on distros I've used, but not in this case), so I hope someone on the list can give me a push in the right direction.
On RHEL and CentOS should sufficient to:
1. install selinux-policy-mls package
2. set SELinux to permissive and mls type
3. run fixfiles -F onboot
4. reboot
5. if everything went fine and the filesystem is correctly relabeled, switch back to enforcing
and if you want to login as root using ssh, you need to turn ssh_sysadm_login boolean on
See
https://docs.fedoraproject.org/en-US/Fedora/24/html/SELinux_Users_and_Administrators_Guide/enabling-mls-in-selinux.html
or
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/SELinux_Users_and_Administrators_Guide/mls.html#enabling-mls-in-selinux
Petr
Quoted 99 lines
Bottom line is that if I try to use the vendor supplied version the system is unusable if set to enforcing (I've used MLS before, so I do mean unusable in this case).
I've now downloaded the latest reference policy, compiled it for mls and systemd including updating the broken labelling due to /bin and /sbin being symlinks. Things look better but there are still many errors.
One group in particular puzzles me (hopefully due to some misunderstanding on my part).
I get AVC's for a number of critical files relating to systemd sockets and
/dev/log, for example. e.g.-- snip --
type=AVC msg=audit(1472476843.913:1124): avc: denied { sendto } for pid=11015 comm="sshd" path="/dev/log" scontext=system_u:system_r:sshd_t:s0-s15:c0.c1023 tcontext=system_u:system_r:kernel_t:s15:c0.c1023 tclass=unix_dgram_socket
Was caused by:
#Constraint rule:
mlsconstrain
unix_dgram_socket{ sendto } ((l1 eq l2 -Fail-) or
(t1=sshd_t eqTYPE_ENTRY-Fail-) {POLICY_SOURCE: mlsnetwriteranged } and (l1 dom l2 -Fail-) and (l1 domby h2 -Pass-) or (t1=sshd_t eqTYPE_ENTRY-Fail-) {POLICY_SOURCE: mlsnetwritetoclr } and (h1 dom L2 -Pass-) and (l1 domby l2 -Pass-) or (t1=sshd_t eqTYPE_ENTRY-Fail-) {POLICY_SOURCE:
mlsnetwrite } or (t2=kernel_t eqTYPE_ENTRY-Fail-) {POLICY_SOURCE:
mlstrustedobject } ); Constraint DENIED# Possible cause is the source level (s0-s15:c0.c1023) and target
level (s15:c0.c1023) are different.-- snip --
Now, given that
/dev/logis labelled as adevlog_t:# ls -lZ /dev/logsrw-rw-rw-. root root system_u:object_r:devlog_t:s15:c0.c1023
/dev/logAnd according to logging.te, this is a trusted object:
mls_trusted_object(devlog_t)Why is the target context for evaluation
kernel_tand notdevlog_t? Surely it should bedevlog_tand therefore pass the constraint rule as a trusted object?Paul
----
http://blog.m0noc.com/ | https://keybase.io/m0noc
4329 E4C5 71F3 58B2 2246 D04D 25DA 39C2 3876 FE3D
_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected].
To get help, send an email containing "help" to [email protected].
Signature · 1 line
Petr
Quoted 10 lines · Petr Lautrbach
On RHEL and CentOS should sufficient to:
1. install selinux-policy-mls package
2. set SELinux to permissive and mls type
3. run fixfiles -F onboot
4. reboot
5. if everything went fine and the filesystem is correctly relabeled, switch back to enforcing
Quoted 3 lines
and if you want to login as root using ssh, you need to turn
ssh_sysadm_loginboolean on
Thanks for the suggestion. Unfortunately that is pretty much what I originally did, which is why I thought I'll give the reference policy a go since getting the source is easier.
The main difference with the original vendor setup was that I touched /.autorelabel rather than run fixfiles (which I think does the same thing). Result is that at (5) cannot log in as root, normal or staff_u on the console, normal user or a staff_u user over the net. I don't want to allow root over the net.
I've just retested as you have mentioned and the same results.
I'll have another look at the vendor supplied mls setup tomorrow (this one didn't have the /dev/log issue), but does have other AVC's listed.
So, looks like I have two challenges-
a. figure out why the vendor setup doesn't appear to work, and b. understand the /dev/log. etc changes from reference policy to vendor policy.
Signature · 4 lines
Paul ---- http://blog.m0noc.com/ | https://keybase.io/m0noc 4329 E4C5 71F3 58B2 2246 D04D 25DA 39C2 3876 FE3D