From 4444db6b6f930f6633b1274121665cc1f8c4fc90 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 13 Jul 2018 15:47:45 +0200 Subject: [PATCH] libnm: avoid deadlock during g_module_open() in _nm_utils_init() _nm_utils_init() is a __attribute__((constructor)) function, that is, it runs during dlopen(). On the other head, g_module_open() itself calls dlopen(). It is prone to deadlock. Don't do it. The check is only an aggressive assertion to crash the application if it wrongly loads libnm and libnm-util/libnm-glib at the same time. If that happens, all is lost already. We can just as well call the assertion later. It's not supposed to fail anyway. https://bugzilla.gnome.org/show_bug.cgi?id=796804 --- libnm-core/nm-setting.c | 15 +++++++++++++++ libnm-core/nm-utils.c | 7 ------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c index 9ce8cdb0b4..1645b4bd88 100644 --- a/libnm-core/nm-setting.c +++ b/libnm-core/nm-setting.c @@ -2057,6 +2057,21 @@ static void nm_setting_class_init (NMSettingClass *setting_class) { GObjectClass *object_class = G_OBJECT_CLASS (setting_class); + GModule *self_module; + gpointer func; + + /* loading libnm and legacy libraries libnm-util/libnm-glib at the same + * time is not supported. The reason is, that both libraries use the same + * glib type names ("NMSetting"), and glib does not support namespacing + * to allow for that. + * + * Arbitrarily, add a check here, see whether a known symbol from libnm-util + * is present. If it is, it indicates that the process is borked and we + * abort. */ + self_module = g_module_open (NULL, 0); + if (g_module_symbol (self_module, "nm_util_get_private", &func)) + g_error ("libnm-util symbols detected; Mixing libnm with libnm-util/libnm-glib is not supported"); + g_module_close (self_module); g_type_class_add_private (setting_class, sizeof (NMSettingPrivate)); diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index bea6b427b0..2c9c1fd0ef 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -236,8 +236,6 @@ static void __attribute__((constructor)) _nm_utils_init (void) { static int initialized = 0; - GModule *self; - gpointer func; if (g_atomic_int_get (&initialized) != 0) return; @@ -249,11 +247,6 @@ _nm_utils_init (void) * Hence, a poor-man guard "initialized" above is more than sufficient, * although it does not guarantee that the code is not run concurrently. */ - self = g_module_open (NULL, 0); - if (g_module_symbol (self, "nm_util_get_private", &func)) - g_error ("libnm-util symbols detected; Mixing libnm with libnm-util/libnm-glib is not supported"); - g_module_close (self); - bindtextdomain (GETTEXT_PACKAGE, NMLOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");