richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
21255d
From c67be1c7d69a0662ab85720aa0209110c39479f9 Mon Sep 17 00:00:00 2001
21255d
From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= <cgzones@googlemail.com>
21255d
Date: Wed, 27 Nov 2019 19:43:47 +0100
21255d
Subject: [PATCH] core: reload SELinux label cache on daemon-reload
21255d
21255d
Reloading the SELinux label cache here enables a light-wight follow-up of a SELinux policy change, e.g. adding a label for a RuntimeDirectory.
21255d
21255d
Closes: #13363
21255d
(cherry picked from commit a9dfac21ec850eb5dcaf1ae9ef729389e4c12802)
21255d
21255d
Resolves: #1888912
21255d
---
21255d
 src/basic/selinux-util.c | 20 ++++++++++++++++++++
21255d
 src/basic/selinux-util.h |  1 +
21255d
 src/core/main.c          |  2 ++
21255d
 3 files changed, 23 insertions(+)
21255d
21255d
diff --git a/src/basic/selinux-util.c b/src/basic/selinux-util.c
21255d
index e15bd7e1fa..f69d88eb1e 100644
21255d
--- a/src/basic/selinux-util.c
21255d
+++ b/src/basic/selinux-util.c
21255d
@@ -105,6 +105,26 @@ void mac_selinux_finish(void) {
21255d
 #endif
21255d
 }
21255d
 
21255d
+void mac_selinux_reload(void) {
21255d
+
21255d
+#if HAVE_SELINUX
21255d
+        struct selabel_handle *backup_label_hnd;
21255d
+
21255d
+        if (!label_hnd)
21255d
+                return;
21255d
+
21255d
+        backup_label_hnd = TAKE_PTR(label_hnd);
21255d
+
21255d
+        /* try to initialize new handle
21255d
+         *    on success close backup
21255d
+         *    on failure restore backup */
21255d
+        if (mac_selinux_init() == 0)
21255d
+                selabel_close(backup_label_hnd);
21255d
+        else
21255d
+                label_hnd = backup_label_hnd;
21255d
+#endif
21255d
+}
21255d
+
21255d
 int mac_selinux_fix(const char *path, LabelFixFlags flags) {
21255d
 
21255d
 #if HAVE_SELINUX
21255d
diff --git a/src/basic/selinux-util.h b/src/basic/selinux-util.h
21255d
index 08314057fb..abcfabe777 100644
21255d
--- a/src/basic/selinux-util.h
21255d
+++ b/src/basic/selinux-util.h
21255d
@@ -13,6 +13,7 @@ void mac_selinux_retest(void);
21255d
 
21255d
 int mac_selinux_init(void);
21255d
 void mac_selinux_finish(void);
21255d
+void mac_selinux_reload(void);
21255d
 
21255d
 int mac_selinux_fix(const char *path, LabelFixFlags flags);
21255d
 int mac_selinux_apply(const char *path, const char *label);
21255d
diff --git a/src/core/main.c b/src/core/main.c
21255d
index d897155644..d5c41da0c4 100644
21255d
--- a/src/core/main.c
21255d
+++ b/src/core/main.c
21255d
@@ -1682,6 +1682,8 @@ static int invoke_main_loop(
21255d
                         saved_log_level = m->log_level_overridden ? log_get_max_level() : -1;
21255d
                         saved_log_target = m->log_target_overridden ? log_get_target() : _LOG_TARGET_INVALID;
21255d
 
21255d
+                        mac_selinux_reload();
21255d
+
21255d
                         (void) parse_configuration(saved_rlimit_nofile, saved_rlimit_memlock);
21255d
 
21255d
                         set_manager_defaults(m);