]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- Fix the stream wait stream_wait_count_lock and http2 buffer locks
authorW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Wed, 25 Aug 2021 11:37:50 +0000 (13:37 +0200)
committerW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Wed, 25 Aug 2021 11:37:50 +0000 (13:37 +0200)
  setup and desetup from race condition.

daemon/daemon.c
doc/Changelog
libunbound/context.c
libunbound/libunbound.c
services/listen_dnsport.c
services/listen_dnsport.h
testcode/testbound.c

index 6d666788325a1a4e416ae4ecea82b559202ac79a..08497c5edf808634206f5b59974b5f4d3d3250f4 100644 (file)
@@ -280,6 +280,7 @@ daemon_init(void)
                free(daemon);
                return NULL;
        }
+       listen_setup_locks();
        if(gettimeofday(&daemon->time_boot, NULL) < 0)
                log_err("gettimeofday: %s", strerror(errno));
        daemon->time_last_stat = daemon->time_boot;
@@ -781,6 +782,7 @@ daemon_delete(struct daemon* daemon)
        alloc_clear(&daemon->superalloc);
        acl_list_delete(daemon->acl);
        tcl_list_delete(daemon->tcl);
+       listen_desetup_locks();
        free(daemon->chroot);
        free(daemon->pidfile);
        free(daemon->env);
index e8f75a2a09ffccf14d8a6c75b280545e4eb32056..ed7da6ace17da125e5101c39e820f017d1a5f6f7 100644 (file)
@@ -5,6 +5,8 @@
          are fully supported, and this now includes the tcp-only action.
        - Fix #536: error: RPZ: name of record (drop.spamhaus.org.rpz.local.)
          to insert into RPZ.
+       - Fix the stream wait stream_wait_count_lock and http2 buffer locks
+         setup and desetup from race condition.
 
 20 August 2021: Wouter
        - Fix #529: Fix: log_assert does nothing if UNBOUND_DEBUG is
index e589c6ae28d700efcfadfc7f60dcdc84afcf7f67..c8d911f13c7f9b90fa4c605313fb89b5612c7e63 100644 (file)
@@ -48,6 +48,7 @@
 #include "services/cache/rrset.h"
 #include "services/cache/infra.h"
 #include "services/authzone.h"
+#include "services/listen_dnsport.h"
 #include "util/data/msgreply.h"
 #include "util/storage/slabhash.h"
 #include "util/edns.h"
@@ -73,6 +74,7 @@ context_finalize(struct ub_ctx* ctx)
        config_apply(cfg);
        if(!modstack_setup(&ctx->mods, cfg->module_conf, ctx->env))
                return UB_INITFAIL;
+       listen_setup_locks();
        log_edns_known_options(VERB_ALGO, ctx->env);
        ctx->local_zones = local_zones_create();
        if(!ctx->local_zones)
index c9e24ba8d8f23567a263bf2d4b6057af71f8c29f..8ec8e417acfa9651460918470242c38b81b5daee 100644 (file)
@@ -185,6 +185,7 @@ ub_ctx_create(void)
                ub_randfree(ctx->seed_rnd);
                config_delete(ctx->env->cfg);
                modstack_desetup(&ctx->mods, ctx->env);
+               listen_desetup_locks();
                edns_known_options_delete(ctx->env);
                edns_strings_delete(ctx->env->edns_strings);
                free(ctx->env);
@@ -198,6 +199,7 @@ ub_ctx_create(void)
                ub_randfree(ctx->seed_rnd);
                config_delete(ctx->env->cfg);
                modstack_desetup(&ctx->mods, ctx->env);
+               listen_desetup_locks();
                edns_known_options_delete(ctx->env);
                edns_strings_delete(ctx->env->edns_strings);
                free(ctx->env);
@@ -344,6 +346,7 @@ ub_ctx_delete(struct ub_ctx* ctx)
        }
        ub_randfree(ctx->seed_rnd);
        alloc_clear(&ctx->superalloc);
