]> git.ipfire.org Git - thirdparty/bind9.git/log
thirdparty/bind9.git
2 months agoFix output token and GSS context leaks in TKEY/GSS-API error paths
Ondřej Surý [Fri, 10 Apr 2026 10:51:31 +0000 (12:51 +0200)] 
Fix output token and GSS context leaks in TKEY/GSS-API error paths

In dst_gssapi_acceptctx(), rename outtoken to outtokenp (matching BIND
convention for output pointer parameters) and free the allocated output
token buffer on error in the cleanup path.

In process_gsstkey(), route the empty-principal error path through
cleanup via CLEANUP() instead of returning early, so that the output
token, GSS context, and TSIG key are all freed consistently by the
existing cleanup block.

2 months agoVerify integrity flag on server-side GSS-API context
Ondřej Surý [Wed, 18 Mar 2026 00:02:24 +0000 (01:02 +0100)] 
Verify integrity flag on server-side GSS-API context

After gss_accept_sec_context() completes, verify that the INTEG flag
is set in ret_flags.  Without integrity protection, GSS-TSIG message
authentication cannot function correctly.

The server side was previously passing NULL for ret_flags, meaning it
never verified the negotiated security properties.  The client side
was fixed in the previous commit; this fixes the server side.

2 months agoTest CHAOS view recursion behavior
Evan Hunt [Tue, 17 Mar 2026 20:45:11 +0000 (13:45 -0700)] 
Test CHAOS view recursion behavior

Check that recursive and forward queries to views of type CHAOS
are REFUSED, but that authoritative queries are answered correctly.

2 months ago[CVE-2026-3592] sec: usr: Limit resolver server list size
Colin Vidal [Thu, 30 Apr 2026 18:49:05 +0000 (20:49 +0200)] 
[CVE-2026-3592] sec: usr: Limit resolver server list size

When resolving a domain with many nameservers that share overlapping IP addresses (e.g., 10 NS records all pointing at the same set of addresses), BIND could previously waste time querying duplicate addresses and build up excessively large server lists.  Deduplicate addresses in the resolver's server list so that each unique IP is only queried once per resolution attempt, regardless of how many NS records point to it and cap the number of addresses stored per nameserver name to 6 (combined A and AAAA), preventing memory and CPU overhead from domains with unusually large NS/glue sets.

Closes isc-projects/bind9#5641

Merge branch '5641-selfpointedglue' into 'security-main'

See merge request isc-private/bind9!909

2 months agoFix use-after-free in resolver SIG(0) async verification path
Ondřej Surý [Tue, 17 Mar 2026 03:45:16 +0000 (04:45 +0100)] 
Fix use-after-free in resolver SIG(0) async verification path

When a SIG(0)-signed response triggers async ECDSA verification via
dns_message_checksig_async(), the respctx_t holds a raw pointer to
the resquery_t. If the fetch context is shut down while verification
is in flight (e.g. due to recursive-clients quota exhaustion), the
query is destroyed and the callback dereferences a dangling pointer.

Take a reference on the resquery_t when initializing the respctx_t,
and release it in both cleanup paths. The query's own reference to
the fetch context keeps the fctx alive transitively.

2 months agoAdd regression test for GSS-API context leak via TKEY CONTINUE
Ondřej Surý [Fri, 20 Mar 2026 07:43:28 +0000 (08:43 +0100)] 
Add regression test for GSS-API context leak via TKEY CONTINUE

Send crafted SPNEGO NegTokenInit tokens that propose the krb5
mechanism without a mechToken.  This causes gss_accept_sec_context()
to return GSS_S_CONTINUE_NEEDED, which on unfixed code leaks the
GSS context handle (~520 bytes per query).

The test verifies that the server rejects the negotiation (TKEY
error != 0, no continuation token) rather than returning a CONTINUE
response (error=0 with output token).

2 months agoImplement RFC 3645 Section 3.1.1 ret_flags check in GSS-API client
Ondřej Surý [Tue, 17 Mar 2026 23:28:19 +0000 (00:28 +0100)] 
Implement RFC 3645 Section 3.1.1 ret_flags check in GSS-API client

After gss_init_sec_context() completes, verify that both MUTUAL and
INTEG flags are set in ret_flags.  RFC 3645 Section 3.1.1 requires
the client to abandon the algorithm if either flag is missing, as
the security context would not provide mutual authentication or
message integrity.

Also fix uninitialized gss_name_t variable in dst_gssapi_initctx()
that could cause undefined behavior if gss_import_name() fails and
the cleanup path calls gss_release_name() on the uninitialized
value.

2 months agoSkip "deny-answer-address" for non-IN addresses
Evan Hunt [Tue, 17 Mar 2026 20:24:43 +0000 (13:24 -0700)] 
Skip "deny-answer-address" for non-IN addresses

Ensure that we don't attempt an ACL match for answer addresses
when handling a class-CHAOS zone. This is an additional line of
defense for YWH-PGM40640-74.

2 months agofix: usr: Do not resend query after BADCOOKIE answer on TCP
Colin Vidal [Thu, 30 Apr 2026 17:41:47 +0000 (19:41 +0200)] 
fix: usr: Do not resend query after BADCOOKIE answer on TCP

When an upstream server answers BADCOOKIE, no matter which transport is used,
the resolver resends the query using TCP. However, if the upstream
server responded with BADCOOKIE again over TCP, the resolver would keep
resending until the maximum query count was reached.

This is now fixed by no longer resending once the query has already been
sent over TCP.

See isc-projects/bind9#5804

Merge branch '5804-resend-loop-badcookie' into 'security-main'

See merge request isc-private/bind9!988

2 months agoupdate `max-delegation-servers` documentation
Colin Vidal [Thu, 2 Apr 2026 08:43:00 +0000 (10:43 +0200)] 
update `max-delegation-servers` documentation

Clarify how `max-delegation-servers` is used in the resolver, in
particular, the fact that it, in practice, caps the maximum outgoing
queries to resolve a name at a given delegation point.

2 months agoFix GSS-API context leak in TKEY negotiation
Ondřej Surý [Tue, 17 Mar 2026 23:10:35 +0000 (00:10 +0100)] 
Fix GSS-API context leak in TKEY negotiation

Reject multi-round GSS-API negotiation (GSS_S_CONTINUE_NEEDED) in
dst_gssapi_acceptctx().  Each call to gss_accept_sec_context()
allocates a context inside the GSS library; without this fix, the
context handle was passed back to process_gsstkey() which did not
store it persistently, leaking it on every incomplete negotiation.

An unauthenticated attacker could exhaust server memory by sending
repeated TKEY queries with GSSAPI tokens, each leaking one GSS
context.  The leaked memory is allocated by the GSS library via
malloc(), bypassing BIND's memory accounting.

In practice, Kerberos/SPNEGO (the only mechanism used with BIND)
completes in a single round, so rejecting continuation does not
affect real-world deployments.  See RFC 3645 Section 4.1.3.

2 months agoReject meta-classes in UPDATE and NOTIFY messages
Mark Andrews [Tue, 3 Mar 2026 23:00:56 +0000 (10:00 +1100)] 
Reject meta-classes in UPDATE and NOTIFY messages

NOTIFY and UPDATE messages must specify a data class in the
QUESTION/ZONE section.  NONE and ANY are meta-classes and not
appropriate here.  Return FORMERR if either is used.

Rejecting messages with a query class of NONE addresses YWH-PGM40640-72,
YWH-PGM40640-82, and YWH-PGM40640-83.  Rejecting messages with a query
class of ANY addresses YWH-PGM40640-87, YWH-PGM40640-88, and
YWH-PGM40640-117.

Fixes: isc-projects/bind9#5778
Fixes: isc-projects/bind9#5782
Fixes: isc-projects/bind9#5783
Fixes: isc-projects/bind9#5797
Fixes: isc-projects/bind9#5798
Fixes: isc-projects/bind9#5853
2 months ago[CVE-2026-5950] sec: usr: Avoid unbounded recursion loop
Colin Vidal [Thu, 30 Apr 2026 15:57:57 +0000 (17:57 +0200)] 
[CVE-2026-5950] sec: usr: Avoid unbounded recursion loop

A bug during bad server handling could cause the resolver to enter an infinite loop, continuously sending queries to an upstream server with no exit condition, until the resolver query timeout was hit. This has been fixed.

