|
|
2485c5 |
From 3d442dbf936d197aa11ca0a71663c2bc61696151 Mon Sep 17 00:00:00 2001
|
|
|
2485c5 |
From: fujiwarat <takao.fujiwara1@gmail.com>
|
|
|
2485c5 |
Date: Fri, 13 Sep 2019 15:59:03 +0900
|
|
|
2485c5 |
Subject: [PATCH] bus: Implement GDBusAuthObserver callback
|
|
|
2485c5 |
|
|
|
2485c5 |
ibus uses a GDBusServer with G_DBUS_SERVER_FLAGS_AUTHENTICATION_ALLOW_ANONYMOUS,
|
|
|
2485c5 |
and doesn't set a GDBusAuthObserver, which allows anyone who can connect
|
|
|
2485c5 |
to its AF_UNIX socket to authenticate and be authorized to send method calls.
|
|
|
2485c5 |
It also seems to use an abstract AF_UNIX socket, which does not have
|
|
|
2485c5 |
filesystem permissions, so the practical effect might be that a local
|
|
|
2485c5 |
attacker can connect to another user's ibus service and make arbitrary
|
|
|
2485c5 |
method calls.
|
|
|
2485c5 |
|
|
|
2485c5 |
BUGS=rhbz#1717958
|
|
|
2485c5 |
---
|
|
|
2485c5 |
bus/server.c | 89 ++++++++++++++++++++++++++++++++++++++++++----------
|
|
|
2485c5 |
1 file changed, 73 insertions(+), 16 deletions(-)
|
|
|
2485c5 |
|
|
|
2485c5 |
diff --git a/bus/server.c b/bus/server.c
|
|
|
2485c5 |
index 3a626230..2439de14 100644
|
|
|
2485c5 |
--- a/bus/server.c
|
|
|
2485c5 |
+++ b/bus/server.c
|
|
|
2485c5 |
@@ -2,7 +2,8 @@
|
|
|
2485c5 |
/* vim:set et sts=4: */
|
|
|
2485c5 |
/* bus - The Input Bus
|
|
|
2485c5 |
* Copyright (C) 2008-2010 Peng Huang <shawn.p.huang@gmail.com>
|
|
|
2485c5 |
- * Copyright (C) 2008-2010 Red Hat, Inc.
|
|
|
2485c5 |
+ * Copyright (C) 2011-2019 Takao Fujiwara <takao.fujiwara1@gmail.com>
|
|
|
2485c5 |
+ * Copyright (C) 2008-2019 Red Hat, Inc.
|
|
|
2485c5 |
*
|
|
|
2485c5 |
* This library is free software; you can redistribute it and/or
|
|
|
2485c5 |
* modify it under the terms of the GNU Lesser General Public
|
|
|
2485c5 |
@@ -70,16 +71,63 @@ _restart_server (void)
|
|
|
2485c5 |
}
|
|
|
2485c5 |
|
|
|
2485c5 |
/**
|
|
|
2485c5 |
+ * bus_allow_mechanism_cb:
|
|
|
2485c5 |
+ * @observer: A #GDBusAuthObserver.
|
|
|
2485c5 |
+ * @mechanism: The name of the mechanism.
|
|
|
2485c5 |
+ * @user_data: always %NULL.
|
|
|
2485c5 |
+ *
|
|
|
2485c5 |
+ * Check if @mechanism can be used to authenticate the other peer.
|
|
|
2485c5 |
+ * Returns: %TRUE if the peer's mechanism is allowed.
|
|
|
2485c5 |
+ */
|
|
|
2485c5 |
+static gboolean
|
|
|
2485c5 |
+bus_allow_mechanism_cb (GDBusAuthObserver *observer,
|
|
|
2485c5 |
+ const gchar *mechanism,
|
|
|
2485c5 |
+ G_GNUC_UNUSED gpointer user_data)
|
|
|
2485c5 |
+{
|
|
|
2485c5 |
+ if (g_strcmp0 (mechanism, "EXTERNAL") == 0)
|
|
|
2485c5 |
+ return TRUE;
|
|
|
2485c5 |
+ return FALSE;
|
|
|
2485c5 |
+}
|
|
|
2485c5 |
+
|
|
|
2485c5 |
+/**
|
|
|
2485c5 |
+ * bus_authorize_authenticated_peer_cb:
|
|
|
2485c5 |
+ * @observer: A #GDBusAuthObserver.
|
|
|
2485c5 |
+ * @stream: A #GIOStream.
|
|
|
2485c5 |
+ * @credentials: A #GCredentials.
|
|
|
2485c5 |
+ * @user_data: always %NULL.
|
|
|
2485c5 |
+ *
|
|
|
2485c5 |
+ * Check if a peer who has already authenticated should be authorized.
|
|
|
2485c5 |
+ * Returns: %TRUE if the peer's credential is authorized.
|
|
|
2485c5 |
+ */
|
|
|
2485c5 |
+static gboolean
|
|
|
2485c5 |
+bus_authorize_authenticated_peer_cb (GDBusAuthObserver *observer,
|
|
|
2485c5 |
+ GIOStream *stream,
|
|
|
2485c5 |
+ GCredentials *credentials,
|
|
|
2485c5 |
+ G_GNUC_UNUSED gpointer user_data)
|
|
|
2485c5 |
+{
|
|
|
2485c5 |
+ gboolean authorized = FALSE;
|
|
|
2485c5 |
+ if (credentials) {
|
|
|
2485c5 |
+ GCredentials *own_credentials = g_credentials_new ();
|
|
|
2485c5 |
+ if (g_credentials_is_same_user (credentials, own_credentials, NULL))
|
|
|
2485c5 |
+ authorized = TRUE;
|
|
|
2485c5 |
+ g_object_unref (own_credentials);
|
|
|
2485c5 |
+ }
|
|
|
2485c5 |
+ return authorized;
|
|
|
2485c5 |
+}
|
|
|
2485c5 |
+
|
|
|
2485c5 |
+/**
|
|
|
2485c5 |
* bus_new_connection_cb:
|
|
|
2485c5 |
- * @user_data: always NULL.
|
|
|
2485c5 |
- * @returns: TRUE when the function can handle the connection.
|
|
|
2485c5 |
+ * @observer: A #GDBusAuthObserver.
|
|
|
2485c5 |
+ * @dbus_connection: A #GDBusconnection.
|
|
|
2485c5 |
+ * @user_data: always %NULL.
|
|
|
2485c5 |
*
|
|
|
2485c5 |
* Handle incoming connections.
|
|
|
2485c5 |
+ * Returns: %TRUE when the function can handle the connection.
|
|
|
2485c5 |
*/
|
|
|
2485c5 |
static gboolean
|
|
|
2485c5 |
-bus_new_connection_cb (GDBusServer *server,
|
|
|
2485c5 |
- GDBusConnection *dbus_connection,
|
|
|
2485c5 |
- gpointer user_data)
|
|
|
2485c5 |
+bus_new_connection_cb (GDBusServer *server,
|
|
|
2485c5 |
+ GDBusConnection *dbus_connection,
|
|
|
2485c5 |
+ G_GNUC_UNUSED gpointer user_data)
|
|
|
2485c5 |
{
|
|
|
2485c5 |
BusConnection *connection = bus_connection_new (dbus_connection);
|
|
|
2485c5 |
bus_dbus_impl_new_connection (dbus, connection);
|
|
|
2485c5 |
@@ -94,9 +142,9 @@ bus_new_connection_cb (GDBusServer *
|
|
|
2485c5 |
}
|
|
|
2485c5 |
|
|
|
2485c5 |
static void
|
|
|
2485c5 |
-_server_connect_start_portal_cb (GObject *source_object,
|
|
|
2485c5 |
- GAsyncResult *res,
|
|
|
2485c5 |
- gpointer user_data)
|
|
|
2485c5 |
+_server_connect_start_portal_cb (GObject *source_object,
|
|
|
2485c5 |
+ GAsyncResult *res,
|
|
|
2485c5 |
+ G_GNUC_UNUSED gpointer user_data)
|
|
|
2485c5 |
{
|
|
|
2485c5 |
GVariant *result;
|
|
|
2485c5 |
GError *error = NULL;
|
|
|
2485c5 |
@@ -113,9 +161,9 @@ _server_connect_start_portal_cb (GObject
|
|
|
2485c5 |
}
|
|
|
2485c5 |
|
|
|
2485c5 |
static void
|
|
|
2485c5 |
-bus_acquired_handler (GDBusConnection *connection,
|
|
|
2485c5 |
- const gchar *name,
|
|
|
2485c5 |
- gpointer user_data)
|
|
|
2485c5 |
+bus_acquired_handler (GDBusConnection *connection,
|
|
|
2485c5 |
+ const gchar *name,
|
|
|
2485c5 |
+ G_GNUC_UNUSED gpointer user_data)
|
|
|
2485c5 |
{
|
|
|
2485c5 |
g_dbus_connection_call (connection,
|
|
|
2485c5 |
IBUS_SERVICE_PORTAL,
|
|
|
2485c5 |
@@ -136,22 +184,27 @@ void
|
|
|
2485c5 |
bus_server_init (void)
|
|
|
2485c5 |
{
|
|
|
2485c5 |
GError *error = NULL;
|
|
|
2485c5 |
+ GDBusServerFlags flags = G_DBUS_SERVER_FLAGS_NONE;
|
|
|
2485c5 |
+ gchar *guid;
|
|
|
2485c5 |
+ GDBusAuthObserver *observer;
|
|
|
2485c5 |
|
|
|
2485c5 |
dbus = bus_dbus_impl_get_default ();
|
|
|
2485c5 |
ibus = bus_ibus_impl_get_default ();
|
|
|
2485c5 |
bus_dbus_impl_register_object (dbus, (IBusService *)ibus);
|
|
|
2485c5 |
|
|
|
2485c5 |
/* init server */
|
|
|
2485c5 |
- GDBusServerFlags flags = G_DBUS_SERVER_FLAGS_AUTHENTICATION_ALLOW_ANONYMOUS;
|
|
|
2485c5 |
- gchar *guid = g_dbus_generate_guid ();
|
|
|
2485c5 |
- if (!g_str_has_prefix (g_address, "unix:tmpdir=")) {
|
|
|
2485c5 |
- g_error ("Your socket address does not have the format unix:tmpdir=$DIR; %s",
|
|
|
2485c5 |
- g_address);
|
|
|
2485c5 |
+ guid = g_dbus_generate_guid ();
|
|
|
2485c5 |
+ observer = g_dbus_auth_observer_new ();
|
|
|
2485c5 |
+ if (!g_str_has_prefix (g_address, "unix:tmpdir=") &&
|
|
|
2485c5 |
+ !g_str_has_prefix (g_address, "unix:path=")) {
|
|
|
2485c5 |
+ g_error ("Your socket address does not have the format unix:tmpdir=$DIR "
|
|
|
2485c5 |
+ "or unix:path=$FILE; %s", g_address);
|
|
|
2485c5 |
+
|
|
|
2485c5 |
}
|
|
|
2485c5 |
server = g_dbus_server_new_sync (
|
|
|
2485c5 |
g_address, /* the place where the socket file lives, e.g. /tmp, abstract namespace, etc. */
|
|
|
2485c5 |
flags, guid,
|
|
|
2485c5 |
- NULL /* observer */,
|
|
|
2485c5 |
+ observer,
|
|
|
2485c5 |
NULL /* cancellable */,
|
|
|
2485c5 |
&error);
|
|
|
2485c5 |
if (server == NULL) {
|
|
|
2485c5 |
@@ -161,7 +214,13 @@ bus_server_init (void)
|
|
|
2485c5 |
}
|
|
|
2485c5 |
g_free (guid);
|
|
|
2485c5 |
|
|
|
2485c5 |
- g_signal_connect (server, "new-connection", G_CALLBACK (bus_new_connection_cb), NULL);
|
|
|
2485c5 |
+ g_signal_connect (observer, "allow-mechanism",
|
|
|
2485c5 |
+ G_CALLBACK (bus_allow_mechanism_cb), NULL);
|
|
|
2485c5 |
+ g_signal_connect (observer, "authorize-authenticated-peer",
|
|
|
2485c5 |
+ G_CALLBACK (bus_authorize_authenticated_peer_cb), NULL);
|
|
|
2485c5 |
+ g_object_unref (observer);
|
|
|
2485c5 |
+ g_signal_connect (server, "new-connection",
|
|
|
2485c5 |
+ G_CALLBACK (bus_new_connection_cb), NULL);
|
|
|
2485c5 |
|
|
|
2485c5 |
g_dbus_server_start (server);
|
|
|
2485c5 |
|
|
|
2485c5 |
--
|
|
|
2485c5 |
2.21.0
|
|
|
2485c5 |
|