From 4b362a82ebf511d0915585bbe55bdb9b989f439a Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Mon, 11 Oct 2021 18:13:39 +0000 Subject: [PATCH 1/3] Fix catalog zone reconfiguration crash The following scenario triggers a "named" crash: 1. Configure a catalog zone. 2. Start "named". 3. Comment out the "catalog-zone" clause. 4. Run `rndc reconfig`. 5. Uncomment the "catalog-zone" clause. 6. Run `rndc reconfig` again. Implement the required cleanup of the in-memory catalog zone during the first `rndc reconfig`, so that the second `rndc reconfig` could find it in an expected state. (cherry picked from commit 43ac2cd229813c04438e027c42c0b93b9661adda) --- bin/named/server.c | 2 ++ lib/dns/include/dns/zone.h | 20 ++++++++++++++++++++ lib/dns/win32/libdns.def.in | 2 ++ lib/dns/zone.c | 18 ++++++++++++++++++ 4 files changed, 42 insertions(+) diff --git a/bin/named/server.c b/bin/named/server.c index 860ccae8a1..9c0f12f63f 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -6523,6 +6523,8 @@ configure_zone(const cfg_obj_t *config, const cfg_obj_t *zconfig, if (zone_is_catz) { dns_zone_catz_enable(zone, view->catzs); + } else if (dns_zone_catz_is_enabled(zone)) { + dns_zone_catz_disable(zone); } /* diff --git a/lib/dns/include/dns/zone.h b/lib/dns/include/dns/zone.h index 08e2263c5b..33ab5c60fd 100644 --- a/lib/dns/include/dns/zone.h +++ b/lib/dns/include/dns/zone.h @@ -2605,6 +2605,26 @@ dns_zone_catz_enable(dns_zone_t *zone, dns_catz_zones_t *catzs); * \li prior to calling, zone->catzs is NULL or is equal to 'catzs' */ +void +dns_zone_catz_disable(dns_zone_t *zone); +/*%< + * Disable zone as catalog zone, if it is one. + * + * Requires: + * + * \li 'zone' is a valid zone object + */ + +bool +dns_zone_catz_is_enabled(dns_zone_t *zone); +/*%< + * Return a boolean indicating whether the zone is enabled as catalog zone. + * + * Requires: + * + * \li 'zone' is a valid zone object + */ + void dns_zone_catz_enable_db(dns_zone_t *zone, dns_db_t *db); /*%< diff --git a/lib/dns/win32/libdns.def.in b/lib/dns/win32/libdns.def.in index 31f511103f..1e0f7cf64a 100644 --- a/lib/dns/win32/libdns.def.in +++ b/lib/dns/win32/libdns.def.in @@ -1173,8 +1173,10 @@ dns_xfrin_shutdown dns_zone_addnsec3chain dns_zone_asyncload dns_zone_attach +dns_zone_catz_disable dns_zone_catz_enable dns_zone_catz_enable_db +dns_zone_catz_is_enabled dns_zone_cdscheck dns_zone_checknames dns_zone_clearforwardacl diff --git a/lib/dns/zone.c b/lib/dns/zone.c index 65a3aacab7..bc33e6ede8 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -1942,6 +1942,24 @@ dns_zone_catz_enable(dns_zone_t *zone, dns_catz_zones_t *catzs) { UNLOCK_ZONE(zone); } +void +dns_zone_catz_disable(dns_zone_t *zone) { + REQUIRE(DNS_ZONE_VALID(zone)); + + LOCK_ZONE(zone); + if (zone->catzs != NULL) { + dns_catz_catzs_detach(&zone->catzs); + } + UNLOCK_ZONE(zone); +} + +bool +dns_zone_catz_is_enabled(dns_zone_t *zone) { + REQUIRE(DNS_ZONE_VALID(zone)); + + return (zone->catzs != NULL); +} + /* * If a zone is a catalog zone, attach it to update notification in database. */ From a6572062b15bf0601538b433d2e646712b8e9adc Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Mon, 11 Oct 2021 18:33:06 +0000 Subject: [PATCH 2/3] Add CHANGES and release notes for [GL #1608] (cherry picked from commit e64473831010f3e8c76d9d0e1f222f4237e053e1) --- CHANGES | 4 ++++ doc/notes/notes-current.rst | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 8888494638..74f033a9dc 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,10 @@ 5764. [bug] dns_sdlz_putrr failed to process some valid resource records. [GL #3021] +5762. [bug] Fix a "named" crash related to removing and restoring a + `catalog-zone` entry in the configuration file and + running `rndc reconfig`. [GL #1608] + 5758. [bug] mdig now honors the operating system's preferred ephemeral port range. [GL #2374] diff --git a/doc/notes/notes-current.rst b/doc/notes/notes-current.rst index c761045b0c..1a6ffaa8ab 100644 --- a/doc/notes/notes-current.rst +++ b/doc/notes/notes-current.rst @@ -39,4 +39,7 @@ Feature Changes Bug Fixes ~~~~~~~~~ -- None. +- Removing a configured ``catalog-zone`` clause from the configuration, running + ``rndc reconfig``, then bringing back the removed ``catalog-zone`` clause and + running ``rndc reconfig`` again caused ``named`` to crash. This has been fixed. + :gl:`#1608` From c243daf8395bf8406f6697dde5ba62a25d188a1b Mon Sep 17 00:00:00 2001 From: Evan Hunt Date: Mon, 11 Oct 2021 13:01:20 -0700 Subject: [PATCH 3/3] Add a regression test Reconfigure the server without catalog-zone configuration, and then put it back and reconfigure again, to confirm that there's no crash. (cherry picked from commit bb411af31dd78ceda7a16f7ecfab483fb3746af9) --- .../ns2/{named.conf.in => named1.conf.in} | 0 bin/tests/system/catz/ns2/named2.conf.in | 60 +++++++++++++++++++ bin/tests/system/catz/setup.sh | 2 +- bin/tests/system/catz/tests.sh | 16 ++++- 4 files changed, 74 insertions(+), 4 deletions(-) rename bin/tests/system/catz/ns2/{named.conf.in => named1.conf.in} (100%) create mode 100644 bin/tests/system/catz/ns2/named2.conf.in diff --git a/bin/tests/system/catz/ns2/named.conf.in b/bin/tests/system/catz/ns2/named1.conf.in similarity index 100% rename from bin/tests/system/catz/ns2/named.conf.in rename to bin/tests/system/catz/ns2/named1.conf.in diff --git a/bin/tests/system/catz/ns2/named2.conf.in b/bin/tests/system/catz/ns2/named2.conf.in new file mode 100644 index 0000000000..fcd99ca0d4 --- /dev/null +++ b/bin/tests/system/catz/ns2/named2.conf.in @@ -0,0 +1,60 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * See the COPYRIGHT file distributed with this work for additional + * information regarding copyright ownership. + */ + +include "../../common/rndc.key"; + +controls { + inet 10.53.0.2 port @CONTROLPORT@ allow { any; } keys { rndc_key; }; +}; + +options { + query-source address 10.53.0.2; + notify-source 10.53.0.2; + transfer-source 10.53.0.2; + port @PORT@; + pid-file "named.pid"; + listen-on { 10.53.0.2; }; + listen-on-v6 { fd92:7065:b8e:ffff::2; }; + notify no; + recursion no; + serial-query-rate 100; + # removed catalog-zone option, otherwise this is + # identical to named1.conf.in +}; + +zone "catalog1.example" { + type secondary; + file "catalog1.example.db"; + primaries { 10.53.0.1; }; +}; + +zone "catalog2.example" { + type secondary; + file "catalog2.example.db"; + primaries { 10.53.0.3; }; +}; + +zone "catalog3.example" { + type secondary; + file "catalog3.example.db"; + primaries { 10.53.0.1; }; +}; + +zone "catalog4.example" { + type secondary; + file "catalog4.example.db"; + primaries { 10.53.0.1; }; +}; + +key tsig_key. { + secret "LSAnCU+Z"; + algorithm hmac-md5; +}; diff --git a/bin/tests/system/catz/setup.sh b/bin/tests/system/catz/setup.sh index 960cffe9a7..e23ea4f058 100644 --- a/bin/tests/system/catz/setup.sh +++ b/bin/tests/system/catz/setup.sh @@ -15,7 +15,7 @@ SYSTEMTESTTOP=.. $SHELL clean.sh copy_setports ns1/named.conf.in ns1/named.conf -copy_setports ns2/named.conf.in ns2/named.conf +copy_setports ns2/named1.conf.in ns2/named.conf copy_setports ns3/named.conf.in ns3/named.conf cp -f ns1/catalog.example.db.in ns1/catalog1.example.db diff --git a/bin/tests/system/catz/tests.sh b/bin/tests/system/catz/tests.sh index c443b739ff..cd2084e59a 100644 --- a/bin/tests/system/catz/tests.sh +++ b/bin/tests/system/catz/tests.sh @@ -1179,7 +1179,7 @@ status=$((status+ret)) n=$((n+1)) echo_i "reconfiguring secondary - adding catalog4 catalog zone ($n)" ret=0 -sed -e "s/^#T1//g" < ns2/named.conf.in > ns2/named.conf.tmp +sed -e "s/^#T1//g" < ns2/named1.conf.in > ns2/named.conf.tmp copy_setports ns2/named.conf.tmp ns2/named.conf rndccmd 10.53.0.2 reconfig || ret=1 if [ $ret -ne 0 ]; then echo_i "failed"; fi @@ -1210,7 +1210,7 @@ status=$((status+ret)) n=$((n+1)) echo_i "reconfiguring secondary - removing catalog4 catalog zone, adding non-existent catalog5 catalog zone ($n)" ret=0 -sed -e "s/^#T2//" < ns2/named.conf.in > ns2/named.conf.tmp +sed -e "s/^#T2//" < ns2/named1.conf.in > ns2/named.conf.tmp copy_setports ns2/named.conf.tmp ns2/named.conf $RNDC -c ../common/rndc.conf -s 10.53.0.2 -p 9953 reconfig > /dev/null 2>&1 && ret=1 if [ $ret -ne 0 ]; then echo_i "failed"; fi @@ -1219,7 +1219,7 @@ status=$((status+ret)) n=$((n+1)) echo_i "reconfiguring secondary - removing non-existent catalog5 catalog zone ($n)" ret=0 -copy_setports ns2/named.conf.in ns2/named.conf +copy_setports ns2/named1.conf.in ns2/named.conf rndccmd 10.53.0.2 reconfig || ret=1 if [ $ret -ne 0 ]; then echo_i "failed"; fi status=$((status+ret)) @@ -1730,5 +1730,15 @@ wait_for_no_soa @10.53.0.2 dom16.example. dig.out.test$n || ret=1 if [ $ret -ne 0 ]; then echo_i "failed"; fi status=$((status+ret)) +n=$((n+1)) +echo_i "checking that reconfig can delete and restore catalog zone configuration ($n)" +ret=0 +copy_setports ns2/named2.conf.in ns2/named.conf +rndccmd 10.53.0.2 reconfig || ret=1 +copy_setports ns2/named1.conf.in ns2/named.conf +rndccmd 10.53.0.2 reconfig || ret=1 +if [ $ret -ne 0 ]; then echo_i "failed"; fi +status=$((status+ret)) + echo_i "exit status: $status" [ $status -eq 0 ] || exit 1