]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix "shutdown system test crashed in dns_dispatchmgr_getblackhole"
authorMark Andrews <marka@isc.org>
Wed, 22 Oct 2025 05:53:46 +0000 (16:53 +1100)
committerMark Andrews <marka@isc.org>
Mon, 27 Oct 2025 22:02:12 +0000 (09:02 +1100)
While shutting down view->dispatchmgr is no longer valid.  Attach
to it and when creates a fetch context and use that pointer instead
of view->dispatchmgr.  Use dns_view_getdispatchmgr to do the attaching
as view->dispatchmgr is it managed using rcu.

lib/dns/resolver.c

index f8e76f22e585e5ee444cf8b1b6f26516a75ba7c0..3d915b95f234500e3a1409bd891b0f62dafca300 100644 (file)
@@ -266,7 +266,6 @@ typedef struct query {
        isc_refcount_t references;
        fetchctx_t *fctx;
        dns_message_t *rmessage;
-       dns_dispatchmgr_t *dispatchmgr;
        dns_dispatch_t *dispatch;
        dns_adbaddrinfo_t *addrinfo;
        isc_time_t start;
@@ -396,6 +395,7 @@ struct fetchctx {
        ISC_LIST(dns_validator_t) validators;
        dns_db_t *cache;
        dns_adb_t *adb;
+       dns_dispatchmgr_t *dispatchmgr;
        bool ns_ttl_ok;
        uint32_t ns_ttl;
        isc_counter_t *qc;
@@ -2041,7 +2041,6 @@ fctx_query(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo,
        *query = (resquery_t){
                .options = options,
                .addrinfo = addrinfo,
-               .dispatchmgr = res->view->dispatchmgr,
                .link = ISC_LINK_INITIALIZER,
        };
 
@@ -2090,7 +2089,7 @@ fctx_query(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo,
                }
                isc_sockaddr_setport(&addr, 0);
 
-               result = dns_dispatch_createtcp(res->view->dispatchmgr, &addr,
+               result = dns_dispatch_createtcp(fctx->dispatchmgr, &addr,
                                                &sockaddr, addrinfo->transport,
                                                DNS_DISPATCHOPT_UNSHARED,
                                                &query->dispatch);
@@ -2101,9 +2100,8 @@ fctx_query(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo,
                FCTXTRACE("connecting via TCP");
        } else {
                if (have_addr) {
-                       result = dns_dispatch_createudp(res->view->dispatchmgr,
-                                                       &addr,
-                                                       &query->dispatch);
+                       result = dns_dispatch_createudp(
+                               fctx->dispatchmgr, &addr, &query->dispatch);
                        if (result != ISC_R_SUCCESS) {
                                goto cleanup_query;
                        }
@@ -3744,7 +3742,7 @@ possibly_mark(fetchctx_t *fctx, dns_adbaddrinfo_t *addr) {
        const char *msg = NULL;
 
        isc_netaddr_fromsockaddr(&ipaddr, sa);
-       blackhole = dns_dispatchmgr_getblackhole(res->view->dispatchmgr);
+       blackhole = dns_dispatchmgr_getblackhole(fctx->dispatchmgr);
        (void)dns_peerlist_peerbyaddr(res->view->peers, &ipaddr, &peer);
 
        if (blackhole != NULL) {
@@ -4469,6 +4467,7 @@ fctx_destroy(fetchctx_t *fctx) {
        }
        dns_db_detach(&fctx->cache);
        dns_adb_detach(&fctx->adb);
+       dns_dispatchmgr_detach(&fctx->dispatchmgr);
 
        dns_resolver_detach(&fctx->res);
 
@@ -4867,10 +4866,19 @@ fctx_create(dns_resolver_t *res, isc_loop_t *loop, const dns_name_t *name,
        isc_interval_set(&fctx->interval, 2, 0);
 
        /*
-        * Attach to the view's cache and adb.
+        * Attach to the view's adb, dispatchmgr and cache adb.
         */
-       dns_db_attach(res->view->cachedb, &fctx->cache);
        dns_view_getadb(res->view, &fctx->adb);
+       if (fctx->adb == NULL) {
+               result = ISC_R_SHUTTINGDOWN;
+               goto cleanup_qmessage;
+       }
+       fctx->dispatchmgr = dns_view_getdispatchmgr(res->view);
+       if (fctx->dispatchmgr == NULL) {
+               result = ISC_R_SHUTTINGDOWN;
+               goto cleanup_adb;
+       }
+       dns_db_attach(res->view->cachedb, &fctx->cache);
 
        ISC_LIST_INIT(fctx->resps);
        fctx->magic = FCTX_MAGIC;
@@ -4894,6 +4902,9 @@ fctx_create(dns_resolver_t *res, isc_loop_t *loop, const dns_name_t *name,
 
        return ISC_R_SUCCESS;
 
+cleanup_adb:
+       dns_adb_detach(&fctx->adb);
+
 cleanup_qmessage:
        dns_message_detach(&fctx->qmessage);