Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Unsupported Software
  • Search

selinux services wrong context [Solved]

This forum covers all Gentoo-related software not officially supported by Gentoo. Ebuilds/software posted here might harm the health and stability of your system(s), and are not supported by Gentoo developers. Bugs/errors caused by ebuilds from overlays.gentoo.org are covered by this forum, too.
Post Reply
Advanced search
4 posts • Page 1 of 1
Author
Message
Cheesyjuggler64
n00b
n00b
Posts: 64
Joined: Thu May 16, 2024 3:17 pm

selinux services wrong context [Solved]

  • Quote

Post by Cheesyjuggler64 » Tue Sep 02, 2025 1:54 am

Currently my system service files are being given the wrong context now I'm quite certain this is because I'am mounting the selinux filesystem within my dinit script after my initramfs has run. I believe that I need to mount the sytem before changing to /sbin/init
this is my current init script

Code: Select all

#!/bin/busybox sh

rescue_shell() (
    echo "$@"
    echo "Something went wrong. Dropping you to a shell."
    /bin/busybox --install -s
    exec /bin/sh
}

busybox mount -t devtmpfs none /dev || rescue_shell "Error"
busybox mount -t proc none /proc || rescue_shell "Error"
busybox mount -t sysfs none /sys || rescue_shell "Error"

cryptsetup luksOpen /dev/nvme0n1p2 cryptroot || rescue_shell "Failed to decrypt"
wait
mount -o rw,noatime,compress-force=zstd:3,ssd,space_cache=v2,subvol=/@ /dev/mapper/cryptroot /mnt/root || rescue_shell "Error root mount failed"
umount /proc
mount -o move /dev /mnt/root/dev
exec switch_root /mnt/root /sbin/init
how and where could I mount the selinuxfs (i.e mount -t selinuxfs selinuxfs /sys/fs/selinux)
Help appreciated
Last edited by Cheesyjuggler64 on Wed Sep 03, 2025 1:48 am, edited 1 time in total.
Top
zen_desu
Guru
Guru
Posts: 501
Joined: Fri Oct 25, 2024 3:14 pm
Location: your area

Re: when should I mount selinuxfs

  • Quote

Post by zen_desu » Tue Sep 02, 2025 2:06 am

Cheesyjuggler64 wrote:Currently my system service files are being given the wrong context now I'm quite certain this is because I'am mounting the selinux filesystem within my dinit script after my initramfs has run. I believe that I need to mount the sytem before changing to /sbin/init
this is my current init script

Code: Select all

#!/bin/busybox sh

rescue_shell() (
    echo "$@"
    echo "Something went wrong. Dropping you to a shell."
    /bin/busybox --install -s
    exec /bin/sh
}

busybox mount -t devtmpfs none /dev || rescue_shell "Error"
busybox mount -t proc none /proc || rescue_shell "Error"
busybox mount -t sysfs none /sys || rescue_shell "Error"

cryptsetup luksOpen /dev/nvme0n1p2 cryptroot || rescue_shell "Failed to decrypt"
wait
mount -o rw,noatime,compress-force=zstd:3,ssd,space_cache=v2,subvol=/@ /dev/mapper/cryptroot /mnt/root || rescue_shell "Error root mount failed"
umount /proc
mount -o move /dev /mnt/root/dev
exec switch_root /mnt/root /sbin/init
how and where could I mount the selinuxfs (i.e mount -t selinuxfs selinuxfs /sys/fs/selinux)
Help appreciated
I don't think selinux stuff is typically handled within the initramfs because it won't be able to reasonably load a policy, and the initramfs itself won't have any selinux contexts.
µgRD dev
Wiki writer
Top
Cheesyjuggler64
n00b
n00b
Posts: 64
Joined: Thu May 16, 2024 3:17 pm

  • Quote

Post by Cheesyjuggler64 » Tue Sep 02, 2025 2:09 pm

But how does the init recieve the right context than because until that file system is mounted I don't think the selinux is enabled, if I boot without mounting it it comes up as disabled, so how then would the init system recive the right context if it can't properly communcate?, after further research its only used to communcate with the userspace so it should'nt be needed why then are all my services being spaawned under kernel_t instead of init_t domain, I've changed the context of the init (/sbin/dinit) to init_exec_t so when its loaded by the kernel it should transition into the init_t domain but its not?

help appreciated
Top
Cheesyjuggler64
n00b
n00b
Posts: 64
Joined: Thu May 16, 2024 3:17 pm

  • Quote

Post by Cheesyjuggler64 » Wed Sep 03, 2025 1:46 am

Okay so from more reading the selinuxfs is used to communicate with the userspace, what I didn't realise was that the sepolicy needs to be loaded by the initramfs in order for the init and the rest of the services to be loaded, from reading the sourcecode for dracut and its selinux module
https://github.com/dracutdevs/dracut/b ... policy.sh
specifically amending this to my initramfs init was all it needed,

Code: Select all

mount -o bind /sys "$NEWROOT"/sys
out=$(LANG=C chroot "$NEWROOT" /sbin/load_policy -i 2>&1)
ret=$?
echo "$out"
now they are recieveing the correct context, i will amend the title to solved
Top
Post Reply

4 posts • Page 1 of 1

Return to “Unsupported Software”

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