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.
Created attachment 1075355[details]
Fix restorecon so it works when a path does not contain context
Description of problem:
When selinux is disabled, selinux.restorecon fail withh ENODATA,
when restoring contents of a file created when selinux was disabled.
The failure is caused by assuming that the path has a label, which
is not true when selinux is disabled.
Version-Release number of selected component (if applicable):
# rpm -qa | grep selinux
libselinux-utils-2.2.2-6.el7.x86_64
libselinux-python-2.2.2-6.el7.x86_64
selinux-policy-3.13.1-23.el7_1.17.noarch
selinux-policy-targeted-3.13.1-23.el7_1.17.noarch
libselinux-2.2.2-6.el7.x86_64
libselinux-devel-2.2.2-6.el7.x86_64
How reproducible:
Always
Steps to Reproduce:
1. disbale selinux by setting /etc/selinux/config SELINUX to disabled
2. reboot
3. create a new file (touch /etc/multipath.conf.new)
4. Open python shell
5. run
selinux.restorecon("/etc/multipath.conf.new")
Actual results:
>>> selinux.restorecon('/etc/multipath.conf.new')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/site-packages/selinux/__init__.py", line 88, in restorecon
status, oldcontext = lgetfilecon(path)
OSError: [Errno 61] No data available
Expected results:
Operation should succeed.
Additional info:
The file indeed contains no labels:
>>> os.system('ls -Z multipath.conf*')
-rw-r--r--. root root system_u:object_r:etc_t:s0 multipath.conf
-rw-r--r-- root root ? multipath.conf.new
0
But we can match the selinux context for this path:
>>> selinux.matchpathcon("/etc/multipath.con.new",
os.lstat("/etc/multipath.conf.new").st_mode)
[0, 'system_u:object_r:etc_t:s0']
And we can set the context using chcon:
>>> selinux.chcon("/etc/multipath.con.new", 'system_u:object_r:etc_t:s0')
>>> os.system('ls -Z multipath.conf*')
-rw-r--r--. root root system_u:object_r:etc_t:s0 multipath.conf
-rw-r--r--. root root system_u:object_r:etc_t:s0 multipath.conf.new
0
Attached a patch I sent to selinux.gov.
This is not new issue; Vdsm currently use this workaround in many places:
if selinux.is_selinux_enabled():
selinux.restorecon(path)
Which means that after activating selinux, the files we tried
to restore may have no label.
(In reply to Daniel Walsh from comment #2)
> Shouldn't the fix be to check if selinux is enabled?
Do you mean to avoid the lgetfilecon() call if selinux or disabled, or
just avoid the call to restorecon() (see comment 1)?
Can we get this fix in 7.2? It would be nice to eliminate the
is_selinux_enabled() checks in vdsm.
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.
https://rhn.redhat.com/errata/RHBA-2016-2276.html