Commit graph

15840 commits

Author SHA1 Message Date
Mark Andrews
19cf7bb2cd dsync_from struct produced an invalid record
uint16_tobuffer was used instead of uint8_tobuffer when adding the
scheme to the buffer.  This produced a record that was one octet
too long.  This has been fixed.

(cherry picked from commit 3180e50459)
2026-01-23 14:24:27 +00:00
Nicki Křížek
324d726377 Merge tag 'v9.20.18' into bind-9.20 2026-01-21 14:37:29 +00:00
Mark Andrews
31bdd01227 Use const pointer with strchr of const pointer
C23 now has qualifier preserving standard functions for strchr,
bsearch, strpbrk, strrchr, strstr, memchr.  There where a few places
where the return value was not assigned to a const qualified pointer.
These have been fixed.

(cherry picked from commit af379e10cc)
2026-01-20 06:00:50 +00:00
Aram Sargsyan
439e4ddf2f Make catalog zones' entry names case-insensitive
Previously, the isc_ht hash table module was case-sensitive, but now
it supports case-insensitive mode. Use the case-insensitive mode
for the catalog zones' entry names.

(cherry picked from commit 6f4b5d6958)
2026-01-12 13:01:53 +00:00
Aram Sargsyan
5f30b6a9be Make catalog zone names case-insensitive
Previously, the isc_ht hash table module was case-sensitive, but now
it supports case-insensitive mode. Use the case-insensitive mode
for catalog zone names.

(cherry picked from commit 0e0ba06dbf)
2026-01-12 13:01:53 +00:00
Mark Andrews
c8279f7c69 Fix incorrect length checks for BRID and HHIT records
Fix incorrect length checks in the towire_*() methods for BRID and HHIT
records to prevent assertion failures when trying to serve short
records.

(cherry picked from commit 14e299995f)
2026-01-08 12:37:50 +01:00
Giulio Benetti
ad25f0c514 Fix building on uclibc
While building on uclibc this error is thrown:
In file included from ./include/dns/log.h:20,
                 from callbacks.c:19:
../../lib/isc/include/isc/log.h:141:9: error: unknown type name ‘off_t’
  141 |         off_t maximum_size;
      |         ^~~~~

This is due to missing include unistd.h, so let's add it on top of
isc/log.h

Signed-off-by: Giulio Benetti <giulio.benetti@benettiengineering.com>
(cherry picked from commit 0e43f62c12)
2026-01-04 20:47:47 +00:00
Matthijs Mekking
1b3fb1b966 Refactor code that checks if records are seen
There are three places that do roughly the same. Refactor the code to
a helper function.

(cherry picked from commit ae151a7a76)
2025-12-22 15:31:43 +11:00
Matthijs Mekking
07a4d63fd9 Add NSEC for opt-out names
When switching from NSEC3 opt-out to NSEC, add NSEC records if we saw an
RR. This corrects a mistake in style cleanups done in commit
308ab1b4a5.

(cherry picked from commit 6f285bff6a)
2025-12-22 15:31:43 +11:00
Matthijs Mekking
d3e74983bb Nit fix removing a newline in the logs
(cherry picked from commit 780e8e8f1c)
2025-12-22 15:31:42 +11:00
Aram Sargsyan
ee6e7e6d00 Lock the catalog zone when reconfiguring it
A catalog zone is updated in an offloaded thread, which is not
stopped during a reconfiguration in an exclusive mode, and so
can cause a race condition with it.

Waiting for the offloaded threads to complete their work before
entering into the exclusive mode can potentially cause unwanted
delays, because offloaded threads are generally "allowed" to take
a longer amount of time before they complete.

Add a dns_catz_zone_prereconfig()/dns_catz_zone_postreconfig() pair
of functions which currently just lock the catalog zone when
reconfiguring it. The change should eliminate the race.

As a side note, there was already a similar pair of functions,
dns_catz_prereconfig() and dns_catz_postreconfig() which are called
before and after reconfiguring a 'dns_catz_zones_t' object.

