Attach to the dns_dispatchmgr in the dns_view object

The dns_dispatchmgr object was only set in the dns_view object making it
prone to use-after-free in the dns_xfrin unit when shutting down named.

Remove dns_view_setdispatchmgr() and optionally pass the dispatchmgr
directly to dns_view_create() when it is attached and not just assigned,
so the dns_dispatchmgr doesn't cease to exist too early.

The dns_view_getdnsdispatchmgr() is now protected by the RCU lock, the
dispatchmgr reference is incremented, so the caller needs to detach from
it, and the function can return NULL in case the dns_view has been
already shut down.
This commit is contained in:
Ondřej Surý
2023-08-15 17:29:27 +02:00
committed by Evan Hunt
parent cfad194e1d
commit d76ab69772
16 changed files with 90 additions and 57 deletions

View File

@@ -45,6 +45,7 @@
#include <dns/callbacks.h>
#include <dns/db.h>
#include <dns/dispatch.h>
#include <dns/fixedname.h>
#include <dns/log.h>
#include <dns/name.h>
@@ -59,12 +60,27 @@ dns_zonemgr_t *zonemgr = NULL;
* Create a view.
*/
isc_result_t
dns_test_makeview(const char *name, bool with_cache, dns_view_t **viewp) {
dns_test_makeview(const char *name, bool with_dispatchmgr, bool with_cache,
dns_view_t **viewp) {
isc_result_t result;
dns_view_t *view = NULL;
dns_cache_t *cache = NULL;
dns_dispatchmgr_t *dispatchmgr = NULL;
if (with_dispatchmgr) {
result = dns_dispatchmgr_create(mctx, netmgr, &dispatchmgr);
if (result != ISC_R_SUCCESS) {
return (result);
}
}
result = dns_view_create(mctx, dispatchmgr, dns_rdataclass_in, name,
&view);
if (dispatchmgr != NULL) {
dns_dispatchmgr_detach(&dispatchmgr);
}
result = dns_view_create(mctx, dns_rdataclass_in, name, &view);
if (result != ISC_R_SUCCESS) {
return (result);
}
@@ -124,7 +140,7 @@ dns_test_makezone(const char *name, dns_zone_t **zonep, dns_view_t *view,
* If requested, create a view.
*/
if (createview) {
result = dns_test_makeview("view", false, &view);
result = dns_test_makeview("view", false, false, &view);
if (result != ISC_R_SUCCESS) {
goto detach_zone;
}

View File

@@ -439,7 +439,8 @@ ns_test_qctx_create(const ns_test_qctx_create_params_t *params,
/*
* Every client needs to belong to a view.
*/
result = dns_test_makeview("view", params->with_cache, &client->view);
result = dns_test_makeview("view", false, params->with_cache,
&client->view);
if (result != ISC_R_SUCCESS) {
goto detach_client;
}