]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Revert "selinux: split up mac_selinux_have() from mac_selinux_use()"
authorGary Tierney <gary.tierney@gmx.com>
Tue, 2 May 2017 16:42:19 +0000 (17:42 +0100)
committerGary Tierney <gary.tierney@gmx.com>
Fri, 12 May 2017 13:43:39 +0000 (14:43 +0100)
This reverts commit 6355e75610a8d47fc3ba5ab8bd442172a2cfe574.

The previously mentioned commit inadvertently broke a lot of SELinux related
functionality for both unprivileged users and systemd instances running as
MANAGER_USER.  In particular, setting the correct SELinux context after a User=
directive is used would fail to work since we attempt to set the security
context after changing UID.  Additionally, it causes activated socket units to
be mislabeled for systemd --user processes since setsockcreatecon() would never
be called.

Reverting this fixes the issues with labeling outlined above, and reinstates
SELinux access checks on unprivileged user services.

src/basic/selinux-util.c
src/basic/selinux-util.h
src/journal/journald-native.c
src/journal/journald-server.c
src/journal/journald-stream.c
src/journal/journald-syslog.c
src/libsystemd/sd-bus/bus-socket.c
src/shared/condition.c
src/test/test-condition.c
src/test/test-selinux.c

index bc07654668e80da867d068f707c6baa7d2ff9f50..380285d57335ec504bff1930b67e3e9748e76741 100644 (file)
@@ -53,7 +53,7 @@ static struct selabel_handle *label_hnd = NULL;
 #define log_enforcing(...) log_full(security_getenforce() == 1 ? LOG_ERR : LOG_DEBUG, __VA_ARGS__)
 #endif
 
