Skip to contentSkip to conversation

boot failure due to ambiguous SELinux config

DISCUSSION Laurent Bigonville 3 participants 4 messages Jun 9, 2017 SELinux security module

lore
Share & tools
lore
#0 lore raw

Hello,

I just got the following bugreport in debian that I've been able to reproduce myself:

When booting with a kernel cmdline 'security=selinux' and a /etc/selinux/config setting 'SELINUX=disabled', dbus fails to start and thereby systemd-logind and the system is unusable:

Jun 08 16:23:43 server02 systemd[1]: Started D-Bus System Message Bus.
Jun 08 16:23:43 server02 dbus-daemon[703]: Failed to set up security
class mapping (selinux_set_mapping():Invalid argument).
Jun 08 16:24:08 server02 systemd[1]: dbus.service: Main process
exited, code=exited, status=1/FAILURE
Jun 08 16:24:08 server02 systemd[1]: dbus.service: Unit entered failed state.
Jun 08 16:24:08 server02 systemd[1]: dbus.service: Failed with result

'exit-code'.

When accessing the system using a debug shell, I can see that the selinuxfs is mounted and sestatus is telling me that selinux is enabled. I can manually unmount the selinuxfs and then sestatus is telling me that selinux is disabled on the system.

Looking quickly at the code, the selinux_init_load_policy() function (which is used in systemd) is supposed to unmount the selinuxfs itself if the SELINUX parameter is set to disabled in /etc/selinux/config file. I'm not too sure why it's not happening or maybe something else is remounting it? I don't think anything else on the system is trying to load the policy though.

An idea?

Laurent Bigonville

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=864479

#1 lore raw
Quoted 36 lines · Laurent Bigonville

Hello,

I just got the following bugreport in debian that I've been able to reproduce myself:

When booting with a kernel cmdline 'security=selinux' and a /etc/selinux/config setting 'SELINUX=disabled', dbus fails to start and thereby systemd-logind and the system is unusable:

Jun 08 16:23:43 server02 systemd[1]: Started D-Bus System Message
Bus.
Jun 08 16:23:43 server02 dbus-daemon[703]: Failed to set up security
class mapping (selinux_set_mapping():Invalid argument).
Jun 08 16:24:08 server02 systemd[1]: dbus.service: Main process
exited, code=exited, status=1/FAILURE
Jun 08 16:24:08 server02 systemd[1]: dbus.service: Unit entered
failed state.
Jun 08 16:24:08 server02 systemd[1]: dbus.service: Failed with result

'exit-code'.

When accessing the system using a debug shell, I can see that the selinuxfs is mounted and sestatus is telling me that selinux is enabled.
I can manually unmount the selinuxfs and then sestatus is telling me that selinux is disabled on the system.

Looking quickly at the code, the selinux_init_load_policy() function (which is used in systemd) is supposed to unmount the selinuxfs itself
if the SELINUX parameter is set to disabled in /etc/selinux/config file.
I'm not too sure why it's not happening or maybe something else is remounting it? I don't think anything else on the system is trying to
load the policy though.

Quoted 5 lines

An idea?

Laurent Bigonville

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=864479

Kernel version and config, particularly the CONFIG_SECURITY_SELINUX ones? And are you using any other SELinux-related kernel command line options (e.g. enforcing=, selinux=)?

#2 lore raw

2017-06-09 14:45 GMT+02:00 Stephen Smalley <[email protected]>:

Quoted 3 lines

Kernel version and config, particularly the CONFIG_SECURITY_SELINUX ones? And are you using any other SELinux-related kernel command line options (e.g. enforcing=, selinux=)?

standard Debian sid kernel: Linux server02 4.9.0-3-amd64 #1 SMP Debian 4.9.30-1 (2017-06-04) x86_64 GNU/Linux

$ grep -i selinux /boot/config-4.9.0-3-amd64
CONFIG_SECURITY_SELINUX=y
# CONFIG_SECURITY_SELINUX_BOOTPARAM is not set
# CONFIG_SECURITY_SELINUX_DISABLE is not set
CONFIG_SECURITY_SELINUX_DEVELOP=y
CONFIG_SECURITY_SELINUX_AVC_STATS=y
CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE=0
# CONFIG_DEFAULT_SECURITY_SELINUX is not set
$ cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-4.9.0-3-amd64
root=UUID=1e528afb-83e1-489e-b2f7-1ad1d73d145c ro security=selinux
nomodeset elevator=noop
#3 lore raw
Quoted 19 lines · Christian Göttsche

2017-06-09 14:45 GMT+02:00 Stephen Smalley <[email protected]>:

Quoted 4 lines

Kernel version and config, particularly the CONFIG_SECURITY_SELINUX ones?  And are you using any other SELinux-related kernel command line
options (e.g. enforcing=, selinux=)?

standard Debian sid kernel: Linux server02 4.9.0-3-amd64 #1 SMP Debian
4.9.30-1 (2017-06-04) x86_64 GNU/Linux

$ grep -i selinux /boot/config-4.9.0-3-amd64
CONFIG_SECURITY_SELINUX=y
# CONFIG_SECURITY_SELINUX_BOOTPARAM is not set
# CONFIG_SECURITY_SELINUX_DISABLE is not set
CONFIG_SECURITY_SELINUX_DEVELOP=y
CONFIG_SECURITY_SELINUX_AVC_STATS=y
CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE=0
# CONFIG_DEFAULT_SECURITY_SELINUX is not set
Quoted 4 lines
$ cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-4.9.0-3-amd64
root=UUID=1e528afb-83e1-489e-b2f7-1ad1d73d145c ro security=selinux
nomodeset elevator=noop

Thanks, that makes it clear. On the one hand, this is a case of misconfiguration, and on the other, it is a bug/regression in libselinux.

Your kernel configuration says "Enable SELinux, and don't allow disabling it at boot via selinux=0 nor from userspace via /sys/fs/selinux/disable (the latter is what is used for /etc/selinux/config SELINUX=disabled)." Your userspace configuration says "Disable SELinux from userspace via /sys/fs/selinux/disable". You really shouldn't use that set of configurations together.

That said, libselinux could handle this situation more gracefully (and in fact, used to do so, so this is also a regression). libselinux selinux_init_load_policy() tries to honor your /etc/selinux/config SELINUX=disabled setting and tries to write to /sys/fs/selinux/disable via security_disable(). This fails since you disabled that in your kernel configuration. So selinux_init_load_policy() tries to fall back to just not loading policy (and setting SELinux to permissive if not already, in case a policy has already been loaded earlier, e.g. in the case of a systemd switch-root from a SELinux enabled to a SELinux disabled environment).

This used to be sufficient, since is_selinux_enabled() used to also test whether a policy has been loaded and treat that as disabled. However, we reduced is_selinux_enabled() to only testing for a selinuxfs mount in commit 685f4aeeadc0b60f3770404d4f149610d656e3c8 since the no-policy-loaded test was a relic of the time before there was runtime disable support and the no-policy-loaded test was creating deadlock when using nvidia libGL,
https://bugzilla.redhat.com/show_bug.cgi?id=1195074

So selinux_init_load_policy() really ought to unmount selinuxfs after setting SELinux permissive in this case so that is_selinux_enabled() will still return disabled. Then dbus and the rest of userspace will handle things properly.