Commit Graph

37949 Commits

Author SHA1 Message Date
Timo Teräs
c8bcf3a34e Refactor OpenSSL RSA exponent bits checking to a helper function
- Make it a separate opensslrsa_check_exponent_bits() function to
  clean up the code a bit
- Always use provider API first if using openssl 3.0, and fallback
  to EVP API for older openssl or if built with engine support
- Use RSA_get0_key() (with shim for openssl 1.0) to avoid memory
  allocations
2023-01-09 14:58:55 +01:00
Ondřej Surý
e78d61e2f5 Merge branch '3785-openssl-refactoring-2' into 'main'
Refactor OpenSSL RSA type check to opensslrsa_valid_key_alg helper

Closes #3785

See merge request isc-projects/bind9!7315
2023-01-09 13:34:41 +00:00
Timo Teräs
8bc52f836c Refactor OpenSSL RSA type check to opensslrsa_valid_key_alg helper
Move the repetetive code into a small opensslrsa_valid_key_alg() helper
function.
2023-01-09 14:33:09 +01:00
Ondřej Surý
df2b767d45 Merge branch '3785-openssl-refactoring-1' into 'main'
Remove obsolete and unused EVP_dss1 compat #define

Closes #3785

See merge request isc-projects/bind9!7314
2023-01-09 13:32:59 +00:00
Timo Teräs
04c7f30690 Remove obsolete and unused EVP_dss1 compat #define 2023-01-09 14:21:41 +01:00
Ondřej Surý
2d3d44d59e Merge branch '3671-override-ISC_R_EXISTS-in-findnodeintree' into 'main'
Change ISC_R_EXISTS to ISC_R_SUCCESS in dns/rbtdb.c:findnodeintree()

Closes #3671

See merge request isc-projects/bind9!7312
2023-01-09 12:33:12 +00:00
Ondřej Surý
e3d4d34744 Change ISC_R_EXISTS to ISC_R_SUCCESS in dns/rbtdb.c:findnodeintree()
In the previous refactoring, the findnodeintree() function could return
ISC_R_EXISTS (from dns_db_addnode() call) instead of ISC_R_SUCCESS
leading to node being attached, but never detached.

Change the ISC_R_EXISTS result code returned from dns_rbt_addnode() to
the ISC_R_SUCCESS in the findnodeintree() function (called internally by
dns_db_findnode() and dns_db_findnsec3node()).
2023-01-09 12:48:19 +01:00
Matthijs Mekking
e18a24f7e7 Merge branch '3678-serve-stale-servfailing-unexpectedly' into 'main'
Resolve "stale-serve and RPZ put in SERVFAIL cache unexpected record"

Closes #3678

