Hide Forgot
Description of problem: During development of CC tests we found an issue with semanage. It is changing permissions of /etc/selinux files according to the set umask. This has large side effects, e.g. with umask 027 it makes restorecon unusable for ordinary users. This bug was found on an MLS machine applies generally. Reproducer: # umask 0027 # ll /etc/selinux/mls/contexts/files/file_contexts -rw-r--r--. 1 root root 224235 Oct 19 09:29 /etc/selinux/mls/contexts/files/file_contexts # mkdir /d # semanage fcontext -a -t home_root_t /d # ll /etc/selinux/mls/contexts/files/file_contexts -rw-r-----. 1 root root 224235 Oct 19 09:38 /etc/selinux/mls/contexts/files/file_contexts Version-Release number of selected component (if applicable): policycoreutils-python-2.0.83-19.16.el6 How reproducible: 100% Steps to Reproduce: see description Actual results: semanage changes file permissions Expected results: semanage doesn't change file permissions Additional info: I can reproduce this also in policycoreutils-python from RHEL6.0: policycoreutils-python-2.0.83-19.1.el6.x86_64
I am not sure if this is a bug or not. Users generally should not be running restorecon. Currently we do not have hard coded permissions for these files.
This is an issue with semanage changing permissions on several files in /etc/selinux according to umask. Is this on purpose? For example if user wants to use ssh-copy-id he ends up with permission denied because it runs restorecon: # grep -n restorecon $(which ssh-copy-id) 41:{ eval "$GET_ID" ; } | ssh $1 "umask 077; test -d .ssh || mkdir .ssh ; cat >> .ssh/authorized_keys; test -x /sbin/restorecon && /sbin/restorecon .ssh .ssh/authorized_keys" || exit 1
I would say, if an admin sets umask, then probably is expected the restorecon won't work for users.
If this won't be fixed in semanage, we will need to fix openssh.
Maybe libsemanage should save and restore umask() when creating files? It already allows file mode to be specified via semanage.conf, but doesn't save/restore umask and thus is subject to caller's umask.
I'd say this is similar to the situation when someone runs adduser and /etc/passwd gets re-created; the permissions of /etc/passwd aren't subject to the caller's umask, right? So libsemanage ought to save and clear the umask before creating files and restore it afterward. Simple patch to semanage_copy_file().
(In reply to comment #5) > Maybe libsemanage should save and restore umask() when creating files? It > already allows file mode to be specified via semanage.conf, but doesn't > save/restore umask and thus is subject to caller's umask. I agree, you are reading my thoughts. I think that unless there is another way how to preserve the correct contexts for ssh-copy-id this is the most appropriate solution.
Created attachment 529059 [details] Save, clear, and restore umask around file creation by libsemanage.
Or it should copy the permissions from the original file with chmod() call.
Patch applied in libsemanage-2.0.45-1.1.el6
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-2011-1770.html