From: W.C.A. Wijngaards Date: Wed, 25 Aug 2021 11:37:50 +0000 (+0200) Subject: - Fix the stream wait stream_wait_count_lock and http2 buffer locks X-Git-Tag: release-1.14.0rc1~59 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c93a7fb38ac3e2805dd298c4076f28ee7b1f5a54;p=thirdparty%2Funbound.git - Fix the stream wait stream_wait_count_lock and http2 buffer locks setup and desetup from race condition. --- diff --git a/daemon/daemon.c b/daemon/daemon.c index 6d6667883..08497c5ed 100644 --- a/daemon/daemon.c +++ b/daemon/daemon.c @@ -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); diff --git a/doc/Changelog b/doc/Changelog index e8f75a2a0..ed7da6ace 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -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 diff --git a/libunbound/context.c b/libunbound/context.c index e589c6ae2..c8d911f13 100644 --- a/libunbound/context.c +++ b/libunbound/context.c @@ -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) diff --git a/libunbound/libunbound.c b/libunbound/libunbound.c index c9e24ba8d..8ec8e417a 100644 --- a/libunbound/libunbound.c +++ b/libunbound/libunbound.c @@ -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); diff --git a/services/listen_dnsport.c b/services/listen_dnsport.c index b43def567..1bb855c16 100644 --- a/services/listen_dnsport.c +++ b/services/listen_dnsport.c @@ -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 diff --git a/services/listen_dnsport.h b/services/listen_dnsport.h index 1e51be9bf..0e63236bc 100644 --- a/services/listen_dnsport.h +++ b/services/listen_dnsport.h @@ -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. diff --git a/testcode/testbound.c b/testcode/testbound.c index c92900142..66299d693 100644 --- a/testcode/testbound.c +++ b/testcode/testbound.c @@ -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 */ +}