Below are the stack traces of the reconfiguration thread which has
asserted, and a catalog zone update thread which was caught in the
middle of its work despite the fact that the exclusive mode is
turned on.

                Stack trace of thread 23859:
                #0  0x00007f80e7b8e52f raise (libc.so.6)
                #1  0x00007f80e7b61e65 abort (libc.so.6)
                #2  0x0000000000422558 assertion_failed (named)
                #3  0x00007f80eaa6799e isc_assertion_failed (libisc-9.18.41.so)
                #4  0x00007f80ea5bc788 dns_catz_entry_getname (libdns-9.18.41.so)
                #5  0x000000000042ce0e catz_reconfigure (named)
                #6  0x000000000042d3c5 configure_catz_zone (named)
                #7  0x000000000042d7a4 configure_catz (named)
                #8  0x0000000000430645 configure_view (named)
                #9  0x000000000043d998 load_configuration (named)
                #10 0x000000000044184f loadconfig (named)
                #11 0x0000000000442525 named_server_reconfigcommand (named)
                #12 0x000000000041b277 named_control_docommand (named)
                #13 0x000000000041c74a control_command (named)
                #14 0x00007f80eaa912ae task_run (libisc-9.18.41.so)
                #15 0x00007f80eaa914cd isc_task_run (libisc-9.18.41.so)
                #16 0x00007f80eaa46435 isc__nm_async_task (libisc-9.18.41.so)
                #17 0x00007f80eaa467aa process_netievent (libisc-9.18.41.so)
                #18 0x00007f80eaa475a6 process_queue (libisc-9.18.41.so)
                #19 0x00007f80eaa46227 process_all_queues (libisc-9.18.41.so)
                #20 0x00007f80eaa462a1 async_cb (libisc-9.18.41.so)
                #21 0x00007f80e8d01893 uv__async_io.part.3 (libuv.so.1)
                #22 0x00007f80e8d13ac4 uv__io_poll (libuv.so.1)
                #23 0x00007f80e8d023fb uv_run (libuv.so.1)
                #24 0x00007f80eaa45ced nm_thread (libisc-9.18.41.so)
                #25 0x00007f80eaa9bda3 isc__trampoline_run (libisc-9.18.41.so)
                #26 0x00007f80e7f1e1ca start_thread (libpthread.so.0)
                #27 0x00007f80e7b798d3 __clone (libc.so.6)
    ...
    ...
                Stack trace of thread 23912:
                #0  0x00007f80ea5bc2da dns_catz_options_setdefault (libdns-9.18.41.so)
                #1  0x00007f80ea5bd411 dns__catz_zones_merge (libdns-9.18.41.so)
                #2  0x00007f80ea5c3c2f dns__catz_update_cb (libdns-9.18.41.so)
                #3  0x00007f80eaa4fee9 isc__nm_work_run (libisc-9.18.41.so)
                #4  0x00007f80eaa9bda3 isc__trampoline_run (libisc-9.18.41.so)
                #5  0x00007f80eaa4ff48 isc__nm_work_cb (libisc-9.18.41.so)
                #6  0x00007f80e8cfc75e worker (libuv.so.1)
                #7  0x00007f80e7f1e1ca start_thread (libpthread.so.0)
                #8  0x00007f80e7b798d3 __clone (libc.so.6)

(cherry picked from commit aed9cafd5c)
2025-12-17 17:48:28 +00:00
Ondřej Surý
038b3cd468 Add more information to the rndc recursing output about fetches
It is possible to have a fetch that is active, but it has been cloned,
so it won't be used when found in the hash table.   The fetch options
also prevent matching in the hash table, so add a hexadecimal dump of
the fctx->options to the output.

(cherry picked from commit 23ae5544be)
2025-12-17 11:59:11 +01:00
Evan Hunt
aa13e62355 allow glue in delegations with QTYPE=ANY
when a query for type ANY triggers a delegation response, all
additional data was omitted from the response, including
mandatory glue. this has been corrected.
2025-12-11 10:36:09 -08:00
Matthijs Mekking
64017871a8 Don't create NSEC3 nodes for unsigned delegations
Instead of creating new nodes for every possible NSEC3 record, only
create them if we are actually going to add a new NSEC3 record.

