Skip to content

Commit cace924

Browse files
committed
broker: fix use-after-free segfault
Problem: on Ubuntu 22.04, t0014-runlevel.t triggers a segfault when it runs the broker with broker.rc3_path=/bin/false. If a module has not been fully unloaded by the time modhash_destroy() is called, the module's context could be destroyed before its service entry is removed. Then a disconnect message sent when another module context is destroyed may cause the destroyed module context to be dereferenced. Add code to ensure the service hash is removed when the module is destroyed, if that hasn't happened already. Fixes #4564.
1 parent 5380875 commit cace924

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/broker/module.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,15 @@ static void module_destroy (module_t *p)
379379
if (p->t) {
380380
if ((e = pthread_join (p->t, &res)) != 0)
381381
log_errn_exit (e, "pthread_cancel");
382+
if (p->status != FLUX_MODSTATE_EXITED) {
383+
/* Calls broker.c module_status_cb() => service_remove_byuuid()
384+
* and releases a reference on 'p'. Without this, disconnect
385+
* requests sent when other modules are destroyed can still find
386+
* this service name and trigger a use-after-free segfault.
387+
* See also: flux-framework/flux-core#4564.
388+
*/
389+
module_set_status (p, FLUX_MODSTATE_EXITED);
390+
}
382391
}
383392

384393
/* Send disconnect messages to services used by this module.

0 commit comments

Comments
 (0)