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 1240788 - setfiles shows an error message when selinux is disabled
Summary: setfiles shows an error message when selinux is disabled
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: policycoreutils
Version: 6.6
Hardware: All
OS: Linux
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Petr Lautrbach
QA Contact: Milos Malik
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2015-07-07 18:19 UTC by João Avelino Bellomo Filho
Modified: 2016-05-10 17:03 UTC (History)
13 users (show)

Fixed In Version: policycoreutils-2.0.83-26.el6
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2016-05-10 17:03:19 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2016:0791 0 normal SHIPPED_LIVE policycoreutils bug fix update 2016-05-10 21:02:22 UTC

Description João Avelino Bellomo Filho 2015-07-07 18:19:57 UTC
Description of problem:


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


How reproducible:


Steps to Reproduce:
1. Disable SELinux:

sed -i "s/^SELINUX=.*/SELINUX=disable/g" /etc/selinux/config 

2. Reboot

3. Check if SELinux is disabled:

# getenforce 
Disabled

4. Execute the follow command line:

 sosreport -vvv --batch --alloptions &> /tmp/sosreport.$(date +%Y%m%d-%H%M%S).log

Actual results:

# sosreport -vvv --batch --alloptions &> /tmp/sosreport.$(date +%Y%m%d-%H%M%S).log
usage:  /sbin/setfiles [-dnpqvW] [-o filename] [-r alt_root_path ] spec_file pathname...
usage:  /sbin/setfiles -c policyfile spec_file
usage:  /sbin/setfiles -s [-dnpqvW] [-o filename ] spec_file


Expected results:

# sosreport -vvv --batch --alloptions &> /tmp/sosreport.$(date +%Y%m%d-%H%M%S).log

Additional info:

It happens because the option '--alloptions' force the 'sosreport' to enable all plugins and the SELinux plugin does not detect that the SELinux is disabled.

As a workaround is possible to avoid the error message enabling all plugins, except the SELinux plugins, for example:

sosreport -vvv --batch --alloptions -k selinux.fixfiles=off -k selinux.list=off &> /tmp/sosreport.$(date +%Y%m%d-%H%M%S).log

Comment 2 João Avelino Bellomo Filho 2015-07-07 18:42:57 UTC
Hi!

There is a typo on step 3:

sed -i "s/^SELINUX=.*/SELINUX=disable/g" /etc/selinux/config 

The correct is:

sed -i "s/^SELINUX=.*/SELINUX=disabled/g" /etc/selinux/config

Sorry!

Comment 3 Bryn M. Reeves 2015-07-16 13:15:17 UTC
> It happens because the option '--alloptions' force the 'sosreport' to enable 
> all plugins and the SELinux plugin does not detect that the SELinux is 
> disabled.

No: --alloptions sets every boolean *plugin option* to True, as it says in the man page:

       -a, --alloptions
              Set all boolean options to True for all enabled plug-ins.

It does not have any effect on plugin enablement; the SELinux plugin (like most) is enabled when its packages list is satisfied:

class SELinux(Plugin, RedHatPlugin):
[...]
    packages = ('libselinux',)

So it'll run on any system with libselinux installed regardless of whether SELinux is active or not.

This is intended as it means that configuration and diagnostic information is captured even when SELinux is disabled or in permissive mode.

The plugin doesn't run setfiles itself; it calls 'fixfiles' when the selinux.fixfiles plugin option is True.

Given that it seems that this is a problem in `fixfiles` when run with SELinux disabled; we could work around this in sos by not calling it when that is the case but I think it would be better to fix it at source: `fixfiles` should exit with an error if SELinux is off rather than continuing to call 'setfiles'.

Comment 4 Daniel Walsh 2015-07-21 13:36:08 UTC
sosreport should check inside fo the SELinux plugin.

Not fixfiles problem.

Comment 5 Daniel Walsh 2015-07-21 13:38:57 UTC
/usr/lib/python3.4/site-packages/sos/plugins/selinux.py should check if SELinux is enabled

python -c "import selinux; print(selinux.is_selinux_enabled())"
1

Comment 6 Bryn M. Reeves 2015-07-21 14:20:07 UTC
How come fixfiles can't just do something like that and exit with a reasonable status or error message?

I know it's a shell script but it's still trivial to check the SELinux status.

[root@bmr-rhel6-vm1 ~]# getenforce 
Disabled
[root@bmr-rhel6-vm1 ~]# fixfiles check
usage:  /sbin/setfiles [-dnpqvW] [-o filename] [-r alt_root_path ] spec_file pathname...
usage:  /sbin/setfiles -c policyfile spec_file
usage:  /sbin/setfiles -s [-dnpqvW] [-o filename ] spec_file

Entirely independently of sos that is a _really_ confusing error; what did I do wrong? And why is setfiles talking to me?

There's nothing to tell me it's just because SELinux is disabled (unless I already know that).

I would like to see something like:

[root@bmr-rhel6-vm1 ~]# getenforce 
Disabled
[root@bmr-rhel6-vm1 ~]# fixfiles check
SELinus is disabled.
[root@bmr-rhel6-vm1 ~]# echo $?
1
[root@bmr-rhel6-vm1 ~]#

Comment 7 Bryn M. Reeves 2015-07-21 14:23:01 UTC
S/Linus/Linux/

Comment 8 Daniel Walsh 2015-07-21 15:03:27 UTC
Ok, I can see that.

Comment 9 Daniel Walsh 2015-07-21 15:04:20 UTC
But sosreport is still going to be doing other SELinux checks which should probably not do.

Comment 10 Bryn M. Reeves 2015-07-21 16:05:55 UTC
Agreed - we've not had other reports of problems so far but I've filed an issue upstream to go through and audit this:

https://github.com/sosreport/sos/issues/605

Comment 11 Petr Lautrbach 2015-07-22 10:07:38 UTC
The fix would be quite easy:

--- /sbin/fixfiles.orig 2015-07-22 11:49:19.733659820 +0200
+++ /sbin/fixfiles      2015-07-22 12:06:32.008337081 +0200
@@ -140,6 +140,11 @@
 # if called with -n will only check file context
 #
 restore () {
+if ! selinuxenabled; then
+       echo $"SELinux is disabled."
+       exit 1
+fi
+
 if [ ! -z "$PREFC" ]; then
     diff_filecontext $*
     exit $?
@@ -192,6 +197,11 @@
 }
 
 relabel() {
+    if ! selinuxenabled; then
+        echo $"SELinux is disabled."
+        exit 1
+    fi
+
     if [ ! -z "$RPMFILES" ]; then
        restore 
     fi

Comment 17 errata-xmlrpc 2016-05-10 17:03:19 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://rhn.redhat.com/errata/RHBA-2016-0791.html


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