Commit graph

14601 commits

Author SHA1 Message Date
Matthijs Mekking
b5f3e92fa7 Rename isdelegation() to is_insecure_referral()
The name 'isdelegation()' was confusing. This function is not checking
whether this message is a delegation, but whether the denial of
existence proofs in this message is a proof of a referral to an
unsigned zone.

The name 'is_unsecure_referral()' is more appropriate.

(cherry picked from commit e0f09bb374)
2026-04-07 09:53:34 +02:00
Matthijs Mekking
33a3e1ebff Revert isdelegation() to return boolean value again
The isdelegation() was changed to return an isc_result_t because the
idea was to have a separate return value DNS_R_NSEC3ITERRANGE to signal
to the caller we could not verify the proof because of too many
iterations in the NSEC3 record, or perhaps ISC_R_UNEXPECTED for a more
generic cause that verification was not done.

But this would make error handling more fragile and all we care about
is whether we can reliably say the NS bit was not set.

If we can not reliably say so, we have to treat it as an insecure
referrral.

Since the answer is either yes or no, we can revert back to returning
a boolean value.

(cherry picked from commit 3ac1bb1c39)
2026-04-07 09:52:27 +02:00
Ondřej Surý
f6fdc77c46
Fix TOCTOU race in DNS UPDATE SSU table handling
Pass the SSU table through the update event struct from
send_update() to update_action() instead of reading it from the
zone twice.  If rndc reconfig changed the zone's update policy
between the two reads (e.g., from allow-update to update-policy),
send_update() would skip the maxbytype allocation but
update_action() would see a non-NULL ssutable, triggering
INSIST(ssutable == NULL || maxbytype != NULL) and crashing named.

The ssutable reference is now taken once in send_update() and
transferred to update_action() via the event struct, ensuring
both functions see the same value.

(cherry picked from commit c172416559)
2026-03-30 19:02:45 +02:00
Michał Kępień
6d6c28f628 Merge tag 'v9.18.47' into bind-9.18 2026-03-25 14:24:34 +00:00
Ondřej Surý
8a0a0b01ff Add MOVE_OWNERSHIP() macro for transferring pointer ownership
A helper macro that returns the current value of a pointer and sets
it to NULL in one expression, useful for transferring ownership in
designated initializers.

(cherry picked from commit 0f3be0beb8)
2026-03-23 12:05:18 +01:00
Ondřej Surý
af7ba0c0fd
Remove extra fctx->result assignment from broken backport
The backport added extra line, but forgot to remove the old one.
2026-03-20 08:57:51 +01:00
Ondřej Surý
1a5f560387
Fix data race on fctx->vresult in validated()
Move the write to fctx->vresult after LOCK(&fctx->lock).  The field was
being set before acquiring the lock, but dns_resolver_logfetch() reads
it under the same lock from another thread.

(cherry picked from commit a2bd833909)
2026-03-20 01:47:54 +01:00
Mark Andrews
92f0ff77a2 Clear errno before calling strtol
The previous code was incorrectly clearing errno after calling
strtol but before testing the result rather than clearing it and
then calling strtol so that changes to errno can be correctly
determined.

(cherry picked from commit d3ffa1f007)
2026-03-17 00:28:13 +00:00
Aram Sargsyan
6e07cc19cc OpenSSL 4 compatibility fix
Starting from OpenSSL 4 the the X509_get_subject_name() function
returns a 'const' pointer to a name instead of a regular pointer.
Duplicate the name before operating on it, then free it.

(cherry picked from commit 336c523b79)
2026-03-16 11:18:31 +00:00
Matthijs Mekking
85fcd704e2
Check RRset trust in validate_neg_rrset()
In many places we only create a validator if the RRset has too low
trust (the RRset is pending validation, or could not be validated
before). This check was missing prior to validating negative response
data.

(cherry picked from commit 6ca67f65cd)
2026-03-13 13:10:30 +01:00
Matthijs Mekking
8890a91c1c
Don't verify already trusted rdatasets
If we already marked an rdataset as secure (or it has even stronger
trust), there is no need to cryptographically verify it again.

