Bug 2221251

Summary: Redundant line in mozilla.if causes problems compiling non-standard modules
Product: Red Hat Enterprise Linux 9 Reporter: Roger Sewell <roger.sewell>
Component: selinux-policyAssignee: Nobody <nobody>
Status: CLOSED ERRATA QA Contact: Milos Malik <mmalik>
Severity: medium Docs Contact:
Priority: low    
Version: 9.2CC: lvrabec, mmalik, zpytela
Target Milestone: rcKeywords: Reopened, Triaged
Target Release: ---Flags: pm-rhel: mirror+
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: selinux-policy-38.1.20-1.el9 Doc Type: Bug Fix
Doc Text:
Cause: Nsplugin module was removed from SELinux policy, but interface nsplugin_role was still included in mozilla_role interface, which caused syntax error, when using this interface. Consequence: Redundant line in mozilla.if causes problems when compiling additional selinux modules Fix: Remove nsplugin_role from mozilla.if Result: No more syntax errors when compiling selinux modules
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-11-07 08:52:30 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:
Deadline: 2023-08-08   

Description Roger Sewell 2023-07-07 16:30:51 UTC
Description of problem: Redundant line in mozilla.if causes problems when compiling additional selinux modules


Version-Release number of selected component (if applicable): 38.1.11-2.el9_2.3

How reproducible: Always


Steps to Reproduce:
1. Install the above version of selinux-policy, selinux-policy-targeted, selinux-policy-doc, and selinux-policy-devel .

2. Write a simple module additional module called say mymodule.te .

3. From the directory containing mymodule.te, which should not contain any wanted subdirectory called tmp, issue the commands
 
\rm -rf tmp
make mymodule.pp


Actual results: Syntax error at line nnnn of tmp/.... at token nsplugin_role


Expected results: Successful compilation


Additional info: I assume that this is because there is no longer a module nsplugin in this current version of selinux. I note also that the line containing nsplugin_role in mozilla.if is optional_policy, and that it compiles fine when the source package is built - but it doesn't when additional modules are compiled using the selinux-devel make system - perhaps this is an additional issue (I'm not sure).

Comment 1 Nikola Knazekova 2023-07-14 13:28:56 UTC
Hi Roger, 

I tried to reproduce the issue but everything works properly:

# rpm -qa selinux-policy*
selinux-policy-38.1.11-2.el9_2.3.noarch
selinux-policy-targeted-38.1.11-2.el9_2.3.noarch
selinux-policy-devel-38.1.11-2.el9_2.3.noarch
selinux-policy-doc-38.1.11-2.el9_2.3.noarch

# sepolicy generate --init /usr/bin/wget
Created the following files:
/root/wget-selinux/wget.te # Type Enforcement file
/root/wget-selinux/wget.if # Interface file
/root/wget-selinux/wget.fc # File Contexts file
/root/wget-selinux/wget_selinux.spec # Spec file
/root/wget-selinux/wget.sh # Setup Script

# rm -rf tmp

# make -f /usr/share/selinux/devel/Makefile wget.pp
Compiling targeted wget module
Creating targeted wget.pp policy package
rm tmp/wget.mod tmp/wget.mod.fc

# semodule -i wget.pp

# semodule -lfull | grep wget
400 wget                  pp

Comment 2 Roger Sewell 2023-07-14 19:10:10 UTC
Nikola,

I'm very sorry - on further investigation I now realise I needed to give you another piece of information, namely the contents of the .te file being compiled. After paring it down to the minimum possible that still shows the problem, the following file (whose contents is now of course pointless) demonstrates the bug:

<unconfmoz.te contains:>

policy_module(unconfmoz, 1.1)

gen_require(`
        role unconfined_r;
        type unconfined_t;
')


mozilla_role(unconfined_r, unconfined_t)

<end of file>

then on doing 

make -f /usr/share/selinux/devel/Makefile unconfmoz.pp

I get

Compiling targeted unconfmoz module
unconfmoz.te:9:ERROR 'syntax error' at token 'nsplugin_role' on line 4246:
	       nsplugin_role(unconfined_r, mozilla_t)
#line 9
/usr/bin/checkmodule:  error(s) encountered while parsing configuration
make: *** [/usr/share/selinux/devel/include/Makefile:157: tmp/unconfmoz.mod] Error 1

If, however, I replace the mozilla module with one with the line containing nsplugin_role removed from mozilla.if then it compiles correctly.

(If it's any consolation, your time has not been totally wasted - I had not realised before how useful the sepolicy generate --init command was - so thank you for the education.)

Thanks, Roger.

Comment 3 Nikola Knazekova 2023-07-18 13:46:42 UTC
Hi Roger, 

you are right with the nsplugin, we will investigate it.  

For the loadable modules is good to use optional policy block:

optional_policy(`
       mozilla_role(unconfined_r, unconfined_t)
')

https://selinuxproject.org/page/PolicyStatements

Comment 4 Roger Sewell 2023-07-18 18:43:38 UTC
Nikola,
Thank you for the further education - appreciated.
Roger.

Comment 5 Nikola Knazekova 2023-08-08 08:54:57 UTC
PR: https://github.com/fedora-selinux/selinux-policy/pull/1821

Comment 16 errata-xmlrpc 2023-11-07 08:52:30 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 (selinux-policy 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-2023:6617