Bug 1406520 - calling libselinux python restorecon fails on /var/lib/nfs/rpc_pipefs
calling libselinux python restorecon fails on /var/lib/nfs/rpc_pipefs
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libselinux (Show other bugs)
7.3
All Linux
high Severity high
: rc
: ---
Assigned To: Petr Lautrbach
Milos Malik
:
: 1396293 (view as bug list)
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2016-12-20 14:09 EST by Brent Baude
Modified: 2017-08-01 13:43 EDT (History)
11 users (show)

See Also:
Fixed In Version: libselinux-2.5-7.el7
Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1411700 (view as bug list)
Environment:
Last Closed: 2017-08-01 13:43:16 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


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

  None (edit)
Description Brent Baude 2016-12-20 14:09:59 EST
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 14:11 EST
Created attachment 1234028 [details]
cloud-init log
Comment 2 Brent Baude 2016-12-20 14:12:27 EST
This is blocking enablement of RHEL Atomic on Azure which is why I jacked up the priority.
Comment 3 Jonathan Lebon 2016-12-20 14:16:35 EST
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 16:51:05 EST
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 10:23:45 EST
Petr can we get this backported to RHEL7?
Comment 11 Milos Malik 2017-01-06 06:40:48 EST
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 10:18:17 EST
Brent do we need this prior to 7.4?
Comment 14 Brent Baude 2017-01-09 11:15:55 EST
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 14:55:26 EST
*** Bug 1396293 has been marked as a duplicate of this bug. ***
Comment 19 Petr Lautrbach 2017-01-13 02:51:00 EST
*** Bug 1396293 has been marked as a duplicate of this bug. ***
Comment 20 J. Guthrie 2017-01-18 18:52:31 EST
(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 13:43:16 EDT
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.