Skip to content

lsm: Use libselinux for process availability - #2445

Merged
Johan-Liebert1 merged 1 commit into
bootc-dev:mainfrom
cgwalters:fix-selinux-enabled
Sep 9, 2026
Merged

Johan-Liebert1 merged 1 commit into
bootc-dev:mainfrom
cgwalters:fix-selinux-enabled

Conversation

@cgwalters

Copy link
Copy Markdown
Collaborator

Closes: #2444

Basically us trying to use libselinux more to lookup the unlabeled type breaks in the osbuild scenario where it mounts /sys/fs/selinux readonly, which libselinux treats the same as not existing.

Assisted-by: https://github.com/cgwalters/cgwalters#llms

Closes: bootc-dev#2444

Basically us trying to use libselinux more to lookup the
unlabeled type breaks in the osbuild scenario where it mounts /sys/fs/selinux
readonly, which libselinux treats the same as not existing.

Assisted-by: https://github.com/cgwalters/cgwalters#llms
Signed-off-by: Colin Walters <[email protected]>
@github-actions github-actions Bot added the area/install Issues related to `bootc install` label Sep 8, 2026
@bootc-bot
bootc-bot Bot requested a review from jeckersb September 8, 2026 20:29
Comment thread crates/lib/src/lsm.rs
/// libselinux caches this state process-wide, so mounting selinuxfs requires a
/// re-exec before this result can change.
pub(crate) fn selinux_enabled() -> bool {
selinux::kernel_support() != selinux::KernelSupport::Unsupported

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to do similar operation here as we do in host_selinux_enabled. I was just testing around on how the selinux module checks for support and it just stats

statfs(
    "/sys/fs/selinux", 
    {f_type=SELINUX_MAGIC, f_bsize=4096, f_blocks=0, f_bfree=0, f_bavail=0, f_files=0, f_ffree=0, f_fsid={val=[0x16, 0]},
    f_namelen=255, f_frsize=4096, f_flags=ST_VALID| ST_NOSUID|ST_NOEXEC|ST_RELATIME}
) = 0

This wouldn't really check if selinux is "enabled" or not right as this directory would still exist even if selinux is disabled?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, if SELinux is e.g. compiled into the Linux kernel but the system is booted with selinux=0, then /sys/fs/selinux which is an instance of selinuxfs doesn't exist at all. You can see this in e.g. bcvk ephemeral run-ssh quay.io/centos-bootc/centos-bootc:stream10

[root@localhost ~]# cat /proc/cmdline 
systemd.journald.storage=volatile selinux=0
[root@localhost ~]# stat /sys/fs/selinux
stat: cannot statx '/sys/fs/selinux': No such file or directory

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, yeah, that's correct. I had updated /etc/selinux/config to disable but didn't read the note

# NOTE: In earlier Fedora kernel builds, SELINUX=disabled would also                                                                                                                           
# fully disable SELinux during boot. If you need a system with SELinux                                                                                                                         
# fully disabled instead of SELinux running with no policy loaded, you                                                                                                                         
# need to pass selinux=0 to the kernel command line. You can use grubby                                                                                                                        
# to persistently set the bootloader to boot with selinux=0: 

@Johan-Liebert1
Johan-Liebert1 merged commit 31e21e5 into bootc-dev:main Sep 9, 2026
56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/install Issues related to `bootc install`

Projects

None yet

Development

Successfully merging this pull request may close these issues.

install: Handle osbuild making selinuxfs read-only

2 participants