Bug 973647

Summary: missing error message when useradd cannot create user with homedir in location without default selinux context
Product: Red Hat Enterprise Linux 7 Reporter: Michal Trunecka <mtruneck>
Component: shadow-utilsAssignee: Tomas Mraz <tmraz>
Status: CLOSED CURRENTRELEASE QA Contact: Michal Trunecka <mtruneck>
Severity: low Docs Contact:
Priority: medium    
Version: 7.0CC: dwalsh, ebenes, mgrepl, mmalik
Target Milestone: rcKeywords: Reopened
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: shadow-utils-4.1.5.1-6.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-06-13 13:27:33 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 Michal Trunecka 2013-06-12 12:32:15 UTC
Description of problem:
For example /mnt/qa/scratch has not a default selinux context:

# matchpathcon /mnt/qa/scratch
/mnt/qa/scratch	<<none>>

Creating user with homedir in there fails:

# useradd -m -d /mnt/qa/scratch/user19376 user19376
# echo $?
12

The returned 12 means the homedir couldn't be created. It works fine in permissive, no AVCs related to this issue. (even with disabled dontaudit rules)

In useradd.c, there is the following code in create_home function:

> 1762 if (set_selinux_file_context (user_home, NULL) != 0) {
> 1763     fail_exit (E_HOMEDIR);
> 1764 }

And because no orig.context is passed in the second argument and at the same time matchpathcon returns no default context, the set_selinux_file_context function failes.
From lib/selinux.c (in shadow-utils srcrpm):

> 53 int set_selinux_file_context (const char *dst_name, const char *orig_name)
...
> 62         if (selinux_enabled) {
> 63                 /* Get the default security context for this file */
> 64                 if (matchpathcon (dst_name, 0, &scontext) < 0) {
> 65                         /* We could not get the default, copy the original */
> 66                         if (orig_name == NULL)
> 67                                 goto error;



Version-Release number of selected component (if applicable):
shadow-utils-4.1.5.1-5.el7.x86_64

Comment 1 Tomas Mraz 2013-06-12 12:39:01 UTC
I don't think this is a bug. Just specify some default context adequate for the home directory parent with semanage fcontext -a ...

Or disable selinux if you do not want to work with it properly - but I strictly do not recommend that.

Comment 2 Michal Trunecka 2013-06-12 12:51:43 UTC
If not anything else, I definitely think that not logging any message about the reason of not creating home dir is a bug.

Comment 6 Ludek Smid 2014-06-13 13:27:33 UTC
This request was resolved in Red Hat Enterprise Linux 7.0.

Contact your manager or support representative in case you have further questions about the request.