Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Networking & Security
  • Search

SELinux: Unable to switch to permissive mode

Having problems getting connected to the internet or running a server? Wondering about securing your box? Ask here.
Post Reply
Advanced search
18 posts • Page 1 of 1
Author
Message
vyedmic
n00b
n00b
Posts: 51
Joined: Thu Dec 02, 2010 3:39 pm

SELinux: Unable to switch to permissive mode

  • Quote

Post by vyedmic » Mon Dec 16, 2024 1:50 pm

Hello,

I have followed the SELinux installation guide and have now multiple times selected SELinux profile and then de-selected it, rebuilt world and depcleaned all selinux remnants but I always hit this same problem. It does not matter whether SELINUX=permissive is set or whether enforcing=0 is passed to kernel. This error always stops init from running.

Code: Select all

SELinux: Unable to switch to permissive mode: Invalid argument
https://paste.pics/SIYEG
Top
sMueggli
l33t
l33t
Posts: 627
Joined: Sat Sep 03, 2022 9:22 am

  • Quote

Post by sMueggli » Mon Dec 16, 2024 3:26 pm

How or where did you set it?

Does the kernel boot if you pass (ad-hoc) "selinux=0" to the kernel parameters?
Top
vyedmic
n00b
n00b
Posts: 51
Joined: Thu Dec 02, 2010 3:39 pm

  • Quote

Post by vyedmic » Mon Dec 16, 2024 3:27 pm

Yes, kernel boots without lsm=selinux

I set it in /etc/selinux/config and I also tried passing enforcing=0 to kernel
Top
sMueggli
l33t
l33t
Posts: 627
Joined: Sat Sep 03, 2022 9:22 am

  • Quote

Post by sMueggli » Mon Dec 16, 2024 3:45 pm

Can you please share your complete /etc/selinux/config?

And also the kernel parameters, that you pass to the kernel?
Top
vyedmic
n00b
n00b
Posts: 51
Joined: Thu Dec 02, 2010 3:39 pm

  • Quote

Post by vyedmic » Mon Dec 16, 2024 3:59 pm

Kernel parameters

Code: Select all

root=PARTUUID=my-root-part-uuid ro lsm=selinux
/etc/selinux/config is standard, unchanged from the install.

Code: Select all

# This file controls the state of SELinux on the system on boot.

# SELINUX can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - No SELinux policy is loaded.
SELINUX=permissive

# SELINUXTYPE can take one of these four values:
#       targeted - Only targeted network daemons are protected.
#       strict   - Full SELinux protection.
#       mls      - Full SELinux protection with Multi-Level Security
#       mcs      - Full SELinux protection with Multi-Category Security 
#                  (mls, but only one sensitivity level)
SELINUXTYPE=strict
I am at the point of SELinux installation guide where I am supposed to reboot to label my system.
Top
nicop
Apprentice
Apprentice
Posts: 156
Joined: Thu Apr 10, 2014 11:54 am

  • Quote

Post by nicop » Tue Dec 17, 2024 9:04 am

Did you set CONFIG_SECURITY_SELINUX_BOOTPARAM=y ?
Top
vyedmic
n00b
n00b
Posts: 51
Joined: Thu Dec 02, 2010 3:39 pm

  • Quote

Post by vyedmic » Tue Dec 17, 2024 11:10 am

Yes I did.

Since I am in such an early stage I am considering nuking the install and start again.

Unless it would be useful to investigate further?
Top
nicop
Apprentice
Apprentice
Posts: 156
Joined: Thu Apr 10, 2014 11:54 am

  • Quote

Post by nicop » Tue Dec 17, 2024 2:10 pm

I also see 'unlabeled_t', something has to be solved.
Top
Hu
Administrator
Administrator
Posts: 24403
Joined: Tue Mar 06, 2007 5:38 am

  • Quote

Post by Hu » Tue Dec 17, 2024 2:53 pm

Starting over is rarely helpful. If you do not understand how you got into the bad situation this time, how will you avoid doing it wrong again next time?
Top
sMueggli
l33t
l33t
Posts: 627
Joined: Sat Sep 03, 2022 9:22 am

  • Quote

Post by sMueggli » Tue Dec 17, 2024 4:32 pm

Does adding "lsm.debug" to the kernel command line show more output?

Did you install from scratch or did you convert an existing installation?
Top
vyedmic
n00b
n00b
Posts: 51
Joined: Thu Dec 02, 2010 3:39 pm

  • Quote

Post by vyedmic » Tue Dec 17, 2024 8:27 pm

Hu wrote:Starting over is rarely helpful. If you do not understand how you got into the bad situation this time, how will you avoid doing it wrong again next time?
I think I know how I got into this situation. It is an edge case. I have labelled my system directories using file_contexts.local by being overzealous with tab. I didn't realise I need selinux-dbus to get the file_contexts as I don't want dbus on my system. Should it still prevent me from booting even after switching to non-selinux profile, depcleaning and manually deleting all selinux remnants?

I had hoped someone has encountered something similar.

Can I nuke it and be a good person and install selinux-dbus and see how far I can get before inevitably breaking it again?
Top
vyedmic
n00b
n00b
Posts: 51
Joined: Thu Dec 02, 2010 3:39 pm

  • Quote

Post by vyedmic » Sat Dec 21, 2024 10:20 am

Formatted /, followed handbook up until I booted in. Installed only app-misc/screen and then followed SELinux Installation guide. I am at exactly the same spot. Only thing that did not change is the kernel.