(cherry picked from commit 6f7abbfaac)
2025-12-11 13:53:25 +01:00
Matthijs Mekking
63262fd0f4 Implement dns_dbiterator_seek3
This is a new seek function for dbiterator that is meant to find an
NSEC3 node in a zone database. The difference with dns_dbiterator_seek
is that if the node does not exist, this seek function will point the
iterator to the next NSEC3 name.

(cherry picked from commit 41159e9062)
2025-12-11 13:53:25 +01:00
Matthijs Mekking
45c7008ecd Log serial when IXFR version not in journal
It may be useful to know which version (begin serial) is missing when
the IXFR version cannot be found.

(cherry picked from commit a4e6fef81c)
2025-12-10 15:25:23 +00:00
Aram Sargsyan
59e9dfc5b4 Fix a bug in dns_catz_generate_zonecfg()
The dns_catz_generate_zonecfg() function generates a zone configuration
string to use with a new catalog zone member zone. The buffer for the
string is 512 bytes initially (ISC_BUFFER_INCR), but can be reallocated
when required, when using corresponding isc_buffer functions like
isc_buffer_reserve(), isc_buffer_putstr(), isc_buffer_copyregion(), etc.

However, the dns_name_totext() function, which expects the buffer as an
argument, doesn't automatically resize it if the name doesn't fit there,
but instead just returns ISC_R_NOSPACE.

The chance of this occurring increases when the configuration string is
large due to, for example, long zone name, long list of primary servers
which have keys configured and/or TLS configured.

Use dns_name_format() accompanied with isc_buffer_putstr() instead of
dns_name_totext().

(cherry picked from commit 684d7e008a)
2025-12-09 11:12:24 +00:00
Mark Andrews
b677d31fca
In dbiterator_prev, dereference_iter_node was being called too soon
dns_rbtnodechain_prev requires the current node to still be valid
which was not always the case after dereference_iter_node was called.
Move the call to dereference_iter_node to after the dns_rbtnodechain_prev
to preserve the node.
2025-12-08 10:25:17 +01:00
Ondřej Surý
89478d95c3
In dns_qpiter_{prev,next}, defer dereference_iter_node call
dns_qpiter_{prev,next} requires the current iterator node to still be
valid which might not always the case after dereference_iter_node was
called.  Currently, this is ensured via closeversion() mechanism, but it
is not guaranteed to be true in the future.

Move the call to dereference_iter_node to after the dns_qpiter_prev()
and dns_qpiter_next() to prevent a possible use-after-free of the
current iterator node.

(cherry picked from commit 9914bd383e)
2025-12-08 10:25:05 +01:00
Matthijs Mekking
45448fc383 Make keymgr state machine more robust
If the keymgr state machine is in an invalid state, it tries to move
it self to a valid state. But when you do key rollovers during an
invalid state, and the next state is also an invalid state, the keymgr
will happily do the transition.

It would be good to not do key rollovers if there is not a KSK and ZSK
fully omnipresent. But also it would be good to safeguard against
unexpected transitions.

This commit does that by not moving things to unretentive (which is
the state where we would remove the corresponding record from the zone)
if the state machine is currently in an invalid state.

(cherry picked from commit b19871f8a2)
2025-12-05 13:22:00 +01:00
Evan Hunt
25c9fb54da standardize CHECK and RETERR macros
previously, there were over 40 separate definitions of CHECK macros, of
which most used "goto cleanup", and the rest "goto failure" or "goto
out". there were another 10 definitions of RETERR, of which most were
identical to CHECK, but some simply returned a result code instead of
jumping to a cleanup label.

this has now been standardized throughout the code base: RETERR is for
returning an error code in the case of an error, and CHECK is for jumping
to a cleanup tag, which is now always called "cleanup". both macros are
defined in isc/util.h.

