daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
65878a
From 96bb682b6fa33faaff5c3db7506e9864fe5c09dc Mon Sep 17 00:00:00 2001
65878a
From: Dan Walsh <dwalsh@redhat.com>
65878a
Date: Thu, 16 Jan 2014 12:59:10 +0100
65878a
Subject: [PATCH] Fix SELinux check for transient units. (#1008864)
65878a
65878a
SELinux does not have a path to check for a snapshot servic creation.
65878a
This ends up giving us a bogus check.
65878a
65878a
On snapshot creation we should check if the remote process type, has the ability to start a service with the type that systemd is running with.
65878a
---
65878a
 src/core/dbus-manager.c   |  6 +++---
65878a
 src/core/selinux-access.c |  9 +++++----
65878a
 src/core/selinux-access.h | 13 +++++++++++++
65878a
 3 files changed, 21 insertions(+), 7 deletions(-)
65878a
65878a
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
65878a
index 8f4d017..7be5d13 100644
65878a
--- a/src/core/dbus-manager.c
65878a
+++ b/src/core/dbus-manager.c
65878a
@@ -1102,7 +1102,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
65878a
                 dbus_bool_t cleanup;
65878a
                 Snapshot *s;
65878a
 
65878a
-                SELINUX_ACCESS_CHECK(connection, message, "start");
65878a
+                SELINUX_RUNTIME_UNIT_ACCESS_CHECK(connection, message, "start");
65878a
 
65878a
                 if (!dbus_message_get_args(
65878a
                                     message,
65878a
@@ -1155,7 +1155,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
65878a
                         return bus_send_error_reply(connection, message, &error, -ENOENT);
65878a
                 }
65878a
 
65878a
-                SELINUX_UNIT_ACCESS_CHECK(u, connection, message, "stop");
65878a
+                SELINUX_RUNTIME_UNIT_ACCESS_CHECK(connection, message, "stop");
65878a
                 snapshot_remove(SNAPSHOT(u));
65878a
 
65878a
                 reply = dbus_message_new_method_return(message);
65878a
@@ -1765,7 +1765,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
65878a
                 if (r < 0)
65878a
                         return bus_send_error_reply(connection, message, &error, r);
65878a
 
65878a
-                SELINUX_UNIT_ACCESS_CHECK(u, connection, message, "start");
65878a
+                SELINUX_RUNTIME_UNIT_ACCESS_CHECK(connection, message, "start");
65878a
 
65878a
                 if (u->load_state != UNIT_NOT_FOUND || set_size(u->dependencies[UNIT_REFERENCED_BY]) > 0) {
65878a
                         dbus_set_error(&error, BUS_ERROR_UNIT_EXISTS, "Unit %s already exists.", name);
65878a
diff --git a/src/core/selinux-access.c b/src/core/selinux-access.c
65878a
index 0a3ee18..5d85b26 100644
65878a
--- a/src/core/selinux-access.c
65878a
+++ b/src/core/selinux-access.c
65878a
@@ -374,8 +374,9 @@ int selinux_access_check(
65878a
                 goto finish;
65878a
         }
65878a
 
65878a
-        if (path) {
65878a
-                tclass = "service";
65878a
+
65878a
+        tclass = "service";
65878a
+        if (path && !strneq(path,"system", strlen("system"))) {
65878a
                 /* get the file context of the unit file */
65878a
                 r = getfilecon(path, &fcon);
65878a
                 if (r < 0) {
65878a
@@ -384,9 +385,9 @@ int selinux_access_check(
65878a
                         log_error("Failed to get security context on %s: %m",path);
65878a
                         goto finish;
65878a
                 }
65878a
-
65878a
         } else {
65878a
-                tclass = "system";
65878a
+                if (path)
65878a
+                        tclass = "system";
65878a
                 r = getcon(&fcon);
65878a
                 if (r < 0) {
65878a
                         dbus_set_error(error, DBUS_ERROR_ACCESS_DENIED, "Failed to get current context.");
65878a
diff --git a/src/core/selinux-access.h b/src/core/selinux-access.h
65878a
index 2d7ac64..92acd69 100644
65878a
--- a/src/core/selinux-access.h
65878a
+++ b/src/core/selinux-access.h
65878a
@@ -36,6 +36,18 @@ int selinux_access_check(DBusConnection *connection, DBusMessage *message, const
65878a
                 DBusConnection *_c = (connection);                      \
65878a
                 DBusMessage *_m = (message);                            \
65878a
                 dbus_error_init(&_error);                               \
65878a
+                _r = selinux_access_check(_c, _m, "system", (permission), &_error); \
65878a
+                if (_r < 0)                                             \
65878a
+                        return bus_send_error_reply(_c, _m, &_error, _r); \
65878a
+        } while (false)
65878a
+
65878a
+#define SELINUX_RUNTIME_UNIT_ACCESS_CHECK(connection, message, permission) \
65878a
+        do {                                                            \
65878a
+                DBusError _error;                                       \
65878a
+                int _r;                                                 \
65878a
+                DBusConnection *_c = (connection);                      \
65878a
+                DBusMessage *_m = (message);                            \
65878a
+                dbus_error_init(&_error);                               \
65878a
                 _r = selinux_access_check(_c, _m, NULL, (permission), &_error); \
65878a
                 if (_r < 0)                                             \
65878a
                         return bus_send_error_reply(_c, _m, &_error, _r); \
65878a
@@ -57,6 +69,7 @@ int selinux_access_check(DBusConnection *connection, DBusMessage *message, const
65878a
 #else
65878a
 
65878a
 #define SELINUX_ACCESS_CHECK(connection, message, permission) do { } while (false)
65878a
+#define SELINUX_RUNTIME_UNIT_ACCESS_CHECK(connection, message, permission) do { } while (false)
65878a
 #define SELINUX_UNIT_ACCESS_CHECK(unit, connection, message, permission) do { } while (false)
65878a
 
65878a
 #endif