ISC would like to thank Billy Baraja (BielraX) for bringing this issue to our attention.

Closes isc-projects/bind9#5804

Merge branch '5804-resend-loop' into 'security-main'

See merge request isc-private/bind9!985

2 months agoUpdate resend_loop_badcookie system test
Colin Vidal [Fri, 10 Apr 2026 12:55:09 +0000 (14:55 +0200)] 
Update resend_loop_badcookie system test

Update the resend_loop_badcookie system test to ensure there is no
attempt to resend the query using TCP when getting BADCOOKIE from an
upstream server using this transport already.

2 months agoadd max-delegation-servers tests for out domain NS
Colin Vidal [Wed, 1 Apr 2026 20:31:50 +0000 (22:31 +0200)] 
add max-delegation-servers tests for out domain NS

Add a new system test which ensures that the `max-delegation-servers`
limit is correctly respected also in the case a domain has only NS names
(and no glues). In particular, this test when there are multiple NS
names and multiples IPs per names.

If the number of IP (even from the first picked NS name) reaches
`max-delegation-servers`, and the resolution is not a success, the
resolver won't attempt another NS name, as it already used all its
"credit".

2 months agoValidate DNS message CLASS early in request processing
Ondřej Surý [Wed, 4 Mar 2026 09:46:58 +0000 (10:46 +0100)] 
Validate DNS message CLASS early in request processing

Reject requests with unsupported or misused CLASS values before
further processing.  Only IN, CH, HS, RESERVED0 (for DNS Cookies),
ANY (for TKEY negotiation), and NONE (for DNS UPDATE) are accepted;
all other classes return NOTIMP.  Misuse of NONE or ANY outside
their allowed contexts returns FORMERR.

This adds further protection against bugs of the same general class
as YWH-PGM40640-70 and YWH-PGM40640-73.

2 months agosec: usr: Fix outgoing zone transfers' quota issue
Arаm Sаrgsyаn [Thu, 30 Apr 2026 12:36:49 +0000 (12:36 +0000)] 
sec: usr: Fix outgoing zone transfers' quota issue

Unauthorized clients could consume outgoing zone transfers quota
and block authorized zone transfer clients. This has been fixed.

Fixes isc-projects/bind9#3589

Merge branch '3859-security-xfrout-quota-fix' into 'security-main'

See merge request isc-private/bind9!971

2 months agorctx_resend() increment query counters
Colin Vidal [Tue, 7 Apr 2026 20:18:58 +0000 (22:18 +0200)] 
rctx_resend() increment query counters

Calls to `rctx_resend()` are done internally within the resolver, in
flow which are not supposed to happens more than once. For instance,
if some query fails, and a specific flag "F" wasn't set, then set the
flag and try again. This wouldn't occur more than once because if the
query fails the next attempt, the flag "F" would be set already, so the
resolver would move to the next server (or give up).

However, a subtle bug missing checking a flag, for instance, could lead
to an unbounded loop re-trying to query the same server. This is now
impossible as `rctx_resend()` also increment the query counters (so if
such case occurs, it would stop once the maximum limit is reached).

The dns_resstatscounter_retry are also only incremented if the
`fctx_query()` succeeds, similar to as is done in `fctx_try()`.

2 months agoDo not resend after BADCOOKIE answer on TCP
Colin Vidal [Fri, 10 Apr 2026 12:54:49 +0000 (14:54 +0200)] 
Do not resend after BADCOOKIE answer on TCP

When an upstream server answers BADCOOKIE, no matter the transport used,
the resolver eventually resends the query using TCP. However, if the
upstream server responds with BADCOOKIE again over TCP, the resolver
would keep resending until the maximum query count is reached.

This is now fixed by stopping resending once the query has already been
sent over TCP.

2 months agoAdd SRTT-based server selection system test
Colin Vidal [Wed, 4 Mar 2026 17:25:32 +0000 (18:25 +0100)] 
Add SRTT-based server selection system test

Verify that the resolver selects authoritative servers in increasing
SRTT order.  Four servers are configured with increasing response
delays.  100 queries are sent, expecting most to go to the fastest
server (ns2).  Then ns2 stops responding, another 100 queries are
sent and should go to ns3 (the next fastest), and so on through
ns4 and ns5.  Each query uses a unique name to avoid cache hits.

2 months agoDisable UPDATE and NOTIFY for non-IN classes
Evan Hunt [Wed, 4 Mar 2026 21:24:52 +0000 (13:24 -0800)] 
Disable UPDATE and NOTIFY for non-IN classes

Return NOTIMP for UPDATE and NOTIFY requests received for views with a
class other than IN.  Only QUERY is now supported for non-IN views such
as CHAOS.

When running dns dns_rdata_tostruct() with types that are only defined
for class IN, ensure that the class is correct before proceeding.

Add an assertion that any zone being updated is of class IN. (Note
that previously, a DLZ zone could have its class value set incorrectly
to NONE; this has been fixed.)

This addresses YWH-PGM40640-70 and YWH-PGM40640-73 (as well as any
similar problems that might have occurred in the future) by minimizing
the code paths that can be reached by rdata classes other than IN, so it
is safe for the implementation to assume that rdatatypes that are only
defined for class IN, such as SVCB or WKS, have been parsed and
validated, and not accepted as unknown/opaque data.

Fixes: isc-projects/bind9#5777
Fixes: isc-projects/bind9#5779
2 months agoApply XFR-out quota after ACL is checked
Aram Sargsyan [Tue, 31 Mar 2026 13:00:00 +0000 (13:00 +0000)] 
Apply XFR-out quota after ACL is checked

Unauthorized clients can consume XFR-out quota and block authorized
XFR clients. Apply the quota after ACL is checked.

2 months agoRefactor incrementing query counters
Colin Vidal [Tue, 7 Apr 2026 20:18:10 +0000 (22:18 +0200)] 
Refactor incrementing query counters

Move the logic incrementing the query counter and the global query
counter into a dedicated helper function.

2 months agoAdd system test for self-pointed glue deduplication
Colin Vidal [Thu, 5 Feb 2026 10:20:11 +0000 (11:20 +0100)] 
Add system test for self-pointed glue deduplication

Test the resolver's behavior with self-pointed glue where each NS
has the same set of addresses.  Verify that addresses are
deduplicated and each unique IP is only queried once.

Also test the NS processing limit (max-delegation-servers) and the
ADB address limit (adbaddrslimit), both individually and combined.

2 months agoDisable recursion for non-IN classes
Evan Hunt [Tue, 3 Mar 2026 22:00:38 +0000 (14:00 -0800)] 
Disable recursion for non-IN classes

Force recursion off, and set allow-recursion/allow-recursion-on ACLs
to none, for views with a class other than IN. Log a configuration
warning if recursion is explicitly enabled for a non-IN view.

This addresses YWH-PGM40640-74 and YWH-PGM40640-75 by preventing any
attempt at recursive processing in a class-CHAOS view, ensuring that
server addresses used for recursive queries and received in recursive
responses are of the expected format.

Fixes: isc-projects/bind9#5780
Fixes: isc-projects/bind9#5781
2 months agoAdd xfr quota starvation system test
Alessio Podda [Mon, 13 Apr 2026 13:55:38 +0000 (15:55 +0200)] 
Add xfr quota starvation system test

Add a starvation test that tries to starve the XFR quota with
unautorized requests.

2 months agoAdd reproducer for BADCOOKIE resend loop
Matthijs Mekking [Thu, 9 Apr 2026 09:32:07 +0000 (11:32 +0200)] 
Add reproducer for BADCOOKIE resend loop

Run malicious server: resend_loop/ans3/ans.py

Start BIND: ns4

Send single query to test.example

The resolver will repeatedly resend queries until the fetch timeout
expires, resulting in resulting in thousands of qrysent while the quota
counter remains 0.

2 months agoRemove duplicate addresses from the resolver SLIST
Colin Vidal [Wed, 4 Feb 2026 09:18:42 +0000 (10:18 +0100)] 
Remove duplicate addresses from the resolver SLIST

The SLIST (essentially `fctx->finds`, forwarders and dual-stack
alternatives aside) can have duplicate server addresses when multiple
in-domain nameservers share the same IP addresses:

  sub.example.          NS      ns1.sub.example.
  sub.example.          NS      ns2.sub.example.
  ns1.sub.example.      A       1.2.3.4
  ns1.sub.example.      A       5.6.7.8
  ns2.sub.example.      A       1.2.3.4
  ns2.sub.example.      A       5.6.7.8