(cherry picked from commit 52bba5cc34)
2025-12-03 19:17:20 -08:00
Ondřej Surý
95cc515e20
Provide more information when the memory allocation fails
Instead of just crashing when memory allocation fails, also print a
message saying "Out of memory!", the size of the allocation that failed,
total allocated memory from all memory contexts and value of errno.

(cherry picked from commit b0194004d9)
2025-11-28 16:45:08 +01:00
Colin Vidal
9e8994d853 check validity of key and tls in a server-list
If a `key` or `tls` is associated to an IP address inside a server-list,
only the `tls` existence in the configuration was checked. Also, if
`key` or `tls` is associated to a named server-list inside a
server-list, there was no check at all.

Add the check for making sure a `key` is defined in the configuration,
as well as the check for `key` and `tls` when used on a named
server-list.

(cherry picked from commit 2956e4fc45)
2025-11-28 15:15:46 +01:00
Colin Vidal
b260f7be90 check remote-servers list correctness
`check.c` only checks if `remote-servers`, `primaries`, etc. are not
duplicated inside the configuration file, but does not check the
correctness of its definition. This commit fixes this by calling
`validate_remotes()` for each `remote-servers` (and other aliases),
which validates the correctness of the definition itself (this is the
same call done to validate other cases like `also-notify`, etc.).

(cherry picked from commit 1a732b6b8e)
2025-11-28 15:15:46 +01:00
Colin Vidal
743f446d41 allow named remote-servers list with key or tls
The remote-servers clause enables the following pattern:

	remote-servers a { 1.2.3.4; ... };
	remote-servers b { a key foo; };

However, `check.c` was explicitly throwing an error if a `key` or `tls`
was provided after a named server-list. Remove this check, as this is a
valid use case.

(cherry picked from commit 046c6819b2)
2025-11-28 15:15:46 +01:00
Ondřej Surý
5cd69a3dcf
Detect resolution loops between fetches
Maintain the relationship between the parent and child fetch and when
creating a new child fetch, properly check the resolution loops that
would lead to a new fetch would join one of the parent's fetch contexts.

(cherry picked from commit 4d307ac67a)
2025-11-28 09:32:53 +01:00
Aram Sargsyan
7265e33520 Fix a bug where tlsctx_cache could be destroyed while still in use
When named is being reconfigured, it detaches from the old
'isc_tlsctx_cache_t' TLS context cache object and creates a
new one. This can cause an assertion failure within the
resolver when the object is destroyed while still in use,
because the resolver is using the object without getting
attached to it.

Add an attach/detach so that the 'isc_tlsctx_cache_t' doesn't
get destroyed while still being in use.

(cherry picked from commit ed7b08c0c4)
2025-11-27 17:53:50 +00:00
Ondřej Surý
42d59c2ee4 Use atomics for CMM_{LOAD,STORE}_SHARED with ThreadSanitizer
Upstream has removed the atomics implementation of CMM_LOAD_SHARED and
CMM_STORE_SHARED as these can be used also with non-stdatomics types.
As we only use the CMM api with stdatomics types, we can restore the
previous behaviour to prevent ThreadSanitizer warnings.

(cherry picked from commit 539be61b68)
2025-11-27 09:32:36 +00:00
Ondřej Surý
a8af46a39c
Reduce the number of outgoing queries
The dns_resolver mode of operation is to resolve all the domains as it
iterates the DNS tree to fill up the cache as quickly as possible.

This commit reduces the number of outgoing queries by reducing the
number of remote fetches started for the nameserver addresses resolution
via dns_adb_createfind() to a smaller number per depth of the recursion
since the delegation point (3 2 1 0) - where 0 means only create fetch
on demand if we don't have any addresses yet.

(cherry picked from commit 1b90d2ffdb)
2025-11-26 17:53:25 +01:00
Evan Hunt
43b4cebc71
Remove maybe_cancel_validators() function
When shutting down an fctx, validators can just be canceled
without checking whether there are pending finds.

