]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
r/w of rbtdb->current_version requires that rbtdb->lock be held
authorMark Andrews <marka@isc.org>
Thu, 28 Nov 2019 06:58:40 +0000 (17:58 +1100)
committerMark Andrews <marka@isc.org>
Tue, 3 Dec 2019 05:50:06 +0000 (16:50 +1100)
(cherry picked from commit cd2469d3cdbc211ecf8a82c76c1a0a1c4a545fec)

lib/dns/rbtdb.c

index 1b91fd0e51d1cd0911d4c6f1970291321c257c07..2886c64c3323f26b2c82b22b94f4dadb2e3de7bd 100644 (file)
@@ -7157,8 +7157,11 @@ subtractrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
         * Update the zone's secure status.  If version is non-NULL
         * this is deferred until closeversion() is called.
         */
-       if (result == ISC_R_SUCCESS && version == NULL && !IS_CACHE(rbtdb))
+       if (result == ISC_R_SUCCESS && version == NULL && !IS_CACHE(rbtdb)) {
+               RBTDB_LOCK(&rbtdb->lock, isc_rwlocktype_write);
                iszonesecure(db, rbtdb->current_version, rbtdb->origin_node);
+               RBTDB_UNLOCK(&rbtdb->lock, isc_rwlocktype_write);
+       }
 
        return (result);
 }
@@ -7214,8 +7217,11 @@ deleterdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
         * Update the zone's secure status.  If version is non-NULL
         * this is deferred until closeversion() is called.
         */
-       if (result == ISC_R_SUCCESS && version == NULL && !IS_CACHE(rbtdb))
+       if (result == ISC_R_SUCCESS && version == NULL && !IS_CACHE(rbtdb)) {
+               RBTDB_LOCK(&rbtdb->lock, isc_rwlocktype_write);
                iszonesecure(db, rbtdb->current_version, rbtdb->origin_node);
+               RBTDB_UNLOCK(&rbtdb->lock, isc_rwlocktype_write);
+       }
 
        return (result);
 }
@@ -7697,14 +7703,14 @@ endload(dns_db_t *db, dns_rdatacallbacks_t *callbacks) {
        rbtdb->attributes &= ~RBTDB_ATTR_LOADING;
        rbtdb->attributes |= RBTDB_ATTR_LOADED;
 
-       RBTDB_UNLOCK(&rbtdb->lock, isc_rwlocktype_write);
-
        /*
         * If there's a KEY rdataset at the zone origin containing a
         * zone key, we consider the zone secure.
         */
-       if (! IS_CACHE(rbtdb) && rbtdb->origin_node != NULL)
+       if (! IS_CACHE(rbtdb) && rbtdb->origin_node != NULL) {
                iszonesecure(db, rbtdb->current_version, rbtdb->origin_node);
+       }
+       RBTDB_UNLOCK(&rbtdb->lock, isc_rwlocktype_write);
 
        callbacks->add = NULL;
        callbacks->add_private = NULL;
@@ -7970,9 +7976,9 @@ issecure(dns_db_t *db) {
 
        REQUIRE(VALID_RBTDB(rbtdb));
 
-       RWLOCK(&rbtdb->tree_lock, isc_rwlocktype_read);
+       RBTDB_LOCK(&rbtdb->lock, isc_rwlocktype_read);
        secure = (rbtdb->current_version->secure == dns_db_secure);
-       RWUNLOCK(&rbtdb->tree_lock, isc_rwlocktype_read);
+       RBTDB_UNLOCK(&rbtdb->lock, isc_rwlocktype_read);
 
        return (secure);
 }
@@ -7986,9 +7992,9 @@ isdnssec(dns_db_t *db) {
 
        REQUIRE(VALID_RBTDB(rbtdb));
 
-       RWLOCK(&rbtdb->tree_lock, isc_rwlocktype_read);
+       RBTDB_LOCK(&rbtdb->lock, isc_rwlocktype_read);
        dnssec = (rbtdb->current_version->secure != dns_db_insecure);
-       RWUNLOCK(&rbtdb->tree_lock, isc_rwlocktype_read);
+       RBTDB_UNLOCK(&rbtdb->lock, isc_rwlocktype_read);
 
        return (dnssec);
 }
@@ -8086,10 +8092,10 @@ getnsec3parameters(dns_db_t *db, dns_dbversion_t *version, dns_hash_t *hash,
        REQUIRE(VALID_RBTDB(rbtdb));
        INSIST(rbtversion == NULL || rbtversion->rbtdb == rbtdb);
 
-       RWLOCK(&rbtdb->tree_lock, isc_rwlocktype_read);
-
-       if (rbtversion == NULL)
+       RBTDB_LOCK(&rbtdb->lock, isc_rwlocktype_read);
+       if (rbtversion == NULL) {
                rbtversion = rbtdb->current_version;
+       }
 
        if (rbtversion->havensec3) {
                if (hash != NULL)
@@ -8107,7 +8113,7 @@ getnsec3parameters(dns_db_t *db, dns_dbversion_t *version, dns_hash_t *hash,
                        *flags = rbtversion->flags;
                result = ISC_R_SUCCESS;
        }
-       RWUNLOCK(&rbtdb->tree_lock, isc_rwlocktype_read);
+       RBTDB_UNLOCK(&rbtdb->lock, isc_rwlocktype_read);
 
        return (result);
 }
@@ -8125,16 +8131,21 @@ getsize(dns_db_t *db, dns_dbversion_t *version, uint64_t *records,
        REQUIRE(VALID_RBTDB(rbtdb));
        INSIST(rbtversion == NULL || rbtversion->rbtdb == rbtdb);
 
-       if (rbtversion == NULL)
+       RBTDB_LOCK(&rbtdb->lock, isc_rwlocktype_read);
+       if (rbtversion == NULL) {
                rbtversion = rbtdb->current_version;
+       }
 
        RWLOCK(&rbtversion->rwlock, isc_rwlocktype_read);
-       if (records != NULL)
+       if (records != NULL) {
                *records = rbtversion->records;
+       }
 
-       if (bytes != NULL)
+       if (bytes != NULL) {
                *bytes = rbtversion->bytes;
+       }
        RWUNLOCK(&rbtversion->rwlock, isc_rwlocktype_read);
+       RBTDB_UNLOCK(&rbtdb->lock, isc_rwlocktype_read);
 
        return (result);
 }