If both 1.2.3.4 and 5.6.7.8 fail to return a valid answer, the resolver
would query each address twice.

The problem is fixed by replacing the two-phase server selection (sort
each find list by SRTT, sort finds by head SRTT) with a single linear
scan in nextaddress() that finds the lowest-SRTT unmarked, non-duplicate
address across all find lists.

The old approach had a correctness bug: after sorting, the resolver
picked the next address from the "current" find list rather than
globally.  For example, with find lists [1, 15, 26] and [3, 4, 5], the
second pick would be SRTT 15 instead of the correct SRTT 3.

The new approach is both simpler and correct: each call to nextaddress()
walks all addresses, skips marked and duplicate entries, and returns the
one with the lowest SRTT.  While this walk is repeated for each server
attempt, it operates on a small bounded list and is negligible compared
to the network I/O of querying the server.

2 months agoLimit the number of addresses returned per ADB find
Colin Vidal [Thu, 5 Feb 2026 08:46:01 +0000 (09:46 +0100)] 
Limit the number of addresses returned per ADB find

The number of `dns_adbaddrfind_t` (NS address with metadata like SRTT)
returned from an ADB NS name lookup is now limited by the caller. The
default value (outside the resolver) uses `max-delegation-servers`, and
the resolver, for a given fetch, start with `max-delegation-servers` and
decrement it at each ADB fetch. This ensures that, for a given
delegation, no more than 13 nameservers will be contacted.

This is the same mechanism used when looking up `dns_adbaddrfind_t` from
a list of glues (addresses).

2 months agochg: doc: Set up version for BIND 9.21.23
Andoni Duarte [Thu, 7 May 2026 08:30:20 +0000 (08:30 +0000)] 
chg: doc: Set up version for BIND 9.21.23

Merge branch 'andoni/set-up-version-for-bind-9.21.23' into 'main'

See merge request isc-projects/bind9!11980

2 months agoUpdate BIND version to 9.21.23-dev
Andoni Duarte Pintado [Thu, 7 May 2026 08:27:23 +0000 (10:27 +0200)] 
Update BIND version to 9.21.23-dev

2 months agofix: dev: Check validator name when adding EDE text
Evan Hunt [Wed, 6 May 2026 20:48:11 +0000 (20:48 +0000)] 
fix: dev: Check validator name when adding EDE text

When a validator is being shut down, the associated name
`val->name` is set to NULL.  This could cause a crash if a worker
thread subsequently added an EDE code with `val->name` in the
extra text.

`validator_addede()` now checks whether the name is NULL before
trying to add it to the extra text.

Closes #5613

Merge branch 'each-validator-log-after-shutdown' into 'main'

See merge request isc-projects/bind9!11945

2 months agocheck for val->name == NULL when adding EDE text
Evan Hunt [Fri, 1 May 2026 18:12:54 +0000 (11:12 -0700)] 
check for val->name == NULL when adding EDE text

When a validator is being shut down, the associated name
`val->name` is set to NULL.  This could cause a crash if a worker
thread subsequently added an EDE code to the response containing
val->name in the extra text.

`validator_addede()` now checks whether the name is NULL before
trying to add it to the extra text.

2 months agofix: usr: Fix a bug in allow-query/allow-transfer catalog zone custom properties
Arаm Sаrgsyаn [Wed, 6 May 2026 19:36:35 +0000 (19:36 +0000)] 
fix: usr: Fix a bug in allow-query/allow-transfer catalog zone custom properties

The :iscman:`named` process could terminate unexpectedly when
processing a catalog zone with an invalid ``allow-query`` or
``allow-transfer`` custom property (i.e. having a non-APL type)
coexisting with the valid property. This has been fixed.

Closes #5941

Merge branch '5941-catz-catz_process_apl-bug-fix' into 'main'

See merge request isc-projects/bind9!11954

2 months agoFix a bug in catz_process_apl()
Aram Sargsyan [Mon, 4 May 2026 22:34:01 +0000 (22:34 +0000)] 
Fix a bug in catz_process_apl()

The allow-transfer/allow-query catalog zone custom properties support
only APL RRtypes. All other types are correctly rejected by the
catz_process_apl() function. However, when an APL RRtype is processed
by that function, and another (non-APL) RRtype is then attempted to be
processed, there is an assertion failure happening in the prologue
of the function because `*aclbp != NULL` (i.e. an APL has been already
processed). Move the code to do type checking before the affected
REQUIRE assertion.

2 months agoAdd a catz test with invalid allow-transfer property
Aram Sargsyan [Mon, 4 May 2026 22:27:56 +0000 (22:27 +0000)] 
Add a catz test with invalid allow-transfer property

Check that invalid/unexpected RRtypes coexisting with a valid APL
RRtype does not cause an assertion failure.

2 months agofix: usr: Fix a memory leak issue in the catalog zones
Arаm Sаrgsyаn [Wed, 6 May 2026 18:18:58 +0000 (18:18 +0000)] 
fix: usr: Fix a memory leak issue in the catalog zones

The :iscman:`named` process could leak small amounts of memory
when processing a catalog zone entry which had defined custom
primary servers with TSIG keys using both the regular ``primaries``
custom property syntax and the legacy alternative syntax (``masters``)
at the same time. This has been fixed.

Closes #5943

Merge branch '5943-catz-primaries-tsig-key-name-leak-fix' into 'main'

See merge request isc-projects/bind9!11951

2 months agoFix a memory leak issue in catz_process_primaries()
Aram Sargsyan [Mon, 4 May 2026 11:45:21 +0000 (11:45 +0000)] 
Fix a memory leak issue in catz_process_primaries()

Free the old version of the keyname (if it exists) before setting
the new one.

2 months agoAdd a catz test with a duplicate primaries entry (alternative syntax)
Aram Sargsyan [Mon, 4 May 2026 11:40:57 +0000 (11:40 +0000)] 
Add a catz test with a duplicate primaries entry (alternative syntax)

This new check ads a catalog member zone with both variants of
the labeled primaries/masters property. This should not cause
any issues.

2 months agofix: usr: Prevent a crash when using both dns64 and filter-aaaa
Ondřej Surý [Wed, 6 May 2026 04:46:42 +0000 (06:46 +0200)] 
fix: usr: Prevent a crash when using both dns64 and filter-aaaa

An assertion failure could be triggered if both `dns64` and the `filter-aaaa` plugin were in use simultaneously. This happened if the plugin triggered a second recursion process, which then attempted to store DNS64 state information in a pointer that had already been set by the original recursion process. This has been fixed.

Closes #5854

Merge branch '5854-dns64-aaaaok' into 'main'

See merge request isc-projects/bind9!11949

2 months agoClear dns64_aaaaok immediately after use
Evan Hunt [Mon, 4 May 2026 05:00:39 +0000 (22:00 -0700)] 
Clear dns64_aaaaok immediately after use

The DNS64 state information stored in client->query.dns64_aaaaok
could cause an assertion failure in query_respond() if the server
was configured in such a way as to trigger a new recursion before
the query had been reset - for example, by using the filter-aaaa
plugin, which may need to recurse to find out whether an A record
exists.

This has been addressed by clearing DNS64 state information
immediately after the call to query_filter64().

2 months agofix: dev: Fix a stack use-after-free in qpzone
Evan Hunt [Tue, 5 May 2026 23:19:59 +0000 (23:19 +0000)] 
fix: dev: Fix a stack use-after-free in qpzone

In previous_closest_nsec(), a new qpreader was opened to search the NSEC
tree. It was possible for that to be used to update a QP iterator object
owned by the caller, and then be destroyed when the function returned.

This qpreader object isn't necessary anymore; since namespaces were
added to the QP trie in commit 15653c54a0, we can now just reuse the
existing reader for the main tree.

Closes #5942

Merge branch '5942-qpiter-fix' into 'main'

See merge request isc-projects/bind9!11955

2 months agoFix a stack use-after-free in qpzone
Evan Hunt [Mon, 4 May 2026 23:10:49 +0000 (16:10 -0700)] 
Fix a stack use-after-free in qpzone

In previous_closest_nsec(), a new qpreader was opened to search the NSEC
tree. It was possible for that to be used to update a QP iterator object
owned by the caller, and then be destroyed when the function returned.

