Commit 8d73a03179 for bind
commit 8d73a031790b5f83e3d4cbb2c7303d4ff4cc8cb7
Author: Nicki Křížek <nicki@isc.org>
Date: Wed Oct 14 18:00:00 2026 +0000
Test a CD=1 answer arriving after a validated NODATA was cached
A non-validating fetch is still in flight when a CD=0 query for the
same name caches the validated NODATA. The fetch then brings unsigned
positive data of lower trust into the cache, with as many records as
the negative entry has. The resolver must keep the negative entry and
answer the CD=1 client from it.
Assisted-by: Claude:claude-mythos-5-1
diff --git a/bin/tests/system/ncache/ans1/ans.py b/bin/tests/system/ncache/ans1/ans.py
new file mode 100644
index 0000000000..f5ea0f5830
--- /dev/null
+++ b/bin/tests/system/ncache/ans1/ans.py
@@ -0,0 +1,94 @@
+# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+#
+# SPDX-License-Identifier: MPL-2.0
+#
+# 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 https://mozilla.org/MPL/2.0/.
+#
+# See the COPYRIGHT file distributed with this work for additional
+# information regarding copyright ownership.
+
+from collections.abc import AsyncGenerator
+
+import asyncio
+
+import dns.flags
+import dns.rcode
+import dns.rdatatype
+import dns.rrset
+
+from isctest.asyncserver import (
+ ControlCommand,
+ ControllableAsyncDnsServer,
+ QueryContext,
+ ResponseAction,
+)
+from isctest.asyncserver.handlers import StaticResponseHandler
+from isctest.asyncserver.matchers import Matcher, Qname, Qtype
+
+NAME = "nodata.example."
+
+RELEASE = asyncio.Event()
+
+
+class CdFlag(Matcher):
+ """
+ Match queries with the CD flag set.
+ """
+
+ def match(self, qctx: QueryContext) -> bool:
+ return bool(qctx.query.flags & dns.flags.CD)
+
+
+class HeldAddressHandler(StaticResponseHandler):
+ """
+ Answer a CD=1 A query for nodata.example with unsigned addresses, but
+ only once the "release._control." command has been received. CD=0
+ queries are not matched and get the zone's signed NODATA response.
+
+ The RRset has as many records as the negative cache entry built from
+ that NODATA response (SOA, NSEC and their RRSIGs), so that a cache
+ comparing the two does not stop at the record count.
+ """
+
+ matcher = Qname(NAME) & Qtype(dns.rdatatype.A) & CdFlag()
+ rcode = dns.rcode.NOERROR
+ answer = [
+ dns.rrset.from_text(
+ NAME, 300, "IN", "A", "192.0.2.1", "192.0.2.2", "192.0.2.3", "192.0.2.4"
+ )
+ ]
+ authoritative = True
+
+ async def get_responses(
+ self, qctx: QueryContext
+ ) -> AsyncGenerator[ResponseAction, None]:
+ await RELEASE.wait()
+ async for action in super().get_responses(qctx):
+ yield action
+
+
+class ReleaseCommand(ControlCommand):
+ """
+ Release the answers held by HeldAddressHandler.
+ """
+
+ control_subdomain = "release"
+
+ def handle(
+ self, args: list[str], server: ControllableAsyncDnsServer, qctx: QueryContext
+ ) -> str | None:
+ RELEASE.set()
+ return "released"
+
+
+def main() -> None:
+ server = ControllableAsyncDnsServer()
+ server.install_response_handler(HeldAddressHandler())
+ server.install_control_command(ReleaseCommand())
+ server.run()
+
+
+if __name__ == "__main__":
+ main()
diff --git a/bin/tests/system/ncache/ans1/zones/example.db.j2.manual b/bin/tests/system/ncache/ans1/zones/example.db.j2.manual
new file mode 100644
index 0000000000..1f3aaf1f88
--- /dev/null
+++ b/bin/tests/system/ncache/ans1/zones/example.db.j2.manual
@@ -0,0 +1,3 @@
+{% include "_common/zones/template.db.j2.manual" %}
+
+nodata TXT "no address record here"
diff --git a/bin/tests/system/ncache/ns2/named.conf.j2 b/bin/tests/system/ncache/ns2/named.conf.j2
new file mode 100644
index 0000000000..43d74137b7
--- /dev/null
+++ b/bin/tests/system/ncache/ns2/named.conf.j2
@@ -0,0 +1,17 @@
+// validating resolver
+
+options {
+ {% include_indented "_common/options.conf.j2" %}
+ dnssec-validation yes;
+};
+
+{% include "_common/controls.conf.j2" %}
+
+{% include "_common/root.hint.conf" %}
+
+zone "example" {
+ type static-stub;
+ server-addresses { 10.53.0.1; };
+};
+
+{% include "_common/trusted.conf.j2" %}
diff --git a/bin/tests/system/ncache/tests_ncache_cd.py b/bin/tests/system/ncache/tests_ncache_cd.py
new file mode 100644
index 0000000000..799902f03c
--- /dev/null
+++ b/bin/tests/system/ncache/tests_ncache_cd.py
@@ -0,0 +1,75 @@
+# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+#
+# SPDX-License-Identifier: MPL-2.0
+#
+# 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 https://mozilla.org/MPL/2.0/.
+#
+# See the COPYRIGHT file distributed with this work for additional
+# information regarding copyright ownership.
+
+import concurrent.futures
+
+import pytest
+
+import isctest
+import isctest.template
+import isctest.zone
+
+NAME = "nodata.example."
+
+pytestmark = pytest.mark.extra_artifacts(
+ [
+ "ans*/dsset-*",
+ "ans*/keys/",
+ "ans*/zones/*.db",
+ "ans*/zones/*.db.signed",
+ ]
+)
+
+
+def bootstrap():
+ zone = isctest.zone.Zone("example.", isctest.template.ANS1, signed=True)
+ zone.configure(csk=True)
+ return {"trust_anchors": zone.trust_anchors()}
+
+
+def test_late_cd_answer_meets_cached_nodata(ans1, ns2):
+ """
+ ans1 serves a signed zone in which nodata.example has no A record. A
+ CD=1 client query starts a non-validating fetch on ns2, which ans1
+ holds; meanwhile a CD=0 query for the same name gets the validated
+ NODATA cached. ans1 then answers the held fetch with an unsigned
+ address, which ns2 must discard in favour of the higher-trust negative
+ entry it already holds.
+ """
+ # Cache the zone's DNSKEY so that the NODATA below is validated, and
+ # therefore cached, as soon as it arrives.
+ msg = isctest.query.create("example.", "DNSKEY")
+ res = isctest.query.udp(msg, ns2.ip)
+ isctest.check.noerror(res)
+ isctest.check.adflag(res)
+
+ with concurrent.futures.ThreadPoolExecutor(max_workers=1) as pool:
+ with ans1.watch_log_from_here() as watcher:
+ # TCP, so that ns2 going away closes the connection and
+ # fails the query at once instead of after the UDP retries.
+ msg = isctest.query.create(NAME, "A", cd=True)
+ pending = pool.submit(isctest.query.tcp, msg, ns2.ip)
+ watcher.wait_for_line(f"Received {NAME.rstrip('.')}/IN/A ")
+
+ msg = isctest.query.create(NAME, "A")
+ res = isctest.query.udp(msg, ns2.ip)
+ isctest.check.noerror(res)
+ isctest.check.adflag(res)
+ isctest.check.empty_answer(res)
+
+ msg = isctest.query.create("release._control.", "TXT")
+ res = isctest.query.udp(msg, ans1.ip)
+ isctest.check.noerror(res)
+
+ res = pending.result()
+
+ isctest.check.noerror(res)
+ isctest.check.empty_answer(res)