(cherry picked from commit 0ec08c2120)
2026-03-13 13:10:30 +01:00
Matthijs Mekking
85c21feff9
Check iterations in isdelegation()
When looking up an NSEC3 as part of an insecurity proof, check the
number of iterations. If this is too high, treat the answer as insecure
by marking the answer with trust level "answer", indicating that they
did not validate, but could be cached as insecure.

(cherry picked from commit 988040a5e0)
2026-03-13 13:10:30 +01:00
Mark Andrews
9ffcac3726 Set length in dns_rdata_in_dhcid structure
tostruct_in_dhcid was not setting the length field in the
dns_rdata_in_dhcid structure.

(cherry picked from commit cfa21d1e8b)
2026-03-12 20:32:18 +11:00
Michal Nowak
be2ee6bfa0
Use clang-format-22 to update formatting
(cherry picked from commit 239464f276)
2026-03-04 12:24:53 +01:00
Ondřej Surý
15b5d4c917 Clear serve-stale flags when following the CNAME chains
A stale answer or SERVFAIL could have been served in case of multiple
upstream failures when following the CNAME chains. This has been fixed.

(cherry picked from commit d46277b398)
2026-02-25 17:17:07 +01:00
Mark Andrews
7eeefdc36a
Remove invalid REQUIRE in NSEC3 fromstruct method
The NSEC3 fromstruct method only worked for hash type 1
when it should work for all hash types.

(cherry picked from commit f030bc6756)
2026-02-24 16:42:19 +01:00
Mark Andrews
8d6e1c1a48
Enforce NSEC3 record consistency
NSEC3 hashes are required to fit within a single DNS label.  Since there
are 5 bits per label byte without pad characters, the maximum hash size
is floor(63*5/8) (39 bytes).

This patch enforces this maximum length for unknown algorithms, while
strictly enforcing the exact expected digest length for known algorithms
like SHA-1.

(cherry picked from commit 3801d0ebbf)
2026-02-24 16:31:33 +01:00
Ondřej Surý
368c75a9f5
Invalid NSEC3 can cause OOB read of the isdelegation() stack
When .next_length is longer than NSEC3_MAX_HASH_LENGTH, it causes a
harmless out-of-bound read of the isdelegation() stack.  This patch
fixes the issue by skipping NSEC3 records with an oversized hash length
during validation.

(cherry picked from commit 67b4fb56e4)
2026-02-24 16:31:10 +01:00
Ondřej Surý
7a90d3c406
Release gnamebuf also on the error path
In dst_gssapi_acceptctx(), the gnamebuf could leak a little bit of
memory if dns_name_fromtext() would theoretically fail.  This would
require a Kerberos principal with invalid DNS name.

(cherry picked from commit 3ad87f1ad6)
2026-02-06 18:37:44 +01:00
Mark Andrews
3b049e21cf Remove extraneous space at start of brid and hhit records
(cherry picked from commit 10366e4f4e)
2026-01-27 05:46:22 +00:00
Mark Andrews
bf237274fc Fix isc_base64_tobuffer call for brid and hhit
Zero length records were not being rejected.

(cherry picked from commit bdb9c838a8)
2026-01-27 05:46:22 +00:00
Mark Andrews
17341ea835 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:32 +00:00
Nicki Křížek
ebf35d88df Merge tag 'v9.18.44' into bind-9.18 2026-01-21 14:37:38 +00:00
Mark Andrews
1771bd5760 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:56 +00:00
Mark Andrews
291d05be34 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:38:24 +01:00
Giulio Benetti
49199add7b 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:52 +00:00
Matthijs Mekking
c66ac93b90 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 08:29:31 +01:00
Matthijs Mekking
4e82584b73 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 08:26:11 +01:00
Matthijs Mekking
0a0f71d511 Nit fix removing a newline in the logs
(cherry picked from commit 780e8e8f1c)
2025-12-22 08:26:11 +01:00
Evan Hunt
31b46473ac 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.

(cherry picked from commit aa13e62355)
2025-12-11 19:58:08 +00:00
Mark Andrews
7708678482
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.