See merge request isc-projects/bind9!7231
2023-01-09 10:09:47 +00:00
Aram Sargsyan
40dee61a1e Add a CHANGES note for [GL #3678] 2023-01-09 10:44:20 +01:00
Matthijs Mekking
91a1a8efc5 Consider non-stale data when in serve-stale mode
With 'stale-answer-enable yes;' and 'stale-answer-client-timeout off;',
consider the following situation:

A CNAME record and its target record are in the cache, then the CNAME
record expires, but the target record is still valid.

When a new query for the CNAME record arrives, and the query fails,
the stale record is used, and then the query "restarts" to follow
the CNAME target. The problem is that the query's multiple stale
options (like DNS_DBFIND_STALEOK) are not reset, so 'query_lookup()'
treats the restarted query as a lookup following a failed lookup,
and returns a SERVFAIL answer when there is no stale data found in the
cache, even if there is valid non-stale data there available.

With this change, query_lookup() now considers non-stale data in the
cache in the first place, and returns it if it is available.
2023-01-09 10:44:01 +01:00
Aram Sargsyan
537187bf2f Add serve-stale CNAME check with stale-answer-client-timeout off
Prime the cache with the following records:

    shortttl.cname.example.	1	IN	CNAME	longttl.target.example.
    longttl.target.example.	600	IN	A	10.53.0.2

Wait for the CNAME record to expire, disable the authoritative server,
and query 'shortttl.cname.example' again, expecting a stale answer.
2023-01-09 10:44:01 +01:00
Evan Hunt
7a677e45d1 Merge branch '3770-separate-barriers' into 'main'
use separate barriers for "stop" and "listen" operations

Closes #3770

See merge request isc-projects/bind9!7308
2023-01-09 03:00:57 +00:00
Evan Hunt
9c577e10c3 use separate barriers for "stop" and "listen" operations
On some platforms, when a synchronizing barrier is cleared, one
thread can progress while other threads are still in the process
of releasing the barrier. If a barrier is reused by the progressing
thread during this window, it can cause a deadlock. This can occur if,
for example, we stop listening immediately after we start, because the
stop and listen functions both use socket->barrier.  This has been
addressed by using separate barrier objects for stop and listen.
2023-01-07 16:30:21 -08:00
Ondřej Surý
f0bba87db0 Merge branch 'ondrej/dns_rbtdb-locking-fixups' into 'main'
Couple of small fixes in dns_rbtdb rwlock refactoring

See merge request isc-projects/bind9!7304
2023-01-07 06:15:07 +00:00
Ondřej Surý
44135371df Deduplicate DNS_RBTDB_STRONG_RWLOCK_CHECK macros
There were couple of redundant macros on both sides of
DNS_RBTDB_STRONG_RWLOCK_CHECK #ifdef block.  Use a single set of
macros, but disable the extra REQUIRES if the #define is not set.
2023-01-06 08:56:31 +01:00
Ondřej Surý
d693c2e7a0 Extend expire_header() to check node lock type
Extend the expire_header() to accept the node lock type as one of the
arguments and check whether the the node lock is always write locked +
fix that bug.

While doing that, it was found that expire_header() invocation in
rdataset_expire() passes `false` as a type of tree lock instead of
`isc_rwlocktype_none`.

(Un)fortunately, both values mapped to 0, so no harm was done, but it
has been fixed nevertheless.
2023-01-06 08:43:16 +01:00
Ondřej Surý
20670ee22d Replace repetetive _TRYUPGRADE() with _FORCEUPGRADE() macros
There was a repetetive pattern:

    if (NODE_TRYUPGRADE(&nodelock->lock, nlocktypep) != ISC_R_SUCCESS)
    {
        NODE_UNLOCK(&nodelock->lock, nlocktypep);
        NODE_WRLOCK(&nodelock->lock, nlocktypep);
    }

Instead of doing that over again, introduce new NODE_FORCEUPGRADE()
and TREE_FORCEUPGRADE() that does exactly this code, and simplify
the aforementioned code with just:

    NODE_FORCEUPGRADE(&nodelock->lock, nlocktypep);
2023-01-05 22:18:40 +01:00
Ondřej Surý
15f2f90bda Merge branch 'ondrej/isc_loop-reference-tracking' into 'main'
Enhance the isc_loop unit to allow reference count tracking

See merge request isc-projects/bind9!7291
2023-01-05 12:33:19 +00:00
Ondřej Surý
6613f89c62 Enhance the isc_loop unit to allow reference count tracking
Use ISC_REFCOUNT_TRACE_{IMPL,DECL} to allow better isc_loop reference
tracking - use `#define ISC_LOOP_TRACE 1` in <isc/loop.h> to enable.
2023-01-05 12:33:15 +00:00
Ondřej Surý
5e956d3cba Merge branch 'ondrej/enforce-thread-affinity-on-dnsstream' into 'main'
Enforce strong thread-affinity on StreamDNS sockets

See merge request isc-projects/bind9!7301
2023-01-05 12:33:02 +00:00
Ondřej Surý
6553927d27 Enforce strong thread-affinity on StreamDNS sockets
Add a check that the isc__nm_streamdns_read(), isc__nm_streamdns_send(),
and isc__nm_streamdns_close() are being called from the matching thread.
2023-01-05 09:43:09 +01:00
Ondřej Surý
06b70e0927 Merge branch '3766-pin-TCP-dispatch-to-threads' into 'main'
Pin the dns_dispatch to threads when reusing

Closes #3766

See merge request isc-projects/bind9!7299
2023-01-05 08:12:41 +00:00
Ondřej Surý
1a999353cd Pin the dns_dispatch to threads when reusing
Previously, dns_dispatch_gettcp() could pick a TCP connection created by
different thread - this breaks our contractual promise to DNS dispatch
by using the TCP connection on a different thread than it was created.
Add .tid member to the dns_dispatch_t struct and skip the dispatches
from other threads when looking up a TCP dispatch that we can reuse in
dns_request.

NOTE: This is going to be properly refactored, but this change could be
also backported to 9.18 for better stability and thread-affinity.
2023-01-05 09:11:42 +01:00
Evan Hunt
480b5c7ca7 Merge branch '3640-fix-control-flow' into 'main'
Fix control flow issues in zone.c

Closes #3640

See merge request isc-projects/bind9!7013
2023-01-04 22:48:16 +00:00
Evan Hunt
24a81fefe6 Fix control flow issues in zone.c
Since dns_master_dump() can no longer return DNS_R_CONTINUE,
the error recovery code in synchronous calls to zone_dump() had
branches that could no longer be reached. This has been cleaned
up by using a boolean variable to determine whether the write
is asynchronous rather than depending on the result code.
2023-01-04 14:14:42 -08:00
Tony Finch
0e489b9ed4 Merge branch '3745-delzone-catz' into 'main'
Don't crash when rndc delzone encounters a catz member

Closes #3745

See merge request isc-projects/bind9!7232
2023-01-04 17:04:48 +00:00
Tony Finch
9fa20d6f6c Don't crash when rndc delzone encounters a catz member
This bug was masked in the tests because the `catz` test script did an
`rndc addzone` before an `rndc delzone`. The `addzone` autovivified
the NZF config, so `delzone` worked OK.

This commit swaps the order of two sections of the `catz` test script
so that it uses `delzone` before `addzone`, which provokes a crash
when `delzone` requires a non-NULL NZF config.

To fix the crash, we now try to remove the zone from the NZF config
only if it was dynamically added but not by a catalog zone.
2023-01-04 14:04:22 +00:00
Matthijs Mekking
a4063f7d20 Merge branch '3760-cid-432259-sizeof-not-portable-in-lib-dns-remote' into 'main'
Fix CID 432259: Sizeof not portable (remote.c)

Closes #3760

See merge request isc-projects/bind9!7288
2023-01-04 07:58:12 +00:00
Matthijs Mekking
abd8c1cad0 Fix CID 432259: Sizeof not portable (remote.c)
The following report suggests that the 'size' parameter in the two
calls to 'isc_mem_get()' should be set to the
'count * sizeof(*tlsnames)' and 'count * sizeof(*keynames)'
respectively.

/lib/dns/remote.c: 117 in dns_remote_init()
111		}
112	} else {
113		remote->keynames = NULL;
114	}
115
116	if (tlsnames != NULL) {

>>>     CID 432259:    (SIZEOF_MISMATCH)
>>>     Passing argument "count * 8UL /* sizeof (tlsnames) */" to
>>>	function "isc__mem_get" and then casting the return value to
>>>	"dns_name_t **" is suspicious.  In this particular case
>>>	"sizeof (dns_name_t **)" happens to be equal to
>>>	"sizeof (dns_name_t *)", but this is not a portable assumption.

117	remote->tlsnames = isc_mem_get(mctx, count * sizeof(tlsnames));
118		for (i = 0; i < count; i++) {
119			remote->tlsnames[i] = NULL;
120		}
121		for (i = 0; i < count; i++) {
122			if (tlsnames[i] != NULL) {

/lib/dns/remote.c: 99 in dns_remote_init()
93		memmove(remote->dscps, dscp, count * sizeof(isc_dscp_t));
94	} else {
95		remote->dscps = NULL;
96	}
97
98	if (keynames != NULL) {

>>>     CID 432259:    (SIZEOF_MISMATCH)
>>>     Passing argument "count * 8UL /* sizeof (keynames) */" to
>>>	function "isc__mem_get" and then casting the return value to
>>>	"dns_name_t **" is suspicious.  In this particular case
>>>	"sizeof (dns_name_t **)" happens to be equal to "sizeof
>>>	(dns_name_t *)", but this is not a portable assumption.

99	 remote->keynames = isc_mem_get(mctx, count * sizeof(keynames));
100	 for (i = 0; i < count; i++) {
101		remote->keynames[i] = NULL;
102	 }
103	 for (i = 0; i < count; i++) {
104		if (keynames[i] != NULL) {
2023-01-03 16:47:57 +01:00
Arаm Sаrgsyаn
0667cd6cc4 Merge branch '3735-fix-rpz-shutdown-bugs' into 'main'
Fix shutdown and error path bugs in the rpz unit

Closes #3735

See merge request isc-projects/bind9!7289
2023-01-03 15:11:08 +00:00
Aram Sargsyan
2824422e78 Add a CHANGES note for [GL #3735] 2023-01-03 14:21:17 +00:00
Aram Sargsyan
ef4f15d2d1 Fix an error path bug in rpz.c:update_nodes()
When dns_db_createiterator() fails, 'updbit' should not be destroyed
for obvious reasons, i.e. it is NULL.
2023-01-03 14:21:17 +00:00
Aram Sargsyan
d36728e42f Fix a shutdown and error path bugs in rpz.c:update_nodes()
When shutting down, or when dns_dbiterator_current() fails, 'node'
shouldn't be detached, because it is NULL at that point.
2023-01-03 14:21:17 +00:00
Aram Sargsyan
975d16230b Fix a shutdown bug in update_rpz_cb()
When shutting down, the cleanup path should not try to destroy
'newnodes', because it is NULL at that point.

Introduce another label for the "shuttingdown" scenario.
2023-01-03 13:27:43 +00:00
Arаm Sаrgsyаn
ca2d2568b1 Merge branch '3754-adb-maybe_expire_entry-called-unlocked-bug' into 'main'
Don't expire an ADB entry without holding the entries lock

Closes #3754

See merge request isc-projects/bind9!7275
2023-01-03 09:01:18 +00:00
Aram Sargsyan
268154f899 Add a CHANGES note for [GL #3754] 2023-01-03 08:23:23 +00:00
Aram Sargsyan
da7c448988 Don't expire an ADB entry without holding the entries lock
The clean_namehooks() function does't hold the 'adb->entries_lock'
lock, so calling maybe_expire_entry() is not thread-safe.

Instead of adding a lock/unlock, leave the expiration to later,
e.g. by the get_attached_and_locked_entry() function.

Also fix a couple of comment typos.
2023-01-03 08:21:52 +00:00
Mark Andrews
2e1e398e7d Merge branch '3761-ubsan-error-in-isc_buffer_reserve' into 'main'
Resolve "UBSAN error in isc_buffer_reserve"

Closes #3761

See merge request isc-projects/bind9!7285
2023-01-03 07:30:21 +00:00
Mark Andrews
096b280b1c Do not pass NULL pointer to memmove - undefined behaviour
Check if 'old_base' is NULL and if so skip calling memmove.
2023-01-03 14:40:30 +11:00
Michał Kępień
b2d08c514d Merge branch 'michal/update-copyright-year-to-2023' into 'main'
Update copyright year to 2023

See merge request isc-projects/bind9!7282
2023-01-02 13:06:36 +00:00
Michał Kępień
1a5d707f52 Update copyright year to 2023 2023-01-02 13:58:00 +01:00
Artem Boldariev
b78829a3f8 Merge branch 'artem-tls-use-isc-buffer' into 'main'
TLS: use isc_buffer_t for send requests, reuse isc_buffer_t during send requests

See merge request isc-projects/bind9!7281
2022-12-30 18:35:53 +00:00
Artem Boldariev
fbf1546fb8 TLS: use isc_buffer_t for send requests
This commit replaces ad-hoc code for send requests buffer management
within TLS with the one based on isc_buffer_t.

Previous version of the code was trying to use pre-allocated small
buffers to avoid extra allocations. The code would allocate a larger
dynamic buffer when needed. There is no need to have ad-hoc code for
this, as isc_buffer_t now provides this functionality internally.

Additionally to the above, the old version of the code lacked any
logic to reuse the dynamically allocated buffers. Now, as we do not
manage memory buffers, but isc_buffer_t objects, we can implement this
strategy. It can be in particular helpful for longer lasting
connections, as in this case the buffer will adjust itself to the size
of the messages being transferred. That is, it is in particular useful
for XoT, as Stream DNS happen to order send requests in such a way
that the send request will get reused.
2022-12-30 19:56:25 +02:00
Arаm Sаrgsyаn
0c252fdfc5 Merge branch 'aram/dns_dispatch_createtcp-bugfix' into 'main'
Don't pass a NULL pointer to isc_sockaddr_format()

See merge request isc-projects/bind9!7277
2022-12-28 14:18:52 +00:00
Aram Sargsyan
41ca9d419e Don't pass a NULL pointer to isc_sockaddr_format()
The 'localaddr' pointer can be NULL, which causes an assertion failure.

Use '&disp->local' instead when printing a debug log message.
2022-12-28 12:10:09 +00:00
Matthijs Mekking
eb7275e933 Merge branch '3714-remove-alt-transfer-source' into 'main'
Remove setting alternate transfer source

Closes #3714

See merge request isc-projects/bind9!7163
2022-12-23 15:11:25 +00:00
Matthijs Mekking
e277f1f757 Add CHANGES and release notes for #3714
Update release notes, remove the deprecation entry and add a new
removed feature entry.
2022-12-23 15:32:12 +01:00
Matthijs Mekking
d8e98d4bba Remove unused dns_remote_t functions
Now that setting alternate transfer sources is removed, the functions
to check whether all addresses are considered good have become obsolete.
2022-12-23 15:17:54 +01:00
Matthijs Mekking
8640e70616 Remove setting alternate transfer source from doc
Remove any reference to 'alt-transfer-source', 'alt-transfer-source-v6',
and 'use-alt-transfer-source' from the documentation and manual pages.
2022-12-23 14:44:48 +01:00
Matthijs Mekking
5954ae6458 Remove setting alternate transfer source
Remove parsing the configuration options 'alt-transfer-source',
'alt-transfer-source-v6', and 'use-alt-transfer-source', and remove
the corresponding code that implements the feature.
2022-12-23 14:39:59 +01:00