This qpreader object isn't necessary anymore; since namespaces were
added to the QP trie in commit 15653c54a0, we can now just reuse the
existing reader for the main tree.

2 months agofix: usr: Fix a crash when reconfiguring while an NTA is being rechecked
Ondřej Surý [Tue, 5 May 2026 20:27:46 +0000 (22:27 +0200)] 
fix: usr: Fix a crash when reconfiguring while an NTA is being rechecked

When named was reconfigured or shut down while a negative trust anchor
was being rechecked against authoritative servers, the in-flight recheck
could outlive the view that owned it and cause `named` to crash.  This
has been fixed.

Closes #5938

Merge branch '5938-ref-ntatable' into 'main'

See merge request isc-projects/bind9!11948

2 months agoHold a reference to the NTA table for the lifetime of each NTA
Evan Hunt [Mon, 4 May 2026 07:05:27 +0000 (00:05 -0700)] 
Hold a reference to the NTA table for the lifetime of each NTA

Each dns__nta_t now references its parent ntatable in nta_create() and
releases it in dns__nta_destroy().  This avoids a use-after-free in
fetch_done() and other callbacks that dereference nta->ntatable: the
ntatable could otherwise be released by view destruction while an
in-flight resolver fetch still holds a reference to the NTA.

2 months agofix: dev: handle KSR files with DNSKEY records before any header
Ondřej Surý [Tue, 5 May 2026 19:06:43 +0000 (21:06 +0200)] 
fix: dev: handle KSR files with DNSKEY records before any header

A DNSKEY record appearing before the first ';; KeySigningRequest'
header in a KSR file made dnssec-ksr abort on an internal assertion
instead of producing a structured error, killing pipelines that
fed it crafted or corrupted input.  The tool now exits with a
fatal error naming the file and line.

Closes #5914

Merge branch '5914-dnssec-ksr-rdatalist-null-insist' into 'main'

See merge request isc-projects/bind9!11916

2 months agoReplace INSIST in KSR DNSKEY parser with a structured error
Ondřej Surý [Thu, 30 Apr 2026 04:43:50 +0000 (06:43 +0200)] 
Replace INSIST in KSR DNSKEY parser with a structured error

A DNSKEY record appearing before any ';; KeySigningRequest' header
in a KSR file made dnssec-ksr abort on INSIST(rdatalist != NULL),
which is the wrong tool for a malformed-input case.  Issue a fatal()
naming the file and line instead so pipelines see a clean exit
status and an actionable message; the now-unreachable NULL check on
the rdatalist->ttl update goes away too.

Assisted-by: Claude:claude-opus-4-7
2 months agofix: usr: Reject record sets too large to serve in DNS
Ondřej Surý [Tue, 5 May 2026 16:15:19 +0000 (18:15 +0200)] 
fix: usr: Reject record sets too large to serve in DNS

When BIND was asked to store a record set whose total size exceeds
what fits in a DNS message, it would allocate memory and build the
structure, then fail later at response time. Such oversized record
sets are now rejected at the time of storage with an error, avoiding
wasted work on data that can never be served.

Merge branch 'ondrej/harden-buflen-overflow' into 'main'

See merge request isc-projects/bind9!11963

2 months agoReject oversized RRsets at slab/vec construction
Ondřej Surý [Wed, 8 Apr 2026 10:53:16 +0000 (12:53 +0200)] 
Reject oversized RRsets at slab/vec construction

makeslab(), makevec(), dns_rdatavec_merge() and dns_rdatavec_subtract()
summed per-record storage into an unsigned int with no upper-bound
check.  An RRset whose total encoded size exceeds DNS_RDATA_MAXLENGTH
cannot fit in a DNS message and is unservable; building its in-memory
representation only burns memory on data that will fail at response
time, and at the upper bound the running sum could in theory wrap.

Cap the running total at DNS_RDATA_MAXLENGTH and return ISC_R_NOSPACE
when exceeded.  Update the qpdb cache memory-purge test to use a
record size that fits within the new limit.

Assisted-by: Claude:claude-opus-4-7
2 months agorem: dev: Remove obsolete KEY record flags deprecated by RFC 3445
Ondřej Surý [Tue, 5 May 2026 08:49:37 +0000 (10:49 +0200)] 
rem: dev: Remove obsolete KEY record flags deprecated by RFC 3445

KEY resource records originally defined NOAUTH, NOCONF, EXTENDED, and
ENTITY flags that were removed by RFC 3445 back in 2002. BIND still
carried code to parse and emit them, including the additional two-octet
flags field that followed when the EXTENDED bit was set. That handling
has been removed and the affected bit positions are now reserved.

Dropping the extended-flags handling also eliminates a possible crash
that could be reached when signing a zone containing an invalid key.

Closes #5900

Merge branch '5900-remove-keyflag-extended' into 'main'

See merge request isc-projects/bind9!11961

2 months agoRemove remaining RFC 3445 KEY flags
Mark Andrews [Thu, 30 Apr 2026 23:06:36 +0000 (09:06 +1000)] 
Remove remaining RFC 3445 KEY flags

RFC 3445 also eliminated the DNS_KEYTYPE_NOAUTH, DNS_KEYTYPE_NOCONF,
and DNS_KEYOWNER_ENTITY flags. With NOAUTH and NOCONF gone, the
concept of NOKEY can no longer be expressed in KEY records.

DNS_KEYOWNER_ENTITY was already unused as of 22d688f656 but still
defined; that is now also removed.

2 months agoRemove DNS_KEYFLAG_EXTENDED
Evan Hunt [Thu, 30 Apr 2026 18:28:58 +0000 (11:28 -0700)] 
Remove DNS_KEYFLAG_EXTENDED

The DNS_KEYFLAG_EXTENDED flag was only legitimate for type KEY
and was eliminated by RFC 3445. Dropping the extended-flags
handling in pub_compare() also fixes a possible crash when
signing a zone whose journal contains a crafted DNSKEY: a
6-byte record with the EXTENDED bit set produced a memmove()
length that underflowed and ran off a stack buffer.

2 months agofix: usr: Prevent crafted queries from degrading RRL performance 3134-disable-tls-renegotiations
Ondřej Surý [Mon, 4 May 2026 12:58:42 +0000 (14:58 +0200)] 
fix: usr: Prevent crafted queries from degrading RRL performance

With response rate limiting enabled, an attacker sending queries from many
spoofed source addresses could steer entries into the same slot of the
internal rate-limit table and slow down query processing on the affected
server. The table now uses a per-process keyed hash so the placement of
entries cannot be predicted or influenced from the network.

Closes #5906

Merge branch '5906-rrl-hash-collision-dos' into 'main'

See merge request isc-projects/bind9!11950

2 months agoUse a keyed hash for the RRL bucket table
Ondřej Surý [Wed, 29 Apr 2026 16:20:03 +0000 (18:20 +0200)] 
Use a keyed hash for the RRL bucket table

The previous hash_key() was a deterministic, unkeyed (<<1) + add over the
key words.  An off-path attacker could invert it offline and submit
queries whose source /24, qname hash, and qtype map to a single bucket;
under chaining this turns every lookup into an O(N) walk under
rrl->lock and starves legitimate query processing on the very feature
deployed to mitigate DoS.

Replace it with isc_hash32(), which is HalfSipHash-2-4 keyed by a
per-process random seed, so collision sets cannot be precomputed.

Assisted-by: Claude:claude-opus-4-7
2 months agochg: nil: Minor simplification in dnssec-keygen
Evan Hunt [Fri, 1 May 2026 20:22:58 +0000 (20:22 +0000)] 
chg: nil: Minor simplification in dnssec-keygen

The name of the key to generate can be passed to `keygen()` as a
string; we don't need to pass it using argc/argv.

Merge branch 'each-keygen-cleanup' into 'main'

See merge request isc-projects/bind9!11942

2 months agominor simplification in dnssec-keygen
Evan Hunt [Fri, 1 May 2026 04:30:55 +0000 (21:30 -0700)] 
minor simplification in dnssec-keygen

The name of the key to generate can be passed to `keygen()` as a
string; we don't need to pass it using argc/argv.

2 months agofix: dev: Avoid named assertion failure during parent-NS lookups when none exist
Ondřej Surý [Fri, 1 May 2026 06:18:44 +0000 (08:18 +0200)] 
fix: dev: Avoid named assertion failure during parent-NS lookups when none exist

