RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 955769 - useradd not assigning correct SELinux user to contexts of home directory files
Summary: useradd not assigning correct SELinux user to contexts of home directory files
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: shadow-utils
Version: 6.6
Hardware: All
OS: Linux
unspecified
high
Target Milestone: rc
: ---
Assignee: Tomas Mraz
QA Contact: Dalibor Pospíšil
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2013-04-23 18:40 UTC by Brandon
Modified: 2014-10-14 07:16 UTC (History)
4 users (show)

Fixed In Version: shadow-utils-4.1.4.2-19.el6
Doc Type: Bug Fix
Doc Text:
Cause: The useradd assigned the SELinux user to the new user being created after creating and populating the home directory of the user. Consequence: The SELinux contexts of the home directory files were incorrect. Fix: The SELinux user is assigned to the newly created user before populating the home directory. Result: The SELinux contexts on the home directory files for newly created users are now correct.
Clone Of:
: 1077809 1134450 (view as bug list)
Environment:
Last Closed: 2014-10-14 07:16:47 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2014:1522 0 normal SHIPPED_LIVE shadow-utils bug fix update 2014-10-14 01:22:10 UTC

Description Brandon 2013-04-23 18:40:28 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 2 RHEL Program Management 2013-10-13 23:40:40 UTC
This request was evaluated by Red Hat Product Management for
inclusion in the current release of Red Hat Enterprise Linux.
Because the affected component is not scheduled to be updated
in the current release, Red Hat is unable to address this
request at this time.

Red Hat invites you to ask your support representative to
propose this request, if appropriate, in the next release of
Red Hat Enterprise Linux.

Comment 4 Tomas Mraz 2014-06-05 13:23:52 UTC
The fixed useradd moves the SELinux login entry creation before creation of the user's home directory. This allows SELinux to create the directory with proper context.

Comment 10 errata-xmlrpc 2014-10-14 07:16:47 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.

http://rhn.redhat.com/errata/RHBA-2014-1522.html


Note You need to log in before you can comment on or make changes to this bug.