Blame SOURCES/0105-selinux-fix-SEGV-during-switch-root-if-SELinux-polic.patch

17b0f1
From 3a82f8be03b07b84fa470c6e42cd87865aeaf701 Mon Sep 17 00:00:00 2001
17b0f1
From: Will Woods <wwoods@redhat.com>
17b0f1
Date: Fri, 13 Mar 2015 17:24:46 -0400
17b0f1
Subject: [PATCH] selinux: fix SEGV during switch-root if SELinux policy loaded
17b0f1
17b0f1
If you've got SELinux policy loaded, label_hnd is your labeling handle.
17b0f1
When systemd is shutting down, we free that handle via mac_selinux_finish().
17b0f1
17b0f1
But: switch_root() calls mkdir_p_label(), which tries to look up a label
17b0f1
using that freed handle, and so we get a bunch of garbage and eventually
17b0f1
SEGV in libselinux.
17b0f1
17b0f1
(This doesn't happen in the switch-root from initramfs to real root because
17b0f1
there's no SELinux policy loaded in initramfs, so label_hnd is NULL and we
17b0f1
never attempt any lookups.)
17b0f1
17b0f1
So: make sure that mac_selinux_finish() actually sets label_hnd to NULL, so
17b0f1
nobody tries to use it after it becomes invalid.
17b0f1
17b0f1
https://bugzilla.redhat.com/show_bug.cgi?id=1185604
17b0f1
(cherry picked from commit f5ce2b49585a14cefb6d02f61c8dcdf7628a8605)
17b0f1
---
17b0f1
 src/shared/selinux-util.c | 1 +
17b0f1
 1 file changed, 1 insertion(+)
17b0f1
17b0f1
diff --git a/src/shared/selinux-util.c b/src/shared/selinux-util.c
17b0f1
index a2233e0cfb..a46ddf8498 100644
17b0f1
--- a/src/shared/selinux-util.c
17b0f1
+++ b/src/shared/selinux-util.c
17b0f1
@@ -117,6 +117,7 @@ void mac_selinux_finish(void) {
17b0f1
                 return;
17b0f1
 
17b0f1
         selabel_close(label_hnd);
17b0f1
+        label_hnd = NULL;
17b0f1
 #endif
17b0f1
 }
17b0f1