From dbbbed29e9c8edfeaedbbd37f42bf0dab168af16 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Tue, 30 Apr 2019 09:44:12 +1000 Subject: [PATCH 1/3] clear pointer before hash table (cherry picked from commit 4886701c0389b2f4b35364c2634e0b5b4a12eaa2) --- lib/isc/ht.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/isc/ht.c b/lib/isc/ht.c index 5369aadadb..fde728a4f6 100644 --- a/lib/isc/ht.c +++ b/lib/isc/ht.c @@ -95,6 +95,8 @@ isc_ht_destroy(isc_ht_t **htp) { REQUIRE(htp != NULL); ht = *htp; + *htp = NULL; + REQUIRE(ISC_HT_VALID(ht)); ht->magic = 0; @@ -116,7 +118,6 @@ isc_ht_destroy(isc_ht_t **htp) { isc_mem_put(ht->mctx, ht->table, ht->size * sizeof(isc_ht_node_t*)); isc_mem_putanddetach(&ht->mctx, ht, sizeof(struct isc_ht)); - *htp = NULL; } isc_result_t From a0feec3dbc6d77eb6dd2d3029d4210b59577edb3 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Tue, 30 Apr 2019 09:49:42 +1000 Subject: [PATCH 2/3] lock accesses to hash table (cherry picked from commit 2483a8c76d601f50b4c720730a2ef539b339d900) --- bin/plugins/filter-aaaa.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bin/plugins/filter-aaaa.c b/bin/plugins/filter-aaaa.c index 525a075807..70c163b40a 100644 --- a/bin/plugins/filter-aaaa.c +++ b/bin/plugins/filter-aaaa.c @@ -91,6 +91,7 @@ typedef struct filter_instance { * Hash table associating a client object with its persistent data. */ isc_ht_t *ht; + isc_mutex_t hlock; /* * Values configured when the module is loaded. @@ -378,6 +379,7 @@ plugin_register(const char *parameters, CHECK(isc_mempool_create(mctx, sizeof(filter_data_t), &inst->datapool)); CHECK(isc_ht_init(&inst->ht, mctx, 16)); + isc_mutex_init(&inst->hlock); /* * Fill the mempool with 1K filter_aaaa state objects at @@ -448,6 +450,7 @@ plugin_destroy(void **instp) { if (inst->ht != NULL) { isc_ht_destroy(&inst->ht); + isc_mutex_destroy(&inst->hlock); } if (inst->datapool != NULL) { isc_mempool_destroy(&inst->datapool); @@ -521,8 +524,10 @@ client_state_get(const query_ctx_t *qctx, filter_instance_t *inst) { filter_data_t *client_state = NULL; isc_result_t result; + LOCK(&inst->hlock); result = isc_ht_find(inst->ht, (const unsigned char *)&qctx->client, sizeof(qctx->client), (void **)&client_state); + UNLOCK(&inst->hlock); return (result == ISC_R_SUCCESS ? client_state : NULL); } @@ -540,8 +545,10 @@ client_state_create(const query_ctx_t *qctx, filter_instance_t *inst) { client_state->mode = NONE; client_state->flags = 0; + LOCK(&inst->hlock); result = isc_ht_add(inst->ht, (const unsigned char *)&qctx->client, sizeof(qctx->client), client_state); + UNLOCK(&inst->hlock); RUNTIME_CHECK(result == ISC_R_SUCCESS); } @@ -554,8 +561,10 @@ client_state_destroy(const query_ctx_t *qctx, filter_instance_t *inst) { return; } + LOCK(&inst->hlock); result = isc_ht_delete(inst->ht, (const unsigned char *)&qctx->client, sizeof(qctx->client)); + UNLOCK(&inst->hlock); RUNTIME_CHECK(result == ISC_R_SUCCESS); isc_mempool_put(inst->datapool, client_state); From 0b6a69832013f5014c78363b05ef025897ca4a63 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Tue, 7 May 2019 10:39:49 +1000 Subject: [PATCH 3/3] add CHANGES (cherry picked from commit bdc66eb5d9f703db2c12e2ca4fa9e2df9e7f4f6a) --- CHANGES | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES b/CHANGES index 3da1a93a0d..dc52d22826 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +5223. [bug] Fixed a race in the filter-aaaa plugin accessing + the hash table. [GL #1005] + 5222. [bug] 'delve -t ANY' could leak memory. [GL #983] 5221. [test] Enable parallel execution of system tests on