naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
65878a
From 4083e4d76b61bc9eb40583f941412c1ea1a0285b Mon Sep 17 00:00:00 2001
65878a
From: Colin Walters <walters@verbum.org>
65878a
Date: Fri, 21 Feb 2014 03:29:00 +0100
65878a
Subject: [PATCH] selinux: Don't attempt to load policy in initramfs if it
65878a
 doesn't exist
65878a
65878a
Currently on at least Fedora, SELinux policy does not come in the
65878a
initramfs.  systemd will attempt to load *both* in the initramfs and
65878a
in the real root.
65878a
65878a
Now, the selinux_init_load_policy() API has a regular error return
65878a
value, as well as an "enforcing" boolean.  To determine enforcing
65878a
state, it looks for /etc/selinux/config as well as the presence of
65878a
"enforcing=" on the kernel command line.
65878a
65878a
Ordinarily, neither of those exist in the initramfs, so it will return
65878a
"unknown" for enforcing, and systemd will simply ignore the failure to
65878a
load policy.
65878a
---
65878a
 src/core/selinux-setup.c | 7 +++++++
65878a
 1 file changed, 7 insertions(+)
65878a
65878a
diff --git a/src/core/selinux-setup.c b/src/core/selinux-setup.c
65878a
index 7a32ed5..9a5d6b2 100644
65878a
--- a/src/core/selinux-setup.c
65878a
+++ b/src/core/selinux-setup.c
65878a
@@ -58,6 +58,13 @@ int selinux_setup(bool *loaded_policy) {
65878a
        cb.func_log = null_log;
65878a
        selinux_set_callback(SELINUX_CB_LOG, cb);
65878a
 
65878a
+       /* Don't load policy in the initrd if we don't appear to have
65878a
+        * it.  For the real root, we check below if we've already
65878a
+        * loaded policy, and return gracefully.
65878a
+        */
65878a
+       if (in_initrd() && access(selinux_path(), F_OK) < 0)
65878a
+               return 0;
65878a
+
65878a
        /* Already initialized by somebody else? */
65878a
        r = getcon_raw(&con);
65878a
        if (r == 0) {