Bug 1406439

Summary: the /sbin symlink is not labelled in the targeted policy
Product: Red Hat Enterprise Linux 7 Reporter: (GalaxyMaster) <gm.outside+redhat>
Component: selinux-policyAssignee: Lukas Vrabec <lvrabec>
Status: CLOSED ERRATA QA Contact: Milos Malik <mmalik>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 7.3CC: lvrabec, mgrepl, mmalik, plautrba, pvrabec, ssekidde
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: selinux-policy-3.13.1-124.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-08-01 15:20:12 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description (GalaxyMaster) 2016-12-20 14:18:18 UTC
Description of problem:

The /sbin symlink is not defined in the provided targeted policy

Version-Release number of selected component (if applicable):


How reproducible:

[root@server ~]# ls -ldZ /sbin
lrwxrwxrwx. root root system_u:object_r:bin_t:s0       /sbin -> usr/sbin
[root@server ~]# restorecon -v /sbin
restorecon reset /sbin context system_u:object_r:bin_t:s0->system_u:object_r:user_home_dir_t:s0


Actual results:

The /sbin symlink got labelled as user_home_dir_t .


Expected results:

It was expected that restorecon would not touch the /sbin symlink since it was properly labelled during the installation


Additional info:

[root@server ~]# rpm -q selinux-policy-targeted
selinux-policy-targeted-3.13.1-102.el7_3.7.noarch
[root@server ~]# semanage export
boolean -D
login -D
interface -D
user -D
port -D
node -D
fcontext -D
module -D
boolean -m -1 deny_execmem
boolean -m -1 polyinstantiation_enabled
boolean -m -0 selinuxuser_execmod
boolean -m -0 selinuxuser_execstack
login -a -s root -r 's0-s0:c0.c1023' %root
login -a -s user_u -r 's0' __default__
login -a -s user_u -r 's0' root
port -a -t ssh_port_t -p tcp 940
fcontext -a -f a -t ssh_home_t '/root/.users/[^/].+/\.ssh(/.*)?'
fcontext -a -e /var/tmp-inst /var/tmp/.private
fcontext -a -e /tmp-inst /tmp/.private
[root@server ~]#

Comment 2 (GalaxyMaster) 2016-12-23 04:09:03 UTC
I looked into that a bit further and the following does not look right:
===
# rpm -qf /etc/selinux/targeted/contexts/files/file_contexts.homedirsselinux-policy-targeted-3.13.1-102.el7_3.7.noarch
# grep -A5 -E 'for user (halt|shutdown)' /etc/selinux/targeted/contexts/files/file_contexts.homedirs
# Home Context for user halt
#

/sbin/.+	root:object_r:user_home_t:s0
/sbin/.maildir(/.*)?	root:object_r:mail_home_rw_t:s0
/sbin/.*/plugins/nppdf\.so.*	--	root:object_r:textrel_shlib_t:s0
--
# Home Context for user shutdown
#

/sbin/.+	root:object_r:user_home_t:s0
/sbin/.maildir(/.*)?	root:object_r:mail_home_rw_t:s0
/sbin/.*/plugins/nppdf\.so.*	--	root:object_r:textrel_shlib_t:s0
# grep -E '(halt|shutdown)' /etc/passwd
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
#
===

It seems that the parts for home contexts were generated by a script that was looking up the home directories in /etc/passwd and using that as the base directory for the context.

When it comes to security, such an approach is questionable and at least should be double-checked by a human being -- otherwise we are risking to get too many surprises in the system wide policies.

Comment 3 Milos Malik 2017-01-02 14:32:45 UTC
Is it possible that genhomedircon caused it?

DESCRIPTION
       genhomedircon is a script that executes semodule to  rebuild  the  cur‐
       rently  active  SELinux policy (without reloading it) and to create the
       labels for each user home directory based on directory  paths  returned
       by calls to getpwent().

Comment 4 Milos Malik 2017-01-02 14:42:05 UTC
Reproducible on clean RHEL-7.3 machine:

# semanage export
boolean -D
login -D
interface -D
user -D
port -D
node -D
fcontext -D
module -D
# matchpathcon /sbin/
/sbin	system_u:object_r:bin_t:s0
# genhomedircon 
# matchpathcon /sbin/
/sbin	system_u:object_r:bin_t:s0
# semanage import
login -a -s root -r 's0-s0:c0.c1023' %root
login -a -s user_u -r 's0' __default__
login -a -s user_u -r 's0' root
# matchpathcon /sbin/
/sbin	root:object_r:user_home_dir_t:s0
# grep -A5 -E 'for user (halt|shutdown)' /etc/selinux/targeted/contexts/files/file_contexts.homedirs
# Home Context for user halt
#

/sbin/.+	root:object_r:user_home_t:s0
/sbin/.maildir(/.*)?	root:object_r:mail_home_rw_t:s0
/sbin/.*/plugins/nppdf\.so.*	--	root:object_r:textrel_shlib_t:s0
--
# Home Context for user shutdown
#

/sbin/.+	root:object_r:user_home_t:s0
/sbin/.maildir(/.*)?	root:object_r:mail_home_rw_t:s0
/sbin/.*/plugins/nppdf\.so.*	--	root:object_r:textrel_shlib_t:s0

Comment 5 Milos Malik 2017-01-02 14:45:19 UTC
Forgotten line which should have been part of comment#4 too:

# restorecon -v /sbin
restorecon reset /sbin context system_u:object_r:bin_t:s0->system_u:object_r:user_home_dir_t:s0
#

Comment 8 errata-xmlrpc 2017-08-01 15:20:12 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2017:1861