The crash is in mutter. meta_wayland_client_new_subprocess() reads the
pid of the child it started with g_ascii_strtoll
(g_subprocess_get_identifier (subprocess), NULL, 0). GSubprocess reaps
its child in GLib's worker thread as soon as the child exits, and
g_subprocess_get_identifier() returns NULL from then on, as its
documentation says ("If the subprocess has terminated, this will return
NULL"). When the child exits before mutter's main thread reads the
identifier, g_ascii_strtoll() dereferences NULL, which is the strtol_l
frame of this report.In Ubuntu's session, the desktop icons extension ([email protected]) starts its desktop process with Meta.WaylandClient.new_subprocess(). The child has to exit within microseconds after its exec, which happens when it is killed right after it started. We hit it with mutter 50.1-0ubuntu2.5 on 26.04 (a build with local patches, none of which touch this code), in a test which runs the session headless and logs out right after unlocking the screen. DING, enabled again after the unlock, started its process just as systemd sent SIGTERM to all processes of [email protected], and GNOME Shell crashed 0.4 ms after systemd began to stop it, with DING's call to new_subprocess() on the JavaScript stack. In a core of the crash, meta_wayland_client_new_subprocess() passed the return value of g_subprocess_get_identifier() to g_ascii_strtoll(), and libc faulted reading the string at address 0. Steps which reproduce it: 1. Preload into gnome-shell a library which delays g_subprocess_get_identifier() by 50 ms, so that GLib always reaps a child which exits at once before mutter reads the identifier: #define _GNU_SOURCE #include <dlfcn.h> #include <unistd.h> typedef struct _GSubprocess GSubprocess; const char * g_subprocess_get_identifier (GSubprocess *subprocess) { static const char *(*real) (GSubprocess *); if (!real) real = (const char *(*) (GSubprocess *)) dlsym (RTLD_NEXT, "g_subprocess_get_identifier"); usleep (50000); return real (subprocess); } (gcc -shared -fPIC -o delay-identifier.so delay-identifier.c, and Environment=LD_PRELOAD=/path/to/delay-identifier.so in a drop-in for [email protected].) 2. Run with org.gnome.Shell.Eval: const {Gio, Meta} = imports.gi; const launcher = new Gio.SubprocessLauncher({flags: Gio.SubprocessFlags.STDOUT_PIPE}); Meta.WaylandClient.new_subprocess(global.context, launcher, ['/bin/true']); GNOME Shell crashes at the first call. Without the delay, a loop which calls new_subprocess() for /bin/true every millisecond and then logs out crashed GNOME Shell in 2 of 29 logouts. The following change fixes it: a client whose child is already reaped is returned without a pid, as for any other child, and the caller learns about the exit from the subprocess. With it and the delay above, 20 of 20 calls returned a client with pid 0, whose subprocess reported the exit status of /bin/true. mutter's main branch has the same code, and I have not proposed the change upstream yet. --- a/src/wayland/meta-wayland-client.c +++ b/src/wayland/meta-wayland-client.c @@ -228,6 +228,7 @@ meta_wayland_client_new_subprocess (MetaContext *context, int client_fd[2]; MetaWaylandClient *client; g_autoptr (GSubprocess) subprocess = NULL; + const char *identifier; g_return_val_if_fail (META_IS_CONTEXT (context), NULL); g_return_val_if_fail (G_IS_SUBPROCESS_LAUNCHER (launcher), NULL); @@ -255,8 +256,12 @@ meta_wayland_client_new_subprocess (MetaContext *context, client = g_object_new (META_TYPE_WAYLAND_CLIENT, NULL); client->context = context; client->kind = META_WAYLAND_CLIENT_KIND_SUBPROCESS; - client->pid = - g_ascii_strtoll (g_subprocess_get_identifier (subprocess), NULL, 0); + /* GLib reaps the child in its worker thread, and a subprocess has no + * identifier once its child is reaped, which can already be the case + * for a child killed right after it started. */ + identifier = g_subprocess_get_identifier (subprocess); + if (identifier) + client->pid = g_ascii_strtoll (identifier, NULL, 0); client->subprocess.subprocess = g_steal_pointer (&subprocess); wayland_client = wl_client_create (compositor->wayland_display, client_fd[0]); -- You received this bug notification because you are a member of Ubuntu Desktop Bugs, which is subscribed to gnome-shell in Ubuntu. https://bugs.launchpad.net/bugs/2126624 Title: gnome-shell crashed with SIGSEGV in __GI_____strtol_l_internal() from __GI___isoc23_strtol_l() from g_ascii_strtoll() from meta_wayland_client_new_subprocess() To manage notifications about this bug go to: https://bugs.launchpad.net/ubuntu/+source/gnome-shell/+bug/2126624/+subscriptions -- desktop-bugs mailing list [email protected] https://lists.ubuntu.com/mailman/listinfo/desktop-bugs