+       listen_desetup_locks();
        traverse_postorder(&ctx->queries, delq, NULL);
        if(ctx_logfile_overridden) {
                log_file(NULL);
index b43def567501bb9174ef40a35700ad5bf746817b..1bb855c16b9bd412e68bb96110e826435c7f21d6 100644 (file)
@@ -1306,6 +1306,38 @@ listen_cp_insert(struct comm_point* c, struct listen_dnsport* front)
        return 1;
 }
 
+void listen_setup_locks(void)
+{
+       if(!stream_wait_lock_inited) {
+               lock_basic_init(&stream_wait_count_lock);
+               stream_wait_lock_inited = 1;
+       }
+       if(!http2_query_buffer_lock_inited) {
+               lock_basic_init(&http2_query_buffer_count_lock);
+               http2_query_buffer_lock_inited = 1;
+       }
+       if(!http2_response_buffer_lock_inited) {
+               lock_basic_init(&http2_response_buffer_count_lock);
+               http2_response_buffer_lock_inited = 1;
+       }
+}
+
+void listen_desetup_locks(void)
+{
+       if(stream_wait_lock_inited) {
+               stream_wait_lock_inited = 0;
+               lock_basic_destroy(&stream_wait_count_lock);
+       }
+       if(http2_query_buffer_lock_inited) {
+               http2_query_buffer_lock_inited = 0;
+               lock_basic_destroy(&http2_query_buffer_count_lock);
+       }
+       if(http2_response_buffer_lock_inited) {
+               http2_response_buffer_lock_inited = 0;
+               lock_basic_destroy(&http2_response_buffer_count_lock);
+       }
+}
+
 struct listen_dnsport* 
 listen_create(struct comm_base* base, struct listen_port* ports,
        size_t bufsize, int tcp_accept_count, int tcp_idle_timeout,
@@ -1327,18 +1359,6 @@ listen_create(struct comm_base* base, struct listen_port* ports,
                free(front);
                return NULL;
        }
-       if(!stream_wait_lock_inited) {
-               lock_basic_init(&stream_wait_count_lock);
-               stream_wait_lock_inited = 1;
-       }
-       if(!http2_query_buffer_lock_inited) {
-               lock_basic_init(&http2_query_buffer_count_lock);
-               http2_query_buffer_lock_inited = 1;
-       }
-       if(!http2_response_buffer_lock_inited) {
-               lock_basic_init(&http2_response_buffer_count_lock);
-               http2_response_buffer_lock_inited = 1;
-       }
 
        /* create comm points as needed */
        while(ports) {
@@ -1454,18 +1474,6 @@ listen_delete(struct listen_dnsport* front)
 #endif
        sldns_buffer_free(front->udp_buff);
        free(front);
-       if(stream_wait_lock_inited) {
-               stream_wait_lock_inited = 0;
-               lock_basic_destroy(&stream_wait_count_lock);
-       }
-       if(http2_query_buffer_lock_inited) {
-               http2_query_buffer_lock_inited = 0;
-               lock_basic_destroy(&http2_query_buffer_count_lock);
-       }
-       if(http2_response_buffer_lock_inited) {
-               http2_response_buffer_lock_inited = 0;
-               lock_basic_destroy(&http2_response_buffer_count_lock);
-       }
 }
 
 #ifdef HAVE_GETIFADDRS
index 1e51be9bfcabb6bc111fc505931881bf315f8e6a..0e63236bcbceeb0a03b5204341477ae91212d98f 100644 (file)
@@ -199,6 +199,11 @@ listen_create(struct comm_base* base, struct listen_port* ports,
  */
 void listen_delete(struct listen_dnsport* listen);
 
+/** setup the locks for the listen ports */
+void listen_setup_locks(void);
+/** desetup the locks for the listen ports */
+void listen_desetup_locks(void);
+
 /**
  * delete listen_list of commpoints. Calls commpointdelete() on items.
  * This may close the fds or not depending on flags.
index c92900142870fbd6da7e48d323db46eddf81ef58..66299d693419861515f68fb63bd01afcb9fe97ec 100644 (file)
@@ -604,3 +604,13 @@ int squelch_err_ssl_handshake(unsigned long ATTR_UNUSED(err))
 {
        return 0;
 }
+
+void listen_setup_locks(void)
+{
+       /* nothing */
+}
+
+void listen_desetup_locks(void)
+{
+       /* nothing */
+}