Description of problem: Creating multiple levels of directories together with mkdir -p -Z fails to set the SELinux context for all but the highest and lowest directories. Version-Release number of selected component (if applicable): coreutils-8.25-7.fc24.x86_64 How reproducible: Always for any more than two directory levels. Steps to Reproduce: 1. Create 3 or more directories together with (for eg) mkdir -p -Z a/b/c Actual results: mkdir: failed to set default creation context for 'a/b': No such file or directory SELinux labels set on a and a/b/c, but not on a/b. Expected results: a/b should also be labeled. Additional info: Same problem all intermediary directories, eg mkdir -p -Z a/b/c/d fails to label a/b and a/b/c (but labels a and a/b/c/d). NOTE: mkdir will usually correct the labels on existing directories, but fails to do so here as well.
Confirmed. Minimal example: $ sudo semanage fcontext -a -t user_home_t /tmp/a $ sudo semanage fcontext -a -t mozilla_home_t /tmp/a/b $ sudo semanage fcontext -a -t home_cert_t /tmp/a/b/c $ mkdir -Zp a/b/c $ ls -1Zd a a/b a/b/c unconfined_u:object_r:user_home_t:s0 a unconfined_u:object_r:user_home_t:s0 a/b unconfined_u:object_r:home_cert_t:s0 a/b/c $ restorecon -R a $ ls -1Zd a a/b a/b/c unconfined_u:object_r:user_home_t:s0 a unconfined_u:object_r:mozilla_home_t:s0 a/b unconfined_u:object_r:home_cert_t:s0 a/b/c Same problem with install(1): $ rm -fr a $ install -ZDd a/b/c $ ls -1Zd a a/b a/b/c unconfined_u:object_r:user_home_t:s0 a unconfined_u:object_r:user_home_t:s0 a/b unconfined_u:object_r:home_cert_t:s0 a/b/c
This looks like a copy-paste error (duplicated at two places in the code): --- a/src/install.c +++ b/src/install.c @@ -427,7 +427,7 @@ static int make_ancestor (char const *dir, char const *component, void *options) { struct cp_options const *x = options; - if (x->set_security_context && defaultcon (dir, S_IFDIR) < 0 + if (x->set_security_context && defaultcon (component, S_IFDIR) < 0 && ! ignorable_ctx_err (errno)) error (0, errno, _("failed to set default creation context for %s"), quoteaf (dir)); --- a/src/mkdir.c +++ b/src/mkdir.c @@ -123,7 +123,7 @@ make_ancestor (char const *dir, char const *component, void *options) { struct mkdir_options const *o = options; - if (o->set_security_context && defaultcon (dir, S_IFDIR) < 0 + if (o->set_security_context && defaultcon (component, S_IFDIR) < 0 && ! ignorable_ctx_err (errno)) error (0, errno, _("failed to set default creation context for %s"), quoteaf (dir)); I will submit a patch upstream once I have idea how to test this...
(In reply to Kamil Dudka from comment #2) > I will submit a patch upstream once I have idea how to test this... I have not figured out how to reliably test this without having root access but submitted a patch upstream anyway: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=25052
upstream commit: http://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=commitdiff;h=d8104265
coreutils-8.25-8.fc24 has been submitted as an update to Fedora 24. https://bodhi.fedoraproject.org/updates/FEDORA-2017-b21a847e7a
coreutils-8.25-16.fc25 has been submitted as an update to Fedora 25. https://bodhi.fedoraproject.org/updates/FEDORA-2017-24ce0b63c4
coreutils-8.25-16.fc25 has been pushed to the Fedora 25 testing repository. If problems still persist, please make note of it in this bug report. See https://fedoraproject.org/wiki/QA:Updates_Testing for instructions on how to install test updates. You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2017-24ce0b63c4
coreutils-8.25-8.fc24 has been pushed to the Fedora 24 testing repository. If problems still persist, please make note of it in this bug report. See https://fedoraproject.org/wiki/QA:Updates_Testing for instructions on how to install test updates. You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2017-b21a847e7a
Tested update, bug appears fixed. Karma added.
coreutils-8.25-16.fc25 has been pushed to the Fedora 25 stable repository. If problems still persist, please make note of it in this bug report.
coreutils-8.25-8.fc24 has been pushed to the Fedora 24 stable repository. If problems still persist, please make note of it in this bug report.
(In reply to Scott Shambarger from comment #9) > Tested update, bug appears fixed. Karma added. Thanks for confirmation!