Blame SOURCES/gvfsdaemon-Check-that-the-connecting-client-is-the-s.patch

1a0d93
From e3808a1b4042761055b1d975333a8243d67b8bfe Mon Sep 17 00:00:00 2001
1a0d93
From: Simon McVittie <smcv@collabora.com>
1a0d93
Date: Wed, 5 Jun 2019 13:33:38 +0100
1a0d93
Subject: [PATCH] gvfsdaemon: Check that the connecting client is the same user
1a0d93
1a0d93
Otherwise, an attacker who learns the abstract socket address from
1a0d93
netstat(8) or similar could connect to it and issue D-Bus method
1a0d93
calls.
1a0d93
1a0d93
Signed-off-by: Simon McVittie <smcv@collabora.com>
1a0d93
---
1a0d93
 daemon/gvfsdaemon.c | 36 +++++++++++++++++++++++++++++++++++-
1a0d93
 1 file changed, 35 insertions(+), 1 deletion(-)
1a0d93
1a0d93
diff --git a/daemon/gvfsdaemon.c b/daemon/gvfsdaemon.c
1a0d93
index 406d4f8e..be148a7b 100644
1a0d93
--- a/daemon/gvfsdaemon.c
1a0d93
+++ b/daemon/gvfsdaemon.c
1a0d93
@@ -79,6 +79,7 @@ struct _GVfsDaemon
1a0d93
   
1a0d93
   gint mount_counter;
1a0d93
   
1a0d93
+  GDBusAuthObserver *auth_observer;
1a0d93
   GDBusConnection *conn;
1a0d93
   GVfsDBusDaemon *daemon_skeleton;
1a0d93
   GVfsDBusMountable *mountable_skeleton;
1a0d93
@@ -171,6 +172,8 @@ g_vfs_daemon_finalize (GObject *object)
1a0d93
     }
1a0d93
   if (daemon->conn != NULL)
1a0d93
     g_object_unref (daemon->conn);
1a0d93
+  if (daemon->auth_observer != NULL)
1a0d93
+    g_object_unref (daemon->auth_observer);
1a0d93
   
1a0d93
   g_hash_table_destroy (daemon->registered_paths);
1a0d93
   g_hash_table_destroy (daemon->client_connections);
1a0d93
@@ -236,6 +239,35 @@ name_vanished_handler (GDBusConnection *connection,
1a0d93
   daemon->lost_main_daemon = TRUE;
1a0d93
 }
1a0d93
 
1a0d93
+/*
1a0d93
+ * Authentication observer signal handler that authorizes connections
1a0d93
+ * from the same uid as this process. This matches the behaviour of a
1a0d93
+ * libdbus DBusServer/DBusConnection when no DBusAllowUnixUserFunction
1a0d93
+ * has been set, but is not the default in GDBus.
1a0d93
+ */
1a0d93
+static gboolean
1a0d93
+authorize_authenticated_peer_cb (GDBusAuthObserver *observer,
1a0d93
+                                 G_GNUC_UNUSED GIOStream *stream,
1a0d93
+                                 GCredentials *credentials,
1a0d93
+                                 G_GNUC_UNUSED gpointer user_data)
1a0d93
+{
1a0d93
+  gboolean authorized = FALSE;
1a0d93
+
1a0d93
+  if (credentials != NULL)
1a0d93
+    {
1a0d93
+      GCredentials *own_credentials;
1a0d93
+
1a0d93
+      own_credentials = g_credentials_new ();
1a0d93
+
1a0d93
+      if (g_credentials_is_same_user (credentials, own_credentials, NULL))
1a0d93
+        authorized = TRUE;
1a0d93
+
1a0d93
+      g_object_unref (own_credentials);
1a0d93
+    }
1a0d93
+
1a0d93
+  return authorized;
1a0d93
+}
1a0d93
+
1a0d93
 static void
1a0d93
 g_vfs_daemon_init (GVfsDaemon *daemon)
1a0d93
 {
1a0d93
@@ -265,6 +297,8 @@ g_vfs_daemon_init (GVfsDaemon *daemon)
1a0d93
 
1a0d93
   daemon->conn = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
1a0d93
   g_assert (daemon->conn != NULL);
1a0d93
+  daemon->auth_observer = g_dbus_auth_observer_new ();
1a0d93
+  g_signal_connect (daemon->auth_observer, "authorize-authenticated-peer", G_CALLBACK (authorize_authenticated_peer_cb), NULL);
1a0d93
 
1a0d93
   daemon->daemon_skeleton = gvfs_dbus_daemon_skeleton_new ();
1a0d93
   g_signal_connect (daemon->daemon_skeleton, "handle-get-connection", G_CALLBACK (handle_get_connection), daemon);
1a0d93
@@ -876,7 +910,7 @@ handle_get_connection (GVfsDBusDaemon *object,
1a0d93
   server = g_dbus_server_new_sync (address1,
1a0d93
                                    G_DBUS_SERVER_FLAGS_NONE,
1a0d93
                                    guid,
1a0d93
-                                   NULL, /* GDBusAuthObserver */
1a0d93
+                                   daemon->auth_observer,
1a0d93
                                    NULL, /* GCancellable */
1a0d93
                                    &error);
1a0d93
   g_free (guid);
1a0d93
-- 
1a0d93
2.21.0
1a0d93