(cherry picked from commit b677d31fca)
2025-12-08 10:27:03 +01:00
Evan Hunt
9e879600c1 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 25c9fb54da)
(cherry picked from commit 52bba5cc34)
2025-12-03 19:18:12 -08:00
Mark Andrews
3a133fa560 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:27 +00:00
Ondřej Surý
e47f810466
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:35 +01:00
Ondřej Surý
0fa3984f8c
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:48 +01:00
Michał Kępień
e2bf5e63e7 Merge tag 'v9.18.41' into bind-9.18 2025-10-22 16:18:20 +00:00
Michal Nowak
973f594409
Use clang-format-21 to update formatting 2025-10-21 12:13:05 +02:00
Aram Sargsyan
40c396ba2d
Fix an issue with selfsigned_dnskey() return value
The selfsigned_dnskey() function currently returns boolean. There
was a recent change to make it return a isc_result_t error code,
which is implicitly converted to bool, which is obviously an error.

If instead of the result code we return true/false, it still doesn't
indicate the error to the caller that has happened before.

Change the function to return isc_result_t, and change the caller
routine to process the new return type.
2025-10-17 14:41:09 +02:00
Ondřej Surý
8330b49fb9
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:53:14 +02:00
Mark Andrews
4c6d03b0bb
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.

To prevent test failures, this required adding TCP support to the
ans3 and ans4 servers in the chain system test.

(cherry picked from commit 2e40705c06)
2025-10-02 13:07:06 +02:00
Mark Andrews
cd17dfe696
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 13:07:06 +02:00
Mark Andrews
025d61bacd
Tighten restrictions on caching NS RRsets in authority section
To prevent certain spoofing attacks, a new check has been added
to the existing rules for whether NS data can be cached: the owner
name of the NS RRset must be an ancestor of the name being queried.

(cherry picked from commit fa153f791f)
2025-10-02 13:07:06 +02:00
Ondřej Surý
7c5b8ef055
Fail the DNSSEC validation if matching but invalid DNSKEY is found
If a matching but cryptographically invalid key was encountered during
the DNSSEC validation, the key would be just skipped and not counted
towards validation failures.  Treat such DNSSEC keys as hard failures
and fail the DNSSEC validation immediatelly instead of continuing the
DNSSEC validation with the next DNSKEYs in the RRset.

Co-authored-by: Matthijs Mekking <matthijs@isc.org>

(cherry picked from commit f00117a422)
2025-10-02 12:32:45 +02:00
Mark Andrews
955874f0bc
re-split STATIC_ASSERT message
(cherry picked from commit ccc41c7044)
2025-09-29 13:08:24 +02:00
Mark Andrews
7b4315b7a6
re-split log message text
(cherry picked from commit a64c350523)
2025-09-29 13:08:24 +02:00
Mark Andrews
f866f7a1e8 Remove dns_rdataset_equals as unneeded
(cherry picked from commit 7d765a3514)
2025-09-11 08:27:50 +10:00
Mark Andrews
018ecbb0c8 Fix missing RRSIGs for "glue" lookups with CD=1
The code to test whether to store the RRSIGs on DNS_R_UNCHANGED
with CD=1 was failing because the comparison methods of the two
rdatatset instances were not compatible.  Move the testing into
dns_db_addrdataset(), and request it by setting the DNS_ADD_EQUALOK
option.  If the option is set and the old and new rrsets compare
as equal, dns_db_addrdataset() returns ISC_R_SUCCESS instead of
DNS_R_UNCHANGED.

(cherry picked from commit b954a1df43)
2025-09-11 08:27:50 +10:00
Mark Andrews
4a076fd0c0 Add support for parsing and displaying BRID rdata type
(cherry picked from commit 6b29da55fc)
2025-09-03 11:10:52 +10:00
Mark Andrews
3df5d60de8 Add support for parsing and displaying HHIT rdata type
(cherry picked from commit 37041c3ec3)
2025-09-03 11:10:51 +10:00
Mark Andrews
823e39a932 RPZ canonical warning displays zone entry incorrectly
Do not insert a NUL into ip_str too early as the full value
is needed later.  Only insert the NUL immediately before
displaying just the prefix string.

(cherry picked from commit 283da99f02)
2025-09-02 23:43:45 +00:00