-bool mac_selinux_have(void) {
+bool mac_selinux_use(void) {
 #ifdef HAVE_SELINUX
         if (cached_use < 0)
                 cached_use = is_selinux_enabled() > 0;
@@ -64,16 +64,6 @@ bool mac_selinux_have(void) {
 #endif
 }
 
-bool mac_selinux_use(void) {
-        if (!mac_selinux_have())
-                return false;
-
-        /* Never try to configure SELinux features if we aren't
-         * root */
-
-        return getuid() == 0;
-}
-
 void mac_selinux_retest(void) {
 #ifdef HAVE_SELINUX
         cached_use = -1;
@@ -205,7 +195,7 @@ int mac_selinux_get_create_label_from_exe(const char *exe, char **label) {
         assert(exe);
         assert(label);
 
-        if (!mac_selinux_have())
+        if (!mac_selinux_use())
                 return -EOPNOTSUPP;
 
         r = getcon_raw(&mycon);
@@ -231,7 +221,7 @@ int mac_selinux_get_our_label(char **label) {
         assert(label);
 
 #ifdef HAVE_SELINUX
-        if (!mac_selinux_have())
+        if (!mac_selinux_use())
                 return -EOPNOTSUPP;
 
         r = getcon_raw(label);
@@ -255,7 +245,7 @@ int mac_selinux_get_child_mls_label(int socket_fd, const char *exe, const char *
         assert(exe);
         assert(label);
 
-        if (!mac_selinux_have())
+        if (!mac_selinux_use())
                 return -EOPNOTSUPP;
 
         r = getcon_raw(&mycon);
@@ -310,7 +300,7 @@ char* mac_selinux_free(char *label) {
         if (!label)
                 return NULL;
 
-        if (!mac_selinux_have())
+        if (!mac_selinux_use())
                 return NULL;
 
 
index ce6bc8e44c1eb49d13c75aabf7dc2abdb43420c4..5bf72364b440a8346bff222e5374263a56af4bb9 100644 (file)
@@ -26,7 +26,6 @@
 #include "macro.h"
 
 bool mac_selinux_use(void);
-bool mac_selinux_have(void);
 void mac_selinux_retest(void);
 
 int mac_selinux_init(void);
index c9bf3832c7a73843781af9dbb4f52fa340fb0ad8..74b00ad47ec08d65b371543f441bbbfd4a85dd8c 100644 (file)
@@ -479,7 +479,7 @@ int server_open_native_socket(Server*s) {
                 return log_error_errno(errno, "SO_PASSCRED failed: %m");
 
 #ifdef HAVE_SELINUX
-        if (mac_selinux_have()) {
+        if (mac_selinux_use()) {
                 r = setsockopt(s->native_fd, SOL_SOCKET, SO_PASSSEC, &one, sizeof(one));
                 if (r < 0)
                         log_warning_errno(errno, "SO_PASSSEC failed: %m");
index 667dfa00ff219f20bca593d011ff44a13fc9786e..5dfc9013f5ece2846008c26ca4c102467cdccf22 100644 (file)
@@ -918,7 +918,7 @@ static void dispatch_message_real(
                 }
 
 #ifdef HAVE_SELINUX
-                if (mac_selinux_have()) {
+                if (mac_selinux_use()) {
                         if (label) {
                                 x = alloca(strlen("_SELINUX_CONTEXT=") + label_len + 1);
 
index bc092f3c126fbac55a9f80c09a9c25e733c66d8e..77551dc14b25520f677dcf43bc5ae0fe77c210f3 100644 (file)
@@ -494,7 +494,7 @@ static int stdout_stream_install(Server *s, int fd, StdoutStream **ret) {
         if (r < 0)
                 return log_error_errno(r, "Failed to determine peer credentials: %m");
 
-        if (mac_selinux_have()) {
+        if (mac_selinux_use()) {
                 r = getpeersec(fd, &stream->label);
                 if (r < 0 && r != -EOPNOTSUPP)
                         (void) log_warning_errno(r, "Failed to determine peer security context: %m");
index 474369039a6ce5501d73d7f2f941c404ea661057..8e034c8fa9cdaf5e9bfd8869d0d95f490ad50cda 100644 (file)
@@ -410,7 +410,7 @@ int server_open_syslog_socket(Server *s) {
                 return log_error_errno(errno, "SO_PASSCRED failed: %m");
 
 #ifdef HAVE_SELINUX
-        if (mac_selinux_have()) {
+        if (mac_selinux_use()) {
                 r = setsockopt(s->syslog_fd, SOL_SOCKET, SO_PASSSEC, &one, sizeof(one));
                 if (r < 0)
                         log_warning_errno(errno, "SO_PASSSEC failed: %m");
index e6ed15eb71d4d97f4c7993db4d601c7abda5ea19..8b25002f0106b3718662b378bbe0723b33245077 100644 (file)
@@ -607,7 +607,7 @@ static void bus_get_peercred(sd_bus *b) {
         b->ucred_valid = getpeercred(b->input_fd, &b->ucred) >= 0;
 
         /* Get the SELinux context of the peer */
-        if (mac_selinux_have()) {
+        if (mac_selinux_use()) {
                 r = getpeersec(b->input_fd, &b->label);
                 if (r < 0 && r != -EOPNOTSUPP)
                         log_debug_errno(r, "Failed to determine peer security context: %m");
index 0b77d2c22dc3ce8f16d0f4fa63f52880e5fdc88d..aec7ebb9cfef8f35f09c7d7b183f97c822d235b7 100644 (file)
@@ -235,7 +235,7 @@ static int condition_test_security(Condition *c) {
         assert(c->type == CONDITION_SECURITY);
 
         if (streq(c->parameter, "selinux"))
-                return mac_selinux_have();
+                return mac_selinux_use();
         if (streq(c->parameter, "smack"))
                 return mac_smack_use();
         if (streq(c->parameter, "apparmor"))
index dd985f58634fac1691bf7a25307e2927219ffba7..3bb7f9223041660407a74d284e3f708ac543acdc 100644 (file)
@@ -243,7 +243,7 @@ static void test_condition_test_security(void) {
 
         condition = condition_new(CONDITION_SECURITY, "selinux", false, true);
         assert_se(condition);
-        assert_se(condition_test(condition) != mac_selinux_have());
+        assert_se(condition_test(condition) != mac_selinux_use());
         condition_free(condition);
 
         condition = condition_new(CONDITION_SECURITY, "ima", false, false);
index b676c259134c36926e1b265e8e108f4a5345ad99..190736aa47b26633ad35f4cc8ec687216b96f195 100644 (file)
@@ -35,16 +35,16 @@ static void test_testing(void) {
         b = mac_selinux_use();
         log_info("mac_selinux_use → %s", yes_no(b));
 
-        b = mac_selinux_have();
-        log_info("mac_selinux_have → %s", yes_no(b));
+        b = mac_selinux_use();
+        log_info("mac_selinux_use → %s", yes_no(b));
 
         mac_selinux_retest();
 
         b = mac_selinux_use();
         log_info("mac_selinux_use → %s", yes_no(b));
 
-        b = mac_selinux_have();
-        log_info("mac_selinux_have → %s", yes_no(b));
+        b = mac_selinux_use();
+        log_info("mac_selinux_use → %s", yes_no(b));
 }
 
 static void test_loading(void) {