orion / rpms / dbus

Forked from rpms/dbus a year ago
Clone
9703b1
diff -urN dbus-1.10.24.old/bus/driver.c dbus-1.10.24/bus/driver.c
9703b1
--- dbus-1.10.24.old/bus/driver.c	2017-09-25 16:20:08.000000000 +0100
9703b1
+++ dbus-1.10.24/bus/driver.c	2018-02-13 10:15:09.570439595 +0000
9703b1
@@ -555,6 +555,9 @@
744420
   char **services;
744420
   BusRegistry *registry;
744420
   int i;
744420
+#ifdef HAVE_SELINUX
744420
+  dbus_bool_t mls_enabled;
744420
+#endif
744420
   DBusMessageIter iter;
744420
   DBusMessageIter sub;
744420
 
9703b1
@@ -601,9 +604,58 @@
744420
       }
744420
   }
744420
 
744420
+#ifdef HAVE_SELINUX
744420
+  mls_enabled = bus_selinux_mls_enabled ();
744420
+#endif
744420
   i = 0;
744420
   while (i < len)
744420
     {
744420
+#ifdef HAVE_SELINUX
744420
+      if (mls_enabled)
744420
+        {
744420
+          const char *requester;
744420
+          BusService *service;
744420
+          DBusString str;
744420
+          DBusConnection *service_conn;
744420
+          DBusConnection *requester_conn;
744420
+
744420
+          requester = dbus_message_get_destination (reply);
744420
+          _dbus_string_init_const (&str, requester);
744420
+          service = bus_registry_lookup (registry, &str);
744420
+
744420
+          if (service == NULL)
744420
+            {
744420
+              _dbus_warn_check_failed ("service lookup failed: %s", requester);
744420
+              ++i;
744420
+              continue;
744420
+            }
744420
+          requester_conn = bus_service_get_primary_owners_connection (service);
744420
+          _dbus_string_init_const (&str, services[i]);
744420
+          service = bus_registry_lookup (registry, &str);
744420
+          if (service == NULL)
744420
+            {
744420
+              _dbus_warn_check_failed ("service lookup failed: %s", services[i]);
744420
+              ++i;
744420
+              continue;
744420
+            }
744420
+          service_conn = bus_service_get_primary_owners_connection (service);
744420
+
744420
+          if (!bus_selinux_allows_name (requester_conn, service_conn, error))
744420
+            {
744420
+              if (dbus_error_is_set (error) &&
744420
+                  dbus_error_has_name (error, DBUS_ERROR_NO_MEMORY))
744420
+                {
744420
+                  dbus_free_string_array (services);
744420
+                  dbus_message_unref (reply);
744420
+                  return FALSE;
744420
+                }
744420
+
744420
+              /* Skip any services which are disallowed by SELinux policy. */
744420
+              ++i;
744420
+              continue;
744420
+            }
744420
+        }
744420
+#endif
744420
       if (!dbus_message_iter_append_basic (&sub, DBUS_TYPE_STRING,
744420
                                            &services[i]))
744420
         {
9703b1
diff -urN dbus-1.10.24.old/bus/selinux.c dbus-1.10.24/bus/selinux.c
9703b1
--- dbus-1.10.24.old/bus/selinux.c	2017-07-28 07:24:16.000000000 +0100
9703b1
+++ dbus-1.10.24/bus/selinux.c	2018-02-13 10:35:14.311477447 +0000
9703b1
@@ -61,6 +61,9 @@
744420
 /* Store the value telling us if SELinux is enabled in the kernel. */
744420
 static dbus_bool_t selinux_enabled = FALSE;
744420
 
744420
+/* Store the value telling us if SELinux with MLS is enabled in the kernel. */
744420
+static dbus_bool_t selinux_mls_enabled = FALSE;
744420
+
744420
 /* Store an avc_entry_ref to speed AVC decisions. */
744420
 static struct avc_entry_ref aeref;
744420
 
9703b1
@@ -273,6 +276,20 @@
744420
 }
744420
 
744420
 /**
744420
+ * Return whether or not SELinux with MLS support is enabled; must be
744420
+ * called after bus_selinux_init.
744420
+ */
744420
+dbus_bool_t
744420
+bus_selinux_mls_enabled (void)
744420
+{
744420
+#ifdef HAVE_SELINUX
744420
+  return selinux_mls_enabled;
744420
+#else
744420
+  return FALSE;
744420
+#endif /* HAVE_SELINUX */
744420
+}
744420
+
744420
+/**
744420
  * Do early initialization; determine whether SELinux is enabled.
744420
  */
744420
 dbus_bool_t
9703b1
@@ -292,6 +309,16 @@
744420
     }
744420
 
744420
   selinux_enabled = r != 0;
744420
+
744420
+  r = is_selinux_mls_enabled ();
744420
+  if (r < 0)
744420
+    {
744420
+      _dbus_warn ("Could not tell if SELinux MLS is enabled: %s\n",
744420
+                  _dbus_strerror (errno));
744420
+      return FALSE;
744420
+    }
744420
+
744420
+  selinux_mls_enabled = r != 0;
744420
   return TRUE;
744420
 #else
744420
   return TRUE;
9703b1
@@ -304,14 +331,18 @@
9703b1
  */
9703b1
 /* security dbus class constants */
9703b1
 #define SECCLASS_DBUS       1
9703b1
+#define SECCLASS_CONTEXT    2
9703b1
 
9703b1
 /* dbus's per access vector constants */
9703b1
 #define DBUS__ACQUIRE_SVC   1
9703b1
 #define DBUS__SEND_MSG      2
9703b1
 
