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 1269989 - result of how selinux fcontexts with regexps work depends on adding order
Summary: result of how selinux fcontexts with regexps work depends on adding order
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: policycoreutils
Version: 7.3
Hardware: All
OS: Linux
medium
unspecified
Target Milestone: rc
: ---
Assignee: Vit Mojzis
QA Contact: Dalibor Pospíšil
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2015-10-08 17:40 UTC by Rafał Mielnik
Modified: 2018-02-01 17:13 UTC (History)
7 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-02-01 17:13:13 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github SELinuxProject selinux issues 40 0 None open libsemanage should sort file_contexts.local by precedence too 2021-01-05 09:55:48 UTC

Description Rafał Mielnik 2015-10-08 17:40:08 UTC
Description of problem:

the order of adding the regexp fcontext rules shouldn't matter but it looks like it actually does matter

Version-Release number of selected component (if applicable):

selinux-policy-3.13.1-23.el7_1.18.noarch

How reproducible:


Steps to Reproduce:

1. semanage fcontext -a -t httpd_log_t '/tmp/selinux/log(/.*)?'
semanage fcontext -a -t var_log_t '/tmp/selinux(/.*)?'

2. mkdir /tmp/selinux/log -p
touch /tmp/selinux/log/file
restorecon -Rv /tmp/selinux/

3. semanage fcontext -d -t var_log_t '/tmp/selinux(/.*)?'
semanage fcontext -d -t httpd_log_t '/tmp/selinux/log(/.*)?'
semanage fcontext -a -t var_log_t '/tmp/selinux(/.*)?'
semanage fcontext -a -t httpd_log_t '/tmp/selinux/log(/.*)?'

4. rm -rf /tmp/selinux/
mkdir /tmp/selinux/log -p
touch /tmp/selinux/log/file

5. restorecon -Rv /tmp/selinux/

Actual results:

restorecon reset /tmp/selinux context
unconfined_u:object_r:user_tmp_t:s0->unconfined_u:object_r:var_log_t:s0
restorecon reset /tmp/selinux/log context
unconfined_u:object_r:user_tmp_t:s0->unconfined_u:object_r:var_log_t:s0
restorecon reset /tmp/selinux/log/file context
unconfined_u:object_r:user_tmp_t:s0->unconfined_u:object_r:var_log_t:s0

and after removing and adding the rules in different order:

restorecon reset /tmp/selinux context
unconfined_u:object_r:user_tmp_t:s0->unconfined_u:object_r:var_log_t:s0
restorecon reset /tmp/selinux/log context
unconfined_u:object_r:user_tmp_t:s0->unconfined_u:object_r:httpd_log_t:s0
restorecon reset /tmp/selinux/log/file context
unconfined_u:object_r:user_tmp_t:s0->unconfined_u:object_r:httpd_log_t:s0

Expected results:

both ways should be:

restorecon reset /tmp/selinux context
unconfined_u:object_r:user_tmp_t:s0->unconfined_u:object_r:var_log_t:s0
restorecon reset /tmp/selinux/log context
unconfined_u:object_r:user_tmp_t:s0->unconfined_u:object_r:httpd_log_t:s0
restorecon reset /tmp/selinux/log/file context
unconfined_u:object_r:user_tmp_t:s0->unconfined_u:object_r:httpd_log_t:s0

Additional info:

Comment 2 Miroslav Grepl 2015-10-12 08:07:35 UTC
We have some fixes related to a context order in policycoreutils.

Comment 4 Vit Mojzis 2018-02-01 17:13:13 UTC
Thank you for taking the time to report this issue to us. We appreciate the feedback and use reports such as this one to guide our efforts at improving our products. That being said, this particular issue is well documented and there is not a clear consensus about a better solution ( please see https://bugzilla.redhat.com/show_bug.cgi?id=678577 ). 
The issue will be tracked in Fedora bug mentioned above. Closing as WONTFIX.


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