Did I make a mistake by using H/SElinux stage3?

lsm.debug does not add anything

Can I dump kernel config here or is there a preferred way?
Top
grknight
Retired Dev
Retired Dev
Posts: 2565
Joined: Fri Feb 20, 2015 9:36 pm

  • Quote

Post by grknight » Sat Dec 21, 2024 2:02 pm

vyedmic wrote:Formatted /, followed handbook up until I booted in. Installed only app-misc/screen and then followed SELinux Installation guide. I am at exactly the same spot. Only thing that did not change is the kernel.
Do you mean https://wiki.gentoo.org/wiki/SELinux/Installation ? If so, this guide is for an existing install that did not include an SELinux stage3 originally. The stage3 includes all of those listed steps.
From that link:

Code: Select all

This document assumes the reader starts with an existing Gentoo Linux system which needs to be converted to Gentoo with SELinux. It is possible to make the right decisions during a Gentoo installation to immediately start with an SELinux system. However, this article is focusing on a conversion of an existing system as that is the most common approach.
Top
vyedmic
n00b
n00b
Posts: 51
Joined: Thu Dec 02, 2010 3:39 pm

  • Quote

Post by vyedmic » Sat Dec 21, 2024 3:05 pm

Thanks. I'll try again.
Top
vyedmic
n00b
n00b
Posts: 51
Joined: Thu Dec 02, 2010 3:39 pm

  • Quote

Post by vyedmic » Sun Dec 22, 2024 9:51 pm

I formatted again and followed the guide to the letter using Hardened stage 3 and then converting it to SELinux. I get exactly the same result as in the screenshot in the first post. So it does not seem to be anything I did wrong after all...

Code: Select all

SELinux: Unable to switch to permissive mode: Invalid argument
I tried following the below from https://wiki.gentoo.org/wiki/SELinux/Installation using the H/SELinux stage 3

Code: Select all

SELinux stage3 tarballs are also available and supported - this is significantly easier than performing the steps below. The tarballs can be simply unpacked onto a target system, relabel the entire system, add the initial user to the administration SELinux user and reboot.
This is the result when I try relabelling as the above suggests

Code: Select all

localhost / # rlpkg -a
Relabeling filesystem types: btrfs encfs ext2 ext3 ext4 ext4dev f2fs gfs gfs2 gpfs jffs2 jfs lustre xfs zfs
Running /sbin/setfiles /etc/selinux/strict/contexts/files/file_contexts /
/etc/selinux/strict/contexts/files/file_contexts: No such file or directory
Scanning for shared libraries with text relocations...
/usr/lib/python3.12/subprocess.py:1016: RuntimeWarning: line buffering (buffering=1) isn't supported in binary mode, the default buffer size will be used
  self.stdout = io.open(c2pread, 'rb', bufsize)
0 libraries with text relocations, 0 not relabeled.
Scanning for PIE binaries with text relocations...
0 binaries with text relocations detected.

localhost / # ls -Z /etc/portage/make.conf 
? /etc/portage/make.conf

localhost / # semanage login -a -s staff_u admin
libsemanage.semanage_read_policydb: Could not open kernel policy /var/lib/selinux/strict/active/policy.kern for reading. (No such file or directory).
FileNotFoundError: No such file or directory


I am really trying to decipher these guides but they are proving to be full of catch 22s. How am I supposed to relabel a system when no file_contexts exists? Is it even possible to assign a user to staff_u while being booted into a Live CD kernel?
Top
vyedmic
n00b
n00b
Posts: 51
Joined: Thu Dec 02, 2010 3:39 pm

  • Quote

Post by vyedmic » Sun Dec 29, 2024 5:17 pm

So finally success with new-from-scratch kernel, H/SELinux stage3 onto which selinux-dbus and selinux-policykit need to be emerged first before attempting to relabel and adding user to staff_u.
Top
nicop
Apprentice
Apprentice
Posts: 156
Joined: Thu Apr 10, 2014 11:54 am

  • Quote

Post by nicop » Mon Dec 30, 2024 7:56 am

Too bad that it affects the installation media ...
I had encountered the same bug recently : https://bugs.gentoo.org/941785

authlogin.pp (sec-policy/selinux-base-policy) does not install without selinux-dbus but it doesn’t interrupt emerge.
Top
salam
Apprentice
Apprentice
Posts: 231
Joined: Thu Sep 29, 2005 8:52 am

  • Quote

Post by salam » Sat Jan 11, 2025 11:12 am

Had the same mess with authlogin, I decided to get rid of that manually

Code: Select all

# cat /etc/portage/patches/sec-policy/selinux-base-policy/make-authlogin-systemd-optional.patch
--- a/refpolicy/policy/modules/system/authlogin.te      2024-09-16 19:52:00.000000000 +0200
+++ b/refpolicy/policy/modules/system/authlogin2.te     2024-10-02 09:37:34.511501889 +0200
@@ -142,7 +142,10 @@

 auth_read_shadow_history(chkpwd_t)
 auth_use_nsswitch(chkpwd_t)
-auth_use_pam_systemd(chkpwd_t)
+
+ifdef(`init_systemd',`
+       auth_use_pam_systemd(chkpwd_t)
+')

 logging_send_audit_msgs(chkpwd_t)
 logging_send_syslog_msg(chkpwd_t)
Top
Post Reply

18 posts • Page 1 of 1

Return to “Networking & Security”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic