From 56003e9f9f72c8be67d553f4dbd16eba849ca864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Mon, 24 Sep 2018 19:33:16 +0200 Subject: [PATCH 1/2] Prevent a race after zone load Zone loading happens in a different task (zone->loadtask) than other zone actions (zone->task). Thus, when zone_postload() is called in the context of zone->loadtask, it may cause zone maintenance to be queued in zone->task and another thread can then execute zone_maintenance() before zone_postload() gets a chance to finish its work in the first thread. This would not be a problem if zone_maintenance() accounted for this possibility by locking the zone before checking the state of its DNS_ZONEFLG_LOADPENDING flag. However, the zone is currently not locked before the state of that flag is checked, which may prevent zone maintenance from happening despite zone_postload() scheduling it. Fix by locking the zone in zone_maintenance() before checking the state of the zone's DNS_ZONEFLG_LOADPENDING flag. --- lib/dns/zone.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/dns/zone.c b/lib/dns/zone.c index e11398e63a..60545141c7 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -10006,7 +10006,7 @@ zone_maintenance(dns_zone_t *zone) { const char me[] = "zone_maintenance"; isc_time_t now; isc_result_t result; - bool dumping; + bool dumping, load_pending; REQUIRE(DNS_ZONE_VALID(zone)); ENTER; @@ -10014,8 +10014,13 @@ zone_maintenance(dns_zone_t *zone) { /* * Are we pending load/reload? */ - if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_LOADPENDING)) + LOCK_ZONE(zone); + load_pending = DNS_ZONE_FLAG(zone, DNS_ZONEFLG_LOADPENDING); + UNLOCK_ZONE(zone); + + if (load_pending) { return; + } /* * Configuring the view of this zone may have From feb2a41b7c6017c75c59ad47e26a9ba0eed663a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Mon, 24 Sep 2018 19:33:16 +0200 Subject: [PATCH 2/2] Add CHANGES entry 5034. [bug] A race between threads could prevent zone maintenance scheduled immediately after zone load from being performed. [GL #542] --- CHANGES | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES b/CHANGES index 02a932688b..0b13795aa4 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +5034. [bug] A race between threads could prevent zone maintenance + scheduled immediately after zone load from being + performed. [GL #542] + 5033. [bug] When adding NTAs to multiple views using "rndc nta", the text returned via rndc was incorrectly terminated after the first line, making it look as if only one