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 1406520 - calling libselinux python restorecon fails on /var/lib/nfs/rpc_pipefs
Summary: calling libselinux python restorecon fails on /var/lib/nfs/rpc_pipefs
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libselinux
Version: 7.3
Hardware: All
OS: Linux
high
high
Target Milestone: rc
: ---
Assignee: Petr Lautrbach
QA Contact: Milos Malik
URL:
Whiteboard:
: 1396293 (view as bug list)
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-12-20 19:09 UTC by Brent Baude
Modified: 2020-02-14 18:22 UTC (History)
11 users (show)

Fixed In Version: libselinux-2.5-7.el7
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 1411700 (view as bug list)
Environment:
Last Closed: 2017-08-01 17:43:16 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
replicato-log (15.97 KB, text/plain)
2016-12-20 19:09 UTC, Brent Baude
no flags Details
cloud-init log (379.98 KB, text/x-vhdl)
2016-12-20 19:11 UTC, Brent Baude
no flags Details


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2017:1853 0 normal SHIPPED_LIVE libselinux bug fix update 2017-08-01 18:03:23 UTC

Description Brent Baude 2016-12-20 19:09:59 UTC
Created attachment 1234027 [details]
replicato-log

I am working on RHEL Atomic enablement on MS Azure, which requires a slightly newer version of cloud-init.  Cloud-init eventually calls a restore con on /var/lib before it does any writing of its own.  When doing so, it reveals a traceback in libselinux code for the file '/var/lib/nfs/rpc_pipefs'.  The unhandled exception causes the provisioning to fail.

In looking at the restorecon method, the first failure occurs when matchpathcon is called.  The 'OSError' except catches it but then fails again when it is called again in the exception condition.

def restorecon(path, recursive=False):
    """ Restore SELinux context on a given path """

    try:
        mode = os.lstat(path)[stat.ST_MODE]
        status, context = matchpathcon(path, mode)
    except OSError:
        path = os.path.realpath(os.path.expanduser(path))
        mode = os.lstat(path)[stat.ST_MODE]
        status, context = matchpathcon(path, mode)
    ...

Because matchpathcon is likely? in the .so, I am not able to debug further as to why an OSError (file not found) is being thrown.  The file is definitely there but probably suffers from some selinux context issue.

You can replicate this easily with:

>>> import selinux
>>> selinux.restorecon('/var/lib/nfs/rpc_pipefs')
...
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, context = matchpathcon(path, mode)
OSError: [Errno 2] No such file or directory

I'll attach a full log for the above as well as the cloud-init log.

Comment 1 Brent Baude 2016-12-20 19:11:03 UTC
Created attachment 1234028 [details]
cloud-init log

Comment 2 Brent Baude 2016-12-20 19:12:27 UTC
This is blocking enablement of RHEL Atomic on Azure which is why I jacked up the priority.

Comment 3 Jonathan Lebon 2016-12-20 19:16:35 UTC
Just to elaborate, it seems like the issue is that /var/lib/nfs/rpc_pipefs is explicitly undefined:

# semanage fcontext -l | grep rpc_pipefs
/var/lib/nfs/rpc_pipefs(/.*)?                      all files          <<None>>

which is probably why the matchpathcon() fails. The rpc_pipefs mount itself is indeed properly labeled as per the refpolicy.

Maybe selinux.restorecon() should have a skip_undefined optional bool? To compare the CLI equivalent does not error out on this and instead just prints a warning message.

Comment 4 Brent Baude 2016-12-20 21:51:05 UTC
I tested the suggestion by Dan Walsh at https://github.com/fedora-selinux/selinux/pull/35 and it worked perfectly for my use.  Let's monitor the upstream response and then patch the RH package as soon as possible.

Comment 5 Daniel Walsh 2017-01-05 15:23:45 UTC
Petr can we get this backported to RHEL7?

