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.

Bug 2012145

Summary: Make selinux config parser more robust
Product: Red Hat Enterprise Linux 8 Reporter: Thorsten Scherf <tscherf>
Component: libselinuxAssignee: Vit Mojzis <vmojzis>
Status: CLOSED ERRATA QA Contact: Amith <apeetham>
Severity: low Docs Contact:
Priority: low    
Version: 8.4CC: dwalsh, lvrabec, mmalik, plautrba, ssekidde, vmojzis
Target Milestone: rcKeywords: Triaged
Target Release: ---Flags: pm-rhel: mirror+
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: libselinux-2.9-6.el8 Doc Type: No Doc Update
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-11-08 10:54:52 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 Thorsten Scherf 2021-10-08 12:15:27 UTC
Description of problem:
Any typo in /etc/selinux/config will create issues during package installation when the config can't be parsed as expected.

E.g., "SELINUXTYPE= targeted" (note the space after '=') will result in the following yum error:

RPM: error: selabel_open (/etc/selinux/ targeted/contexts/files/files_contexts) No such file or directory
RPM: error: Plugin selinux: hook tsm_pre failed
Error: Could not run transaction

The same issue occurs when you put some invalid configuration values into /etc/selinux/config:

E.g.; "SELINUXTYPE=disabled" (valid configuration values would be "targeted", "minimum", or "mls".

Version-Release number of selected component (if applicable):
RHEL-8.4 and earlier releases

How reproducible:


Steps to Reproduce:
1.
2.
3.

Actual results:
yum package installation fails.

Expected results:
A configuration error in /etc/selinux/config show not lead to failed package installations.


Additional info:

Comment 1 Petr Lautrbach 2021-10-12 08:17:28 UTC
(In reply to Thorsten Scherf from comment #0)
> Description of problem:
> Any typo in /etc/selinux/config will create issues during package
> installation when the config can't be parsed as expected.

A typo in /etc/selinux/config means that libselinux is misconfigured and errors during package installation is just a side effect.

 
> E.g., "SELINUXTYPE= targeted" (note the space after '=') will result in the
> following yum error:
> 
> RPM: error: selabel_open (/etc/selinux/
> targeted/contexts/files/files_contexts) No such file or directory
> RPM: error: Plugin selinux: hook tsm_pre failed
> Error: Could not run transaction


Spaces at the end of SELINUXTYPE value is already stripped so I guess spaces on the beginning could be stripped as well.

But there's no way how to make it more robust if there's a different typo of typo like SELINUXTYPE=Xtargeted 
For libselinux it means that the admin wants to use SELinux policy called 'Xtargeted' which is supposed to have files in '/etc/selinux/Xtargeted' and '/var/lib/selinux/Xtargeted'


> The same issue occurs when you put some invalid configuration values into
> /etc/selinux/config:
> 
> E.g.; "SELINUXTYPE=disabled" (valid configuration values would be
> "targeted", "minimum", or "mls".

There's no such thing as a valid value for SELINUXTYPE.
In Red Hat Enterprise Linux we package "targeted", "minimum", or "mls", but there's also upstream policy called "refpolicy" - https://github.com/SELinuxProject/refpolicy and others.
The type of policy is set during build process and users could simply rebuild "targeted" policy and called it "test" and it would be valid.

Comment 2 Petr Lautrbach 2021-10-12 08:22:22 UTC
The simplest way how to check whether SELINUXTYPE is valid is to run `semodule -l`

If there's "No modules", something is wrong:

# semodule -l
No modules.

Users could get also some helpful information from `sestatus`:

# sestatus 
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             test
Current mode:                   permissive
Mode from config file:          permissive
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Memory protection checking:     actual (secure)
Max kernel policy version:      33


As you can see, "Loaded policy name:             test" which is probably not correct.

Comment 3 Petr Lautrbach 2021-10-12 08:25:31 UTC
Looking into '/etc/selinux/config' I see a misleading comment:

# SELINUXTYPE= can take one of these three values:

This is not exactly correct. As I already wrote, these 3 policies are packaged in Red Hat Enterprise Linux but SELINUXTYPE could be anything.

Comment 17 errata-xmlrpc 2022-11-08 10:54:52 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 (libselinux bug fix and enhancement update), 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-2022:7786