Configuring the root zone as a signed primary with parental agents (or with
notify-on-cds-changes) caused named to exit on an internal assertion as soon
as the DS-publication machinery tried to look up the parent NS RRset — the root
has no parent. The lookup is now short-circuited cleanly.

Similar, a zone with no NS records in the parent caused named to exit in the same way.

Closes #5910

Merge branch '5910-nsfetch-start-root-domain-assertion' into 'main'

See merge request isc-projects/bind9!11909

2 months agoGuard parent-NS walk against running off the root
Ondřej Surý [Wed, 29 Apr 2026 18:20:04 +0000 (20:20 +0200)] 
Guard parent-NS walk against running off the root

Once the walk reaches the root, splitting one more label off would
trip an internal assertion and abort named.  Stop cleanly with
ISC_R_NOTFOUND so the dispatcher cancels the fetch.  Only reachable
through misconfiguration (root configured as a primary with parental
agents, or a parent zone that NODATAs its own NS).

Assisted-by: Claude:claude-opus-4-7
2 months agoChange isctest.kasp.dnssec_verify to take FQDN
Matthijs Mekking [Thu, 30 Apr 2026 08:20:43 +0000 (10:20 +0200)] 
Change isctest.kasp.dnssec_verify to take FQDN

This is required to AXFR and verify the root zone and it makes no
difference for non-root zones (dnssec-verify takes FQDN or makes the
provided name absolute).

2 months agoAdd kasp test case for root with checkds enabled
Matthijs Mekking [Thu, 30 Apr 2026 08:17:40 +0000 (10:17 +0200)] 
Add kasp test case for root with checkds enabled

Add a test case where the root zone has dnssec-policy configured, with
checkds enabled. This is a silly case because the root does not have
any parent NS records, but it should not crash the server.

The same is true for zones that do not have parent NS records, but
eventually they will hit the same code path.

2 months agochg: dev: Catch rare named crash in recursive resolution earlier for diagnosis
Ondřej Surý [Fri, 1 May 2026 05:50:38 +0000 (07:50 +0200)] 
chg: dev: Catch rare named crash in recursive resolution earlier for diagnosis

A rare crash has been observed in named while it is resolving upstream nameserver
addresses for a recursive query, surfacing as a segmentation fault with no immediate
clue as to the cause. This change adds internal consistency checks so that a future
occurrence of the same condition aborts named with a diagnostic message at the point
the inconsistency arises, rather than corrupting state and crashing later in
an unrelated location.

Closes #5602

Merge branch '5602-adb-find-sanity-checks' into 'main'

See merge request isc-projects/bind9!11943

2 months agoAssert adb find loop-affinity invariant at lifetime entry points
Ondřej Surý [Fri, 1 May 2026 04:44:06 +0000 (06:44 +0200)] 
Assert adb find loop-affinity invariant at lifetime entry points

The dns_adbfind_t lifetime model has no reference counting; storage
liveness is held together by find->lock and the FIND_EVENT_SENT
idempotency flag, plus an unwritten cross-module rule that all
non-trivial operations on a find run on find->loop. If a caller
violates that rule, the unlock-relock window in dns_adb_cancelfind
(and similar paths) becomes a use-after-free and we crash later
inside libpthread on a corrupted mutex.

Add REQUIREs at dns_adb_cancelfind, dns_adb_destroyfind and
find_sendevent so a violation aborts at the offending call site
rather than silently freeing storage another loop is still touching.
Also poison find->magic with ~DNS_ADBFIND_MAGIC in free_adbfind so
DNS_ADBFIND_VALID catches reuse-after-free at the next public entry
point instead of letting the dangling pointer reach the mutex code.

Assisted-by: Claude:claude-opus-4-7
2 months agofix: dev: Harden dig's EDNS option parsing against malformed replies
Ondřej Surý [Fri, 1 May 2026 05:19:57 +0000 (07:19 +0200)] 
fix: dev: Harden dig's EDNS option parsing against malformed replies

dig's parser for EDNS options in a DNS reply now stops cleanly when an
option declares a length that runs past the end of the option data,
rather than trusting the upstream OPT-record validator to reject the
reply first. This is a defensive change; behavior is unchanged in
practice.

Merge branch 'ondrej/dig-process-opt-edns-optlen-oob' into 'main'

See merge request isc-projects/bind9!11937

2 months agoBound EDNS option length in dig's process_opt() walk
Ondřej Surý [Thu, 30 Apr 2026 12:12:50 +0000 (14:12 +0200)] 
Bound EDNS option length in dig's process_opt() walk

process_opt() reads the per-option (optcode, optlen) header from the
OPT rdata and then advances the buffer by optlen, both for the COOKIE
branch (via process_cookie()) and for any other optcode.  The walk
itself never compared optlen to the buffer remainder; the only reason
it cannot trip the isc_buffer_forward() REQUIRE today is that
fromwire_opt() (lib/dns/rdata/generic/opt_41.c) already validates each
option's length against the rdata bounds before the rdataset is
handed back, so process_opt() never sees a self-inconsistent rdata.

That upstream guarantee is fine, but it leaves the local walker
trusting an invariant established elsewhere.  Add a defensive check
that just stops the walk when a future caller (a cached message, an
alternate parser, a refactor of the OPT validator) hands process_opt()
a buffer where optlen would run past the end.

Assisted-by: Claude:claude-opus-4-7
2 months agofix: ci: Use "git push --force-with-lease" for autorebases
Michał Kępień [Thu, 30 Apr 2026 20:34:55 +0000 (22:34 +0200)] 
fix: ci: Use "git push --force-with-lease" for autorebases

If a merge request is merged to an autorebased branch while it is
getting rebased, the "git push -f" command at the end of the autorebase
job will cause the contents of that merge request to be silently deleted
from Git history even though the merge request will still be (correctly)
shown as "merged" by GitLab.

Use "git push --force-with-lease" instead to prevent force-pushing the
rebased version of the branch if it is pushed to after its pre-rebase
version is fetched by the autorebase job.  Report such an event
accordingly.  For simplicity, no retries are attempted as the problem is
expected to be resolved by the next autorebase and the chances of this
scenario happening in practice are already low to begin with.

Merge branch 'michal/use-git-push-force-with-lease-for-autorebases' into 'main'

See merge request isc-projects/bind9!11939

2 months agoUse "git push --force-with-lease" for autorebases
Michał Kępień [Thu, 30 Apr 2026 20:19:59 +0000 (22:19 +0200)] 
Use "git push --force-with-lease" for autorebases

If a merge request is merged to an autorebased branch while it is
getting rebased, the "git push -f" command at the end of the autorebase
job will cause the contents of that merge request to be silently deleted
from Git history even though the merge request will still be (correctly)
shown as "merged" by GitLab.

Use "git push --force-with-lease" instead to prevent force-pushing the
rebased version of the branch if it is pushed to after its pre-rebase
version is fetched by the autorebase job.  Report such an event
accordingly.  For simplicity, no retries are attempted as the problem is
expected to be resolved by the next autorebase and the chances of this
scenario happening in practice are already low to begin with.

2 months agofix: usr: Reject negative and out-of-range TTLs in dnssec-* tools
Ondřej Surý [Thu, 30 Apr 2026 15:40:39 +0000 (17:40 +0200)] 
fix: usr: Reject negative and out-of-range TTLs in dnssec-* tools

The dnssec-* tools accepted negative and out-of-range values for TTL
flags such as dnssec-keygen -L, dnssec-signzone -t and
dnssec-settime -L, silently turning them into TTLs of around 136 years
in the resulting key or zone files. The flag values are now validated
and rejected with a clear "TTL must be non-negative" or "TTL out of
range" error.

Closes #5923

Merge branch '5923-dnssectool-strtottl-negative-ttl-accepted' into 'main'

See merge request isc-projects/bind9!11933

2 months agoReject negative and out-of-range TTLs in dnssec-* tools
Ondřej Surý [Thu, 30 Apr 2026 11:16:12 +0000 (13:16 +0200)] 
Reject negative and out-of-range TTLs in dnssec-* tools

