]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix a race condition between shutdown and route_connected()
authorAram Sargsyan <aram@isc.org>
Tue, 14 Jun 2022 10:49:04 +0000 (10:49 +0000)
committerAram Sargsyan <aram@isc.org>
Tue, 14 Jun 2022 14:31:24 +0000 (14:31 +0000)
When shutting down, the interface manager can be destroyed
before the `route_connected()` callback is called, which is
unexpected for the latter and can cause a crash.

Move the interface manager attachment code from the callback
to the place before the callback is registered using
`isc_nm_routeconnect()` function, which will make sure that
the interface manager will live at least until the callback
is called.

Make sure to detach the interface manager if the
`isc_nm_routeconnect()` function is not implemented, or when
the callback is called with a result value which differs from
`ISC_R_SUCCESS`.

lib/ns/interfacemgr.c

index 473a79f0c15fb1c3971ad7d31c8198551168b395..118b7c03678d7ea0c73912be57077a5e88e6ac32 100644 (file)
@@ -262,12 +262,12 @@ route_connected(isc_nmhandle_t *handle, isc_result_t eresult, void *arg) {
                      "route_connected: %s", isc_result_totext(eresult));
 
        if (eresult != ISC_R_SUCCESS) {
+               ns_interfacemgr_detach(&mgr);
                return;
        }
 
        INSIST(mgr->route == NULL);
 
-       ns_interfacemgr_attach(mgr, &(ns_interfacemgr_t *){ NULL });
        isc_nmhandle_attach(handle, &mgr->route);
        isc_nm_read(handle, route_recv, mgr);
 }
@@ -345,7 +345,14 @@ ns_interfacemgr_create(isc_mem_t *mctx, ns_server_t *sctx,
        }
 
        if (scan) {
-               result = isc_nm_routeconnect(nm, route_connected, mgr);
+               ns_interfacemgr_t *imgr = NULL;
+
+               ns_interfacemgr_attach(mgr, &imgr);
+
+               result = isc_nm_routeconnect(nm, route_connected, imgr);
+               if (result == ISC_R_NOTIMPLEMENTED) {
+                       ns_interfacemgr_detach(&imgr);
+               }
                if (result != ISC_R_SUCCESS) {
                        isc_log_write(IFMGR_COMMON_LOGARGS, ISC_LOG_INFO,
                                      "unable to open route socket: %s",