From a8ba2403254ea120f31f849ee7f0cb2f996e6c2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Wed, 9 Nov 2022 18:04:23 +0100 Subject: [PATCH 1/2] Don't use view->resolver directly when priming in dns_view_find() When starting priming from dns_view_find(), the dns_view shutdown could be initiated by different thread, detaching from the resolver. Use dns_view_getresolver() to attach to the resolver under view->lock, so we don't try to call dns_resolver_prime() with NULL pointer. There are more accesses to view->resolver, (and also view->adb and view->requestmgr that suffer from the same problem) in the dns_view module, but they are all done in exclusive mode or under a view->lock. --- lib/dns/view.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/dns/view.c b/lib/dns/view.c index 38fb06a665..e2cd0c1577 100644 --- a/lib/dns/view.c +++ b/lib/dns/view.c @@ -1037,9 +1037,14 @@ db_find: * We just used a hint. Let the resolver know it * should consider priming. */ - dns_resolver_prime(view->resolver); - dns_db_attach(view->hints, &db); - result = DNS_R_HINT; + dns_resolver_t *res = NULL; + result = dns_view_getresolver(view, &res); + if (result == ISC_R_SUCCESS) { + dns_resolver_prime(res); + dns_db_attach(view->hints, &db); + dns_resolver_detach(&res); + result = DNS_R_HINT; + } } else if (result == DNS_R_NXRRSET) { dns_db_attach(view->hints, &db); result = DNS_R_HINTNXRRSET; From 417097450a014e070aa943f364155582c1a97937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Thu, 10 Nov 2022 09:30:52 +0100 Subject: [PATCH 2/2] Check view->adb in dns_view_flushcache() The call to dns_view_flushcache() is done under exclusive mode, but we still need to check if view->adb is still attached before calling dns_adb_flush() because the shutdown might have been already initialized. This most likely only a theoretical problem on shutdown because there's either no way how to initiate cache flush when shutting down or very slim window where the `rndc flush` would have to hit the slim time during named shutdown. --- lib/dns/view.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/dns/view.c b/lib/dns/view.c index e2cd0c1577..8fcf23345c 100644 --- a/lib/dns/view.c +++ b/lib/dns/view.c @@ -1528,7 +1528,10 @@ dns_view_flushcache(dns_view_t *view, bool fixuponly) { dns_badcache_flush(view->failcache); } - dns_adb_flush(view->adb); + if (view->adb) { + dns_adb_flush(view->adb); + } + return (ISC_R_SUCCESS); }