Bug 1583241

Summary: setroubleshoot-server dies trying to open SELinux policy file /sys/fs/selinux/policy
Product: Red Hat Enterprise Linux 7 Reporter: Renaud Métrich <rmetrich>
Component: setroubleshootAssignee: Vit Mojzis <vmojzis>
Status: CLOSED ERRATA QA Contact: Milos Malik <mmalik>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.5CC: lvrabec, mezhang, mmalik, nduffy, plautrba, vmojzis
Target Milestone: rcKeywords: AutoVerified
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: setroubleshoot-3.2.30-6.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-08-06 13:00:39 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 Renaud Métrich 2018-05-28 14:22:48 UTC
Description of problem:

Sometimes, if the /sys/fs/selinux/policy file is already being processed by some other tool (e.g. "seinfo"), setroubleshootd daemon fails to start with "server.py:702:RunFaultServer:ValueError: unable to open /sys/fs/selinux/policy:  Device or resource busy"


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

setroubleshoot-server-3.2.29-3.el7


How reproducible:

Often using the reproducer below:


Steps to Reproduce:
1. In a terminal, run "seinfo" in loop

  # while :; do seinfo; done

2. In the GUI, start the SELinux Troubleshooter applet ("sealert")

Actual results:

# abrt-cli ls
id 4b008c272b2d6c24b3378be400d4912e7aaae210
reason:         server.py:702:RunFaultServer:ValueError: unable to open /sys/fs/selinux/policy:  Device or resource busy
time:           Mon 28 May 2018 04:17:13 PM CEST
cmdline:        /usr/bin/python -Es /usr/sbin/setroubleshootd -f ''
package:        setroubleshoot-server-3.2.29-3.el7
uid:            995 (setroubleshoot)
Directory:      /var/spool/abrt/Python-2018-05-28-16:17:13-3416
Run 'abrt-cli report /var/spool/abrt/Python-2018-05-28-16:17:13-3416' for creating a case in Red Hat Customer Portal

The Autoreporting feature is disabled. Please consider enabling it by issuing
'abrt-auto-reporting enabled' as a user with root privileges


Expected results:

More tries opening the file?

Comment 2 Petr Lautrbach 2018-05-29 06:46:30 UTC
I guess you can't avoid some kind of backtrace on one or other side in these situations. But we could race to who will get the file first during pre-defined timeout like this:

diff --git a/framework/src/setroubleshoot/server.py b/framework/src/setroubleshoot/server.py
index e320ae2..b491578 100755
--- a/framework/src/setroubleshoot/server.py
+++ b/framework/src/setroubleshoot/server.py
@@ -698,8 +698,18 @@ def goodbye(database):
     audit2why.finish()
 
 def RunFaultServer(timeout=10):
-    # FIXME
-    audit2why.init()
+
+    signal.alarm(timeout)
+    while True:
+        try:
+            audit2why.init()
+            signal.alarm(0)
+            break
+        except ValueError as e:
+            if "Device or resource busy" in str(e):
+                continue
+            raise e
+
     global host_database, analysis_queue, email_recipients
 
     signal.signal(signal.SIGHUP, sighandler)

Comment 14 errata-xmlrpc 2019-08-06 13:00:39 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-2019:2168