(cherry picked from commit e62895e999)
2025-11-26 17:53:24 +01:00
Matthijs Mekking
34b5030336 Skip private records when syncing secure db
When synchronizing the secure database, we skip DNSSEC records that
BIND 9 maintains with inline-signing. We should also skip private
RDATA type records that are used to track the current state of a
zone-signing process.

(cherry picked from commit 6dcb9ce77f)
2025-11-24 13:23:48 +00:00
Colin Vidal
8cdb1d71ad attach socket before async streamdns_resume_processing
Call to `streamdns_resume_processing` is asynchronous but the socket
passed as argument is not attached when scheduling the call.

While there is no reproducible way (so far) to make the socket reference
number down to 0 before `streamdns_resume_processing` is called, attach
the socket before scheduling the call. This guard against an hypothetic
case where, for some reasons, the socket refcount would reach 0, and be
freed from memory when `streamdns_resume_processing` is called.

(cherry picked from commit 7c8b517d56)
2025-11-20 17:55:00 +00:00
Mark Andrews
b6d9d4f7a6 AMTRELAY type 0 presentation format handling was wrong
RFC 8777 specifies a placeholder value of "." for the gateway field
when the gateway type is 0 (no gateway).

(cherry picked from commit ae484d4501)
2025-11-20 08:47:22 +00:00
Alessio Podda
d4fd6b323d Skip buffer allocations if not logging
Currently, during IXFR we allocate a 2KB buffer for IXFR change logging
regardless of the log level. This commit introduces an early check
on the log level in dns_diff_print to avoid this.

Results in a speedup from 28% in the test case from issue #5442.

(cherry picked from commit a164492f3c)
2025-11-05 18:38:33 +01:00
Ondřej Surý
619db66c47
Skip unsupported algorithms when looking for signing key
When looking for a signing key in select_signing_key(), the result code
indicating unsupported algorithm would abort the search.  Instead, skip
such keys and continue searching for the right key.

Co-Authored-By: Aram Sargsyan <aram@isc.org>
Co-Authored-By: Petr Menšík <pemensik@redhat.com>
(cherry picked from commit a94a7c1a1e)
2025-11-05 04:36:00 +01:00
Ondřej Surý
2c2cb31394
Drop the unit test for testing randomness
Since we are using system routines for randomness, there's no point
in spending time and run the statistical suite for testing PRNG.

(cherry picked from commit 90b3def5e9)
2025-11-04 20:51:22 +01:00
Evan Hunt
5ed3bebbf4 fix a "max-cache-size" configuration bug
"max-cache-size default;" is allowed, according to the documentation
and the parser, but when it's configured, named crashes due to an
INSIST that the only legal string value is "unlimited". this has
been fied.

the configuration has also been simplified. previously, we checked for
max-cache-size in view and options, then determined whether to look in
the global default options based on whether the view had recursion set.
the default value set there was only applicable to views with recursion.
now, the default is an explicit "default", which affects views with
and without recursion in different ways.

the cfg type for "max-cache-size" has been changed from
cfg_type_sizeorpercent to cfg_type_maxcachesize.

(cherry picked from commit cd921cc7ef)
2025-10-29 11:30:25 -07:00
Mark Andrews
31ae3dc355 Fix "shutdown system test crashed in dns_dispatchmgr_getblackhole"
While shutting down view->dispatchmgr is no longer valid.  Attach
to it and when creates a fetch context and use that pointer instead
of view->dispatchmgr.  Use dns_view_getdispatchmgr to do the attaching
as view->dispatchmgr is it managed using rcu.

(cherry picked from commit 012a47476d)
2025-10-27 22:39:47 +00:00
Ondřej Surý
97487d1abb Fix assertion failure from arc4random_uniform with invalid limit
When the arc4random_uniform() is called on NetBSD with upper_bound that
makes no sense statistically (0 or 1), the call crashes the calling
program.  Fix this by returning 0 when upper bound is < 2 as does Linux,
FreeBSD and NetBSD.  (Hint: System CSPRNG should never crash.)