Comment 11 Milos Malik 2017-01-06 11:40:48 UTC
old version
========
# rpm -qa libselinux\*
libselinux-2.5-6.el7.x86_64
libselinux-utils-2.5-6.el7.x86_64
libselinux-python-2.5-6.el7.x86_64
# matchpathcon /run/*.pid
/run/auditd.pid	system_u:object_r:auditd_var_run_t:s0
/run/crond.pid	system_u:object_r:crond_var_run_t:s0
/run/dhclient-eth0.pid	system_u:object_r:dhcpc_var_run_t:s0
/run/gssproxy.pid	system_u:object_r:gssproxy_var_run_t:s0
/run/lvmetad.pid	<<none>>
/run/rhnsd.pid	system_u:object_r:rhnsd_var_run_t:s0
/run/rpc.statd.pid	system_u:object_r:rpcd_var_run_t:s0
/run/sm-notify.pid	system_u:object_r:rpcd_var_run_t:s0
/run/sshd.pid	system_u:object_r:sshd_var_run_t:s0
/run/syslogd.pid	system_u:object_r:syslogd_var_run_t:s0
# python
Python 2.7.5 (default, Aug  2 2016, 04:20:16) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import selinux
>>> selinux.restorecon('/run/lvmetad.pid')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/site-packages/selinux/__init__.py", line 85, in restorecon
    status, context = matchpathcon(path, mode)
OSError: [Errno 2] No such file or directory
>>>

new version
========
# rpm -qa libselinux\*
libselinux-2.5-7.el7.x86_64
libselinux-utils-2.5-7.el7.x86_64
libselinux-python-2.5-7.el7.x86_64
# matchpathcon /run/*.pid
/run/auditd.pid	system_u:object_r:auditd_var_run_t:s0
/run/crond.pid	system_u:object_r:crond_var_run_t:s0
/run/dhclient-eth0.pid	system_u:object_r:dhcpc_var_run_t:s0
/run/gssproxy.pid	system_u:object_r:gssproxy_var_run_t:s0
/run/lvmetad.pid	<<none>>
/run/rhnsd.pid	system_u:object_r:rhnsd_var_run_t:s0
/run/rpc.statd.pid	system_u:object_r:rpcd_var_run_t:s0
/run/sm-notify.pid	system_u:object_r:rpcd_var_run_t:s0
/run/sshd.pid	system_u:object_r:sshd_var_run_t:s0
/run/syslogd.pid	system_u:object_r:syslogd_var_run_t:s0
[0 root@qeos-100 ~]# python
Python 2.7.5 (default, Aug  2 2016, 04:20:16) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import selinux
>>> selinux.restorecon('/run/lvmetad.pid')
>>> 

The fix is OK. Of course, it works well with /var/lib/nfs/rpc_pipefs.

Comment 13 Daniel Walsh 2017-01-06 15:18:17 UTC
Brent do we need this prior to 7.4?

Comment 14 Brent Baude 2017-01-09 16:15:55 UTC
In comment 6, Milos says he will do a zstream which will help with testing.  Other that, we dont need earlier (like RHEL6)

Comment 18 Lars Kellogg-Stedman 2017-01-12 19:55:26 UTC
*** Bug 1396293 has been marked as a duplicate of this bug. ***

Comment 19 Petr Lautrbach 2017-01-13 07:51:00 UTC
*** Bug 1396293 has been marked as a duplicate of this bug. ***

Comment 20 J. Guthrie 2017-01-18 23:52:31 UTC
(In reply to Brent Baude from comment #14)
> In comment 6, Milos says he will do a zstream which will help with testing. 
> Other that, we dont need earlier (like RHEL6)

Actually, I am seeing the symptoms of bug 1396293 in CentOS 6.8:

# python
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import selinux
>>> selinux.restorecon('/var/lib/nfs/rpc_pipefs')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.6/site-packages/selinux/__init__.py", line 80, in restorecon
    status, context = matchpathcon(path, mode)
OSError: [Errno 2] No such file or directory

I'm aware that since this comes from CentOS, it doesn't necessarily affect RHEL, but I thought I would mention it since there probably are chef users affected by bug 1396293 under RHEL 6.8.

Comment 21 errata-xmlrpc 2017-08-01 17:43:16 UTC
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://access.redhat.com/errata/RHBA-2017:1853


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