strtottl() parsed the operator's TTL string with strtol() and assigned
the long directly to dns_ttl_t (uint32_t) with no sign or ERANGE
check. The only validation was the "no digits parsed" branch, so a
fully-consumed "-1" became UINT32_MAX (~136 years) and was silently
written into DNSKEY/key files by dnssec-keygen -L, dnssec-signzone -t,
dnssec-settime -L, etc. Any signing pipeline interpolating the TTL
from a variable could mint a key with a multi-decade TTL and never see
an error.

Switch to strtoul(), reject a leading '-' explicitly (strtoul silently
negates), check errno == ERANGE, and reject values exceeding
UINT32_MAX before handing the result to time_units(). The pre-existing
multiplication wrap inside time_units() is tracked separately.

Assisted-by: Claude:claude-opus-4-7
2 months agofix: test: Fix `cyclic_glue` system test
Colin Vidal [Thu, 30 Apr 2026 14:31:21 +0000 (16:31 +0200)] 
fix: test: Fix `cyclic_glue` system test

The `cyclic_glue` system test was not explicitly waiting for the dump to
complete. As a result, the test could read an outdated dump file and
perform assertions on database state. Fix this by waiting for `dumpdb`
command to finish before reading `named_dump.db`.

Merge branch 'colin/fix-cyclic_glue-test' into 'main'

See merge request isc-projects/bind9!11934

2 months agoFix `cyclic_glue` system test
Colin Vidal [Thu, 30 Apr 2026 13:18:03 +0000 (14:18 +0100)] 
Fix `cyclic_glue` system test

The `cyclic_glue` system test was not explicitly waiting for the dump to
complete. As a result, the test could read an outdated dump file and
perform assertions on database state. Fix this by waiting for `dumpdb`
command to finish before reading `named_dump.db`.

2 months agofix: dev: Reject RSA DNSKEYs with degenerate modulus
Ondřej Surý [Thu, 30 Apr 2026 13:50:37 +0000 (15:50 +0200)] 
fix: dev: Reject RSA DNSKEYs with degenerate modulus

A crafted DNSKEY rdata whose declared exponent length consumed the
whole buffer produced an RSA key with no modulus, which dnssec-importkey
accepted as valid and wrote to a .private file with no key material.
The wire-format parser now rejects RSA public keys with a modulus
smaller than 512 bits, the lowest legitimate size across the RSA
DNSSEC algorithms.

Closes #5920

Merge branch '5920-opensslrsa-fromdns-zero-modulus-accepted' into 'main'

See merge request isc-projects/bind9!11929

2 months agoReject RSA DNSKEYs with degenerate modulus at parse time
Ondřej Surý [Thu, 30 Apr 2026 09:55:14 +0000 (11:55 +0200)] 
Reject RSA DNSKEYs with degenerate modulus at parse time

The wire-format RSA DNSKEY parser used the residual rdata length after
the exponent as the modulus length, with no positive lower bound.  A
crafted DNSKEY whose declared exponent length consumed the whole buffer
produced n = 0; the BN_bin2bn(_, 0, _) returned a non-NULL BIGNUM, the
NULL-check passed, and dnssec-importkey -f wrote out a "valid" key with
no key material.  RSASHA1 also bypassed the algorithm-specific lower
bound in opensslrsa_createctx (which only checks an upper bound for the
SHA1 algorithms), so the degenerate key reached the verify path with
whatever behaviour the linked OpenSSL exhibits for n = 0.

Add OPENSSLRSA_MIN_MODULUS_BITS = 512 (the lowest legitimate modulus
across the RSA DNSSEC algorithms per RFC 5702) and reject smaller
moduli at parse time in opensslrsa_fromdns, opensslrsa_parse, and
opensslrsa_fromlabel — the same three load paths where the existing
exponent upper-bound check lives.

Assisted-by: Claude:claude-opus-4-7
2 months agofix: usr: Fix dig -x crash on excessively long arguments
Ondřej Surý [Thu, 30 Apr 2026 12:02:08 +0000 (14:02 +0200)] 
fix: usr: Fix dig -x crash on excessively long arguments

dig -x crashed with a segmentation fault rather than printing an
error when given an argument with thousands of dot-separated
components. dig -x now rejects such inputs cleanly with "Invalid IP
address".

Closes #5917

Merge branch '5917-dig-reverse-octets-stack-overflow' into 'main'

See merge request isc-projects/bind9!11928

2 months agoProcess dig -x reverse octets iteratively
Ondřej Surý [Thu, 30 Apr 2026 09:31:51 +0000 (11:31 +0200)] 
Process dig -x reverse octets iteratively

reverse_octets() recursed once per dot, with depth bounded only by
ARG_MAX (~2 MiB on Linux), so feeding dig -x a deep input like
'1.1.1.…1' busted the call stack and crashed the tool with SIGSEGV
instead of a structured error.  The transformation it performs is
purely textual (split on '.', emit components in reverse), so the
recursion was never load-bearing.

Walk the input once into a fixed-size array of label slices, capped at
DNS_NAME_MAXLABELS (which is the most we could ever fit into the
result buffer anyway), then iterate the array in reverse to write the
output.  Inputs with more than DNS_NAME_MAXLABELS labels now return
DNS_R_NAMETOOLONG, which dig.c surfaces as 'Invalid IP address' and
exit 1.  Drop the unnecessary (int) casts on ptrdiff_t/size_t lengths
while at it.

Assisted-by: Claude:claude-opus-4-7
2 months agonew: ci: Set up automatic rebasing for security-* branches
Michał Kępień [Thu, 30 Apr 2026 10:17:32 +0000 (12:17 +0200)] 
new: ci: Set up automatic rebasing for security-* branches

Introduce a set of private branches containing only security fixes that
are automatically rebased onto the corresponding open source branches
whenever new changes are merged.  Each rebase triggers a basic build,
failing the CI job if the build breaks.

When a security-* branch is rebased, create a CI pipeline for its new
revision and rebase its corresponding bind-9.x-sub branch (if it exists)
on top of it, creating a rebase chain.

Report any failures in the process via Mattermost.

These changes enable treating security fixes similarly to other code
changes, without deferring merges all the way until release prep.

Merge branch 'michal/autorebase-chain' into 'main'

See merge request isc-projects/bind9!11930

2 months agoSet up automatic rebasing for security-* branches
Michał Kępień [Thu, 30 Apr 2026 09:58:55 +0000 (11:58 +0200)] 
Set up automatic rebasing for security-* branches

Introduce a set of private branches containing only security fixes that
are automatically rebased onto the corresponding open source branches
whenever new changes are merged.  Each rebase triggers a basic build,
failing the CI job if the build breaks.

When a security-* branch is rebased, create a CI pipeline for its new
revision and rebase its corresponding bind-9.x-sub branch (if it exists)
on top of it, creating a rebase chain.

Report any failures in the process via Mattermost.

These changes enable treating security fixes similarly to other code
changes, without deferring merges all the way until release prep.

2 months agofix: usr: Stop delv from aborting on a malformed query name
Ondřej Surý [Thu, 30 Apr 2026 08:56:18 +0000 (10:56 +0200)] 
fix: usr: Stop delv from aborting on a malformed query name

delv aborts with SIGABRT instead of exiting cleanly when given a query
name that fails wire-format conversion (e.g. a label longer than 63
octets). After this change delv prints the parse error and exits with
a normal failure code.

Closes #5916

Merge branch '5916-delv-run-resolve-null-detach-abort' into 'main'

See merge request isc-projects/bind9!11921

2 months agoSkip detach when delv's client never created
Ondřej Surý [Thu, 30 Apr 2026 07:38:40 +0000 (09:38 +0200)] 
Skip detach when delv's client never created

run_resolve allocates dns_client_t late, but the cleanup epilogue
called dns_client_detach() unconditionally. When convert_name() or
dns_client_create() failed first, the detach hit a NULL client and
the REQUIRE(DNS_CLIENT_VALID) inside it aborted the process with
SIGABRT instead of a clean error exit.

Guard the detach with a NULL check. Add a digdelv test that runs
delv on a query name whose first label exceeds 63 octets and
asserts the process does not exit 134.

Assisted-by: Claude:claude-opus-4-7
2 months agofix: usr: prevent malicious DNSSEC zones from exhausting validator CPU
Ondřej Surý [Thu, 30 Apr 2026 08:55:49 +0000 (10:55 +0200)] 
fix: usr: prevent malicious DNSSEC zones from exhausting validator CPU

