Bug 1134450

Summary: useradd not assigning correct SELinux user to contexts of home directory files
Product: Red Hat Enterprise Linux 7 Reporter: Tomas Mraz <tmraz>
Component: shadow-utilsAssignee: Tomas Mraz <tmraz>
Status: CLOSED DUPLICATE QA Contact: BaseOS QE Security Team <qe-baseos-security>
Severity: high Docs Contact:
Priority: unspecified    
Version: 7.1CC: brandon, dapospis, mmalik, spencer
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 955769 Environment:
Last Closed: 2014-08-27 14:18:16 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 Tomas Mraz 2014-08-27 14:16:07 UTC
Description of problem:
Users created using useradd -Z are not given the correct user in the context of their home directory

Version-Release number of selected component (if applicable):
shadow-utils-4.1.4.2-13.el6.x86_64
possibly,
policycoreutils-python-2.0.8-19.30.el6_64

How reproducible:
Easily

Steps to Reproduce:
1.Switch to root
2.useradd -m testuser -Z staff_u
3.ls -Z /home/testuser 
  
Actual results:
drwx------. testuser testuser unconfined_u:object_r:user_home_dir_t:s0 .
drwxr-xr-x. root     root     system_u:object_r:home_root_t:s0 ..
-rw-r--r--. testuser testuser unconfined_u:object_r:user_home_t:s0 .bash_logout
-rw-r--r--. testuser testuser unconfined_u:object_r:user_home_t:s0 .bash_profile
-rw-r--r--. testuser testuser unconfined_u:object_r:user_home_t:s0 .bashrc
-rw-r--r--. testuser testuser unconfined_u:object_r:user_home_t:s0 .emacs
drwxr-xr-x. testuser testuser unconfined_u:object_r:gnome_home_t:s0 .gnome2
drwxr-xr-x. testuser testuser unconfined_u:object_r:mozilla_home_t:s0 .mozilla

Expected results:
ls -Za /home/testuser
drwx------. testuser testuser staff_u:object_r:user_home_dir_t:s0 .
drwxr-xr-x. root     root     system_u:object_r:home_root_t:s0 ..
-rw-r--r--. testuser testuser staff_u:object_r:user_home_t:s0 .bash_logout
-rw-r--r--. testuser testuser staff_u:object_r:user_home_t:s0 .bash_profile
-rw-r--r--. testuser testuser staff_u:object_r:user_home_t:s0 .bashrc
-rw-r--r--. testuser testuser staff_u:object_r:user_home_t:s0 .emacs
drwxr-xr-x. testuser testuser staff_u:object_r:gnome_home_t:s0 .gnome2
drwxr-xr-x. testuser testuser staff_u:object_r:mozilla_home_t:s0 .mozilla

Additional info:
If you run restorecon, the context is updated correctly
[root@owf SPECS]# restorecon -RF /home/testuser
[root@owf SPECS]# ls -Za /home/testuser
drwx------. testuser testuser staff_u:object_r:user_home_dir_t:s0 .
drwxr-xr-x. root     root     system_u:object_r:home_root_t:s0 ..
-rw-r--r--. testuser testuser staff_u:object_r:user_home_t:s0  .bash_logout
-rw-r--r--. testuser testuser staff_u:object_r:user_home_t:s0  .bash_profile
-rw-r--r--. testuser testuser staff_u:object_r:user_home_t:s0  .bashrc
-rw-r--r--. testuser testuser staff_u:object_r:user_home_t:s0  .emacs
drwxr-xr-x. testuser testuser staff_u:object_r:gnome_home_t:s0 .gnome2
drwxr-xr-x. testuser testuser staff_u:object_r:mozilla_home_t:s0 .mozilla

I've tested this on F18 and it's there as well. Looking at the code in useradd.c what is happening is that all of the files in a users home directories are written out before the SELinux user mappings are updated. So the system is using the default mapping of unconfined_u to write it out. There seem to be 2 quick fixes
1) Run restorecon -RF following the calls to semanage in useradd.c
2) Update semanage to have a flag to check if files need to be relabeled after adding a login mapping and update them.

Comment 1 Tomas Mraz 2014-08-27 14:18:16 UTC

*** This bug has been marked as a duplicate of bug 1077809 ***