From: Evan Hunt Date: Sun, 17 Oct 2021 23:45:22 +0000 (-0700) Subject: attach the interface manager when activating a route socket X-Git-Tag: v9.17.20~38^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=75427139ad4ecd283a8841e0b9cbba99fa1fb6c2;p=thirdparty%2Fbind9.git attach the interface manager when activating a route socket it was possible for the route socket's udp_recv() callback to fire after the interfacemgr was detached, causing an assertion failure. this has now been fixed by referencing the interfacemgr when setting up the route socket, and dereferencing it when shutting it down. --- diff --git a/lib/ns/interfacemgr.c b/lib/ns/interfacemgr.c index 316d0142f40..1bca46768ad 100644 --- a/lib/ns/interfacemgr.c +++ b/lib/ns/interfacemgr.c @@ -116,6 +116,14 @@ route_recv(isc_nmhandle_t *handle, isc_result_t eresult, isc_region_t *region, return; } + if (eresult == ISC_R_SHUTTINGDOWN) { + /* + * The mgr->route and mgr is detached in + * ns_interfacemgr_shutdown() + */ + return; + } + if (eresult != ISC_R_SUCCESS) { if (eresult != ISC_R_CANCELED) { isc_log_write(IFMGR_COMMON_LOGARGS, ISC_LOG_ERROR, @@ -124,6 +132,7 @@ route_recv(isc_nmhandle_t *handle, isc_result_t eresult, isc_region_t *region, isc_result_totext(eresult)); } isc_nmhandle_detach(&mgr->route); + ns_interfacemgr_detach(&mgr); return; } @@ -136,6 +145,7 @@ route_recv(isc_nmhandle_t *handle, isc_result_t eresult, isc_region_t *region, "recompile required", rtm->rtm_version, RTM_VERSION); isc_nmhandle_detach(&mgr->route); + ns_interfacemgr_detach(&mgr); return; } #endif /* ifdef RTM_VERSION */ @@ -164,6 +174,7 @@ route_recv(isc_nmhandle_t *handle, isc_result_t eresult, isc_region_t *region, if (done) { isc_nmhandle_detach(&mgr->route); + ns_interfacemgr_detach(&mgr); } return; } @@ -181,6 +192,7 @@ route_connected(isc_nmhandle_t *handle, isc_result_t eresult, void *arg) { 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); } @@ -283,9 +295,6 @@ ns_interfacemgr_destroy(ns_interfacemgr_t *mgr) { isc_refcount_destroy(&mgr->references); - if (mgr->route != NULL) { - isc_nmhandle_detach(&mgr->route); - } dns_aclenv_detach(&mgr->aclenv); ns_listenlist_detach(&mgr->listenon4); ns_listenlist_detach(&mgr->listenon6); @@ -346,19 +355,18 @@ ns_interfacemgr_shutdown(ns_interfacemgr_t *mgr) { /*% * Shut down and detach all interfaces. - * By incrementing the generation count, we make purge_old_interfaces() - * consider all interfaces "old". + * By incrementing the generation count, we make + * purge_old_interfaces() consider all interfaces "old". */ mgr->generation++; atomic_store(&mgr->shuttingdown, true); - LOCK(&mgr->lock); + purge_old_interfaces(mgr); + if (mgr->route != NULL) { isc_nmhandle_detach(&mgr->route); + ns_interfacemgr_detach(&mgr); } - UNLOCK(&mgr->lock); - - purge_old_interfaces(mgr); } static isc_result_t