]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Prepare a zone for shutting down when deleting it from a view
authorAram Sargsyan <aram@isc.org>
Mon, 12 May 2025 13:58:38 +0000 (13:58 +0000)
committerOndřej Surý <ondrej@isc.org>
Wed, 28 May 2025 18:30:45 +0000 (18:30 +0000)
After b171cacf4f0123ba96bef6eedfc92dfb608db6b7, a zone object can
remain in the memory for a while, until garbage collection is run.
Setting the DNS_ZONEFLG_EXITING flag should prevent the zone
maintenance function from running while it's in that state.
Otherwise, a secondary zone could initiate a zone transfer after
it had been deleted.

(cherry picked from commit 874ca5ca2f1f381e434304e262ea08e77e3bdf65)

lib/dns/include/dns/zone.h
lib/dns/view.c
lib/dns/zone.c

index 57ff194c2b83649d402cf80b5d2da0aaa18f57f6..8573c1dce53dd75b245306e4296d5daedd89b82c 100644 (file)
@@ -1757,6 +1757,20 @@ dns_zone_findkeys(dns_zone_t *zone, dns_db_t *db, dns_dbversion_t *ver,
  *\li  Error
  */
 
+void
+dns_zone_prepare_shutdown(dns_zone_t *zone);
+/*%<
+ * Prepare a zone for shutdown by setting the DNS_ZONEFLG_EXITING flag even
+ * before the final reference is detached. Useful, because the zone object can
+ * be kept around with a valid reference from the zonetable until qp garbage
+ * collector runs, and we don't want, for example, zone maintenance to happen
+ * while waiting for it. Note that the zone can not be used normally again after
+ * this function is called.
+ *
+ * Requires:
+ *\li  'zone' to be a valid initialised zone.
+ */
+
 void
 dns_zonemgr_create(isc_mem_t *mctx, isc_nm_t *netmgr, dns_zonemgr_t **zmgrp);
 /*%<
index a82c078a70b6767571122644d05f99d9c27ead9b..b5d751ad5449837caad70434331a0688a88a3c82 100644 (file)
@@ -785,6 +785,8 @@ dns_view_delzone(dns_view_t *view, dns_zone_t *zone) {
 
        REQUIRE(DNS_VIEW_VALID(view));
 
+       dns_zone_prepare_shutdown(zone);
+
        rcu_read_lock();
        zonetable = rcu_dereference(view->zonetable);
        if (zonetable != NULL) {
index 845902b160252c21e5ff881410f84afa49905fe5..c070b38810d53689f8a602d8a26b1295e010b680 100644 (file)
@@ -6401,6 +6401,15 @@ failure:
        return result;
 }
 
+void
+dns_zone_prepare_shutdown(dns_zone_t *zone) {
+       REQUIRE(DNS_ZONE_VALID(zone));
+
+       LOCK_ZONE(zone);
+       DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_EXITING);
+       UNLOCK_ZONE(zone);
+}
+
 /*%
  * Find DNSSEC keys used for signing zone with dnssec-policy. Load these keys
  * into 'keys'. Requires KASP to be locked.