2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 06:25:31 +00:00
Commit Graph

36832 Commits

Author SHA1 Message Date
Michał Kępień
7009f9d270 Improve reporting for read-write lock errors
Replace direct uses of implementation-specific rwlock functions in
lib/isc/include/isc/rwlock.h with preprocessor macros that use
ERRNO_CHECK(), in order to augment rwlock-related error messages with
file/line/caller information and the error string corresponding to
errno.  Adjust the implementation-specific functions for pthreads-based
rwlocks so that they return any errors encountered to the caller instead
of aborting execution immediately using RUNTIME_CHECK().

To keep code modifications simple, make the non-pthreads-based
implementation-specific rwlock functions always return 0; these
functions continue to handle errors using less verbose run-time
assertions as they do not set errno anyway.
2022-07-13 13:19:32 +02:00
Michał Kępień
77aead5ab6 Enable tracking of pthreads barriers
Some POSIX threads implementations (e.g. FreeBSD's libthr) allocate
memory on the heap when pthread_barrier_init() is called.  Every call to
that function must be accompanied by a corresponding call to
pthread_barrier_destroy() or else the memory allocated for the barrier
will leak.

jemalloc can be used for detecting memory allocations which are not
released by a process when it exits.  Unfortunately, since jemalloc is
also the system allocator on FreeBSD and a special (profiling-enabled)
build of jemalloc is required for memory leak detection, this method
cannot be used for detecting leaked memory allocated by libthr on a
stock FreeBSD installation.

However, libthr's behavior can be emulated on any platform by
implementing alternative versions of libisc functions for creating and
destroying barriers that allocate memory using malloc() and release it
using free().  This enables using jemalloc for detecting missing
pthread_barrier_destroy() calls on any platform on which it works
reliably.

When the newly introduced ISC_TRACK_PTHREADS_OBJECTS preprocessor macro
is set, allocate isc_barrier_t structures on the heap in
isc_barrier_init() and free them in isc_barrier_destroy().  Reuse
existing barrier macros (after renaming them appropriately) for other
operations.
2022-07-13 13:19:32 +02:00
Ondřej Surý
8e5e0fa522 Use library constructor to create default mutex attr once
Instead of using isc_once_do() on every isc_mutex_init() call, use the
global library constructor to initialize the default mutex attr
object (optionally with PTHREAD_MUTEX_ADAPTIVE_NP if supported) just
once when the library is loaded.
2022-07-13 13:19:32 +02:00
Michał Kępień
badeeff0ac Improve reporting for condition variable errors
Replace all uses of RUNTIME_CHECK() in lib/isc/include/isc/condition.h
with ERRNO_CHECK(), in order to improve error reporting for any
condition-variable-related run-time failures (by augmenting error
messages with file/line/caller information and the error string
corresponding to errno).
2022-07-13 13:19:32 +02:00
Ondřej Surý
e4606da2c6 Enable tracking of pthreads rwlocks
Some POSIX threads implementations (e.g. FreeBSD's libthr) allocate
memory on the heap when pthread_rwlock_init() is called.  Every call to
that function must be accompanied by a corresponding call to
pthread_rwlock_destroy() or else the memory allocated for the rwlock
will leak.

jemalloc can be used for detecting memory allocations which are not
released by a process when it exits.  Unfortunately, since jemalloc is
also the system allocator on FreeBSD and a special (profiling-enabled)
build of jemalloc is required for memory leak detection, this method
cannot be used for detecting leaked memory allocated by libthr on a
stock FreeBSD installation.

However, libthr's behavior can be emulated on any platform by
implementing alternative versions of libisc functions for creating and
destroying rwlocks that allocate memory using malloc() and release it
using free().  This enables using jemalloc for detecting missing
pthread_rwlock_destroy() calls on any platform on which it works
reliably.

When the newly introduced ISC_TRACK_PTHREADS_OBJECTS preprocessor macro
is set (and --enable-pthread-rwlock is used), allocate isc_rwlock_t
structures on the heap in isc_rwlock_init() and free them in
isc_rwlock_destroy().  Reuse existing functions defined in
lib/isc/rwlock.c for other operations, but rename them first, so that
they contain triple underscores (to indicate that these functions are
implementation-specific, unlike their mutex and condition variable
counterparts, which always use the pthreads implementation).  Define the
isc__rwlock_init() macro so that it is a logical counterpart of
isc__mutex_init() and isc__condition_init(); adjust isc___rwlock_init()
accordingly.  Remove a redundant function prototype for
isc__rwlock_lock() and rename that (static) function to rwlock_lock() in
order to avoid having to use quadruple underscores.
2022-07-13 13:19:32 +02:00
Michał Kępień
5759ace07f Handle pthread_*_init() failures consistently
isc_rwlock_init() currently detects pthread_rwlock_init() failures using
a REQUIRE() assertion.  Use the ERRNO_CHECK() macro for that purpose
instead, so that read-write lock initialization failures are handled
identically as condition variable (pthread_cond_init()) and mutex
(pthread_mutex_init()) initialization failures.
2022-07-13 13:19:32 +02:00
Michał Kępień
f352a834a7 Improve reporting for mutex errors
Replace all uses of RUNTIME_CHECK() in lib/isc/include/isc/mutex.h with
ERRNO_CHECK(), in order to improve error reporting for any mutex-related
run-time failures (by augmenting error messages with file/line/caller
information and the error string corresponding to errno).
2022-07-13 13:19:32 +02:00
Ondřej Surý
8dfdb95a20 Enable tracking of pthreads condition variables
Some POSIX threads implementations (e.g. FreeBSD's libthr) allocate
memory on the heap when pthread_cond_init() is called.  Every call to
that function must be accompanied by a corresponding call to
pthread_cond_destroy() or else the memory allocated for the condition
variable will leak.

jemalloc can be used for detecting memory allocations which are not
released by a process when it exits.  Unfortunately, since jemalloc is
also the system allocator on FreeBSD and a special (profiling-enabled)
build of jemalloc is required for memory leak detection, this method
cannot be used for detecting leaked memory allocated by libthr on a
stock FreeBSD installation.

However, libthr's behavior can be emulated on any platform by
implementing alternative versions of libisc functions for creating and
destroying condition variables that allocate memory using malloc() and
release it using free().  This enables using jemalloc for detecting
missing pthread_cond_destroy() calls on any platform on which it works
reliably.

When the newly introduced ISC_TRACK_PTHREADS_OBJECTS preprocessor macro
is set, allocate isc_condition_t structures on the heap in
isc_condition_init() and free them in isc_condition_destroy().  Reuse
existing condition variable macros (after renaming them appropriately)
for other operations.
2022-07-13 13:19:32 +02:00
Michał Kępień
365b47caee Add an ERRNO_CHECK() preprocessor macro
In a number of situations in pthreads-related code, a common sequence of
steps is taken: if the value returned by a library function is not 0,
pass errno to strerror_r(), log the string returned by the latter, and
immediately abort execution.  Add an ERRNO_CHECK() preprocessor macro
which takes those exact steps and use it wherever (conveniently)
possible.

Notes:

 1. The "log the return value of strerror_r() and abort" pattern is used
    in a number of other places that this commit does not touch; only
    "!= 0" checks followed by isc_error_fatal() calls with
    non-customized error messages are replaced here.

 2. This change temporarily breaks file name & line number reporting for
    isc__mutex_init() errors, to prevent breaking the build.  This issue
    will be rectified in a subsequent change.
2022-07-13 13:19:32 +02:00
Ondřej Surý
ebcfb16576 Enable tracking of pthreads mutexes
Some POSIX threads implementations (e.g. FreeBSD's libthr) allocate
memory on the heap when pthread_mutex_init() is called.  Every call to
that function must be accompanied by a corresponding call to
pthread_mutex_destroy() or else the memory allocated for the mutex will
leak.

jemalloc can be used for detecting memory allocations which are not
released by a process when it exits.  Unfortunately, since jemalloc is
also the system allocator on FreeBSD and a special (profiling-enabled)
build of jemalloc is required for memory leak detection, this method
cannot be used for detecting leaked memory allocated by libthr on a
stock FreeBSD installation.

However, libthr's behavior can be emulated on any platform by
implementing alternative versions of libisc functions for creating and
destroying mutexes that allocate memory using malloc() and release it
using free().  This enables using jemalloc for detecting missing
pthread_mutex_destroy() calls on any platform on which it works
reliably.

Introduce a new ISC_TRACK_PTHREADS_OBJECTS preprocessor macro, which
causes isc_mutex_t structures to be allocated on the heap by
isc_mutex_init() and freed by isc_mutex_destroy().  Reuse existing mutex
macros (after renaming them appropriately) for other operations.
2022-07-13 13:19:32 +02:00
Ondřej Surý
9968a6292d Merge branch 'ondrej-update-dir-locals-for-libtest' into 'main'
Update the .dir-locals.el for libtest

See merge request isc-projects/bind9!6565
2022-07-13 10:21:35 +00:00
Ondřej Surý
80fbd849d5 Update the .dir-locals.el for libtest
The tests/libtest directory is missing from the .dir-locals.el, so the
emacs flycheck would not work for the unit tests.  Add it to the
configuration.
2022-07-13 12:17:34 +02:00
Michał Kępień
5415ecbd7c Merge branch '3439-stop-resolving-invalid-names-in-resume_dslookup' into 'main'
Stop resolving invalid names in resume_dslookup()

Closes #3439

See merge request isc-projects/bind9!6563
2022-07-13 08:59:30 +00:00
Michał Kępień
cfa398ad37 Add CHANGES entry and release note for GL #3439 2022-07-13 10:31:16 +02:00
Michał Kępień
1a79aeab44 Stop resolving invalid names in resume_dslookup()
Commit 7b2ea97e46 introduced a logic bug
in resume_dslookup(): that function now only conditionally checks
whether DS chasing can still make progress.  Specifically, that check is
only performed when the previous resume_dslookup() call invokes
dns_resolver_createfetch() with the 'nameservers' argument set to
something else than NULL, which may not always be the case.  Failing to
perform that check may trigger assertion failures as a result of
dns_resolver_createfetch() attempting to resolve an invalid name.

Example scenario that leads to such outcome:

 1. A validating resolver is configured to forward all queries to
    another resolver.  The latter returns broken DS responses that
    trigger DS chasing.

 2. rctx_chaseds() calls dns_resolver_createfetch() with the
    'nameservers' argument set to NULL.

 3. The fetch fails, so resume_dslookup() is called.  Due to
    fevent->result being set to e.g. DNS_R_SERVFAIL, the default branch
    is taken in the switch statement.

 4. Since 'nameservers' was set to NULL for the fetch which caused the
    resume_dslookup() callback to be invoked
    (fctx->nsfetch->private->nameservers), resume_dslookup() chops off
    one label off fctx->nsname and calls dns_resolver_createfetch()
    again, for a name containing one label less than before.

 5. Steps 3-4 are repeated (i.e. all attempts to find the name servers
    authoritative for the DS RRset being chased fail) until fctx->nsname
    becomes stripped down the the root name.

 6. Since resume_dslookup() does not check whether DS chasing can still
    make progress, it strips off a label off the root name and continues
    its attempts at finding the name servers authoritative for the DS
    RRset being chased, passing an invalid name to
    dns_resolver_createfetch().

Fix by ensuring resume_dslookup() always checks whether DS chasing can
still make progress when a name server fetch fails.  Update code
comments to ensure the purpose of the relevant dns_name_equal() check is
clear.
2022-07-13 10:31:16 +02:00
Mark Andrews
75027bc6ce Merge branch '3446-autosign-s-checking-revoked-key-with-duplicate-key-id-test-was-incomplete' into 'main'
Resolve "Autosign's 'checking revoked key with duplicate key ID' test was incomplete"

Closes #3446

See merge request isc-projects/bind9!6555
2022-07-13 00:48:09 +00:00
Mark Andrews
513cb24b55 Make "checking revoked key with duplicate key ID" work
There should be 2 keys with the same key id after the numerically
lower one is revoked (serial space arithmetic).  The DS points
at the non-revoked key so validation should still succeed.
2022-07-13 00:47:49 +00:00
Mark Andrews
e28492dc04 Merge branch '3445-update-libdns_la_libadd-instead-of-libdns_la_ldflags' into 'main'
Resolve "Update libdns_la_LIBADD instead of libdns_la_LDFLAGS"

Closes #3445

See merge request isc-projects/bind9!6553
2022-07-13 00:44:51 +00:00
Mark Andrews
5b51610174 Update libdns_la_LIBADD rather than libdns_la_LDFLAGS
the wrong macro was being update with MAXMINDDB_LIBS making
it difficult to adjust link order.
2022-07-13 00:14:13 +00:00
Evan Hunt
47bf1e95ad Merge branch '2962-invalid-fctx' into 'main'
clear fctx->magic and fetch->magic when destroying

See merge request isc-projects/bind9!6543
2022-07-12 23:54:25 +00:00
Evan Hunt
5ec077e6aa clear fctx->magic and fetch->magic when destroying
fctx_destroy() and dns_resolver_destroyfetch() did not clear the
'magic' field during destruction.
2022-07-12 23:40:47 +00:00
Evan Hunt
24e52a623f Merge branch '2683-ixfr-logging' into 'main'
log the reason for falling back to AXFR from IXFR at level info

Closes #2683

See merge request isc-projects/bind9!6511
2022-07-12 23:25:34 +00:00
Evan Hunt
df1d81cf96 log the reason for falling back to AXFR from IXFR at level info
messages indicating the reason for a fallback to AXFR (i.e, because
the requested serial number is not present in the journal, or because
the size of the IXFR response would exceeed "max-ixfr-ratio") are now
logged at level info instead of debug(4).
2022-07-12 16:02:54 -07:00
Artem Boldariev
0b221bf326 Merge branch 'artem-backport-tls-related-fixes-from-loopmgr-branch' into 'main'
Backport TLS-related fixes from the loopmgr-branch

See merge request isc-projects/bind9!6501
2022-07-12 12:11:21 +00:00
Artem Boldariev
ffcb54211e TLS: do not ignore accept callback result
Before this change the TLS code would ignore the accept callback result,
and would not try to gracefully close the connection. This had not been
noticed, as it is not really required for DoH. Now the code tries to
shut down the TLS connection gracefully when accepting it is not
successful.
2022-07-12 14:40:22 +03:00
Artem Boldariev
0f9b6a7bc1 *_noresponse, tlsdns_listen_noalpn: csends == 1 is not guaranteed
This commit removes an assertion from the unit test which cannot be
guaranteed.

According to the test, exactly one client send must succeed. However,
it cannot really be guaranteed, as do not start to read data in the
accept callback on the server nor attach to the accepted handle. Thus,
we can expect the connection to be closed soon after we have returned
from the callback.

Interestingly enough, the test would pass just fine on TCP because:

a) there are fewer layers involved and thus there is less processing;

b) it is possible for the data to be sent and end up in an internal OS
socket buffer without being touched by an application's code on the
server. In such a case the client's write callback still would be
called successfully;

There is a chance for the test to succeed over TLS as well (as it
happily did before), but as the code has been changed to close unused
connections as soon as possible, the chance is far slimmer now.

What can be guaranteed is:

* cconnects == 1 (number client connections equals 1);
* saccepts == 1 (number of accepted connections equals 1).
2022-07-12 14:40:22 +03:00
Artem Boldariev
8585b92f98 TLSDNS: try pass incoming data to OpenSSL if there are any
Otherwise the code path will lead to a call to SSL_get_error()
returning SSL_ERROR_SSL, which in turn might lead to closing
connection to early in an unexpected way, as it is clearly not what is
intended.

The issue was found when working on loppmgr branch and appears to
be timing related as well. Might be responsible for some unexpected
transmission failures e.g. on zone transfers.
2022-07-12 14:40:22 +03:00
Artem Boldariev
fc74b15e67 TLS: bail out earlier when NM is stopping
In some operations - most prominently when establishing connection -
it might be beneficial to bail out earlier when the network manager
is stopping.

The issue is backported from loopmgr branch, where such a change is
not only beneficial, but required.
2022-07-12 14:40:22 +03:00
Artem Boldariev
ac4fb34f18 TLS: sometimes TCP conn. handle might be NULL on when connecting
In some cases - in particular, in case of errors, NULL might be passed
to a connection callback instead of a handle that could have led to
an abort. This commit ensures that such a situation will not occur.

The issue was found when working on the loopmgr branch.
2022-07-12 14:40:22 +03:00
Artem Boldariev
88524e26ec TLS: try to close sockets whenever there are no pending operations
This commit ensures that the underlying TCP socket of a TLS connection
gets closed earlier whenever there are no pending operations on it.

In the loop-manager branch, in some circumstances the connection
could have remained opened for far too long for no reason. This
commit ensures that will not happen.
2022-07-12 14:40:22 +03:00
Artem Boldariev
237ce05b89 TLS: Implement isc_nmhandle_setwritetimeout()
This commit adds a proper implementation of
isc_nmhandle_setwritetimeout() for TLS connections. Now it passes the
value to the underlying TCP handle.
2022-07-12 14:40:22 +03:00
Michal Nowak
56d9938328 Merge branch 'mnowak/alpine-3.16' into 'main'
Add Alpine Linux 3.16

See merge request isc-projects/bind9!6360
2022-07-12 11:10:28 +00:00
Michal Nowak
0d0ab3db10 Add Alpine Linux 3.16 2022-07-12 12:27:10 +02:00
Matthijs Mekking
0851ace0d3 Merge branch '3438-dnssec-policy-does-not-set-inline-signing' into 'main'
Fix inheritance for dnssec-policy when checking for inline-signing

Closes #3438

See merge request isc-projects/bind9!6541
2022-07-12 10:12:39 +00:00
Matthijs Mekking
689215a675 Add release note and change entry for #3438
Bug worth mentioning.
2022-07-12 11:29:39 +02:00
Matthijs Mekking
576b21b168 Inherit dnssec-policy in check for inline-signing
When dnssec-policy is used, and the zone is not dynamic, BIND will
assume that the zone is inline-signed. But the function responsible
for this did not inherit the dnssec-policy option from the view or
options level, and thus never enabled inline-signing, while the zone
should have been.

This is fixed by this commit.
2022-07-12 11:29:03 +02:00
Matthijs Mekking
efa8a4e88d Test setting of inline-signing with dnssec-policy
When dnssec-policy is used, and the zone is not dynamic, BIND will
assume that the zone is inline-signed. Add test cases to verify this.
2022-07-12 11:29:03 +02:00
Matthijs Mekking
ff65f07779 Fix kasp system test bugs
Fix a comment, ensuring the right parameters are used (zone is
parameter $3, not $2) and add view and policy parameters to the comment.

Fix the view tests and test the correct view (example3 instead of
example2).

Fix placement of "n=$((n+1)" for two test cases.
2022-07-12 11:29:03 +02:00
Mark Andrews
c33c947415 Merge branch '3389-unexpected-badkey-in-upforwd-system-test' into 'main'
Clone UPDATE message buffer before forwarding

Closes #3389

See merge request isc-projects/bind9!6388
2022-07-12 08:57:47 +00:00
Mark Andrews
09d8ed3970 Add CHANGES note for [GL #3389] 2022-07-12 17:14:11 +10:00
Mark Andrews
7a42417d61 Clone the message buffer before forwarding UPDATE messages
this prevents named forwarding a buffer that may have been over
written.
2022-07-12 17:13:24 +10:00
Mark Andrews
50a86e9119 Merge branch '3440-use-default_algorithm-more-often' into 'main'
Resolve "Use DEFAULT_ALGORITHM more often"

Closes #3440

See merge request isc-projects/bind9!6532
2022-07-12 03:46:28 +00:00
Mark Andrews
be88c583bd Add CHANGES not for [GL #3440] 2022-07-12 13:29:07 +10:00
Mark Andrews
459e6980e5 zonechecks: use $DEFAULT_ALGORITHM 2022-07-12 13:29:07 +10:00
Mark Andrews
3f65c9cf85 wildcard: use $DEFAULT_ALGORITHM 2022-07-12 13:29:07 +10:00
Mark Andrews
86b29606c3 views: use $DEFAULT_ALGORITHM 2022-07-12 13:29:07 +10:00
Mark Andrews
93f7c7cdcd verify: use $DEFAULT_ALGORITHM 2022-07-12 13:29:07 +10:00
Mark Andrews
5585909904 upforwd: use $DEFAULT_ALGORITHM 2022-07-12 13:29:07 +10:00
Mark Andrews
9970d4317d unknown: use $DEFAULT_ALGORITHM 2022-07-12 13:29:07 +10:00
Mark Andrews
73fd49f8bb synthfromdnssec: use $DEFAULT_ALGORITHM 2022-07-12 13:29:07 +10:00