Repository navigation
lsm: Use libselinux for process availability - #2445
Conversation
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]>
| /// 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 |
There was a problem hiding this comment.
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}
) = 0This wouldn't really check if selinux is "enabled" or not right as this directory would still exist even if selinux is disabled?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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:
bootc v1.16.12 (bootc-dev/bootc#2445) started linking libselinux via the `selinux` crate, and the `selinux-sys` build script fails when libselinux headers are absent: selinux-sys: Failed to find 'selinux/selinux.h' Arch's official repositories do not ship libselinux, so build the library and headers from the SELinux userspace 3.11 release tarball, pinned by version and verified by sha256 before compiling. Only src/ and include/ are built, so libsepol is not needed. libselinux.so.1 stays in the image because bootc links it dynamically. The insertion moves the pam_wheel sed from Containerfile line 188 to 210; update the reflection that names it so check-invariants resolves the right line. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Danathar <[email protected]>
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