2
1

0006-gvfsdaemon-Check-that-the-connecting-client-is-the-same-user.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. From 70dbfc68a79faac49bd3423e079cb6902522082a Mon Sep 17 00:00:00 2001
  2. From: Simon McVittie <smcv@collabora.com>
  3. Date: Wed, 5 Jun 2019 13:33:38 +0100
  4. Subject: [PATCH] gvfsdaemon: Check that the connecting client is the same user
  5. Otherwise, an attacker who learns the abstract socket address from
  6. netstat(8) or similar could connect to it and issue D-Bus method
  7. calls.
  8. Signed-off-by: Simon McVittie <smcv@collabora.com>
  9. [Retrieved from:
  10. https://gitlab.gnome.org/GNOME/gvfs/commit/70dbfc68a79faac49bd3423e079cb6902522082a]
  11. Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
  12. ---
  13. daemon/gvfsdaemon.c | 36 +++++++++++++++++++++++++++++++++++-
  14. 1 file changed, 35 insertions(+), 1 deletion(-)
  15. diff --git a/daemon/gvfsdaemon.c b/daemon/gvfsdaemon.c
  16. index 406d4f8e..be148a7b 100644
  17. --- a/daemon/gvfsdaemon.c
  18. +++ b/daemon/gvfsdaemon.c
  19. @@ -79,6 +79,7 @@ struct _GVfsDaemon
  20. gint mount_counter;
  21. + GDBusAuthObserver *auth_observer;
  22. GDBusConnection *conn;
  23. GVfsDBusDaemon *daemon_skeleton;
  24. GVfsDBusMountable *mountable_skeleton;
  25. @@ -171,6 +172,8 @@ g_vfs_daemon_finalize (GObject *object)
  26. }
  27. if (daemon->conn != NULL)
  28. g_object_unref (daemon->conn);
  29. + if (daemon->auth_observer != NULL)
  30. + g_object_unref (daemon->auth_observer);
  31. g_hash_table_destroy (daemon->registered_paths);
  32. g_hash_table_destroy (daemon->client_connections);
  33. @@ -236,6 +239,35 @@ name_vanished_handler (GDBusConnection *connection,
  34. daemon->lost_main_daemon = TRUE;
  35. }
  36. +/*
  37. + * Authentication observer signal handler that authorizes connections
  38. + * from the same uid as this process. This matches the behaviour of a
  39. + * libdbus DBusServer/DBusConnection when no DBusAllowUnixUserFunction
  40. + * has been set, but is not the default in GDBus.
  41. + */
  42. +static gboolean
  43. +authorize_authenticated_peer_cb (GDBusAuthObserver *observer,
  44. + G_GNUC_UNUSED GIOStream *stream,
  45. + GCredentials *credentials,
  46. + G_GNUC_UNUSED gpointer user_data)
  47. +{
  48. + gboolean authorized = FALSE;
  49. +
  50. + if (credentials != NULL)
  51. + {
  52. + GCredentials *own_credentials;
  53. +
  54. + own_credentials = g_credentials_new ();
  55. +
  56. + if (g_credentials_is_same_user (credentials, own_credentials, NULL))
  57. + authorized = TRUE;
  58. +
  59. + g_object_unref (own_credentials);
  60. + }
  61. +
  62. + return authorized;
  63. +}
  64. +
  65. static void
  66. g_vfs_daemon_init (GVfsDaemon *daemon)
  67. {
  68. @@ -265,6 +297,8 @@ g_vfs_daemon_init (GVfsDaemon *daemon)
  69. daemon->conn = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
  70. g_assert (daemon->conn != NULL);
  71. + daemon->auth_observer = g_dbus_auth_observer_new ();
  72. + g_signal_connect (daemon->auth_observer, "authorize-authenticated-peer", G_CALLBACK (authorize_authenticated_peer_cb), NULL);
  73. daemon->daemon_skeleton = gvfs_dbus_daemon_skeleton_new ();
  74. g_signal_connect (daemon->daemon_skeleton, "handle-get-connection", G_CALLBACK (handle_get_connection), daemon);
  75. @@ -876,7 +910,7 @@ handle_get_connection (GVfsDBusDaemon *object,
  76. server = g_dbus_server_new_sync (address1,
  77. G_DBUS_SERVER_FLAGS_NONE,
  78. guid,
  79. - NULL, /* GDBusAuthObserver */
  80. + daemon->auth_observer,
  81. NULL, /* GCancellable */
  82. &error);
  83. g_free (guid);
  84. --
  85. 2.24.1