(cherry picked from commit 871bce312b)
2025-10-24 20:23:32 +00:00
Michał Kępień
b35d6513d8 Merge tag 'v9.20.15' into bind-9.20 2025-10-22 16:16:59 +00:00
Michal Nowak
184cb00814 Use SET_IF_NOT_NULL in isc__nm_base64*
(cherry picked from commit d91e8ed575)
2025-10-22 11:30:33 +00:00
Mark Andrews
2d496ef257 Don't log spurious error "bad key type" in findmatchingkeys
(cherry picked from commit 4c5d48926a)
2025-10-22 12:55:43 +11:00
Aram Sargsyan
3a1922f464 Fix dnssec-keygen key collision checking for KEY rrtype keys
When generating a new key, dnssec-keygen checks for possible
key ID collisions with existing keys. The dnssec.c:findmatchingkeys()
function, which is supposed to get the list of the existing keys,
fails to do that for the existing KEY rrtype keys (i.e. generated
using 'dnssec-keygen -T KEY') because it doesn't pass down to the
dst_key_fromnamedfile() -> dst_key_read_public() functions the type
of the keys it's interested in. Fix the issue by introducing a new
function parameter which tells in which type of keys the caller is
currently interested in.

(cherry picked from commit 49b7ce9a54)
2025-10-22 12:55:41 +11:00
Michal Nowak
bc35b646b9
Use clang-format-21 to update formatting 2025-10-21 12:12:01 +02:00
Ondřej Surý
13b88233be
Fix the assertion failure in the selfsigned DNSKEY handling
The selfsigned_dnskey() function can now return all the return codes
that dns_dnssec_keyfromrdata() can return and this would cause an
assertion failure as we were not expecting new isc_result_t codes.

(cherry picked from commit 7b26176c46)
2025-10-18 09:36:58 +02:00
Mark Andrews
d70cb26231 Fix parse_rr in lib/dns/skr.c was failing to reset the comments
If dns_name_fromtext failed or the subsequent dns_name_compare
failed the lexer's comments state wasn't cleaned up.

(cherry picked from commit e5ceda617d)
2025-10-14 06:48:57 +00:00
Ondřej Surý
26c77915d5
Use arc4random for CSPRNG when available
Use arc4random on platforms where available.  arc4random() provides high
quality cryptographically-secure pseudo-random numbers and is generally
recommended for application use.

The uv_random() call unfortunately uses getentropy() on platforms like
MacOS, OpenBSD or NetBSD which is not recommended for application use.

(cherry picked from commit 4db9e5d90e)
2025-10-02 13:49:33 +02:00
Ondřej Surý
2924910eee
Use cryptographically-secure pseudo-random generator everywhere
It was discovered in an upcoming academic paper that a xoshiro128**
internal state can be recovered by an external 3rd party allowing to
predict UDP ports and DNS IDs in the outgoing queries.  This could lead
to an attacker spoofing the DNS answers with great efficiency and
poisoning the DNS cache.

Change the internal random generator to system CSPRNG with buffering to
avoid excessive syscalls.

Thanks Omer Ben Simhon and Amit Klein of Hebrew University of Jerusalem
for responsibly reporting this to us.  Very cool research!

(cherry picked from commit cffcab9d5f)
2025-10-02 13:49:33 +02:00
Mark Andrews
a266f329e9
Retry lookups with unsigned DNAME over TCP
To prevent spoofed unsigned DNAME responses being accepted retry
response with unsigned DNAMEs over TCP if the response is not TSIG
signed or there isn't a good DNS CLIENT COOKIE.

(cherry picked from commit 2e40705c06)
2025-10-02 12:58:54 +02:00
Mark Andrews
ab97f6e9f4
Further restrict addresses that are cached when processing referrals
Use the owner name of the NS record as the bailwick apex name
when determining which additional records to cache, rather than
the name of the delegating zone (or a parent thereof).

(cherry picked from commit a41054e9e6)
2025-10-02 12:58:54 +02:00