9703b1
+#define CONTEXT__CONTAINS   1
9703b1
+
9703b1
 #ifdef HAVE_SELINUX
9703b1
 static struct security_class_mapping dbus_map[] = {
9703b1
   { "dbus", { "acquire_svc", "send_msg", NULL } },
9703b1
+  { "context", { "contains", NULL } },
9703b1
   { NULL }
9703b1
 };
9703b1
 #endif /* HAVE_SELINUX */
9703b1
@@ -734,6 +765,102 @@
744420
 #endif /* HAVE_SELINUX */
744420
 
744420
 /**
744420
+ * Check if SELinux security controls allow one connection to determine the
744420
+ * name of the other, taking into account MLS considerations.
744420
+ *
744420
+ * @param source the requester of the name.
744420
+ * @param destination the name being requested.
744420
+ * @returns whether the name should be visible by the source of the request
744420
+ */
744420
+dbus_bool_t
744420
+bus_selinux_allows_name (DBusConnection     *source,
744420
+                         DBusConnection     *destination,
744420
+                         DBusError          *error)
744420
+{
744420
+#ifdef HAVE_SELINUX
744420
+  int err;
744420
+  char *policy_type;
744420
+  unsigned long spid, tpid;
744420
+  BusSELinuxID *source_sid;
744420
+  BusSELinuxID *dest_sid;
744420
+  dbus_bool_t ret;
744420
+  dbus_bool_t string_alloced;
744420
+  DBusString auxdata;
744420
+
744420
+  if (!selinux_mls_enabled)
744420
+    return TRUE;
744420
+
744420
+  err = selinux_getpolicytype (&policy_type);
744420
+  if (err < 0)
744420
+    {
744420
+      dbus_set_error_const (error, DBUS_ERROR_IO_ERROR,
744420
+                            "Failed to get SELinux policy type");
744420
+      return FALSE;
744420
+    }
744420
+
744420
+  /* Only check against MLS policy if running under that policy. */
744420
+  if (strcmp (policy_type, "mls") != 0)
744420
+    {
744420
+      free (policy_type);
744420
+      return TRUE;
744420
+    }
744420
+
744420
+  free (policy_type);
744420
+
744420
+  _dbus_assert (source != NULL);
744420
+  _dbus_assert (destination != NULL);
744420
+
744420
+  if (!source || !dbus_connection_get_unix_process_id (source, &spid))
744420
+    spid = 0;
744420
+  if (!destination || !dbus_connection_get_unix_process_id (destination, &tpid))
744420
+    tpid = 0;
744420
+
744420
+  string_alloced = FALSE;
744420
+  if (!_dbus_string_init (&auxdata))
744420
+    goto oom;
744420
+  string_alloced = TRUE;
744420
+
744420
+  if (spid)
744420
+    {
744420
+      if (!_dbus_string_append (&auxdata, " spid="))
744420
+	goto oom;
744420
+
744420
+      if (!_dbus_string_append_uint (&auxdata, spid))
744420
+	goto oom;
744420
+    }
744420
+
744420
+  if (tpid)
744420
+    {
744420
+      if (!_dbus_string_append (&auxdata, " tpid="))
744420
+	goto oom;
744420
+
744420
+      if (!_dbus_string_append_uint (&auxdata, tpid))
744420
+	goto oom;
744420
+    }
744420
+
744420
+  source_sid = bus_connection_get_selinux_id (source);
744420
+  dest_sid = bus_connection_get_selinux_id (destination);
744420
+
744420
+  ret = bus_selinux_check (source_sid,
744420
+                           dest_sid,
744420
+                           SECCLASS_CONTEXT,
744420
+                           CONTEXT__CONTAINS,
744420
+                           &auxdata);
744420
+
744420
+  _dbus_string_free (&auxdata);
744420
+  return ret;
744420
+
744420
+ oom:
744420
+  if (string_alloced)
744420
+    _dbus_string_free (&auxdata);
744420
+  BUS_SET_OOM (error);
744420
+  return FALSE;
744420
+#else
744420
+  return TRUE;
744420
+#endif /* HAVE_SELINUX */
744420
+}
744420
+
744420
+/**
744420
  * Read the SELinux ID from the connection.
744420
  *
744420
  * @param connection the connection to read from
9703b1
Binary files dbus-1.10.24.old/bus/.selinux.c.swp and dbus-1.10.24/bus/.selinux.c.swp differ
9703b1
diff -urN dbus-1.10.24.old/bus/selinux.h dbus-1.10.24/bus/selinux.h
9703b1
--- dbus-1.10.24.old/bus/selinux.h	2017-07-28 07:24:16.000000000 +0100
9703b1
+++ dbus-1.10.24/bus/selinux.h	2018-02-13 10:15:09.573439444 +0000
9703b1
@@ -32,6 +32,7 @@
744420
 void        bus_selinux_shutdown (void);
744420
 
744420
 dbus_bool_t bus_selinux_enabled  (void);
744420
+dbus_bool_t bus_selinux_mls_enabled (void);
744420
 
744420
 void bus_selinux_id_ref    (BusSELinuxID *sid);
744420
 void bus_selinux_id_unref  (BusSELinuxID *sid);
9703b1
@@ -54,6 +55,10 @@
744420
 						const char     *service_name,
744420
 						DBusError      *error);
744420
 
744420
+dbus_bool_t bus_selinux_allows_name            (DBusConnection *source,
744420
+                                                DBusConnection *destination,
744420
+                                                DBusError      *error);
744420
+
744420
 dbus_bool_t bus_selinux_allows_send            (DBusConnection *sender,
744420
                                                 DBusConnection *proposed_recipient,
744420
 						const char     *msgtype, /* Supplementary audit data */