Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
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 2178968

Summary: Bind mounts affected by relabelling.
Product: Red Hat Enterprise Linux 8 Reporter: Siddharth <sgandhi>
Component: selinux-policyAssignee: Zdenek Pytela <zpytela>
Status: CLOSED NOTABUG QA Contact: BaseOS QE Security Team <qe-baseos-security>
Severity: medium Docs Contact:
Priority: medium    
Version: 8.6CC: damien.chargy, lvrabec, mmalik, nknazeko, plautrba, rmetrich, ssekidde
Target Milestone: rcKeywords: Triaged
Target Release: ---Flags: pm-rhel: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: No Doc Update
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-03-29 19:11:56 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 Siddharth 2023-03-16 10:02:46 UTC
Description of problem: 

When SELinux autorelabel acts, it set the context "unconfined_u:object_r:user_home_t:s0" to /home directories and files inculding rbind mounts, because of the context :
# semanage fcontext -l |grep 'user_home_t'
/home/[^/]+/.+                                     all files          unconfined_u:object_r:user_home_t:s0

But bind mounts shouldn't be affected by relabelling.


Steps to Reproduce:

# mkdir -p /root_directory/first_directory
# mkdir -p /root_directory/second_directory
# touch /root_directory/first_directory/file1
# touch /root_directory/second_directory/file2
# useradd test
# su - test
# mkdir -p /home/test/root_directory

##############################
# display SElinux contexts for /root_directory -> default_t : OK
##############################
# ll -RZ /root_directory
/root_directory:
total 0
drwxr-xr-x. 2 root root unconfined_u:object_r:default_t:s0 19 Feb 24 17:04 first_directory
drwxr-xr-x. 2 root root unconfined_u:object_r:default_t:s0 19 Feb 24 17:04 second_directory

/root_directory/first_directory:
total 0
-rw-r--r--. 1 root root unconfined_u:object_r:default_t:s0 0 Feb 24 17:04 file1

/root_directory/second_directory:
total 0
-rw-r--r--. 1 root root unconfined_u:object_r:default_t:s0 0 Feb 24 17:04 file2

##############################
# display SElinux contexts for /home/test/ -> user_home_t : OK
##############################
# ll -RZ /home/test/
/home/test/:
total 0
drwxrwxr-x. 2 test test unconfined_u:object_r:user_home_t:s0 6 Feb 24 17:05 root_directory

/home/test/root_directory:
total 0

# exit
logout

# echo "/root_directory /home/test/root_directory none rbind 0 0" >> /etc/fstab
# mount /home/test/root_directory

##############################
# When setting context from /home/test/root_directory, context set is user_home_t
##############################
# restorecon -R /home/test/root_directory
# ll -RZ /root_directory
/root_directory:
total 0
drwxr-xr-x. 2 root root unconfined_u:object_r:user_home_t:s0 19 Feb 24 17:04 first_directory
drwxr-xr-x. 2 root root unconfined_u:object_r:user_home_t:s0 19 Feb 24 17:04 second_directory

/root_directory/first_directory:
total 0
-rw-r--r--. 1 root root unconfined_u:object_r:user_home_t:s0 0 Feb 24 17:04 file1

/root_directory/second_directory:
total 0
-rw-r--r--. 1 root root unconfined_u:object_r:user_home_t:s0 0 Feb 24 17:04 file2

##############################
# When setting context from /root_directory, context is reset to default_t
##############################
# restorecon -R /root_directory
# ll -RZ /root_directory
/root_directory:
total 0
drwxr-xr-x. 2 root root unconfined_u:object_r:default_t:s0 19 Feb 24 17:04 first_directory
drwxr-xr-x. 2 root root unconfined_u:object_r:default_t:s0 19 Feb 24 17:04 second_directory

/root_directory/first_directory:
total 0
-rw-r--r--. 1 root root unconfined_u:object_r:default_t:s0 0 Feb 24 17:04 file1

/root_directory/second_directory:
total 0
-rw-r--r--. 1 root root unconfined_u:object_r:default_t:s0 0 Feb 24 17:04 file2

Expected results:

Bind mounts shouldn't be affected by relabelling.

Additional info:

Comment 1 Renaud Métrich 2023-03-16 11:21:11 UTC
I would expect (r)bind mounts to not be mounted at all when relabeling occurs, or `fixfiles` to skip such mounts.

Note that there is no known workaround available since relabeling happens usually during reboot.

Comment 2 Petr Lautrbach 2023-03-24 10:58:17 UTC
How would `restorecon` or `fixfiles` know whether (r)bind mounts are expected to be relabeled or not? If an user mounts something into /home, it's kind of expected that it would be user related data and therefore relabeling to user_home_t is correct. But if they know that it should not be relabeled according to the policy, they need to adjust system and scripts according to their mount setup:

For `fixfiles`, directories excluded from relabeling directories can be listed in /etc/selinux/fixfiles_exclude_dirs. `/sys /proc /mnt /var/tmp /var/lib/BackupPC /home /root /tmp` are excluded by default

`restorecon` has `-e directory` option which exclude directory from relabeling.

Comment 3 Zdenek Pytela 2023-03-29 19:11:56 UTC
This is not a bug neither in selinux-policy nor fixfiles, see #c2.
For the commands usage details, please refer to fixfiles(8) or restorecon(8) manual pages.
For dealing with customized paths, see also the product documentation examples and semanage fcontext command usage with equivalency rules:

Customizing the SELinux policy for the Apache HTTP server in a non-standard configuration
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html-single/using_selinux/index#customizing-the-selinux-policy-for-the-apache-http-server-in-a-non-standard-configuration_configuring-selinux-for-applications-and-services-with-non-standard-configurations