Bug 2221251 - Redundant line in mozilla.if causes problems compiling non-standard modules
Summary: Redundant line in mozilla.if causes problems compiling non-standard modules
Keywords:
Status: VERIFIED
Alias: None
Deadline: 2023-08-08
Product: Red Hat Enterprise Linux 9
Classification: Red Hat
Component: selinux-policy
Version: 9.2
Hardware: All
OS: Linux
low
medium
Target Milestone: rc
: ---
Assignee: Nikola Knazekova
QA Contact: Milos Malik
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2023-07-07 16:30 UTC by Roger Sewell
Modified: 2023-08-16 07:46 UTC (History)
3 users (show)

Fixed In Version: selinux-policy-38.1.20-1.el9
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2023-08-07 11:18:34 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker RHELPLAN-161799 0 None None None 2023-07-07 16:32:54 UTC

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


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