2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 05:57:52 +00:00

8962 Commits

Author SHA1 Message Date
Tony Finch
44c80c4ae1 Support for off-loop read-ony qp-trie transactions
It is sometimes necessary to access a qp-trie outside an isc_loop,
such as in tests or an isc_work callback. The best option was to use
a `dns_qpmulti_write()` transaction, but that has overheads that are
not necessary for read-only access, such as committing a new version
of the trie even when nothing changed.

So this commit adds a `dns_qpmulti_read()` transaction, which is
nearly as lightweight as a query transaction, but it takes the mutex
like a write transaction.
2023-04-05 12:35:04 +01:00
Tony Finch
fa1b57ee6e Support for finding the longest parent domain in a qp-trie
This is the first of the "fancy" searches that know how the DNS
namespace maps on to the structure of a qp-trie. For example, it will
find the closest enclosing zone in the zone tree.
2023-04-05 12:35:04 +01:00
Tony Finch
8a3a216f40 Support for iterating over the leaves in a qp-trie
The iterator object records a path through the trie, in a similar
manner to the existing dns_rbtnodechain.
2023-04-05 12:35:04 +01:00
Aram Sargsyan
48c506c274 INSIST that openssleddsa_alg_info() is successful
In the check_algorithm() function openssleddsa_alg_info() is
called with two known variants of the 'algorithm' argument, and
both are expected to return a non-NULL value.

Add an INSIST to suppress the following GCC 12 analyzer report:

    openssleddsa_link.c: In function 'raw_key_to_ossl':
    openssleddsa_link.c:92:13: error: dereference of NULL 'alginfo' [CWE-476] [-Werror=analyzer-null-dereference]
       92 |         int pkey_type = alginfo->pkey_type;
          |             ^~~~~~~~~
2023-04-05 08:03:43 +00:00
Evan Hunt
80e2a23f9e
silence coverity warnings
silence coverity warnings in the DNSPRS code:
- CID 451097, failure to check return value of rpz_ready()
- CID 451099, resource leak
2023-04-05 09:23:51 +02:00
Ondřej Surý
b8d34e960b
Change dns_adbentry_overquota() to dns_adb_overquota()
The dns_adbentry_overquota() was violating the layers accessing the
adbentry struct members directly.  Change it to dns_adb_overquota() to
match the dns_adb API.
2023-04-04 16:21:49 +02:00
Ondřej Surý
2ded876db2 Attach catzs to catz instead of doing this explicitly
Instead of explicitly adding a reference to catzs (catalog zones) when
calling the update callback, attach the catzs to the catz (catalog zone)
object to keep it referenced for the whole time the catz exists.
2023-04-04 10:33:04 +00:00
Ondřej Surý
05bb89267e
Don't detach xfr in dns_xfrin_shutdown()
As we are now using dispatch instead of netmgr for XFR TCP connection,
the xfrin_recv_done() will be called when cancelling the dispatch with
ISC_R_CANCELED.  This could lead to double detach from the dns_xfrin_t,
one in the xfrin_recv_done() and one in the dns_xfrin_shutdown().

Remove the extra detach from the dns_xfrin_shutdown() and rely on the
dispatch read callback to be always called.
2023-04-04 10:26:41 +02:00
Ondřej Surý
536e439c79
Fix xfrin_connect_done() error paths
The xfrin_connect_done() had several problems:

- it would not add the server to unreachable table in case of the
  failure coming from the dispatch [GL #3989]

- if dns_dispatch_checkperm() disallowed the connection, the xfr would
  be left undetached

- if xfrin_send_request() failed to send the request, the xfr would be
  left undetached

All of these have been fixed in this commit.
2023-04-04 09:23:51 +02:00
Evan Hunt
361c8868b4 use ISC_REFCOUNT_IMPL for external dns_zone references
use the ISC_REFCOUNT implementation for dns_zone_attach() and
_detach(). (this applies only to external zone references, not
to dns_zone_iattach() and dns_zone_idetach().)

use dns_zone_ref() where previously a dummy zone object had been
used to increment the reference count.
2023-04-04 07:07:55 +00:00
Mark Andrews
21d828241b
dns_view_untrust modifies dnskey->flags when it shouldn't
Copy the structure and declare dnskey as const.
2023-04-03 17:43:43 +02:00
Mark Andrews
b5df9b8591
Handle dns_rdata_fromstruct failure dns_keytable_deletekey
dns_rdata_fromstruct in dns_keytable_deletekey can potentially
fail with ISC_R_NOSPACE.  Handle the error condition.
2023-04-03 17:43:43 +02:00
Mark Andrews
e68fecbdaa
Reduce the number of verifiations required
In selfsigned_dnskey only call dns_dnssec_verify if the signature's
key id matches a revoked key, the trust is pending and the key
matches a trust anchor.  Previously named was calling dns_dnssec_verify
unconditionally resulted in busy work.
2023-04-03 17:43:43 +02:00
Mark Andrews
7278fff579
Add new view method dns_view_istrusted
dns_view_istrusted determines if the given key is treated as
being trusted by the view.
2023-04-03 17:43:40 +02:00
Aram Sargsyan
edcdb881da Do not resend TCP requests
The req_response() function is using 'udpcount' variable to resend
the request 'udpcount' times on timeout even for TCP requests,
which does not make sense, as it would use the same connection.

Add a condition to use the resend logic only for UDP requests.
2023-04-03 15:21:43 +00:00
Aram Sargsyan
5b37359697 Perform request validation in req_response() before using the pointer
The 'request' pointer is used before it is checked. Perform the check
before using the pointer.
2023-04-03 15:21:43 +00:00
Aram Sargsyan
643abfbba7 Synchronize dns_request_createraw() and dns_request_create() UDP timeout
The dns_request_createraw() function, unlike dns_request_create(), when
calculating the UDP timeout value, doesn't check that 'udpretries' is
not zero, and that is the more logical behavior, because the calculation
formula uses division to 'udpretries + 1', where '1' is the first try.

Change the dns_request_create() function to remove the 'udpretries != 0'
condition.

Add a 'REQUIRE(udpretries != UINT_MAX)' check to protect from a division
by zero.

Make the 'request->udpcount' field to represent the number of tries,
instead of the number of retries.
2023-04-03 15:21:43 +00:00
Tony Finch
3c333d02a0 More dns_qpkey_t safety checks
My original idea had been that the core qp-trie code would be mostly
independent of the storage for keys, so I did not make it check at run
time that key lengths are sensible. However, the qp-trie search
routines need to get keys out of leaf objects, for which they provide
storage on the stack, which is particularly dangerous for unchecked
buffer overflows. So this change checks that key lengths are in bounds
at the API boundary between the qp-trie code and the rest of BIND, and
there is no more pretence that keys might be longer.
2023-04-03 15:10:47 +00:00
Matthijs Mekking
92577eaf7e Make checkds yes the default
This seems to be the more common case.
2023-04-03 14:01:22 +00:00
Matthijs Mekking
e72b0df50b Implement auto parental-agents (checkds yes)
Implement the new feature, automatic parental-agents. This is enabled
with 'checkds yes'.

When set to 'yes', instead of querying the explicit configured
parental agents, look up the parental agents by resolving the parent
NS records. The found parent NS RRset is considered to be the list
of parental agents that should be queried during a KSK rollover,
looking up the DS RRset corresponding to the key signing keys.

For each NS record, look up the addresses in the ADB. These addresses
will be used to send the DS requests. Count the number of servers and
keep track of how many good DS responses were seen.
2023-04-03 14:01:22 +00:00
Matthijs Mekking
06cd8b52db Add new 'checkds' configuration option
Add a new configuration option to set how the checkds method should
work. Acceptable values are 'yes', 'no', and 'explicit'.

When set to 'yes', the checkds method is to lookup the parental agents
by querying the NS records of the parent zone.

When set to 'no', no checkds method is enabled. Users should run
the 'rndc checkds' command to signal that DS records are published and
withdrawn.

When set to 'explicit', the parental agents are explicitly configured
with the 'parental-agents' configuration option.
2023-04-03 14:01:22 +00:00
Ondřej Surý
766366e934
Eliminate the dead code in dst_api.c
In write_public_key() and write_key_state(), there were left-over checks
for result, that were effectively dead code after the last refactoring.
Remove those.
2023-04-03 14:09:13 +02:00
Tony Finch
0d353704fb Use isc_histo for the message size statistics
This should have no functional effects.

The message size stats are specified by RSSAC002 so it's best not
to mess around with how they appear in the statschannel. But it's
worth changing the implementation to use general-purpose histograms,
to reduce code size and benefit from sharded counters.
2023-04-03 12:08:05 +01:00
Tony Finch
2354e56ebb Remove obsolete code from dns_stats
It became obsolete in 2008
2023-04-03 12:08:05 +01:00
Ondřej Surý
3a6a0fa867 Replace DE_CONST(k, v) with v = UNCONST(k) macro
Replace the complicated DE_CONST macro that required union with much
simple reference-dereference trick in the UNCONST() macro.
2023-04-03 10:25:56 +00:00
Ondřej Surý
4ec9c4a1db Cleanup the last Windows / MSC ifdefs and comments
Cleanup the remnants of MS Compiler bits from <isc/refcount.h>, printing
the information in named/main.c, and cleanup some comments about Windows
that no longer apply.

The bits in picohttpparser.{h,c} were left out, because it's not our
code.
2023-04-03 09:06:20 +00:00
Mark Andrews
97627c554b Test whether the crypto library supports the HMAC algorithm
When initialising HMAC support check that the crypto library
supports the algorithm rather than just assuming it is supported.
2023-04-03 12:44:27 +10:00
Mark Andrews
c51a39e97a Probe if ED448 and ED25519 are supported
ED448 and ED25519 may or may not be supported in FIPS mode depending
upon the implementation.
2023-04-03 12:06:04 +10:00
Mark Andrews
ba34255648 Report file and line when converting OpenSSL errors
This provides more detail about which instance of specific OpenSSL
calls that have failed by reporting the file name and line numbers
involved when dst__openssl_toresult2 and dst__openssl_toresult3 are
called.
2023-04-03 12:06:04 +10:00
Mark Andrews
07a3b5b02f Don't register FIPS incompatible algorithms in FIPS mode
HMACMD5 is not permitted in FIPS mode.

Note that RSASHA1 is only permitted for verification of signatures.
2023-04-03 12:06:03 +10:00
Mark Andrews
e7aa100e9b Use isc_fips_mode() and isc_fips_set_mode() in
bin/named/server.c and lib/dns/openssl_link.c
2023-04-03 12:05:29 +10:00
Mark Andrews
6e8de4bcdc Allow FIPS mode to be enabled at run time in named
If FIPS mode is supported by the OS 'named -F' will turn on FIPS
mode.
2023-04-03 12:05:29 +10:00
Ondřej Surý
a5f5f68502
Refactor isc_time_now() to return time, and not result
The isc_time_now() and isc_time_now_hires() were used inconsistently
through the code - either with status check, or without status check,
or via TIME_NOW() macro with RUNTIME_CHECK() on failure.

Refactor the isc_time_now() and isc_time_now_hires() to always fail when
getting current time has failed, and return the isc_time_t value as
return value instead of passing the pointer to result in the argument.
2023-03-31 15:02:06 +02:00
Ondřej Surý
263d232c79 Replace isc_fsaccess API with more secure file creation
The isc_fsaccess API was created to hide the implementation details
between POSIX and Windows APIs.  As we are not supporting the Windows
APIs anymore, it's better to drop this API used in the DST part.

Moreover, the isc_fsaccess was setting the permissions in an insecure
manner - it operated on the filename, and not on the file descriptor
which can lead to all kind of attacks if unpriviledged user has read (or
even worse write) access to key directory.

Replace the code that operates on the private keys with code that uses
mkstemp(), fchmod() and atomic rename() at the end, so at no time the
private key files have insecure permissions.
2023-03-31 12:52:59 +00:00
Ondřej Surý
956155f613 Squash dns_name_fullhash() and dns_name_hash()
The only place where dns_name_hash() was being used is the old hash
table in the dns_badcache unit.  Squash the dns_name_fullhash() and
dns_name_hash() into single dns_name_hash() function that's always
case-insensitive as it doesn't make to do case-sensitive hashing of the
domain names and we were not using this anywhere.
2023-03-31 12:43:30 +00:00
Ondřej Surý
4bd6096d4b
Remove isc_stdtime_get() macro
Now that isc_stdtime_get() macro is unused, remove it from the header
file.
2023-03-31 13:33:16 +02:00
Ondřej Surý
46f06c1d6e
Apply the semantic patch to remove isc_stdtime_get()
This is a simple replacement using the semantic patch from the previous
commit and as added bonus, one removal of previously undetected unused
variable in named/server.c.
2023-03-31 13:32:56 +02:00
Ondřej Surý
2c0a9575d7
Replace __attribute__((unused)) with ISC_ATTR_UNUSED attribute macro
Instead of marking the unused entities with UNUSED(x) macro in the
function body, use a `ISC_ATTR_UNUSED` attribute macro that expans to
C23 [[maybe_unused]] or __attribute__((__unused__)) as fallback.
2023-03-30 23:29:25 +02:00
Ondřej Surý
1844590ad9
Refactor isc_job_run to not-make any allocations
Change the isc_job_run() to not-make any allocations.  The caller must
make sure that it allocates isc_job_t - usually as part of the argument
passed to the callback.

For simple jobs, using isc_async_run() is advised as it allocates its
own separate isc_job_t.
2023-03-30 16:00:52 +02:00
Mark Andrews
b8b6b10ad2 clean up library
address style issues, unfreed memory, etc.
2023-03-28 18:41:17 -07:00
Evan Hunt
bed8f85ff2 import libdummyrpz test library for DNSRPS
libdummyrpz is a limited version of the fastrpz library for use in
testing the dnsrps API.
2023-03-28 15:44:31 -07:00
Evan Hunt
f2855cb664 allow configuration of dnsrps library path
for testing purposes, we need to be able to specify a library path from
which to load the dnsrps implementation. this can now be done with the
"dnsrps-library" option.

DNSRPS can now be enabled in configure regardless of whether librpz.so
is currently installed on the system.
2023-03-28 15:44:31 -07:00
Evan Hunt
8ce33dca6a change the log level of "resolver priming query complete"
this log message, formerly at level INFO, is now DEBUG(1),
so it won't be printed when running "delv +ns +nortrace".
2023-03-28 12:39:06 -07:00
Evan Hunt
dbadc97387 on connect error, send the actual result to the caller
formerly if a connection failed in dns_request, the callback
function was called with ISC_R_CANCELED. change this to the
actual result code so the failure is correctly reported.
2023-03-28 12:39:05 -07:00
Evan Hunt
33a741f897 add dns_view_addtrustedkey()
the new dns_view_addtrustedkey() function allows a view's trust
anchors to be updated directly. this code was formerly in
dns_client_addtrustedkey(), which is now a wrapper around
dns_view_addtrustedkey().
2023-03-28 12:38:27 -07:00
Matthijs Mekking
4c33277446 Fix scan-build issue: initialized value never read
Value stored to 'source' during its initialization is never read.
2023-03-28 14:56:56 +02:00
Aram Sargsyan
a2817541b3 Fix a data race in dns__catz_update_cb()
The dns__catz_update_cb() function was earlier updated (see
d2ecff3c4a0d961041b860515858d258d40462d7) to use a separate
'dns_db_t' object ('catz->updb' instead of 'catz->db') to
avoid a race between the 'dns__catz_update_cb()' and
'dns_catz_dbupdate_callback()' functions, but the 'REQUIRE'
check there still checks the validity of the 'catz->db' object.

Fix the omission.
2023-03-27 11:02:25 +00:00
Evan Hunt
833ca463d4 remove {root-}delegation-only
complete the removal of the delegation-only and root-delegation-only
options, and the delegation-only zone type.
2023-03-23 12:57:01 -07:00
Ondřej Surý
93259812dd
Properly handle ISC_R_SHUTTINGDOWN in resquery_response()
When resquery_response() was called with ISC_R_SHUTTINDOWN, the region
argument would be NULL, but rctx_respinit() would try to pass
region->base and region->len to the isc_buffer_init() leading to
a NULL pointer dereference.  Properly handle non-ISC_R_SUCCESS by
ignoring the provided region.
2023-03-23 11:51:22 +01:00
Aram Sargsyan
dc2b8bb1c9 Hold a catz reference while the update process is running
This should delay the catalog zone from being destroyed during
shutdown, if the update process is still running.

Doing this should not introduce significant shutdown delays, as
the update function constantly checks the 'shuttingdown' flag
and cancels the process if it is set.
2023-03-21 10:15:30 +00:00