A DNSSEC-signed zone could publish a DNSKEY with an unusually large
RSA public exponent and force any validator resolving names in that
zone to spend disproportionate CPU verifying signatures.  The
validator now rejects such DNSKEYs, matching the limit already
applied to keys read from files or HSMs.

Closes #5881

Merge branch '5881-rsa-exponent-keytrap-cpu-amplification' into 'main'

See merge request isc-projects/bind9!11917

2 months agoReject RSA DNSKEYs with oversize public exponents at parse time
Ondřej Surý [Thu, 30 Apr 2026 05:01:53 +0000 (07:01 +0200)] 
Reject RSA DNSKEYs with oversize public exponents at parse time

The wire-format RSA DNSKEY parser was the only key path with no upper
bound on the public exponent — opensslrsa_parse and opensslrsa_fromlabel
already cap at RSA_MAX_PUBEXP_BITS.  An attacker-controlled DNSKEY could
therefore force a validator to compute s^e mod n with e up to ~|n| bits,
amplifying every verify by ~120x for typical 2048-bit moduli (OpenSSL
itself only caps the exponent for moduli above 3072 bits).  Apply the
same bit-count cap to wire-format keys.

Assisted-by: Claude:claude-opus-4-7
2 months agofix: usr: prevent rare named crash when notifies are cancelled
Ondřej Surý [Thu, 30 Apr 2026 08:16:46 +0000 (10:16 +0200)] 
fix: usr: prevent rare named crash when notifies are cancelled

Under heavy load, named could occasionally crash when a queued
outbound notify or zone refresh was cancelled at the moment it
was being sent — for example, while a zone was being reloaded or
removed.  The race that caused the crash is now prevented.

Closes #5915

Merge branch '5915-ratelimiter-dequeue-tick-uaf' into 'main'

See merge request isc-projects/bind9!11918

2 months agoDispatch ratelimiter events under the lock
Ondřej Surý [Thu, 30 Apr 2026 05:39:23 +0000 (07:39 +0200)] 
Dispatch ratelimiter events under the lock

isc__ratelimiter_tick() and isc_ratelimiter_shutdown() each pulled
events out of rl->pending into a function-local list, dropped the
mutex, and then iterated.  ISC_LIST_APPEND leaves the link in the
LINKED state, so a concurrent isc_ratelimiter_dequeue() saw an
event as still queued, called ISC_LIST_UNLINK against rl->pending —
which patched the prev/next of the local list — and freed the
event before dispatch finished, producing either an INSIST in the
unlink macro or a use-after-free in the dispatch loop.

isc_async_run() is a non-blocking wfcq enqueue, so there is no
benefit to dropping the mutex around it.  Unlink each event and
hand it to isc_async_run() while still holding rl->lock; the
existing ISC_LINK_LINKED check in dequeue then correctly
distinguishes "still queued and cancellable" from "already taken".

Assisted-by: Claude:claude-opus-4-7
2 months agofix: dev: free per-command rndc state when response serialisation fails
Ondřej Surý [Thu, 30 Apr 2026 07:33:00 +0000 (09:33 +0200)] 
fix: dev: free per-command rndc state when response serialisation fails

When isccc_cc_towire failed while building an rndc reply,
control_respond returned without releasing the per-command request,
response, HMAC secret copy, and text buffer.  They were eventually
freed when the connection closed, but until then the HMAC key copy
stayed in named's memory.  The failure path now goes through the
same cleanup label as every other error.

Closes #5913

Merge branch '5913-controlconf-control-respond-cleanup-leak' into 'main'

See merge request isc-projects/bind9!11915

2 months agoRun conn_cleanup on isccc_cc_towire failure in control_respond
Ondřej Surý [Thu, 30 Apr 2026 04:29:21 +0000 (06:29 +0200)] 
Run conn_cleanup on isccc_cc_towire failure in control_respond

The bare return left conn->secret, conn->response, conn->request, and
conn->text pinned until the connection itself was torn down — every
other error in the function reaches conn_cleanup via goto, and the
success path falls into the same label, so the towire-failure return
was the lone outlier.  Send it through the existing cleanup path.

Assisted-by: Claude:claude-opus-4-7
2 months agofix: dev: remove the rndc testgen command
Ondřej Surý [Thu, 30 Apr 2026 04:35:07 +0000 (06:35 +0200)] 
fix: dev: remove the rndc testgen command

testgen existed only to let the rndc system test generate large response payloads.
It accepted an unbounded count and was reachable from read-only control channels,
so any read-only rndc client could drive named into memory exhaustion. The command
and its supporting test helper are gone; remaining rndc commands already produce
non-trivial responses, so transport coverage is preserved.

Closes #5911

Merge branch '5911-rndc-testgen-32bit-truncation-memory-exhaustion' into 'main'

See merge request isc-projects/bind9!11912

2 months agoRemove the rndc testgen command
Ondřej Surý [Wed, 29 Apr 2026 18:41:20 +0000 (20:41 +0200)] 
Remove the rndc testgen command

testgen existed solely to let the rndc system test exercise large
response payloads — it has no operator value, accepts an unbounded
count, and could be invoked by any read-only rndc client to drive
named into memory exhaustion.  Drop the command, the gencheck helper
that validated its output, and the buffer-size loop in the rndc
system test; the remaining rndc subcommands already produce
non-trivial responses, so the framing path stays exercised.

Assisted-by: Claude:claude-opus-4-7
2 months agofix: dev: Fix swapped arguments in redirect2() single-label branch
Ondřej Surý [Wed, 29 Apr 2026 19:46:32 +0000 (21:46 +0200)] 
fix: dev: Fix swapped arguments in redirect2() single-label branch

On a recursive resolver with nxdomain-redirect configured, an
NXDOMAIN result for a query whose qname is the root could corrupt
the view's nxdomain-redirect target, after which the redirect
feature stopped working for every subsequent query in that view
until named was restarted.

Closes #5908

Merge branch '5908-query-redirect2-name-copy-arg-swap' into 'main'

See merge request isc-projects/bind9!11908

2 months agoFix swapped arguments in redirect2() single-label branch
Ondřej Surý [Wed, 29 Apr 2026 17:23:19 +0000 (19:23 +0200)] 
Fix swapped arguments in redirect2() single-label branch

For a query whose qname is the root, the labels==1 branch in
redirect2() called dns_name_copy(redirectname, view->redirectzone)
with arguments reversed, overwriting the view-global
nxdomain-redirect target with the empty redirectname rather than
copying the configured target into the per-query lookup name.  After
the corruption, view->redirectzone names the root, so
dns_name_issubdomain() makes redirect2() short-circuit for every
subsequent query and the nxdomain-redirect feature stops working
until named is restarted.

Triggering this needs the resolver to receive an NXDOMAIN for the
root from upstream, which does not happen in normal DNS operation.

Swap the arguments to match the dns_name_copy(source, dest)
signature.  Add a system test that issues a root query through the
nxdomain-redirect resolver and verifies the redirect feature still
works for a normal NXDOMAIN-producing query afterwards.

Assisted-by: Claude:claude-opus-4-7
2 months agofix: usr: Fix rndc-confgen aborting on HMAC-SHA-384/512 keys above 512 bits
Ondřej Surý [Wed, 29 Apr 2026 18:34:31 +0000 (20:34 +0200)] 
fix: usr: Fix rndc-confgen aborting on HMAC-SHA-384/512 keys above 512 bits

`rndc-confgen -A hmac-sha384` and `-A hmac-sha512` documented a `-b`
range of 1..1024, but any value above 512 aborted on hardened builds
instead of producing a key. The full advertised range now works.

Closes #5903

Merge branch '5903-hmac-generate-stack-overflow' into 'main'

See merge request isc-projects/bind9!11903

2 months agoSize HMAC key generation buffers to the maximum block size
Ondřej Surý [Wed, 29 Apr 2026 14:23:10 +0000 (16:23 +0200)] 
Size HMAC key generation buffers to the maximum block size

hmac_generate() declared its on-stack nonce buffer as
unsigned char data[ISC_MAX_MD_SIZE], i.e. 64 bytes. That is the maximum
digest size, but the buffer is filled up to the algorithm's HMAC block
size, which is 128 bytes for SHA-384 and SHA-512. Asking rndc-confgen
for an HMAC-SHA-384 or HMAC-SHA-512 key with -b > 512 (the documented
range allows up to 1024) wrote past the end of the stack buffer; on
hardened builds this aborted with a stack-smash detector firing
instead of producing a key.

