Commit fce5bf80f3 for bind
commit fce5bf80f3a236f372eba10ac8bb96546658662c
Author: OndÅ™ej Surý <ondrej@isc.org>
Date: Tue Nov 3 16:13:01 2026 +0100
Refuse recursive ANY queries
A resolver cannot answer an ANY query without sending ANY upstream,
which exposes it to the attacks that abuse that type; answering from
whatever happens to be cached instead makes the response depend on
the cache state. Refuse recursive ANY queries that cannot be answered
from authoritative data, regardless of cache contents, with EDE 21
when EDNS is used.
Authoritative answers are unchanged, and non-recursive ANY queries are
still answered from the cache so that it can be inspected with
"dig +norecurse". Reject meta-type fetches at the resolver and client
APIs and remove their unreachable ANY handling.
Assisted-by: Claude:claude-fable-5-2
diff --git a/bin/delv/delv.rst b/bin/delv/delv.rst
index bad376b046..cf41e4d600 100644
--- a/bin/delv/delv.rst
+++ b/bin/delv/delv.rst
@@ -93,9 +93,10 @@ where:
.. option:: type
- indicates what type of query is required - ANY, A, MX, etc.
- ``type`` can be any valid query type. If no ``type`` argument is
- supplied, :program:`delv` performs a lookup for an A record.
+ indicates the type to request - A, AAAA, MX, etc. ``type`` can be
+ any valid DNS query type, excluding RRSIG and meta types such as ANY. If
+ no ``type`` argument is supplied, :program:`delv` performs a lookup for
+ an A record.
Options
~~~~~~~
diff --git a/bin/dig/dig.c b/bin/dig/dig.c
index 665c9697b7..b208f1ffc6 100644
--- a/bin/dig/dig.c
+++ b/bin/dig/dig.c
@@ -2123,6 +2123,7 @@ plus_option(char *option, bool is_batchfile, bool *need_clone,
if (state) {
lookup->trace_root = true;
lookup->recurse = true;
+ lookup->recurse_set = true;
lookup->identify = true;
lookup->stats = false;
lookup->comments = false;
@@ -2251,12 +2252,14 @@ plus_option(char *option, bool is_batchfile, bool *need_clone,
case 'd': /* rdflag */
FULLCHECK("rdflag");
lookup->recurse = state;
+ lookup->recurse_set = true;
break;
case 'e':
switch (cmd[2]) {
case 'c': /* recurse */
FULLCHECK("recurse");
lookup->recurse = state;
+ lookup->recurse_set = true;
break;
case 't': /* retry / retries */
FULLCHECK2("retry", "retries");
@@ -2495,6 +2498,7 @@ plus_option(char *option, bool is_batchfile, bool *need_clone,
lookup->trace_root = state;
if (state) {
lookup->recurse = true;
+ lookup->recurse_set = true;
lookup->identify = true;
lookup->comments = false;
lookup->rrcomments = 0;
@@ -2630,6 +2634,27 @@ exit_or_usage:
#endif /* if !TARGET_OS_IPHONE */
}
+static void
+adjust_lookup_for_rdtype(dns_rdatatype_t rdtype, bool config_only,
+ dig_lookup_t *lookup) {
+ lookup->rdtype = rdtype;
+ if (!config_only) {
+ lookup->rdtypeset = true;
+ }
+ if (rdtype == dns_rdatatype_axfr) {
+ lookup->section_question = plusquest;
+ lookup->comments = pluscomm;
+ } else if (rdtype == dns_rdatatype_any) {
+ if (!lookup->tcp_mode_set) {
+ lookup->tcp_mode = true;
+ }
+ if (!lookup->recurse_set) {
+ lookup->recurse = false;
+ }
+ }
+ lookup->ixfr_serial = false;
+}
+
/*%
* #true returned if value was used
*/
@@ -2854,19 +2879,8 @@ dash_option(char *option, char *next, dig_lookup_t **lookup,
(*lookup)->tcp_mode = true;
}
} else {
- (*lookup)->rdtype = rdtype;
- if (!config_only) {
- (*lookup)->rdtypeset = true;
- }
- if (rdtype == dns_rdatatype_axfr) {
- (*lookup)->section_question = plusquest;
- (*lookup)->comments = pluscomm;
- } else if (rdtype == dns_rdatatype_any) {
- if (!(*lookup)->tcp_mode_set) {
- (*lookup)->tcp_mode = true;
- }
- }
- (*lookup)->ixfr_serial = false;
+ adjust_lookup_for_rdtype(rdtype, config_only,
+ *lookup);
}
} else {
fprintf(stderr,
@@ -3224,23 +3238,8 @@ parse_args(bool is_batchfile, bool config_only, int argc, char **argv) {
lookup->tcp_mode = true;
}
} else {
- lookup->rdtype = rdtype;
- lookup->rdtypeset = true;
- if (rdtype ==
- dns_rdatatype_axfr)
- {
- lookup->section_question =
- plusquest;
- lookup->comments =
- pluscomm;
- }
- if (rdtype ==
- dns_rdatatype_any &&
- !lookup->tcp_mode_set)
- {
- lookup->tcp_mode = true;
- }
- lookup->ixfr_serial = false;
+ adjust_lookup_for_rdtype(
+ rdtype, false, lookup);
}
continue;
}
diff --git a/bin/dig/dig.rst b/bin/dig/dig.rst
index c57d47ab3c..92a8df5964 100644
--- a/bin/dig/dig.rst
+++ b/bin/dig/dig.rst
@@ -93,9 +93,9 @@ where:
.. option:: type
- indicates what type of query is required - ANY, A, MX, SIG, etc.
- ``type`` can be any valid query type. If no ``type`` argument is
- supplied, :program:`dig` performs a lookup for an A record.
+ indicates the type to request - ANY, A, AAAA, MX, etc. ``type`` can be
+ any valid query type. If no ``type`` argument is supplied,
+ :program:`dig` performs a lookup for an A record.
Options
~~~~~~~
@@ -590,8 +590,9 @@ abbreviation is unambiguous; for example, :option:`+cd` is equivalent to
This option toggles the setting of the RD (recursion desired) bit in the query.
This bit is set by default, which means :program:`dig` normally sends
- recursive queries. Recursion is automatically disabled when the
- :option:`+nssearch` or :option:`+trace` query option is used.
+ recursive queries, unless a type ANY query is requested, in which
+ case the default is not to set it. Recursion is automatically disabled
+ when the :option:`+nssearch` or :option:`+trace` query option is used.
.. option:: +retry=T
@@ -688,10 +689,11 @@ abbreviation is unambiguous; for example, :option:`+cd` is equivalent to
.. option:: +tcp, +notcp
This option indicates whether to use TCP when querying name
- servers. The default behavior is to use UDP unless a type ``any``
- or ``ixfr=N`` query is requested, in which case the default is
- TCP. AXFR queries always use TCP. To prevent retry over TCP when
- TC=1 is returned from a UDP query, use ``+ignore``.
+ servers. The default behavior is to use UDP unless a type ANY
+ or ``ixfr=N`` query is requested. AXFR queries always use TCP;
+ ANY queries use TCP unless this is specifically overridden. To
+ prevent retry over TCP when TC=1 is returned from a UDP query,
+ use ``+ignore``.
.. option:: +timeout=T
diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c
index 1c7f144411..faf097895d 100644
--- a/bin/dig/dighost.c
+++ b/bin/dig/dighost.c
@@ -757,6 +757,7 @@ clone_lookup(dig_lookup_t *lookold, bool servers) {
looknew->edns = lookold->edns;
looknew->original_edns = lookold->original_edns;
looknew->recurse = lookold->recurse;
+ looknew->recurse_set = lookold->recurse_set;
looknew->aaonly = lookold->aaonly;
looknew->adflag = lookold->adflag;
looknew->cdflag = lookold->cdflag;
diff --git a/bin/dig/dighost.h b/bin/dig/dighost.h
index 6213b236f9..1cf9d49c68 100644
--- a/bin/dig/dighost.h
+++ b/bin/dig/dighost.h
@@ -103,27 +103,71 @@ typedef struct dig_searchlist dig_searchlist_t;
struct dig_lookup {
unsigned int magic;
isc_refcount_t references;
- bool aaonly, adflag, badcookie, besteffort, cdflag, cleared, coflag,
- comments, dns64prefix, deflag, dnssec, doing_xfr, done_as_is,
- ednsneg, expandaaaa, svcparamkeycompat, expire, fuzzing,
- header_only, identify, /*%< Append "on server <foo>" message */
- identify_previous_line, /*% Prepend a "Nameserver <foo>:"
- message, with newline and tab */
- idnin, idnout, ignore, multiline, need_search, new_search,
- noclass, nocrypto, nottl, ns_search_only, /*%< dig +nssearch,
- host -C */
- ns_search_success, nsid, /*% Name Server ID (RFC 5001) */
- onesoa, pending, /*%< Pending a successful answer */
- print_unknown_format, qr, raflag, recurse, section_additional,
- section_answer, section_authority, section_question,
- seenbadcookie, sendcookie, servfail_stops,
- setqid, /*% use a speciied query ID */
- showbadcookie, showbadvers, showtruncated, stats, tcflag,
- tcp_keepalive, tcp_mode, tcp_mode_set, tls_mode, /*% connect
- using TLS */
- trace, /*% dig +trace */
- trace_root, /*% initial query for either +trace or +nssearch */
- ttlunits, use_usec, waiting_connect, zflag, zoneversion;
+ bool aaonly;
+ bool adflag;
+ bool badcookie;
+ bool besteffort;
+ bool cdflag;
+ bool cleared;
+ bool coflag;
+ bool comments;
+ bool dns64prefix;
+ bool deflag;
+ bool dnssec;
+ bool doing_xfr;
+ bool done_as_is;
+ bool ednsneg;
+ bool expandaaaa;
+ bool svcparamkeycompat;
+ bool expire;
+ bool fuzzing;
+ bool header_only;
+ bool identify; /*%< Append "on server <foo>" message */
+ bool identify_previous_line; /*% Prepend a "Nameserver <foo>:" message,
+ with newline and tab */
+ bool idnin;
+ bool idnout;
+ bool ignore;
+ bool multiline;
+ bool need_search;
+ bool new_search;
+ bool noclass;
+ bool nocrypto;
+ bool nottl;
+ bool ns_search_only; /*%< dig +nssearch, host -C */
+ bool ns_search_success;
+ bool nsid; /*% Name Server ID (RFC 5001) */
+ bool onesoa;
+ bool pending; /*%< Pending a successful answer */
+ bool print_unknown_format;
+ bool qr;
+ bool raflag;
+ bool recurse;
+ bool recurse_set;
+ bool section_additional;
+ bool section_answer;
+ bool section_authority;
+ bool section_question;
+ bool seenbadcookie;
+ bool sendcookie;
+ bool servfail_stops;
+ bool setqid; /*% use a speciied query ID */
+ bool showbadcookie;
+ bool showbadvers;
+ bool showtruncated;
+ bool stats;
+ bool tcflag;
+ bool tcp_keepalive;
+ bool tcp_mode;
+ bool tcp_mode_set;
+ bool tls_mode; /*% connect using TLS */
+ bool trace; /*% dig +trace */
+ bool trace_root; /*% initial query for either +trace or +nssearch */
+ bool ttlunits;
+ bool use_usec;
+ bool waiting_connect;
+ bool zflag;
+ bool zoneversion;
char textname[MXNAME]; /*% Name we're going to be looking up */
char cmdline[MXNAME];
dns_rdatatype_t rdtype;
diff --git a/bin/dig/host.rst b/bin/dig/host.rst
index 198e3b611c..dfd7ca72e3 100644
--- a/bin/dig/host.rst
+++ b/bin/dig/host.rst
@@ -51,12 +51,15 @@ Options
.. option:: -a
- The :option:`-a` ("all") option is equivalent to :option:`-v` :option:`-t ANY <-t>`.
+ The :option:`-a` ("all") option is equivalent to :option:`-v`
+ :option:`-t ANY <-t>`. (Note that many name servers, including
+ ``named``, refuse to answer type-ANY queries recursively.)
.. option:: -A
- The :option:`-A` ("almost all") option is equivalent to :option:`-a`, except that RRSIG,
- NSEC, and NSEC3 records are omitted from the output.
+ The :option:`-A` ("almost all") option is equivalent to :option:`-a`,
+ except that RRSIG, NSEC, and NSEC3 records are omitted from the output,
+ if any.
.. option:: -c class
@@ -135,7 +138,7 @@ Options
This option specifies TCP or UDP. By default, :program:`host` uses UDP when making queries; the
:option:`-T` option makes it use a TCP connection when querying the name
server. TCP is automatically selected for queries that require
- it, such as zone transfer (AXFR) requests. Type ``ANY`` queries default
+ it, such as zone transfer (AXFR) requests. Type ANY queries default
to TCP, but can be forced to use UDP initially via :option:`-U`.
.. option:: -m flag
diff --git a/bin/tests/system/additional/tests.sh b/bin/tests/system/additional/tests.sh
index 3a69d78451..792ad6345c 100644
--- a/bin/tests/system/additional/tests.sh
+++ b/bin/tests/system/additional/tests.sh
@@ -383,13 +383,12 @@ if [ $ret -eq 1 ]; then
fi
n=$((n + 1))
-echo_i "testing NS handling in ANY responses (recursive) ($n)"
+echo_i "testing REFUSED response to ANY queries (recursive) ($n)"
ret=0
-# pre-cache the address record
-$DIG $DIGOPTS -t A ns1.rt.example @10.53.0.3 >/dev/null || ret=1
-$DIG $DIGOPTS -t ANY rt.example @10.53.0.3 >dig.out.$n || ret=1
-grep "AUTHORITY: 0" dig.out.$n >/dev/null || ret=1
-grep "NS[ ]*ns" dig.out.$n >/dev/null || ret=1
+$DIG $DIGOPTS -t ANY +rec rt.example @10.53.0.3 >dig.out.$n || ret=1
+grep "status: REFUSED" dig.out.$n >/dev/null || ret=1
+grep "ANSWER: 0, AUTHORITY: 0," dig.out.$n >/dev/null || ret=1
+grep "EDE: 21" dig.out.$n >/dev/null || ret=1
if [ $ret -eq 1 ]; then
echo_i "failed"
status=$((status + 1))
diff --git a/bin/tests/system/auth/tests.sh b/bin/tests/system/auth/tests.sh
index b0aef293d5..1af44f4557 100644
--- a/bin/tests/system/auth/tests.sh
+++ b/bin/tests/system/auth/tests.sh
@@ -143,7 +143,7 @@ status=$((status + ret))
n=$((n + 1))
echo_i "check that in-zone CNAME records does not return target data when QTYPE is ANY (rd=1/ra=1) ($n)"
ret=0
-$DIG $DIGOPTS @10.53.0.2 -t any inzone.example.com >dig.out.test$n || ret=1
+$DIG $DIGOPTS +rec @10.53.0.2 -t any inzone.example.com >dig.out.test$n || ret=1
grep 'ANSWER: 1,' dig.out.test$n >/dev/null || ret=1
grep 'flags: qr aa rd ra;' dig.out.test$n >/dev/null || ret=1
grep 'inzone\.example\.com\..*CNAME.a\.example\.com\.' dig.out.test$n >/dev/null || ret=1
@@ -167,7 +167,7 @@ status=$((status + ret))
n=$((n + 1))
echo_i "check that in-zone DNAME records does not return target data when QTYPE is ANY (rd=1/ra=1) ($n)"
ret=0
-$DIG $DIGOPTS @10.53.0.2 -t any inzone.dname.example.com >dig.out.test$n || ret=1
+$DIG $DIGOPTS +rec @10.53.0.2 -t any inzone.dname.example.com >dig.out.test$n || ret=1
grep 'ANSWER: 2,' dig.out.test$n >/dev/null || ret=1
grep 'flags: qr aa rd ra;' dig.out.test$n >/dev/null || ret=1
grep 'dname\.example\.com\..*DNAME.example\.com\.' dig.out.test$n >/dev/null || ret=1
diff --git a/bin/tests/system/chain/tests.sh b/bin/tests/system/chain/tests.sh
index 2917049afa..71cd600587 100644
--- a/bin/tests/system/chain/tests.sh
+++ b/bin/tests/system/chain/tests.sh
@@ -614,12 +614,13 @@ if [ $ret != 0 ]; then echo_i "failed"; fi
status=$((status + ret))
n=$((n + 1))
-echo_i "checking DNAME via ANY query ($n)"
+echo_i "checking ANY query is refused ($n)"
ret=0
$RNDCCMD 10.53.0.7 null --- start test$n --- 2>&1 | sed 's/^/ns7 /' | cat_i
$RNDCCMD 10.53.0.7 flush 2>&1 | sed 's/^/ns7 /' | cat_i
-$DIG $DIGOPTS @10.53.0.7 any short-dname.example >dig.out.7.$n 2>&1
-grep 'status: NOERROR' dig.out.7.$n >/dev/null 2>&1 || ret=1
+$DIG $DIGOPTS +rec @10.53.0.7 any short-dname.example >dig.out.7.$n 2>&1
+grep 'status: REFUSED' dig.out.7.$n >/dev/null 2>&1 || ret=1
+grep 'ANSWER: 0' dig.out.7.$n >/dev/null 2>&1 || ret=1
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$((status + ret))
diff --git a/bin/tests/system/digdelv/tests_dig.py b/bin/tests/system/digdelv/tests_dig.py
index 7f4f8e105d..0a58c8b190 100644
--- a/bin/tests/system/digdelv/tests_dig.py
+++ b/bin/tests/system/digdelv/tests_dig.py
@@ -1211,11 +1211,11 @@ def test_source_address_both_families_no_crash(dig, ns1):
assert result.rc >= 0
-def test_yaml_any_output(dig, ns3):
+def test_yaml_any_output(dig, ns2):
"""
Check the structure of dig +yaml output for an ANY query.
"""
- result = dig(f"+qr +yaml @{ns3.ip} any ns2.example")
+ result = dig(f"+qr +yaml @{ns2.ip} any ns2.example")
messages = parse_yaml(result.out)
query = messages[0]["message"]["query_message_data"]
assert query["status"] == "NOERROR"
@@ -1224,6 +1224,27 @@ def test_yaml_any_output(dig, ns3):
assert response["QUESTION_SECTION"][0] == "ns2.example. IN ANY"
+@pytest.mark.parametrize(
+ "args,recursive",
+ [
+ ("any ns2.example", False),
+ ("-t any ns2.example", False),
+ ("+rec any ns2.example", True),
+ ("any ns2.example +rd", True),
+ ("-t any +recurse ns2.example", True),
+ ("a ns2.example", True),
+ ],
+)
+def test_any_norecurse_by_default(dig, ns2, args, recursive):
+ """
+ Check that dig does not set the RD bit in ANY queries unless it is
+ asked to; resolvers refuse recursive ANY queries.
+ """
+ result = dig(f"+qr +yaml @{ns2.ip} {args}")
+ query = parse_yaml(result.out)[0]["message"]["query_message_data"]
+ assert ("rd" in (query["flags"] or "").split()) == recursive, result.out
+
+
def test_yaml_ipv6_trailing_zeroes(dig, ns3):
"""
Check dig +yaml output of an IPv6 address ending in zeroes.
diff --git a/bin/tests/system/digdelv/tests_digdelv_delv.py b/bin/tests/system/digdelv/tests_digdelv_delv.py
index 88d2de672a..bd3705b88f 100644
--- a/bin/tests/system/digdelv/tests_digdelv_delv.py
+++ b/bin/tests/system/digdelv/tests_digdelv_delv.py
@@ -246,12 +246,11 @@ def test_q_m(delv, ns3):
def test_any_query(delv, ns3):
"""
- Check that delv -t ANY works.
+ Check that delv -t ANY fails; meta-type queries are never sent.
"""
result = delv(f"@{ns3.ip} -t ANY example")
- assert Re(r"^example\.") in result.out
- assert check_ttl_range(result.out, "NS", 300)
- assert check_ttl_range(result.out, "SOA", 300)
+ assert ";; resolution failed: REFUSED" in result.err
+ assert Re(r"^example\.") not in result.out
def test_rrsig_query(delv, ns3):
@@ -302,7 +301,7 @@ def test_yaml_any(delv, ns3):
"""
Check the structure of delv +yaml output.
"""
- result = delv(f"+yaml @{ns3.ip} any ns2.example")
+ result = delv(f"+yaml @{ns3.ip} a ns2.example")
data = parse_yaml(result.out)
assert data["status"] == "success"
assert data["query_name"] == "ns2.example"
diff --git a/bin/tests/system/digdelv/tests_mdig.py b/bin/tests/system/digdelv/tests_mdig.py
index b5c74b7aba..3647a6a8d4 100644
--- a/bin/tests/system/digdelv/tests_mdig.py
+++ b/bin/tests/system/digdelv/tests_mdig.py
@@ -84,11 +84,42 @@ def test_soa_norrcomments(mdig, ns3):
assert "; serial" not in result.out
-def test_yaml_output(mdig, ns3):
+def test_yaml_output(mdig, ns2):
"""
Check the structure of mdig +yaml output.
"""
- result = mdig(f"+yaml @{ns3.ip} -t any ns2.example")
+ result = mdig(f"+yaml @{ns2.ip} -t any ns2.example")
response = parse_yaml(result.out)[0]["message"]["response_message_data"]
assert response["status"] == "NOERROR"
assert response["QUESTION_SECTION"][0] == "ns2.example. IN ANY"
+
+
+@pytest.mark.parametrize(
+ "args,protocol,recursive",
+ [
+ ("-t any ns2.example", "TCP", False),
+ ("+recurse -t any ns2.example", "TCP", True),
+ ("+notcp -t any ns2.example", "UDP", False),
+ ("-t a ns2.example", "UDP", True),
+ ("-t any ns2.example -t a ns2.example", "TCP", None),
+ ],
+)
+def test_any_defaults(mdig, ns2, args, protocol, recursive):
+ """
+ Check that mdig sends ANY queries over TCP and without the RD bit
+ unless it is asked to do otherwise. The transport is shared by all
+ the queries, RD is set per query.
+ """
+ result = mdig(f"+yaml @{ns2.ip} {args}")
+ messages = [entry["message"] for entry in parse_yaml(result.out)]
+ for message in messages:
+ assert message["socket_protocol"] == protocol, result.out
+ rd = {}
+ for message in messages:
+ response = message["response_message_data"]
+ qtype = response["QUESTION_SECTION"][0].split()[-1]
+ rd[qtype] = "rd" in (response["flags"] or "").split()
+ if recursive is None:
+ assert rd == {"ANY": False, "A": True}, result.out
+ else:
+ assert list(rd.values()) == [recursive], result.out
diff --git a/bin/tests/system/dnssec/tests_validation.py b/bin/tests/system/dnssec/tests_validation.py
index e9699c51b8..adbf12a72a 100644
--- a/bin/tests/system/dnssec/tests_validation.py
+++ b/bin/tests/system/dnssec/tests_validation.py
@@ -92,6 +92,17 @@ def test_rrsig_query_formerr(transport, use_edns, dnssec):
isctest.check.ede(res, 30)
+def test_any_query_refused():
+ # a resolver refuses ANY queries with EDE 21 (Not Supported),
+ # with or without DNSSEC requested
+ for do in (False, True):
+ msg = isctest.query.create("foo.example", "ANY", dnssec=do)
+ res = isctest.query.tcp(msg, "10.53.0.4")
+ isctest.check.refused(res)
+ isctest.check.empty_answer(res)
+ isctest.check.ede(res, EDECode.NOT_SUPPORTED)
+
+
def test_adflag():
# compare auth and recursive answers
msg = isctest.query.create("a.example", "A", dnssec=False)
@@ -230,13 +241,16 @@ def answer_has(r, rdtype):
def test_chain_validation():
- # check validation of ANY response
+ # The authoritative server (ns2) answers ANY, while the resolver
+ # (ns4) refuses the query.
msg = isctest.query.create("foo.example", "ANY")
res1 = isctest.query.tcp(msg, "10.53.0.2")
res2 = isctest.query.tcp(msg, "10.53.0.4")
- isctest.check.same_answer(res1, res2)
- isctest.check.noerror(res2)
- isctest.check.rr_count_eq(res2.answer, 6) # 2 records, 1 NSEC, 3 RRSIGs
+ isctest.check.noerror(res1)
+ isctest.check.rr_count_eq(res1.answer, 6) # 2 records, 1 NSEC, 3 RRSIGs
+ isctest.check.refused(res2)
+ isctest.check.empty_answer(res2)
+ isctest.check.ede(res2, EDECode.NOT_SUPPORTED)
# check validation of CNAME response
msg = isctest.query.create("cname1.example", "TXT")
@@ -254,21 +268,24 @@ def test_chain_validation():
isctest.check.noerror(res2)
isctest.check.rr_count_eq(res2.answer, 5) # DNAME, TXT, 2 RRSIGs, synth CNAME
- # check validation of CNAME response to ANY query
+ # check CNAME response to ANY query; the resolver does not even
+ # look the name up and refuses the query
msg = isctest.query.create("cname2.example", "ANY")
res1 = isctest.query.tcp(msg, "10.53.0.2")
res2 = isctest.query.tcp(msg, "10.53.0.4")
- isctest.check.same_answer(res1, res2)
- isctest.check.noerror(res2)
- isctest.check.rr_count_eq(res2.answer, 4) # CNAME, NSEC, 2 RRSIGs
+ isctest.check.noerror(res1)
+ isctest.check.rr_count_eq(res1.answer, 4) # CNAME, NSEC, 2 RRSIGs
+ isctest.check.refused(res2)
+ isctest.check.empty_answer(res2)
- # check validation of DNAME response to ANY query
+ # check DNAME response to ANY query
msg = isctest.query.create("foo.dname2.example", "ANY")
res1 = isctest.query.tcp(msg, "10.53.0.2")
res2 = isctest.query.tcp(msg, "10.53.0.4")
- isctest.check.same_answer(res1, res2)
- isctest.check.noerror(res2)
- isctest.check.rr_count_eq(res2.answer, 3) # DNAME, RSRIG, synth CNAME
+ isctest.check.noerror(res1)
+ isctest.check.rr_count_eq(res1.answer, 3) # DNAME, RRSIG, synth CNAME
+ isctest.check.refused(res2)
+ isctest.check.empty_answer(res2)
# check bad CNAME signature is caught after +CD query
msg = isctest.query.create("bad-cname.example", "A", dnssec=False, cd=True)
@@ -1415,12 +1432,14 @@ def test_cd_any(ns4):
msg = isctest.query.create("a.secure.example", "AAAA", cd=1)
isctest.query.tcp(msg, "10.53.0.4")
- msg = isctest.query.create("a.secure.example", "ANY", cd=1)
+ # recursive ANY queries are refused; inspect the cache with
+ # non-recursive ones instead
+ msg = isctest.query.create("a.secure.example", "ANY", cd=1, rd=False)
res = isctest.query.tcp(msg, "10.53.0.4")
isctest.check.rr_count_eq(res.answer, 4)
isctest.check.noadflag(res)
- msg = isctest.query.create("a.secure.example", "ANY")
+ msg = isctest.query.create("a.secure.example", "ANY", rd=False)
res = isctest.query.tcp(msg, "10.53.0.4")
isctest.check.rr_count_eq(res.answer, 2)
isctest.check.adflag(res)
diff --git a/bin/tests/system/mirror/tests.sh b/bin/tests/system/mirror/tests.sh
index 8381f59718..f7ab79e546 100644
--- a/bin/tests/system/mirror/tests.sh
+++ b/bin/tests/system/mirror/tests.sh
@@ -354,6 +354,19 @@ grep "flags:.* ad" dig.out.ns3.test$n >/dev/null || ret=1
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$((status + ret))
+n=$((n + 1))
+echo_i "checking that an ANY query at a mirror zone apex is refused ($n)"
+ret=0
+$DIG $DIGOPTS +rec @10.53.0.3 . ANY >dig.out.ns3.test$n 2>&1 || ret=1
+# Mirror zone data is served non-authoritatively, so an ANY query must
+# be refused like on any other resolver, not answered from the zone.
+grep "status: REFUSED" dig.out.ns3.test$n >/dev/null || ret=1
+grep "ANSWER: 0" dig.out.ns3.test$n >/dev/null || ret=1
+grep "EDE: 21" dig.out.ns3.test$n >/dev/null || ret=1
+grep "flags:.* aa" dig.out.ns3.test$n >/dev/null && ret=1
+if [ $ret != 0 ]; then echo_i "failed"; fi
+status=$((status + ret))
+
n=$((n + 1))
echo_i "checking that resolution succeeds with unavailable mirror zone data ($n)"
ret=0
diff --git a/bin/tests/system/qpcache_rrsig_any/ans3/ans.py b/bin/tests/system/qpcache_rrsig_any/ans3/ans.py
index c0a6e34153..1c2521b44c 100644
--- a/bin/tests/system/qpcache_rrsig_any/ans3/ans.py
+++ b/bin/tests/system/qpcache_rrsig_any/ans3/ans.py
@@ -36,6 +36,17 @@ def rrsig_covering(
)
+def address(owner: dns.name.Name | str) -> dns.rrset.RRset:
+ """
+ The resolver only fetches ordinary types (standalone RRSIG queries and
+ recursive ANY queries are rejected before any fetch is made), so every
+ answer carries an address record for the RRSIGs to ride along with.
+ """
+ return dns.rrset.from_text(
+ owner, 3600, dns.rdataclass.IN, dns.rdatatype.A, "10.53.0.3"
+ )
+
+
class RrsigCoversRrsigHandler(StaticResponseHandler):
"""
An RRSIG covering RRSIG only trips the QP-cache RRSIG-pairing assertion when
@@ -46,6 +57,7 @@ class RrsigCoversRrsigHandler(StaticResponseHandler):
matcher = Qname("rrsig.attacker.test.")
answer = [
+ address(matcher.qnames[0]),
rrsig_covering(matcher.qnames[0], dns.rdatatype.A),
rrsig_covering(matcher.qnames[0], dns.rdatatype.AAAA),
rrsig_covering(matcher.qnames[0], dns.rdatatype.RRSIG),
@@ -54,9 +66,10 @@ class RrsigCoversRrsigHandler(StaticResponseHandler):
class RrsigCoversTypeHandler(ResponseHandler):
"""
- Answer any other query with a single RRSIG whose Type-Covered field is the
- leftmost QNAME label parsed as a DNS type, so the resolver can be probed
- with any meta-type (e.g. any.attacker.test., axfr.attacker.test.).
+ Answer any other query with an address record and a single RRSIG whose
+ Type-Covered field is the leftmost QNAME label parsed as a DNS type, so
+ the resolver can be probed with any meta-type (e.g. any.attacker.test.,
+ axfr.attacker.test.).
"""
async def get_responses(
@@ -64,6 +77,7 @@ class RrsigCoversTypeHandler(ResponseHandler):
) -> AsyncGenerator[DnsResponseSend, None]:
covered_label = qctx.qname.labels[0].decode("ascii").upper()
covered = dns.rdatatype.from_text(covered_label)
+ qctx.response.answer.append(address(qctx.qname))
qctx.response.answer.append(rrsig_covering(qctx.qname, covered))
yield DnsResponseSend(qctx.response)
diff --git a/bin/tests/system/qpcache_rrsig_any/tests_qpcache_rrsig_any.py b/bin/tests/system/qpcache_rrsig_any/tests_qpcache_rrsig_any.py
index 5444f823df..03765aad3b 100644
--- a/bin/tests/system/qpcache_rrsig_any/tests_qpcache_rrsig_any.py
+++ b/bin/tests/system/qpcache_rrsig_any/tests_qpcache_rrsig_any.py
@@ -38,19 +38,20 @@ SIG_TYPES = ["RRSIG"]
REJECTED_TYPES = META_TYPES + SIG_TYPES
-def any_query(qname):
+def address_query(qname):
"""
- Standalone RRSIG queries are rejected before any fetch is made, so
- use an ANY query to make the resolver fetch the lone RRSIG from ans3;
- with DO set, a cached signature would be returned in the answer.
+ Standalone RRSIG queries and recursive ANY queries are both rejected
+ before any fetch is made, so use an address query to make the resolver
+ fetch the RRSIG from ans3 along with the address record; with DO set,
+ a cached signature would be returned in the answer.
"""
- msg = isctest.query.create(qname, "ANY", dnssec=True, ad=False)
+ msg = isctest.query.create(qname, "A", dnssec=True, ad=False)
return isctest.query.tcp(msg, "10.53.0.2")
@pytest.mark.parametrize("covered_type", REJECTED_TYPES)
def test_rrsig_covers_rejected_type_is_servfail(covered_type):
- res = any_query(f"{covered_type.lower()}.attacker.test.")
+ res = address_query(f"{covered_type.lower()}.attacker.test.")
isctest.check.servfail(res)
@@ -59,9 +60,12 @@ def test_rrsig_covers_ordinary_type_is_answered():
The same query is answered when the RRSIG covers an ordinary type,
so the SERVFAIL above is caused by the malformed RRSIG.
"""
- res = any_query("a.attacker.test.")
+ res = address_query("a.attacker.test.")
isctest.check.noerror(res)
- assert [rrset.rdtype for rrset in res.answer] == [rdatatype.RRSIG], res
+ assert [rrset.rdtype for rrset in res.answer] == [
+ rdatatype.A,
+ rdatatype.RRSIG,
+ ], res
@pytest.mark.parametrize("covered_type", REJECTED_TYPES)
diff --git a/bin/tests/system/redirect/tests.sh b/bin/tests/system/redirect/tests.sh
index e7d65a19b1..ae556e0bd4 100644
--- a/bin/tests/system/redirect/tests.sh
+++ b/bin/tests/system/redirect/tests.sh
@@ -73,12 +73,13 @@ n=$((n + 1))
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$((status + ret))
-echo_i "checking ANY zone redirect works for nonexist ($n)"
+echo_i "checking ANY query is refused instead of redirected ($n)"
ret=0
-$DIG $DIGOPTS nonexist. @10.53.0.2 -b 10.53.0.2 any >dig.out.ns2.test$n || ret=1
-grep "status: NOERROR" dig.out.ns2.test$n >/dev/null || ret=1
-# the answer is minimized to a single RRset
-grep -e "100.100.100.1" -e "2001:ffff:ffff::6464:6401" dig.out.ns2.test$n >/dev/null || ret=1
+$DIG $DIGOPTS +rec nonexist. @10.53.0.2 -b 10.53.0.2 any >dig.out.ns2.test$n || ret=1
+grep "status: REFUSED" dig.out.ns2.test$n >/dev/null || ret=1
+grep "ANSWER: 0" dig.out.ns2.test$n >/dev/null || ret=1
+grep "EDE: 21" dig.out.ns2.test$n >/dev/null || ret=1
+grep "100.100.100.1" dig.out.ns2.test$n >/dev/null && ret=1
n=$((n + 1))
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$((status + ret))
@@ -101,16 +102,6 @@ n=$((n + 1))
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$((status + ret))
-echo_i "checking ANY zone redirect doesn't work for acl miss ($n)"
-ret=0
-$DIG $DIGOPTS nonexist. @10.53.0.2 -b 10.53.0.4 any >dig.out.ns2.test$n || ret=1
-grep "status: NXDOMAIN" dig.out.ns2.test$n >/dev/null || ret=1
-grep "100.100.100.1" dig.out.ns2.test$n >/dev/null && ret=1
-grep "2001:ffff:ffff::6464:6401" dig.out.ns2.test$n >/dev/null && ret=1
-n=$((n + 1))
-if [ $ret != 0 ]; then echo_i "failed"; fi
-status=$((status + ret))
-
echo_i "checking A zone redirect works for signed nonexist, DO=0 ($n)"
ret=0
$DIG $DIGOPTS nonexist.signed. @10.53.0.2 -b 10.53.0.2 a >dig.out.ns2.test$n || ret=1
@@ -129,16 +120,6 @@ n=$((n + 1))
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$((status + ret))
-echo_i "checking ANY zone redirect works for signed nonexist, DO=0 ($n)"
-ret=0
-$DIG $DIGOPTS nonexist.signed. @10.53.0.2 -b 10.53.0.2 any >dig.out.ns2.test$n || ret=1
-grep "status: NOERROR" dig.out.ns2.test$n >/dev/null || ret=1
-# the answer is minimized to a single RRset
-grep -e "100.100.100.1" -e "2001:ffff:ffff::6464:6401" dig.out.ns2.test$n >/dev/null || ret=1
-n=$((n + 1))
-if [ $ret != 0 ]; then echo_i "failed"; fi
-status=$((status + ret))
-
echo_i "checking A zone redirect fails for signed nonexist, DO=1 ($n)"
ret=0
$DIG $DIGOPTS nonexist.signed. +dnssec @10.53.0.2 -b 10.53.0.2 a >dig.out.ns2.test$n || ret=1
@@ -157,16 +138,6 @@ n=$((n + 1))
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$((status + ret))
-echo_i "checking ANY zone redirect fails for signed nonexist, DO=1 ($n)"
-ret=0
-$DIG $DIGOPTS nonexist.signed. +dnssec @10.53.0.2 -b 10.53.0.2 any >dig.out.ns2.test$n || ret=1
-grep "status: NXDOMAIN" dig.out.ns2.test$n >/dev/null || ret=1
-grep "100.100.100.1" dig.out.ns2.test$n >/dev/null && ret=1
-grep "2001:ffff:ffff::6464:6401" dig.out.ns2.test$n >/dev/null && ret=1
-n=$((n + 1))
-if [ $ret != 0 ]; then echo_i "failed"; fi
-status=$((status + ret))
-
echo_i "checking A zone redirect fails for nsec3 signed nonexist, DO=1 ($n)"
ret=0
$DIG $DIGOPTS nonexist.nsec3. +dnssec @10.53.0.2 -b 10.53.0.2 a >dig.out.ns2.test$n || ret=1
@@ -187,17 +158,6 @@ n=$((n + 1))
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$((status + ret))
-echo_i "checking ANY zone redirect fails for nsec3 signed nonexist, DO=1 ($n)"
-ret=0
-$DIG $DIGOPTS nonexist.nsec3. +dnssec @10.53.0.2 -b 10.53.0.2 any >dig.out.ns2.test$n || ret=1
-grep "status: NXDOMAIN" dig.out.ns2.test$n >/dev/null || ret=1
-grep "100.100.100.1" dig.out.ns2.test$n >/dev/null && ret=1
-grep "2001:ffff:ffff::6464:6401" dig.out.ns2.test$n >/dev/null && ret=1
-grep "IN.NSEC3" dig.out.ns2.test$n >/dev/null || ret=1
-n=$((n + 1))
-if [ $ret != 0 ]; then echo_i "failed"; fi
-status=$((status + ret))
-
echo_i "checking A zone redirect works for nonexist authoritative ($n)"
ret=0
$DIG $DIGOPTS nonexist. @10.53.0.1 -b 10.53.0.1 a >dig.out.ns1.test$n || ret=1
@@ -405,12 +365,13 @@ n=$((n + 1))
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$((status + ret))
-echo_i "checking ANY nxdomain-redirect works for nonexist ($n)"
+echo_i "checking ANY query is refused instead of nxdomain-redirected ($n)"
ret=0
-$DIG $DIGOPTS nonexist. @10.53.0.4 -b 10.53.0.2 any >dig.out.ns4.test$n || ret=1
-grep "status: NOERROR" dig.out.ns4.test$n >/dev/null || ret=1
-# the answer is minimized to a single RRset
-grep -e "100.100.100.1" -e "2001:ffff:ffff::6464:6401" dig.out.ns4.test$n >/dev/null || ret=1
+$DIG $DIGOPTS +rec nonexist. @10.53.0.4 -b 10.53.0.2 any >dig.out.ns4.test$n || ret=1
+grep "status: REFUSED" dig.out.ns4.test$n >/dev/null || ret=1
+grep "ANSWER: 0" dig.out.ns4.test$n >/dev/null || ret=1
+grep "EDE: 21" dig.out.ns4.test$n >/dev/null || ret=1
+grep "100.100.100.1" dig.out.ns4.test$n >/dev/null && ret=1
n=$((n + 1))
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$((status + ret))
@@ -433,16 +394,6 @@ n=$((n + 1))
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$((status + ret))
-echo_i "checking ANY nxdomain-redirect works for signed nonexist, DO=0 ($n)"
-ret=0
-$DIG $DIGOPTS nonexist.signed. @10.53.0.4 -b 10.53.0.2 any >dig.out.ns4.test$n || ret=1
-grep "status: NOERROR" dig.out.ns4.test$n >/dev/null || ret=1
-# the answer is minimized to a single RRset
-grep -e "100.100.100.1" -e "2001:ffff:ffff::6464:6401" dig.out.ns4.test$n >/dev/null || ret=1
-n=$((n + 1))
-if [ $ret != 0 ]; then echo_i "failed"; fi
-status=$((status + ret))
-
echo_i "checking A nxdomain-redirect fails for signed nonexist, DO=1 ($n)"
ret=0
$DIG $DIGOPTS nonexist.signed. +dnssec @10.53.0.4 -b 10.53.0.2 a >dig.out.ns4.test$n || ret=1
@@ -461,16 +412,6 @@ n=$((n + 1))
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$((status + ret))
-echo_i "checking ANY nxdomain-redirect fails for signed nonexist, DO=1 ($n)"
-ret=0
-$DIG $DIGOPTS nonexist.signed. +dnssec @10.53.0.4 -b 10.53.0.2 any >dig.out.ns4.test$n || ret=1
-grep "status: NXDOMAIN" dig.out.ns4.test$n >/dev/null || ret=1
-grep "100.100.100.1" dig.out.ns4.test$n >/dev/null && ret=1
-grep "2001:ffff:ffff::6464:6401" dig.out.ns4.test$n >/dev/null && ret=1
-n=$((n + 1))
-if [ $ret != 0 ]; then echo_i "failed"; fi
-status=$((status + ret))
-
echo_i "checking A nxdomain-redirect fails for nsec3 signed nonexist, DO=1 ($n)"
ret=0
$DIG $DIGOPTS nonexist.nsec3. +dnssec @10.53.0.4 -b 10.53.0.2 a >dig.out.ns4.test$n || ret=1
@@ -491,17 +432,6 @@ n=$((n + 1))
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$((status + ret))
-echo_i "checking ANY nxdomain-redirect fails for nsec3 signed nonexist, DO=1 ($n)"
-ret=0
-$DIG $DIGOPTS nonexist.nsec3. +dnssec @10.53.0.4 -b 10.53.0.2 any >dig.out.ns4.test$n || ret=1
-grep "status: NXDOMAIN" dig.out.ns4.test$n >/dev/null || ret=1
-grep "100.100.100.1" dig.out.ns4.test$n >/dev/null && ret=1
-grep "2001:ffff:ffff::6464:6401" dig.out.ns4.test$n >/dev/null && ret=1
-grep "IN.NSEC3" dig.out.ns4.test$n >/dev/null || ret=1
-n=$((n + 1))
-if [ $ret != 0 ]; then echo_i "failed"; fi
-status=$((status + ret))
-
echo_i "checking nxdomain-redirect works (with noerror) when qtype is not found ($n)"
ret=0
$DIG $DIGOPTS nonexist. @10.53.0.4 -b 10.53.0.2 txt >dig.out.ns4.test$n || ret=1
@@ -518,6 +448,21 @@ n=$((n + 1))
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$((status + ret))
+echo_i "checking ANY query is not nxdomain-redirected against authoritative zone ($n)"
+ret=0
+# nonexist.example is redirected from the cache for type A by the
+# previous test, any-nonexist.example has nothing cached; the answer to
+# a recursive ANY query must not depend on that.
+for name in nonexist.example any-nonexist.example; do
+ $DIG $DIGOPTS +rec $name @10.53.0.4 -b 10.53.0.2 any >dig.out.ns4.test$n.$name || ret=1
+ grep "status: NXDOMAIN" dig.out.ns4.test$n.$name >/dev/null || ret=1
+ grep "ANSWER: 0" dig.out.ns4.test$n.$name >/dev/null || ret=1
+ grep "100.100.100.1" dig.out.ns4.test$n.$name >/dev/null && ret=1
+done
+n=$((n + 1))
+if [ $ret != 0 ]; then echo_i "failed"; fi
+status=$((status + ret))
+
echo_i "checking nxdomain-redirect against built-in RFC-1918 zone ($n)"
ret=0
$DIG $DIGOPTS -x 10.0.0.1 @10.53.0.4 -b 10.53.0.2 >dig.out.ns4.test$n || ret=1
@@ -544,7 +489,7 @@ status=$((status + ret))
echo_i "checking nxdomain-redirect survives query for root ($n)"
ret=0
-$DIG $DIGOPTS . any @10.53.0.4 -b 10.53.0.2 >dig.out.ns4.test$n.a || ret=1
+$DIG $DIGOPTS +rec . any @10.53.0.4 -b 10.53.0.2 >dig.out.ns4.test$n.a || ret=1
$DIG $DIGOPTS nonexist. @10.53.0.4 -b 10.53.0.2 a >dig.out.ns4.test$n.b || ret=1
grep "status: NOERROR" dig.out.ns4.test$n.b >/dev/null || ret=1
grep "nonexist. .*100.100.100.1" dig.out.ns4.test$n.b >/dev/null || ret=1
diff --git a/bin/tests/system/redirect/tests_redirect_qmin.py b/bin/tests/system/redirect/tests_redirect_qmin.py
index 9587e0378f..ba82c999ea 100644
--- a/bin/tests/system/redirect/tests_redirect_qmin.py
+++ b/bin/tests/system/redirect/tests_redirect_qmin.py
@@ -9,6 +9,7 @@
# See the COPYRIGHT file distributed with this work for additional
# information regarding copyright ownership.
+import dns.rcode
import pytest
import isctest
@@ -96,25 +97,14 @@ def test_nxdomain_redirect_qmin_a_dnssec(ns11):
isctest.check.nxdomain(response)
-def test_nxdomain_redirect_qmin_any_dnssec(ns11):
+@pytest.mark.parametrize("dnssec", [True, False])
+def test_nxdomain_redirect_qmin_any_refused(ns11, dnssec):
ns11.rndc("flush")
- msg = isctest.query.create("nosuch.fake.test.", "ANY", dnssec=True)
+ msg = isctest.query.create("nosuch.fake.test.", "ANY", dnssec=dnssec)
- # cold cache answer doesn't include proofs, so redirection is allowed
- response = isctest.query.tcp(msg, ns11.ip)
- isctest.check.has_answer(response)
- isctest.check.noerror(response)
-
- # hot cache answer does include proofs, so redirection is skipped
- response = isctest.query.tcp(msg, ns11.ip)
- isctest.check.empty_answer(response)
- isctest.check.nxdomain(response)
-
-
-def test_nxdomain_redirect_qmin_any_no_dnssec(ns11):
- ns11.rndc("flush")
- msg = isctest.query.create("nosuch.spurious.test.", "ANY", dnssec=False)
+ # recursive ANY queries are refused, with a cold or a hot cache,
+ # instead of being redirected
for _ in range(2):
- response = isctest.query.tcp(msg, ns11.ip)
- isctest.check.noerror(response)
- isctest.check.has_answer(response)
+ response = isctest.query.tcp(msg, ns11.ip, expected_rcode=dns.rcode.REFUSED)
+ isctest.check.refused(response)
+ isctest.check.empty_answer(response)
diff --git a/bin/tests/system/redirect/tests_redirect_qminzone.py b/bin/tests/system/redirect/tests_redirect_qminzone.py
index 3e9bcc77ab..28a84976d7 100644
--- a/bin/tests/system/redirect/tests_redirect_qminzone.py
+++ b/bin/tests/system/redirect/tests_redirect_qminzone.py
@@ -81,8 +81,6 @@ def check(ns, qtype, dnssec, has_ad, rcode, has_answer):
("MX", False, False, dns.rcode.NOERROR, False),
("A", True, True, dns.rcode.NXDOMAIN, False),
("A", False, False, dns.rcode.NOERROR, True),
- ("ANY", True, True, dns.rcode.NXDOMAIN, False),
- ("ANY", False, False, dns.rcode.NOERROR, True),
],
)
def test_redirect_zone_qmin(ns11, qtype, dnssec, has_ad, rcode, has_answer):
@@ -92,6 +90,15 @@ def test_redirect_zone_qmin(ns11, qtype, dnssec, has_ad, rcode, has_answer):
# will be allowed. if NXDOMAIN is expected, we'll only see it on the
# second response.
isctest.log.debug("cold cache")
- check(ns11, qtype, dnssec, False, dns.rcode.NOERROR, qtype in ("A", "ANY"))
+ check(ns11, qtype, dnssec, False, dns.rcode.NOERROR, qtype == "A")
isctest.log.debug("warm cache")
check(ns11, qtype, dnssec, has_ad, rcode, has_answer)
+
+
+@pytest.mark.parametrize("dnssec", [True, False])
+def test_redirect_zone_qmin_any_refused(ns11, dnssec):
+ ns11.rndc("flush")
+ # recursive ANY queries are refused, with a cold or a warm cache,
+ # instead of being redirected
+ for _ in range(2):
+ check(ns11, "ANY", dnssec, False, dns.rcode.REFUSED, False)
diff --git a/bin/tests/system/resolver/ns4/tld1.db b/bin/tests/system/resolver/ns4/tld1.db
index 3a5e5c03d8..280d7d1720 100644
--- a/bin/tests/system/resolver/ns4/tld1.db
+++ b/bin/tests/system/resolver/ns4/tld1.db
@@ -22,3 +22,4 @@ ns7 A 10.53.0.7
mixedttl 10 A 10.0.0.1
mixedttl 15 TXT a TXT record
mixedttl 20 AAAA 2001:db8::1
+mx-only MX 10 ns.tld.
diff --git a/bin/tests/system/resolver/ns4/tld2.db b/bin/tests/system/resolver/ns4/tld2.db
index 0b093c5214..b6dd12c737 100644
--- a/bin/tests/system/resolver/ns4/tld2.db
+++ b/bin/tests/system/resolver/ns4/tld2.db
@@ -22,3 +22,4 @@ ns7 A 10.53.0.7
mixedttl 10 A 10.0.0.1
mixedttl 15 TXT a TXT record
mixedttl 20 AAAA 2001:db8::1
+mx-only MX 10 ns.tld.
diff --git a/bin/tests/system/resolver/tests.sh b/bin/tests/system/resolver/tests.sh
index 61a284114f..3803af1643 100755
--- a/bin/tests/system/resolver/tests.sh
+++ b/bin/tests/system/resolver/tests.sh
@@ -561,18 +561,18 @@ status=$((status + ret))
n=$((n + 1))
echo_i "check prefetch qtype * (${n})"
ret=0
-dig_with_opts @10.53.0.5 fetchall.tld any >dig.out.1.${n} || ret=1
+dig_with_opts @10.53.0.5 fetchall.tld a >dig.out.1.${n} || ret=1
ttl1=$(awk '/^fetchall.tld/ { print $2 - 3; exit }' dig.out.1.${n})
# sleep so we are in prefetch range
sleep "${ttl1:-0}"
# trigger prefetch
-dig_with_opts @10.53.0.5 fetchall.tld any >dig.out.2.${n} || ret=1
+dig_with_opts @10.53.0.5 fetchall.tld a >dig.out.2.${n} || ret=1
ttl2=$(awk '/^fetchall.tld/ { print $2; exit }' dig.out.2.${n})
sleep 1
# check that prefetch occurred;
# note that only the first record is prefetched,
# because of the order of the records in the cache
-dig_with_opts @10.53.0.5 fetchall.tld any >dig.out.3.${n} || ret=1
+dig_with_opts @10.53.0.5 fetchall.tld a >dig.out.3.${n} || ret=1
ttl3=$(awk '/^fetchall.tld/ { print $2; exit }' dig.out.3.${n})
test "${ttl3:-0}" -gt "${ttl2:-1}" || ret=1
if [ $ret != 0 ]; then echo_i "failed"; fi
@@ -581,11 +581,11 @@ status=$((status + ret))
n=$((n + 1))
echo_i "check that E was logged on EDNS queries in the query log (${n})"
ret=0
-dig_with_opts @10.53.0.5 +edns edns.fetchall.tld any >dig.out.2.${n} || ret=1
-grep "query: edns.fetchall.tld IN ANY +E" ns5/named.run >/dev/null || ret=1
-dig_with_opts @10.53.0.5 +noedns noedns.fetchall.tld any >dig.out.2.${n} || ret=1
-grep "query: noedns.fetchall.tld IN ANY" ns5/named.run >/dev/null || ret=1
-grep "query: noedns.fetchall.tld IN ANY +E" ns5/named.run >/dev/null && ret=1
+dig_with_opts @10.53.0.5 +edns edns.fetchall.tld a >dig.out.2.${n} || ret=1
+grep "query: edns.fetchall.tld IN A +E" ns5/named.run >/dev/null || ret=1
+dig_with_opts @10.53.0.5 +noedns noedns.fetchall.tld a >dig.out.2.${n} || ret=1
+grep "query: noedns.fetchall.tld IN A" ns5/named.run >/dev/null || ret=1
+grep "query: noedns.fetchall.tld IN A +E" ns5/named.run >/dev/null && ret=1
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$((status + ret))
@@ -620,11 +620,11 @@ edns=$($FEATURETEST --edns-version)
n=$((n + 1))
echo_i "check that EDNS version is logged (${n})"
ret=0
-dig_with_opts @10.53.0.5 +edns edns0.fetchall.tld any >dig.out.2.${n} || ret=1
-grep "query: edns0.fetchall.tld IN ANY +E(0)" ns5/named.run >/dev/null || ret=1
+dig_with_opts @10.53.0.5 +edns edns0.fetchall.tld a >dig.out.2.${n} || ret=1
+grep "query: edns0.fetchall.tld IN A +E(0)" ns5/named.run >/dev/null || ret=1
if test "${edns:-0}" != 0; then
- dig_with_opts @10.53.0.5 +edns=1 edns1.fetchall.tld any >dig.out.2.${n} || ret=1
- grep "query: edns1.fetchall.tld IN ANY +E(1)" ns5/named.run >/dev/null || ret=1
+ dig_with_opts @10.53.0.5 +edns=1 edns1.fetchall.tld a >dig.out.2.${n} || ret=1
+ grep "query: edns1.fetchall.tld IN A +E(1)" ns5/named.run >/dev/null || ret=1
fi
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$((status + ret))
@@ -892,11 +892,16 @@ status=$((status + ret))
n=$((n + 1))
echo_i "check expired TTLs with qtype * (${n})"
ret=0
-dig_with_opts +tcp @10.53.0.5 mixedttl.tld any >dig.out.1.${n} || ret=1
+# recursive ANY queries are refused, so populate the cache one type at
+# a time and then inspect it with non-recursive ANY queries
+dig_with_opts +tcp @10.53.0.5 mixedttl.tld a >dig.out.0.${n}.a || ret=1
+dig_with_opts +tcp @10.53.0.5 mixedttl.tld txt >dig.out.0.${n}.txt || ret=1
+dig_with_opts +tcp @10.53.0.5 mixedttl.tld aaaa >dig.out.0.${n}.aaaa || ret=1
+dig_with_opts +nord +tcp @10.53.0.5 mixedttl.tld any >dig.out.1.${n} || ret=1
ttl1=$(awk '$1 == "mixedttl.tld." && $4 == "A" { print $2 + 1 }' dig.out.1.${n})
# sleep TTL + 1 so that record has expired
sleep "${ttl1:-0}"
-dig_with_opts +tcp @10.53.0.5 mixedttl.tld any >dig.out.2.${n} || ret=1
+dig_with_opts +nord +tcp @10.53.0.5 mixedttl.tld any >dig.out.2.${n} || ret=1
# check preconditions
grep "ANSWER: 3," dig.out.1.${n} >/dev/null || ret=1
lines=$(awk '$1 == "mixedttl.tld." && $2 > 30 { print }' dig.out.1.${n} | wc -l)
diff --git a/bin/tests/system/resolver/tests_resolver.py b/bin/tests/system/resolver/tests_resolver.py
index 51d38e57ff..e1a5469fa3 100644
--- a/bin/tests/system/resolver/tests_resolver.py
+++ b/bin/tests/system/resolver/tests_resolver.py
@@ -11,11 +11,81 @@
import time
+from dns.edns import EDECode
+
import dns.message
+import dns.rcode
+import dns.rdatatype
+import pytest
import isctest
+@pytest.mark.parametrize("transport", [isctest.query.udp, isctest.query.tcp])
+def test_resolver_any_mx_only(ns5, transport):
+ ns5.rndc("flush")
+
+ # A cache miss cannot tell us which types exist at the name. Refuse
+ # ANY instead of substituting an address query or a NODATA answer.
+ msg = isctest.query.create("mx-only.tld.", "ANY", dnssec=False)
+ res = transport(msg, ns5.ip, expected_rcode=dns.rcode.REFUSED)
+ isctest.check.refused(res)
+ isctest.check.empty_answer(res)
+ isctest.check.ede(res, EDECode.NOT_SUPPORTED)
+
+ # An explicit MX query still resolves. Refuse ANY consistently even
+ # after that RRset has been cached.
+ msg = isctest.query.create("mx-only.tld.", "MX", dnssec=False)
+ mx = transport(msg, ns5.ip)
+ isctest.check.noerror(mx)
+ assert len(mx.answer) == 1
+ assert mx.answer[0].rdtype == dns.rdatatype.MX
+
+ msg = isctest.query.create("mx-only.tld.", "ANY", dnssec=False)
+ res = transport(msg, ns5.ip, expected_rcode=dns.rcode.REFUSED)
+ isctest.check.refused(res)
+ isctest.check.empty_answer(res)
+ isctest.check.ede(res, EDECode.NOT_SUPPORTED)
+
+
+@pytest.mark.parametrize("transport", [isctest.query.udp, isctest.query.tcp])
+def test_resolver_any_norecurse(ns5, transport):
+ ns5.rndc("flush")
+
+ # Without RD, an ANY query only inspects the cache. On a cache miss
+ # it is handled like a non-recursive query of any other type; it is
+ # not refused.
+ rcodes = {}
+ for qtype in ("MX", "ANY"):
+ msg = isctest.query.create("mx-only.tld.", qtype, rd=False, dnssec=False)
+ res = transport(msg, ns5.ip)
+ isctest.check.empty_answer(res)
+ rcodes[qtype] = res.rcode()
+ assert rcodes["ANY"] == rcodes["MX"]
+ assert rcodes["ANY"] != dns.rcode.REFUSED
+
+ # Once a recursive query has populated the cache, the non-recursive
+ # ANY query returns what is cached at the name.
+ msg = isctest.query.create("mx-only.tld.", "MX", dnssec=False)
+ mx = transport(msg, ns5.ip)
+ isctest.check.noerror(mx)
+
+ msg = isctest.query.create("mx-only.tld.", "ANY", rd=False, dnssec=False)
+ res = transport(msg, ns5.ip)
+ isctest.check.noerror(res)
+ assert [rrset.rdtype for rrset in res.answer] == [dns.rdatatype.MX]
+
+ # A cached NXDOMAIN is returned for a non-recursive ANY query, too.
+ msg = isctest.query.create("nxdomain-any.tld.", "A", dnssec=False)
+ res = transport(msg, ns5.ip, expected_rcode=dns.rcode.NXDOMAIN)
+ isctest.check.nxdomain(res)
+
+ msg = isctest.query.create("nxdomain-any.tld.", "ANY", rd=False, dnssec=False)
+ res = transport(msg, ns5.ip, expected_rcode=dns.rcode.NXDOMAIN)
+ isctest.check.nxdomain(res)
+ isctest.check.empty_answer(res)
+
+
def test_resolver_cache_reloadfails(ns1, templates):
ns1.rndc("flush")
msg = isctest.query.create("www.example.org.", "A")
@@ -85,3 +155,50 @@ isc.org. 300 IN A 1.2.3.4
msg = isctest.query.create("www.example.gooddname.example.net.", "A")
res = isctest.query.udp(msg, "10.53.0.1")
isctest.check.noerror(res)
+
+
+def test_resolver_any_refused(ns1):
+ ns1.rndc("flush")
+
+ # A resolver refuses recursive ANY queries with REFUSED and EDE 21
+ # (Not Supported), without looking the name up or sending anything
+ # upstream
+ msg = isctest.query.create("www.example.org.", "ANY")
+ res = isctest.query.udp(msg, "10.53.0.1", expected_rcode=dns.rcode.REFUSED)
+ isctest.check.refused(res)
+ isctest.check.empty_answer(res)
+ isctest.check.ede(res, EDECode.NOT_SUPPORTED)
+
+ # ...including when the cache holds records for the queried name
+ msg = isctest.query.create("www.example.org.", "A")
+ res = isctest.query.udp(msg, "10.53.0.1")
+ isctest.check.noerror(res)
+ assert res.answer[0].rdtype == dns.rdatatype.A
+
+ msg = isctest.query.create("www.example.org.", "ANY")
+ res = isctest.query.udp(msg, "10.53.0.1", expected_rcode=dns.rcode.REFUSED)
+ isctest.check.refused(res)
+ isctest.check.empty_answer(res)
+ isctest.check.ede(res, EDECode.NOT_SUPPORTED)
+
+
+def test_resolver_any_refused_below_delegation():
+ # ns7 is authoritative for sub.tld1, which delegates bar.sub.tld1
+ # elsewhere; an ANY query for a name below that delegation could
+ # only be answered by recursing, so it is refused when recursion
+ # is requested...
+ msg = isctest.query.create("foo.bar.sub.tld1.", "ANY")
+ res = isctest.query.udp(msg, "10.53.0.7", expected_rcode=dns.rcode.REFUSED)
+ isctest.check.refused(res)
+ isctest.check.empty_answer(res)
+ isctest.check.ede(res, EDECode.NOT_SUPPORTED)
+
+ # ...and answered with the referral when it is not
+ msg = isctest.query.create("foo.bar.sub.tld1.", "ANY", rd=False)
+ res = isctest.query.udp(msg, "10.53.0.7")
+ isctest.check.noerror(res)
+ isctest.check.empty_answer(res)
+ assert any(
+ rrset.rdtype == dns.rdatatype.NS and str(rrset.name) == "bar.sub.tld1."
+ for rrset in res.authority
+ ), f"expected a referral for bar.sub.tld1: {res}"
diff --git a/bin/tests/system/rpz/tests.sh b/bin/tests/system/rpz/tests.sh
index dbfc5f7428..e2b85d2e59 100644
--- a/bin/tests/system/rpz/tests.sh
+++ b/bin/tests/system/rpz/tests.sh
@@ -463,7 +463,7 @@ nxdomain a0-1s-cname.tld2s +dnssec # 28 DNSSEC too early in CNAME chain
nochange a0-1-scname.tld2 +dnssec # 29 DNSSEC on target in CNAME chain
nochange a0-1.tld2s srv +auth +dnssec # 30 no write for DNSSEC and no record
nxdomain a0-1.tld2s srv +nodnssec # 31
-drop a3-8.tld2 any # 32 drop
+drop a3-8.tld2 a # 32 drop
nochange TCP a3-9.tld2 # 33 tcp-only
here x.servfail <<'EOF' # 34 qname-wait-recurse yes
;; status: SERVFAIL, x
@@ -497,7 +497,7 @@ addr 127.0.0.17 "a4-6-cname3.tld2 @$ns6" # 16 stop short in CNAME chain
nxdomain c1.crash2.tld3 @$ns6 # 17 assert in rbtdb.c
nxdomain a0-1.tld2 +dnssec @$ns6 # 18 simple DO=1 without sigs
nxdomain a0-1s-cname.tld2s +dnssec @$ns6 # 19
-drop a3-8.tld2 any @$ns6 # 20 drop
+drop a3-8.tld2 a @$ns6 # 20 drop
end_group
ckstatsrange $ns3 test1 ns3 22 30
ckstats $ns5 test1 ns5 0
@@ -512,7 +512,6 @@ nochange a4-1.tld2 # 3 obsolete PASSTHRU record style
nxdomain a4-2.tld2 # 4
nochange a4-2.tld2 -taaaa # 5 no A => no policy rewrite
nochange a4-2.tld2 -ttxt # 6 no A => no policy rewrite
-nxdomain a4-2.tld2 -tany # 7 no A => no policy rewrite
nodata a4-3.tld2 # 8
nxdomain a3-1.tld2 -taaaa # 9 IPv6 policy
nochange a4-1-aaaa.tld2 -taaaa # 10
@@ -537,7 +536,7 @@ ck_soa 3 bl.tld2 $ns3
sleep 1 # there's an delay between "DNS" transfer and RPZ being active
nxdomain a7-1.tld2 # 20 secondary policy zone (RT34450)
end_group
-ckstats $ns3 test2 ns3 12
+ckstats $ns3 test2 ns3 11
# check that IP addresses for previous group were deleted from the radix tree
start_group "radix tree deletions"
@@ -547,7 +546,6 @@ nochange a4-1.tld2
nochange a4-2.tld2
nochange a4-2.tld2 -taaaa
nochange a4-2.tld2 -ttxt
-nochange a4-2.tld2 -tany
nochange a4-3.tld2
nochange a3-1.tld2 -tAAAA
nochange a4-1-aaaa.tld2 -tAAAA
@@ -562,7 +560,6 @@ nochange a3-1.tld2 # 1
nochange a3-1.tld2 +dnssec # 2 this once caused problems
nxdomain a3-1.sub1.tld2 # 3 NXDOMAIN *.sub1.tld2 by NSDNAME
nxdomain a3-1.subsub.sub1.tld2 # 4
-nxdomain a3-1.subsub.sub1.tld2 -tany # 5
addr 12.12.12.12 a4-2.subsub.sub2.tld2 # 6 walled garden for *.sub2.tld2
nochange a3-2.tld2. # 7 exempt rewrite by name
nochange a0-1.tld2. # 8 exempt rewrite by address block
@@ -578,7 +575,7 @@ nochange_ns10 a3-1.static-stub-nomatch # 16
nextpart ns3/named.run | grep -F "unrecognized NS rpz_rrset_find() failed: glue" >/dev/null \
&& setret "seen: unrecognized NS rpz_rrset_find() failed: glue"
end_group
-ckstats $ns3 test3 ns3 9
+ckstats $ns3 test3 ns3 8
# these tests assume "min-ns-dots 0"
start_group "NSIP rewrites" test4
@@ -619,7 +616,7 @@ nxdomain a3-5.tld2 +norecurse @$ns5 # 8 bl-nodata global recursive-only no
nxdomain a3-5.tld2s @$ns5 # 9 bl-nodata global break-dnssec
nxdomain a3-5.tld2s +dnssec @$ns5 # 10 bl-nodata global break-dnssec
nxdomain a3-6.tld2 # 11 bl-nxdomain
-here a3-7.tld2 -tany <<'EOF' # 12
+here a3-7.tld2 -ttxt <<'EOF' # 12
;; status: NOERROR, x
a3-7.tld2. x IN CNAME txt-only.tld2.
txt-only.tld2. x IN TXT "txt-only-tld2"
@@ -629,7 +626,7 @@ addr 59.59.59.59 a3-9.sub9.tld2 # 14 bl_wildcname
addr 12.12.12.12 a3-15.tld2 # 15 bl-garden via CNAME to a12.tld2
addr 127.0.0.16 a3-16.tld2 100 # 16 bl max-policy-ttl 100
addr 17.17.17.17 "a3-17.tld2 @$ns5" 90 # 17 ns5 bl max-policy-ttl 90
-drop a3-18.tld2 any # 18 bl-drop
+drop a3-18.tld2 a # 18 bl-drop
nxdomain TCP a3-19.tld2 # 19 bl-tcp-only
end_group
ckstats $ns3 test5 ns3 12
@@ -650,8 +647,9 @@ done
# resolving foo.
# nxdomain 32.3.2.1.127.rpz-ip
end_group
-# RRSIG queries are rejected before RPZ processing.
-ckstats $ns3 bugs ns3 6
+# only the SIG queries are resolved and rewritten by the policy;
+# RRSIG and ANY queries are rejected before RPZ processing
+ckstats $ns3 bugs ns3 2
# Ensure ns3 manages to transfer the fast-expire zone before shutdown.
nextpartreset ns3/named.run
@@ -762,8 +760,8 @@ $DIG -p ${PORT} @$ns3 a6-2.tld2. A >dig.out.$t.after || setret "failed"
grep "status: NXDOMAIN" dig.out.$t.after >/dev/null || setret "failed"
t=$((t + 1))
-echo_i "checking that ttl values are not zeroed when qtype is '*' (${t})"
-$DIG +noall +answer -p ${PORT} @$ns3 any a3-2.tld2 >dig.out.$t || setret "failed"
+echo_i "checking that ttl values are not zeroed by rpz processing (${t})"
+$DIG +noall +answer -p ${PORT} @$ns3 txt a3-2.tld2 >dig.out.$t || setret "failed"
ttl=$(awk '/a3-2 tld2 text/ {print $2}' dig.out.$t)
if test ${ttl:=0} -eq 0; then setret "failed"; fi
diff --git a/bin/tests/system/rpzextra/tests_rpzextra.py b/bin/tests/system/rpzextra/tests_rpzextra.py
index 20d18deed2..057e9b6d2e 100644
--- a/bin/tests/system/rpzextra/tests_rpzextra.py
+++ b/bin/tests/system/rpzextra/tests_rpzextra.py
@@ -99,23 +99,6 @@ def test_rpz_passthru_logging():
dns.rrset.from_text("allowed.", 300, "IN", "A", "10.53.0.2")
]
- # Should also generate a log entry into rpz_passthru.txt
- msg_allowed_any = isctest.query.create("allowed.", "ANY")
- res_allowed_any = isctest.query.udp(
- msg_allowed_any,
- resolver_ip,
- source="10.53.0.1",
- expected_rcode=dns.rcode.NOERROR,
- )
- assert res_allowed_any.answer == [
- dns.rrset.from_text("allowed.", 300, "IN", "NS", "ns1.allowed."),
- dns.rrset.from_text("allowed.", 300, "IN", "A", "10.53.0.2"),
- ]
- # The comparison above doesn't compare the TTL values, and we want to
- # make sure that the "passthru" rpz doesn't cap the TTL with max-policy-ttl.
- assert res_allowed_any.answer[0].ttl > 200
- assert res_allowed_any.answer[1].ttl > 200
-
# baddomain.com isn't allowed (CNAME .), should return NXDOMAIN
# Should generate a log entry into rpz.txt
msg_not_allowed = isctest.query.create("baddomain.", "A")
diff --git a/bin/tests/system/statistics/tests.sh b/bin/tests/system/statistics/tests.sh
index a7b1419b6a..e8344741de 100644
--- a/bin/tests/system/statistics/tests.sh
+++ b/bin/tests/system/statistics/tests.sh
@@ -38,7 +38,7 @@ rndc_stats() {
}
echo_i "fetching a.example from ns2's initial configuration ($n)"
-$DIGCMD +noauth a.example. @10.53.0.2 any >dig.out.ns2.1 || ret=1
+$DIGCMD +noauth a.example. @10.53.0.2 a >dig.out.ns2.1 || ret=1
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$((status + ret))
n=$((n + 1))
@@ -72,7 +72,7 @@ n=$((n + 1))
ret=0
echo_i "checking for 2 entries in adb hash table in named.stats ($n)"
-$DIGCMD a.example.info. @10.53.0.2 any >/dev/null 2>&1
+$DIGCMD a.example.info. @10.53.0.2 a >/dev/null 2>&1
rndc_stats ns2 10.53.0.2 || ret=1
grep "2 Addresses in hash table" $last_stats >/dev/null || ret=1
if [ $ret != 0 ]; then echo_i "failed"; fi
@@ -89,7 +89,7 @@ status=$((status + ret))
n=$((n + 1))
echo_i "sending queries to ns3"
-$DIGCMD +tries=2 +time=1 +recurse @10.53.0.3 foo.info. any >/dev/null 2>&1 || true
+$DIGCMD +tries=2 +time=1 +recurse @10.53.0.3 foo.info. a >/dev/null 2>&1 || true
ret=0
echo_i "dumping updated stats for ns3 ($n)"
diff --git a/bin/tests/system/synthfromdnssec/tests.sh b/bin/tests/system/synthfromdnssec/tests.sh
index ce4f409933..45d651ed59 100644
--- a/bin/tests/system/synthfromdnssec/tests.sh
+++ b/bin/tests/system/synthfromdnssec/tests.sh
@@ -789,6 +789,27 @@ for ns in 2 4 5 6; do
else
echo_i "Skipping JSON statistics checks"
fi
+
+ # This is checked last, because it bumps the statistics counters
+ # checked above.
+ echo_i "check non-recursive ANY query for a nonexistent name (synth-from-dnssec ${description};) ($n)"
+ ret=0
+ nextpart ns1/named.run >/dev/null
+ dig_with_opts +norec c.example. @10.53.0.${ns} any >dig.out.ns${ns}.test$n || ret=1
+ grep "ANSWER: 0," dig.out.ns${ns}.test$n >/dev/null || ret=1
+ if [ ${synth} = yes ]; then
+ # the cached NSEC proves that the name does not exist
+ check_status NXDOMAIN dig.out.ns${ns}.test$n || ret=1
+ check_synth_soa example. dig.out.ns${ns}.test$n || ret=1
+ else
+ # nothing is cached for the name and nothing can be synthesized
+ check_status NXDOMAIN dig.out.ns${ns}.test$n && ret=1
+ fi
+ # either way the cache is only inspected, nothing is sent upstream
+ nextpart ns1/named.run | grep c.example/ >/dev/null && ret=1
+ n=$((n + 1))
+ if [ $ret != 0 ]; then echo_i "failed"; fi
+ status=$((status + ret))
done
echo_i "check redirect response (+dnssec) (synth-from-dnssec <default>;) ($n)"
diff --git a/bin/tools/mdig.c b/bin/tools/mdig.c
index f566a289a9..cf5994c614 100644
--- a/bin/tools/mdig.c
+++ b/bin/tools/mdig.c
@@ -90,6 +90,7 @@ static bool have_ipv4 = false;
static bool have_ipv6 = false;
static bool have_src = false;
static bool tcp_mode = false;
+static bool tcp_mode_set = false;
static bool besteffort = true;
static bool display_short_form = false;
static bool display_headers = true;
@@ -125,6 +126,7 @@ struct query {
char textname[MXNAME]; /*% Name we're going to be
* looking up */
bool recurse;
+ bool recurse_set;
bool have_aaonly;
bool have_adflag;
bool have_cdflag;
@@ -553,7 +555,12 @@ sendquery(struct query *query) {
&message);
message->opcode = dns_opcode_query;
- if (query->recurse) {
+ /*
+ * ANY queries are not recursive unless +recurse was given.
+ */
+ if (query->recurse &&
+ (query->recurse_set || query->rdtype != dns_rdatatype_any))
+ {
message->flags |= DNS_MESSAGEFLAG_RD;
}
if (query->have_aaonly) {
@@ -1383,6 +1390,7 @@ plus_option(char *option, struct query *query, bool global) {
case 'c': /* recurse */
FULLCHECK("recurse");
query->recurse = state;
+ query->recurse_set = true;
break;
case 't': /* retry / retries */
FULLCHECK2("retry", "retries");
@@ -1488,6 +1496,7 @@ plus_option(char *option, struct query *query, bool global) {
FULLCHECK("tcp");
GLOBAL();
tcp_mode = state;
+ tcp_mode_set = true;
break;
case 'i': /* timeout */
FULLCHECK("timeout");
@@ -1573,6 +1582,7 @@ plus_option(char *option, struct query *query, bool global) {
FULLCHECK("vc");
GLOBAL();
tcp_mode = state;
+ tcp_mode_set = true;
break;
case 'y': /* yaml */
FULLCHECK("yaml");
@@ -1784,10 +1794,6 @@ clone_default_query(void) {
}
}
- if (query->timeout == 0) {
- query->timeout = tcp_mode ? TCPTIMEOUT : UDPTIMEOUT;
- }
-
return query;
}
@@ -1900,6 +1906,7 @@ parse_args(bool is_batchfile, int argc, char **argv) {
if (!is_batchfile) {
default_query.textname[0] = 0;
default_query.recurse = true;
+ default_query.recurse_set = false;
default_query.have_aaonly = false;
default_query.have_adflag = true; /*XXX*/
default_query.have_cdflag = false;
@@ -2114,6 +2121,24 @@ main(int argc, char *argv[]) {
fatal("a server '@xxx' is required");
}
+ /*
+ * The transport is shared by all the queries: use TCP if any of
+ * them is an ANY query, unless the transport was set explicitly.
+ */
+ if (!tcp_mode_set) {
+ ISC_LIST_FOREACH(queries, query, link) {
+ if (query->rdtype == dns_rdatatype_any) {
+ tcp_mode = true;
+ break;
+ }
+ }
+ }
+ ISC_LIST_FOREACH(queries, query, link) {
+ if (query->timeout == 0) {
+ query->timeout = tcp_mode ? TCPTIMEOUT : UDPTIMEOUT;
+ }
+ }
+
ns = 0;
result = isc_getaddresses(server, port, &dstaddr, 1, &ns);
if (result != ISC_R_SUCCESS) {
diff --git a/bin/tools/mdig.rst b/bin/tools/mdig.rst
index 9bb1998cb5..5d750a8de6 100644
--- a/bin/tools/mdig.rst
+++ b/bin/tools/mdig.rst
@@ -194,8 +194,9 @@ The global query options are:
.. option:: +tcp, +notcp
- This option uses [or does not use] TCP when querying name servers. The default behavior
- is to use UDP.
+ This option uses [or does not use] TCP when querying name servers. The
+ default behavior is to use UDP unless a type ANY query is requested, in
+ which case the default is TCP.
.. option:: +ttlid, +nottlid
@@ -226,8 +227,8 @@ Local Options
This option sets the query type to ``type``. It can be any valid
query type which is supported in BIND 9. The default query type is "A",
- unless the :option:`-x` option is supplied to indicate a reverse lookup with
- the "PTR" query type.
+ unless the :option:`-x` option is supplied to indicate a reverse lookup
+ with the "PTR" query type.
.. option:: -x addr
@@ -314,7 +315,8 @@ The local query options are:
This toggles the setting of the RD (recursion desired) bit in the query.
This bit is set by default, which means :program:`mdig` normally sends
- recursive queries.
+ recursive queries, unless a type ANY query is requested, in which
+ case the default is not to set it.
.. option:: +retry=T
diff --git a/doc/arm/reference.rst b/doc/arm/reference.rst
index ea4c2e5166..301f1cbeea 100644
--- a/doc/arm/reference.rst
+++ b/doc/arm/reference.rst
@@ -2086,6 +2086,19 @@ Boolean Options
unnecessary records are added to the authority or additional
sections. The default is ``yes``.
+ Queries of type ANY are never resolved recursively. When recursion
+ is requested and available to the client, a query of type ANY that
+ cannot be answered from authoritative data is refused with the
+ REFUSED response code and, when EDNS is used, Extended DNS Error
+ code 21 (Not Supported), even when records are already cached.
+ Response policy zones are not consulted for these queries. ANY
+ queries can still be answered from authoritative data, and
+ non-recursive ANY queries (for example, ``dig +norecurse``) are
+ still answered with whatever the cache holds for the name, subject
+ to this option. The resolver never sends queries of type ANY
+ or other meta types upstream. The ``delv`` utility also refuses
+ queries of type ANY.
+
.. namedconf:statement:: notify
:tags: transfer
:short: Controls whether ``NOTIFY(SOA)`` messages are sent on zone changes.
diff --git a/lib/dns/client.c b/lib/dns/client.c
index 60d71bbdc4..209672709b 100644
--- a/lib/dns/client.c
+++ b/lib/dns/client.c
@@ -647,103 +647,14 @@ client_resfind(resctx_t *rctx, dns_fetchresponse_t *resp) {
goto done;
}
- if (rctx->type == dns_rdatatype_any) {
- int n = 0;
- dns_rdatasetiter_t *rdsiter = NULL;
-
- if (node == NULL) {
- INSIST(db != NULL);
- tresult = dns_db_findnode(db, fname, false,
- &node);
- if (tresult != ISC_R_SUCCESS) {
- result = tresult;
- putrdataset(mctx, &rctx->rdataset);
- if (rctx->sigrdataset != NULL) {
- putrdataset(mctx,
- &rctx->sigrdataset);
- }
- goto done;
- }
- }
-
- tresult = dns_db_allrdatasets(db, node, NULL, 0, 0,
- &rdsiter);
- if (tresult != ISC_R_SUCCESS) {
- result = tresult;
- goto done;
- }
-
- tresult = dns_rdatasetiter_first(rdsiter);
- while (tresult == ISC_R_SUCCESS) {
- dns_rdatasetiter_current(rdsiter,
- rctx->rdataset);
- if (!rctx->rdataset->attributes.negative) {
- ISC_LIST_APPEND(ansname->list,
- rctx->rdataset, link);
- n++;
- rctx->rdataset = NULL;
- } else {
- /*
- * We're not interested in this
- * rdataset.
- */
- dns_rdataset_disassociate(
- rctx->rdataset);
- }
- tresult = dns_rdatasetiter_next(rdsiter);
-
- if (tresult == ISC_R_SUCCESS &&
- rctx->rdataset == NULL)
- {
- tresult = getrdataset(mctx,
- &rctx->rdataset);
- if (tresult != ISC_R_SUCCESS) {
- result = tresult;
- POST(result);
- break;
- }
- }
- }
- if (rctx->rdataset != NULL) {
- putrdataset(mctx, &rctx->rdataset);
- }
- if (rctx->sigrdataset != NULL) {
- putrdataset(mctx, &rctx->sigrdataset);
- }
- if (n == 0) {
- /*
- * We didn't match any rdatasets (which means
- * something went wrong in this
- * implementation).
- */
- result = DNS_R_SERVFAIL; /* better code? */
- POST(result);
- } else {
- ISC_LIST_APPEND(rctx->namelist, ansname, link);
- ansname = NULL;
- }
- dns_rdatasetiter_destroy(&rdsiter);
- if (tresult != ISC_R_NOMORE) {
- result = DNS_R_SERVFAIL; /* ditto */
- } else {
- result = ISC_R_SUCCESS;
- }
- goto done;
- } else {
- /*
- * This is the "normal" case -- an ordinary question
- * to which we've got the answer.
- */
- ISC_LIST_APPEND(ansname->list, rctx->rdataset, link);
- rctx->rdataset = NULL;
- if (rctx->sigrdataset != NULL) {
- ISC_LIST_APPEND(ansname->list,
- rctx->sigrdataset, link);
- rctx->sigrdataset = NULL;
- }
- ISC_LIST_APPEND(rctx->namelist, ansname, link);
- ansname = NULL;
+ ISC_LIST_APPEND(ansname->list, rctx->rdataset, link);
+ rctx->rdataset = NULL;
+ if (rctx->sigrdataset != NULL) {
+ ISC_LIST_APPEND(ansname->list, rctx->sigrdataset, link);
+ rctx->sigrdataset = NULL;
}
+ ISC_LIST_APPEND(rctx->namelist, ansname, link);
+ ansname = NULL;
done:
/*
@@ -870,6 +781,11 @@ startresolve(dns_client_t *client, const dns_name_t *name,
return DNS_R_FORMERR;
}
+ /* Meta types, including ANY, are never resolved upstream. */
+ if (dns_rdatatype_ismeta(type)) {
+ return DNS_R_REFUSED;
+ }
+
mctx = client->mctx;
want_dnssec = ((options & DNS_CLIENTRESOPT_NODNSSEC) == 0);
want_validation = ((options & DNS_CLIENTRESOPT_NOVALIDATE) == 0);
diff --git a/lib/dns/include/dns/resolver.h b/lib/dns/include/dns/resolver.h
index 78cfe1b6cb..7f608d12e1 100644
--- a/lib/dns/include/dns/resolver.h
+++ b/lib/dns/include/dns/resolver.h
@@ -306,14 +306,15 @@ dns_resolver_createfetch(dns_resolver_t *res, const dns_name_t *name,
*\li Fetches for type RRSIG are rejected with #DNS_R_FORMERR;
* no such queries are sent to authoritative servers.
*
+ *\li Fetches for meta types (including ANY) are refused with
+ * #DNS_R_REFUSED; no such queries are sent to authoritative servers.
+ *
* Requires:
*
*\li 'res' is a valid resolver that has been frozen.
*
*\li 'name' is a valid name.
*
- *\li 'type' is not a meta type other than ANY.
- *
*\li 'domain' is a valid name or NULL.
*
*\li 'nameservers' is a valid NS rdataset (whose owner name is 'domain')
@@ -337,6 +338,7 @@ dns_resolver_createfetch(dns_resolver_t *res, const dns_name_t *name,
*\li #DNS_R_DUPLICATE
*\li #DNS_R_DROP
*\li #DNS_R_FORMERR 'type' is RRSIG
+ *\li #DNS_R_REFUSED 'type' is a meta type
*
*\li Many other values are possible, all of which indicate failure.
*/
diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c
index 2ac6f2d13f..0ef4105f4c 100644
--- a/lib/dns/resolver.c
+++ b/lib/dns/resolver.c
@@ -901,9 +901,7 @@ get_attached_fctx(dns_resolver_t *res, isc_loop_t *loop, const dns_name_t *name,
* query (rctx_answer_scan()).
* - For whichever type of response was found, call a separate routine
* to handle it: matching QNAME/QTYPE (rctx_answer_match()),
- * CNAME (rctx_answer_cname()), covering DNAME (rctx_answer_dname()),
- * or any records returned in response to a query of type ANY
- * (rctx_answer_any()).
+ * CNAME (rctx_answer_cname()), or covering DNAME (rctx_answer_dname()).
* - Scan the authority section for NS or other records that may be
* included with a positive answer (rctx_authority_positive()).
*
@@ -1003,9 +1001,6 @@ rctx_answer_scan(respctx_t *rctx);
static void
rctx_authority_positive(respctx_t *rctx);
-static isc_result_t
-rctx_answer_any(respctx_t *rctx);
-
static isc_result_t
rctx_answer_match(respctx_t *rctx);
@@ -4606,8 +4601,7 @@ resume_qmin(void *arg) {
*/
if ((result == DNS_R_CNAME || result == DNS_R_DNAME) &&
fctx->qmin_labels == dns_name_countlabels(fctx->name) &&
- fctx->type != dns_rdatatype_nsec &&
- fctx->type != dns_rdatatype_any)
+ fctx->type != dns_rdatatype_nsec)
{
pull_from_resp(resp, fctx);
@@ -4938,6 +4932,7 @@ fctx__create(dns_resolver_t *res, isc_loop_t *loop, const dns_name_t *name,
*/
REQUIRE(fctxp != NULL && *fctxp == NULL);
REQUIRE(!dns_rdatatype_issig(type));
+ REQUIRE(!dns_rdatatype_ismeta(type));
fctx = isc_mem_get(mctx, sizeof(*fctx));
*fctx = (fetchctx_t){ .type = type,
@@ -8618,9 +8613,9 @@ rctx_answer(respctx_t *rctx) {
/*
* rctx_answer_positive():
* Handles positive responses. Depending which type of answer this is
- * (matching QNAME/QTYPE, CNAME, DNAME, ANY) calls the proper routine
+ * (matching QNAME/QTYPE, CNAME, DNAME) calls the proper routine
* to handle it (rctx_answer_match(), rctx_answer_cname(),
- * rctx_answer_dname(), rctx_answer_any()).
+ * rctx_answer_dname()).
*/
static isc_result_t
rctx_answer_positive(respctx_t *rctx) {
@@ -8634,15 +8629,10 @@ rctx_answer_positive(respctx_t *rctx) {
/*
* Determine which type of positive answer this is:
- * type ANY, CNAME, DNAME, or an answer matching QNAME/QTYPE.
+ * CNAME, DNAME, or an answer matching QNAME/QTYPE.
* Call the appropriate routine to handle the answer type.
*/
- if (rctx->aname != NULL && fctx->type == dns_rdatatype_any) {
- result = rctx_answer_any(rctx);
- if (result == ISC_R_COMPLETE) {
- return rctx->result;
- }
- } else if (rctx->aname != NULL) {
+ if (rctx->aname != NULL) {
result = rctx_answer_match(rctx);
if (result == ISC_R_COMPLETE) {
return rctx->result;
@@ -8725,13 +8715,9 @@ rctx_answer_scan(respctx_t *rctx) {
switch (namereln) {
case dns_namereln_equal:
ISC_LIST_FOREACH(name->list, rdataset, link) {
- if (rdataset->type == fctx->type ||
- fctx->type == dns_rdatatype_any)
- {
+ if (rdataset->type == fctx->type) {
rctx->aname = name;
- if (fctx->type != dns_rdatatype_any) {
- rctx->ardataset = rdataset;
- }
+ rctx->ardataset = rdataset;
break;
}
if (rdataset->type == dns_rdatatype_cname) {
@@ -8801,52 +8787,6 @@ rctx_answer_scan(respctx_t *rctx) {
}
}
-/*
- * rctx_answer_any():
- * Handle responses to queries of type ANY. Scan the answer section,
- * and as long as each RRset is of a type that is valid in the answer
- * section, and the rdata isn't filtered, cache it.
- */
-static isc_result_t
-rctx_answer_any(respctx_t *rctx) {
- fetchctx_t *fctx = rctx->fctx;
-
- ISC_LIST_FOREACH(rctx->aname->list, rdataset, link) {
- if (!validinanswer(rdataset, fctx)) {
- rctx->result = DNS_R_FORMERR;
- return ISC_R_COMPLETE;
- }
-
- if (dns_rdatatype_isaddr(rdataset->type) &&
- !is_answeraddress_allowed(fctx->res->view, rctx->aname,
- rdataset))
- {
- rctx->result = DNS_R_SERVFAIL;
- return ISC_R_COMPLETE;
- }
-
- if (dns_rdatatype_isalias(rdataset->type) &&
- !is_answertarget_allowed(fctx, fctx->name, rctx->aname,
- rdataset, NULL))
- {
- rctx->result = DNS_R_SERVFAIL;
- return ISC_R_COMPLETE;
- }
-
- dns_linkedname_attrs(rctx->aname)->cache = true;
- dns_linkedname_attrs(rctx->aname)->answer = true;
- if (dns_rdatatype_issig(rdataset->type)) {
- rdataset->attributes.answersig = true;
- } else {
- rdataset->attributes.answer = true;
- }
- rdataset->attributes.cache = true;
- rdataset->trust = rctx->trust;
- }
-
- return ISC_R_SUCCESS;
-}
-
/*
* rctx_answer_match():
* Handle responses that match the QNAME/QTYPE of the resolver query.
@@ -8872,7 +8812,6 @@ rctx_answer_match(respctx_t *rctx) {
}
if (dns_rdatatype_isalias(rctx->ardataset->type) &&
fctx->type != rctx->ardataset->type &&
- fctx->type != dns_rdatatype_any &&
!is_answertarget_allowed(fctx, fctx->name, rctx->aname,
rctx->ardataset, NULL))
{
@@ -10681,11 +10620,13 @@ dns_resolver_createfetch(dns_resolver_t *res, const dns_name_t *name,
REQUIRE(VALID_RESOLVER(res));
REQUIRE(res->frozen);
- /* XXXRTH Check for meta type */
if (dns_rdatatype_issig(type)) {
return DNS_R_FORMERR;
}
+ if (dns_rdatatype_ismeta(type)) {
+ return DNS_R_REFUSED;
+ }
if (domain != NULL) {
REQUIRE(DNS_DELEGSET_VALID(delegset));
diff --git a/lib/ns/query.c b/lib/ns/query.c
index e87aa6de4d..7c5d81a284 100644
--- a/lib/ns/query.c
+++ b/lib/ns/query.c
@@ -4649,6 +4649,16 @@ redirect2(ns_client_t *client, dns_name_t *name, dns_rdataset_t *rdataset,
dns_zone_detach(&zone);
}
+ /*
+ * ANY queries are never resolved (see ns__query_start()): unless
+ * the redirect namespace is served locally, there is nothing to
+ * redirect to that would not depend on the cache contents.
+ */
+ if (qtype == dns_rdatatype_any && !is_zone) {
+ dns_db_detach(&db);
+ return ISC_R_NOTFOUND;
+ }
+
/*
* Lookup the requested data in the redirect zone.
*/
@@ -5454,6 +5464,32 @@ ns__query_start(query_ctx_t *qctx) {
}
}
+ /*
+ * ANY queries are never resolved: the resolver does not send
+ * them upstream, and there is no other way to learn which types
+ * exist at a name. When recursion is requested and available,
+ * an ANY query that cannot be answered from authoritative data
+ * is therefore refused, in the spirit of RFC 8482, whether or
+ * not the cache already holds records for the name. The
+ * alternative to an error is a positive answer, never a NODATA
+ * one: resolvers cache a NODATA answer to an ANY query as the
+ * absence of all records at the name, so it would blank the
+ * name in any forwarder that still forwards ANY queries.
+ *
+ * ANY queries that do not recurse (RD=0, or recursion not
+ * available to the client) are processed as usual, so the
+ * cache can still be inspected with them.
+ */
+ if (qctx->qtype == dns_rdatatype_any &&
+ qctx->client->query.recursionok &&
+ (!qctx->authoritative || qctx->is_staticstub_zone))
+ {
+ dns_ede_add(&qctx->client->edectx, DNS_EDE_NOTSUPPORTED,
+ "recursive ANY queries are not supported");
+ QUERY_ERROR(qctx, DNS_R_REFUSED);
+ return ns_query_done(qctx);
+ }
+
/*
* If stale answers are enabled and stale-answer-client-timeout is zero,
* then we can promptly answer with a stale RRset if one is available in
@@ -8260,6 +8296,21 @@ query_zone_delegation(query_ctx_t *qctx) {
}
}
+ /*
+ * An ANY query for a name delegated from this zone could only be
+ * answered by recursing, which is never done for ANY queries (see
+ * ns__query_start()): refuse it, rather than answering with the
+ * referral, when recursion was requested.
+ */
+ if (qctx->qtype == dns_rdatatype_any && qctx->client->query.cacheok &&
+ qctx->client->query.recursionok)
+ {
+ dns_ede_add(&qctx->client->edectx, DNS_EDE_NOTSUPPORTED,
+ "recursive ANY queries are not supported");
+ QUERY_ERROR(qctx, DNS_R_REFUSED);
+ return ns_query_done(qctx);
+ }
+
if (qctx->client->query.cacheok &&
(qctx->client->query.recursionok ||
(qctx->zone != NULL &&
diff --git a/tests/dns/resolver_test.c b/tests/dns/resolver_test.c
index fd3c0e706e..ab06ac6463 100644
--- a/tests/dns/resolver_test.c
+++ b/tests/dns/resolver_test.c
@@ -106,7 +106,7 @@ ISC_LOOP_TEST_IMPL(create) {
static void
unexpected_fetch_done(void *arg) {
UNUSED(arg);
- fail_msg("an RRSIG query must not create a fetch");
+ fail_msg("a rejected query must not create a fetch");
}
ISC_LOOP_TEST_IMPL(rrsig_formerr) {
@@ -131,6 +131,35 @@ ISC_LOOP_TEST_IMPL(rrsig_formerr) {
isc_loopmgr_shutdown();
}
+ISC_LOOP_TEST_IMPL(metatype_refused) {
+ dns_resolver_t *resolver = NULL;
+ dns_rdataset_t rdataset;
+ const dns_rdatatype_t types[] = {
+ dns_rdatatype_any, dns_rdatatype_axfr, dns_rdatatype_ixfr,
+ dns_rdatatype_maila, dns_rdatatype_mailb, dns_rdatatype_opt,
+ dns_rdatatype_tsig, dns_rdatatype_tkey,
+ };
+
+ mkres(&resolver);
+ dns_resolver_freeze(resolver);
+ dns_rdataset_init(&rdataset);
+
+ for (size_t i = 0; i < ARRAY_SIZE(types); i++) {
+ dns_fetch_t *fetch = NULL;
+ isc_result_t result = dns_resolver_createfetch(
+ resolver, dns_rootname, types[i], NULL, NULL, NULL,
+ NULL, 0, 0, 0, NULL, NULL, NULL, isc_loop(),
+ unexpected_fetch_done, NULL, NULL, &rdataset, NULL,
+ &fetch);
+ assert_int_equal(result, DNS_R_REFUSED);
+ assert_null(fetch);
+ assert_false(dns_rdataset_isassociated(&rdataset));
+ }
+
+ destroy_resolver(&resolver);
+ isc_loopmgr_shutdown();
+}
+
/* dns_resolver_gettimeout */
ISC_LOOP_TEST_IMPL(gettimeout) {
dns_resolver_t *resolver = NULL;
@@ -219,6 +248,7 @@ ISC_LOOP_TEST_IMPL(settimeout_overmax) {
ISC_TEST_LIST_START
ISC_TEST_ENTRY_CUSTOM(create, setup_test, teardown_test)
ISC_TEST_ENTRY_CUSTOM(rrsig_formerr, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(metatype_refused, setup_test, teardown_test)
ISC_TEST_ENTRY_CUSTOM(gettimeout, setup_test, teardown_test)
ISC_TEST_ENTRY_CUSTOM(settimeout, setup_test, teardown_test)
ISC_TEST_ENTRY_CUSTOM(settimeout_default, setup_test, teardown_test)