Use the existing ISC_MAX_BLOCK_SIZE (128) for the buffer so the full
1..1024 range advertised by -A hmac-sha{384,512} works as documented.
The matching key_rawsecret[64] in confgen's generate_key() is enlarged
the same way so the generated key fits when dumped to the buffer.

Add a system test that exercises rndc-confgen across the previously
overflowing keysizes; with -Db_sanitize=address it caught the abort
before the fix.

Assisted-by: Claude:claude-opus-4-7
2 months agofix: dev: Do not follow symlinks when chowning the NZD database
Ondřej Surý [Wed, 29 Apr 2026 17:18:55 +0000 (19:18 +0200)] 
fix: dev: Do not follow symlinks when chowning the NZD database

When `named` runs as root, the per-view NZD database file is chowned
to the user `named` drops to. The chown call followed symlinks, so a
symlink at the database path could redirect the ownership change to an
unrelated file. The chown now refuses non-regular files and never
follows symlinks.

Closes #5905

Merge branch '5905-nzd-env-close-symlink-chown' into 'main'

See merge request isc-projects/bind9!11907

2 months agoStop nzd_env_close from chowning through symlinks
Ondřej Surý [Wed, 29 Apr 2026 15:49:46 +0000 (17:49 +0200)] 
Stop nzd_env_close from chowning through symlinks

When named is running as root, nzd_env_close() chowns the per-view
NZD database file to the unprivileged user that named will drop to.
The call used chown(), which follows symlinks, so a symlink at the
NZD path would silently transfer ownership of whatever the link
pointed at instead of the database file itself.

Switch to lstat() + S_ISREG() + lchown() so the chown only fires when
the path is a regular file and never traverses a symlink even if one
is planted between the lstat and the lchown.

Assisted-by: Claude:claude-opus-4-7
2 months agofix: usr: Validate key names in rndc-confgen, tsig-keygen, ddns-confgen
Ondřej Surý [Wed, 29 Apr 2026 16:12:52 +0000 (18:12 +0200)] 
fix: usr: Validate key names in rndc-confgen, tsig-keygen, ddns-confgen

The three tools embedded the key-name argument verbatim into the
generated `named.conf` block, so a name containing characters like
`"`, `{`, or `;` produced output that did not match the intended
`key` clause. Key names are now restricted to letters, digits, dots,
hyphens, and underscores.

Closes #5904

Merge branch '5904-confgen-keyname-config-injection' into 'main'

See merge request isc-projects/bind9!11904

2 months agoReject unsafe key names in rndc-confgen, tsig-keygen, ddns-confgen
Ondřej Surý [Wed, 29 Apr 2026 15:02:11 +0000 (17:02 +0200)] 
Reject unsafe key names in rndc-confgen, tsig-keygen, ddns-confgen

The three tools interpolated their key-name argument verbatim into the
generated 'key "..." { ... };' clause. A name containing '"', '{', '}',
or ';' could close the clause and append additional named.conf
statements — for example, a second key block with an attacker-chosen
secret. The injected output passes named-checkconf and is loaded by
named as a valid configuration. The risk shows up when an automation
wrapper feeds tenant or zone names from a less-trusted source through
-k / -y / -s / -z (or the tsig-keygen positional argument).

Validate the final key name (after the optional -s / -z suffix is
concatenated in tsig-keygen) against [A-Za-z0-9._-]+ and exit with an
error otherwise. The allowlist covers the documented usage; every
character used in the injection vectors is excluded.

Add a system test that runs the documented PoC payloads through each
tool and asserts a non-zero exit, plus sanity coverage for the default
key names and dotted DNS-style names.

Assisted-by: Claude:claude-opus-4-7
2 months agofix: usr: Fix suppressed missing-glue check in named-checkzone
Ondřej Surý [Wed, 29 Apr 2026 15:31:30 +0000 (17:31 +0200)] 
fix: usr: Fix suppressed missing-glue check in named-checkzone

named-checkzone and named-checkconf -z silently skipped the
missing-glue check for any NS name that had already triggered an
extra-AAAA-glue warning, so zones missing required A glue could pass
validation and be deployed with broken delegations.

Merge branch 'ondrej/check-tool-err-glue-code-collision' into 'main'

See merge request isc-projects/bind9!11899

2 months agoResolve ERR_MISSING_GLUE / ERR_EXTRA_AAAA value collision
Ondřej Surý [Wed, 29 Apr 2026 12:03:38 +0000 (14:03 +0200)] 
Resolve ERR_MISSING_GLUE / ERR_EXTRA_AAAA value collision

Both constants were defined as 5. The symbol table used by checkns() to
deduplicate log messages keys on (name, error_code), so logging an
extra-AAAA error caused logged() to also return true for the
missing-glue check, silently skipping the entire missing-glue block for
the same name in named-checkzone and named-checkconf -z.

Convert the ERR_* defines to an auto-numbered enum so the compiler
guarantees the values stay pairwise distinct.

Assisted-by: Claude:claude-opus-4-7
2 months agofix: dev: Validate -l and -L numeric arguments in named-checkzone
Ondřej Surý [Wed, 29 Apr 2026 15:25:53 +0000 (17:25 +0200)] 
fix: dev: Validate -l and -L numeric arguments in named-checkzone

named-checkzone and named-compilezone parsed the -l (max TTL) and -L
(source serial) arguments with strtol(), so a negative value such as
-1 silently became UINT32_MAX and out-of-range values were truncated
to 32 bits without warning; -l in particular appeared to cap TTLs but
no longer enforced anything. Both flags now go through isc_parse_uint32()
and reject any value that is not a valid 32-bit unsigned integer.

Merge branch 'ondrej/named-checkzone-strtol-truncation' into 'main'

See merge request isc-projects/bind9!11900

2 months agoValidate -l and -L arguments in named-checkzone
Ondřej Surý [Wed, 29 Apr 2026 12:52:21 +0000 (14:52 +0200)] 
Validate -l and -L arguments in named-checkzone

The -l (max TTL) and -L (source serial) flags parsed their arguments
with strtol() and assigned the result directly to uint32_t with no
range check. A negative value such as -1 became UINT32_MAX, which made
-l silently disable the TTL cap it claimed to enforce, and out-of-range
values truncated to 32 bits without warning.

Switch both flags to isc_parse_uint32(), which rejects leading non-
alphanumeric input (catching '-'), checks ERANGE, and validates the
32-bit range, so an invalid argument now exits with an error instead
of being silently coerced.

Assisted-by: Claude:claude-opus-4-7
2 months agofix: usr: Stop rndc-confgen from following symlinks when writing the keyfile
Ondřej Surý [Wed, 29 Apr 2026 14:56:37 +0000 (16:56 +0200)] 
fix: usr: Stop rndc-confgen from following symlinks when writing the keyfile

When rndc-confgen -a (re)created the rndc control key, it followed a
symbolic link if one happened to exist at the keyfile path: the
existence check looked through the link, then the file was truncated,
its ownership changed, and the key contents written into whatever file
the link pointed at. rndc-confgen now refuses to follow symbolic links
at the keyfile path and fails with an error instead, so the wrong file
can no longer be overwritten by accident.

Merge branch '5901-rndc-confgen-symlink-attack' into 'main'

See merge request isc-projects/bind9!11902

2 months agoStop isc_file_safecreate from following symlinks
Ondřej Surý [Wed, 29 Apr 2026 13:30:05 +0000 (15:30 +0200)] 
Stop isc_file_safecreate from following symlinks

The function existence-checked the target with stat() and then opened
the same path without O_NOFOLLOW, so a symlink at the target path
passed the regular-file test against the link's destination and the
open() that followed truncated and wrote through the link.
rndc-confgen -a is typically run as root and writes the keyfile under
a directory that service accounts may have write access to, so a stray
symlink there would silently redirect the truncate, fchown, and
overwrite to whatever file the link pointed at.

Switch the existence check to lstat() and use S_ISREG() so a symlink's
S_IFLNK mode is detected directly (a plain bitmask of S_IFREG matches
both, since S_IFLNK shares its high bit). Add O_NOFOLLOW to both
open() flag sets to close the lstat/open TOCTOU window. Hardening
against unexpected symlinks on intermediate path components is out of
scope.

Assisted-by: Claude:claude-opus-4-7