Commit graph

12606 commits

Author SHA1 Message Date
Matthijs Mekking
4dabb688db Check return value of dst_key_getbool()
Fix Coverity CHECKED_RETURN reports for dst_key_getbool().  In most
cases we do not really care about its return value, but it is prudent
to check it.

In one case, where a dst_key_getbool() error should be treated
identically as success, cast the return value to void and add a relevant
comment.

(cherry picked from commit e645d2ef1e)
2020-07-14 17:48:21 +02:00
Mark Andrews
d47c42a0ab Mark 'addr' as unused if HAVE_IF_NAMETOINDEX is not defined
Also 'zone' should be initialised to zero.

(cherry picked from commit e7662c4c63)
2020-07-14 10:53:06 +10:00
Mark Andrews
b955da48aa Handle namespace clash over 'SEC' on illumos.
(cherry picked from commit 18eef20241)
2020-07-14 09:06:46 +10:00
Mark Andrews
f771d75c9b Address potential double unlock in process_fd
(cherry picked from commit cc0089c66b)
2020-07-14 07:35:17 +10:00
Mark Andrews
94288631a9 Add changes for [GL #1989]
(cherry picked from commit 42b2290c3a)
2020-07-13 14:04:53 +10:00
Mark Andrews
67f85d648f Address overrun in remove_old_tsversions
If too many versions of log / dnstap files to be saved where requests
the memory after to_keep could be overwritten.  Force the number of
versions to be saved to a save level.  Additionally the memmove length
was incorrect.

(cherry picked from commit 6ca78bc57d)
2020-07-13 14:04:04 +10:00
Mark Andrews
e67b7a62d0 Assert tsigout is non-NULL
(cherry picked from commit 827746e89b)
2020-07-13 13:21:12 +10:00
Mark Andrews
12fac1ce70 check returns from inet_pton()
(cherry picked from commit 9499adeb5e)
2020-07-13 11:44:58 +10:00
Michał Kępień
0bc4d6cc7a Fix locking for LMDB 0.9.26
When "rndc reconfig" is run, named first configures a fresh set of views
and then tears down the old views.  Consider what happens for a single
view with LMDB enabled; "envA" is the pointer to the LMDB environment
used by the original/old version of the view, "envB" is the pointer to
the same LMDB environment used by the new version of that view:

 1. mdb_env_open(envA) is called when the view is first created.
 2. "rndc reconfig" is called.
 3. mdb_env_open(envB) is called for the new instance of the view.
 4. mdb_env_close(envA) is called for the old instance of the view.

This seems to have worked so far.  However, an upstream change [1] in
LMDB which will be part of its 0.9.26 release prevents the above
sequence of calls from working as intended because the locktable mutexes
will now get destroyed by the mdb_env_close() call in step 4 above,
causing any subsequent mdb_txn_begin() calls to fail (because all of the
above steps are happening within a single named process).

Preventing the above scenario from happening would require either
redesigning the way we use LMDB in BIND, which is not something we can
easily backport, or redesigning the way BIND carries out its
reconfiguration process, which would be an even more severe change.

To work around the problem, set MDB_NOLOCK when calling mdb_env_open()
to stop LMDB from controlling concurrent access to the database and do
the necessary locking in named instead.  Reuse the view->new_zone_lock
mutex for this purpose to prevent the need for modifying struct dns_view
(which would necessitate library API version bumps).  Drop use of
MDB_NOTLS as it is made redundant by MDB_NOLOCK: MDB_NOTLS only affects
where LMDB reader locktable slots are stored while MDB_NOLOCK prevents
the reader locktable from being used altogether.

[1] 2fd44e3251

(cherry picked from commit 53120279b5)
2020-07-10 11:30:31 +02:00
Mark Andrews
86681ca6f1 Adjust range limit of unknown meta types
(cherry picked from commit 092a159dcd)
2020-07-08 13:44:47 +10:00
Ondřej Surý
0279cc76a7 Update STALE and ANCIENT header attributes atomically
The ThreadSanitizer found a data race when updating the stale header.
Instead of trying to acquire the write lock and failing occasionally
which would skew the statistics, the dns_rdatasetheader_t.attributes
field has been promoted to use stdatomics.  Updating the attributes in
the mark_header_ancient() and mark_header_stale() now uses the cmpxchg
to update the attributes forfeiting the need to hold the write lock on
the tree.  Please note that mark_header_ancient() still needs to hold
the lock because .dirty is being updated in the same go.

(cherry picked from commit 81d4230e60)
2020-07-08 12:01:46 +10:00
Mark Andrews
dd32fb9284 Make the stdatomic shim and mutexatomic type complete
The stdatomic shims for non-C11 compilers (Windows, old gcc, ...) and
mutexatomic implemented only and minimal subset of the atomic types.
This commit adds 16-bit operations for Windows and all atomic types as
defined in standard.

(cherry picked from commit bccea5862d)
2020-07-08 10:29:59 +10:00
Mark Andrews
244ebdfb8c remove redundant rctx != NULL check
(cherry picked from commit 2fa2dbd5fb)
2020-07-06 10:30:25 +10:00
Witold Kręcicki
000c7d1340 rbtdb: cleanup_dead_nodes should ignore alive nodes on the deadlist
(cherry picked from commit c8f2d55acf)
2020-07-01 15:35:21 +02:00
Witold Kręcicki
03e583ffa8 Fix assertion failure during startup when the server is under load.
When we're coming back from recursion fetch_callback does not accept
DNS_R_NXDOMAIN as an rcode - query_gotanswer calls query_nxdomain in
which an assertion fails on qctx->is_zone. Yet, under some
circumstances, qname minimization will return an DNS_R_NXDOMAIN - when
root zone mirror is not yet loaded. The fix changes the DNS_R_NXDOMAIN
answer to DNS_R_SERVFAIL.
2020-07-01 12:55:12 +02:00
Matthijs Mekking
9f5a43808f Fix linking problem for #1612
When a library is examined, an object file within it can be left out
of the link if it does not provide symbols that the symbol table
needs.  Introducing `isc_stdtime_tostring` caused a build failure for
`update_test` because it now requires `libisc.a(stdtime.o)` and that
also exports the `isc_stdtime_get` symbol, meaning we have a
multiple definition error.

Add a local version of `isc_stdtime_tostring`, so that the linker
will not search for it in available object files.
2020-07-01 10:55:30 +02:00
Matthijs Mekking
f1b3686cd2 Output rndc dnssec -status
Implement the 'rndc dnssec -status' command that will output
some information about the key states, such as which policy is
used for the zone, what keys are in use, and when rollover is
scheduled.

Add loose testing in the kasp system test, the actual times are
already tested via key file inspection.

(cherry picked from commit 19ce9ec1d4)
2020-07-01 09:57:44 +02:00
Matthijs Mekking
7915327aac Move dst key printtime in separate function
I'd like to use the same functionality (pretty print the datetime
of keytime metadata) in the 'rndc dnssec -status' command.  So it is
better that this logic is done in a separate function.

Since the stdtime.c code have differernt files for unix and win32,
I think the "#ifdef WIN32" define can be dropped.

(cherry picked from commit 9e03f8e8fe)
2020-07-01 09:57:44 +02:00
Evan Hunt
952461b6af restore "blackhole" functionality
the blackhole ACL was accidentally disabled with respect to client
queries during the netmgr conversion.

in order to make this work for TCP, it was necessary to add a return
code to the accept callback functions passed to isc_nm_listentcp() and
isc_nm_listentcpdns().

(cherry picked from commit 23c7373d68)
2020-06-30 21:10:31 -07:00
Tony Finch
b7f7b8128e Fix rndc dnstap -roll N
The `rndc` argument was always overridden by the static configuration,
because the logic for handling the number of dnstap files to retain
was both backwards and a bit redundant.

(cherry picked from commit 7c07129a51)
2020-06-29 22:30:01 +00:00
Michał Kępień
be35b872fd Address compilation warnings on FreeBSD 11.4
With Clang 10.0.0 on FreeBSD 11.4, compiling lib/dns/spnego.c triggers
the following warnings:

    spnego.c:361:11: error: converting the result of '<<' to a boolean always evaluates to true [-Werror,-Wtautological-constant-compare]
                    return (GSS_S_DEFECTIVE_TOKEN);
                            ^
    /usr/include/gssapi/gssapi.h:423:41: note: expanded from macro 'GSS_S_DEFECTIVE_TOKEN'
    #define GSS_S_DEFECTIVE_TOKEN      (9ul << GSS_C_ROUTINE_ERROR_OFFSET)
                                            ^
    spnego.c:366:11: error: converting the result of '<<' to a boolean always evaluates to true [-Werror,-Wtautological-constant-compare]
                    return (GSS_S_DEFECTIVE_TOKEN);
                            ^
    /usr/include/gssapi/gssapi.h:423:41: note: expanded from macro 'GSS_S_DEFECTIVE_TOKEN'
    #define GSS_S_DEFECTIVE_TOKEN      (9ul << GSS_C_ROUTINE_ERROR_OFFSET)
                                            ^
    spnego.c:371:12: error: converting the result of '<<' to a boolean always evaluates to true [-Werror,-Wtautological-constant-compare]
                            return (GSS_S_DEFECTIVE_TOKEN);
                                    ^
    /usr/include/gssapi/gssapi.h:423:41: note: expanded from macro 'GSS_S_DEFECTIVE_TOKEN'
    #define GSS_S_DEFECTIVE_TOKEN      (9ul << GSS_C_ROUTINE_ERROR_OFFSET)
                                            ^
    spnego.c:376:11: error: converting the result of '<<' to a boolean always evaluates to true [-Werror,-Wtautological-constant-compare]
                    return (GSS_S_DEFECTIVE_TOKEN);
                            ^
    /usr/include/gssapi/gssapi.h:423:41: note: expanded from macro 'GSS_S_DEFECTIVE_TOKEN'
    #define GSS_S_DEFECTIVE_TOKEN      (9ul << GSS_C_ROUTINE_ERROR_OFFSET)
                                            ^
    spnego.c:380:11: error: converting the result of '<<' to a boolean always evaluates to true [-Werror,-Wtautological-constant-compare]
                    return (GSS_S_DEFECTIVE_TOKEN);
                            ^
    /usr/include/gssapi/gssapi.h:423:41: note: expanded from macro 'GSS_S_DEFECTIVE_TOKEN'
    #define GSS_S_DEFECTIVE_TOKEN      (9ul << GSS_C_ROUTINE_ERROR_OFFSET)
                                            ^
    5 errors generated.

Address by replacing all instances of the GSS_S_DEFECTIVE_TOKEN constant
with a boolean value.  Invert the values returned by cmp_gss_type() so
that its only call site reads more naturally in the context of the
comment preceding it.
2020-06-29 12:03:01 +02:00
Matthijs Mekking
7eed00502f kasp tests: fix wait for reconfig done
The wait until zones are signed after rndc reconfig is broken
because the zones are already signed before the reconfig.  Fix
by having a different way to ensure the signing of the zone is
complete.  This does require a call to the "wait_for_done_signing"
function after each "check_keys" call after the ns6 reconfig.

The "wait_for_done_signing" looks for a (newly added) debug log
message that named will output if it is done signing with a certain
key.

(cherry picked from commit a47192ed5b)
2020-06-29 08:09:40 +02:00
Witold Kręcicki
4582ef3bb2 Fix a shutdown race in netmgr udp.
We need to mark the socket as inactive early (and synchronously)
in the stoplistening process - otherwise we might destroy the
callback argument before actually stopping listening, and call
the callback on a bad memory.
2020-06-26 01:44:03 -07:00
Witold Kręcicki
97e44fa3df Make netmgr tcpdns send calls asynchronous.
isc__nm_tcpdns_send() was not asynchronous and accessed socket
internal fields in an unsafe manner, which could lead to a race
condition and subsequent crash. Fix it by moving the whole tcpdns
processing to a proper netmgr thread.
2020-06-26 01:18:27 -07:00
Evan Hunt
f171017570 append "0" to IPv6 addresses ending in "::" when printing YAML
such addresses broke some YAML parsers.

(cherry picked from commit a8baf79e33)
2020-06-25 18:57:06 -07:00
Mark Andrews
3612f662da The validator could fail when select_signing_key/get_dst_key failed
to select the signing key because the algorithm was not supported
and the loop was prematurely aborted.

(cherry picked from commit d475f3aeed)
2020-06-25 22:42:43 +10:00
Mark Andrews
3f48a1e06e Add INSIST's to silence cppcheck warnings
(cherry picked from commit 0cf25d7f38)
2020-06-25 21:13:17 +10:00
Mark Andrews
b43641a55d Address potential thread issues:
Assign and then check node for NULL to address another thread
changing radix->head in the meantime.

Move 'node != NULL' check into while loop test to silence cppcheck
false positive.

Fix pointer != NULL style.

(cherry picked from commit 51f08d2095)
2020-06-25 21:11:27 +10:00
Evan Hunt
dca3658720 "check-names primary" and "check-names secondary" were ignored
these keywords were added to the parser as synonyms for "master"
and "slave" but were never hooked in to the configuration of named,
so they were ignored. this has been fixed and the option is now
checked for correctness.

(cherry picked from commit ba31b189b4)
2020-06-22 14:30:14 +02:00
Mark Andrews
34a5ad82d6 Address race between zone_maintenance and dns_zone_setview_helper
There was a possible NULL dereference due to data race between accessing
zone->view and zone->view->adb.

(cherry picked from commit 67c8f7329d)
2020-06-22 12:27:11 +02:00
Mark Andrews
41e38c216d Add missing #pragma once to <dns/lmdb.h> 2020-06-19 12:12:45 +10:00
Tinderbox User
adab85b815 prep 9.16.4 2020-06-18 10:25:50 +02:00
Mark Andrews
6964a21fa6 Remove INSIST from from new_reference
RBTDB node can now appear on the deadnodes lists following the changes
to decrement_reference in 176b23b6cd to
defer checking of node->down when the tree write lock is not held.  The
node should be unlinked instead.

(cherry picked from commit 569cc155b8680d8ed12db1fabbe20947db24a0f9)
2020-06-18 10:18:42 +02:00
Mark Andrews
ee6f60349b Adjust NS_CLIENT_TCP_BUFFER_SIZE and cleanup client_allocsendbuf
NS_CLIENT_TCP_BUFFER_SIZE was 2 byte too large following the
move to netmgr add associated changes to lib/ns/client.c and
as a result an INSIST could be trigger if the DNS message being
constructed had a checkpoint stage that fell in those two extra
bytes.  Adjusted NS_CLIENT_TCP_BUFFER_SIZE and cleaned up
client_allocsendbuf now that the previously reserved 2 bytes
are no longer used.

(cherry picked from commit 5a92af19b7dce684b0e6670ae6ec1c4c58613263)
2020-06-18 10:18:41 +02:00
Ondřej Surý
8b4fe6c6c5 Add missing acquire memory barrier in isc_nmhandle_unref
The ThreadSanitizer uses system synchronization primitives to check for
data race.  The netmgr handle->references was missing acquire memory
barrier before resetting and reusing the memory occupied by isc_nmhandle_t.

(cherry picked from commit 1013c0930e)
2020-06-16 08:58:33 +02:00
Mark Andrews
06cebcb6b7 val->keynode is no longer needed
(cherry picked from commit ff4fc3f8dc)
2020-06-11 16:09:43 +10:00
Mark Andrews
70c27df941 The dsset returned by dns_keynode_dsset needs to be thread safe.
- clone keynode->dsset rather than return a pointer so that thread
  use is independent of each other.
- hold a reference to the dsset (keynode) so it can't be deleted
  while in use.
- create a new keynode when removing DS records so that dangling
  pointers to the deleted records will not occur.
- use a rwlock when accessing the rdatalist to prevent instabilities
  when DS records are added.

(cherry picked from commit e5b2eca1d3)
2020-06-11 16:09:43 +10:00
Witold Kręcicki
aa2282853a Fix a race in TCP accepting.
There's a possibility of a race in TCP accepting code:
T1 accepts a connection C1
T2 accepts a connection C2
T1 tries to accept a connection C3, but we hit a quota,
   isc_quota_cb_init() sets quota_accept_cb for the socket,
   we return from accept_connection
T2 drops C2, but we race in quota_release with accepting C3 so
   we don't see quota->waiting is > 0, we don't launch the callback
T1 accepts a connection C4, we are able to get the quota we clear
   the quota_accept_cb from sock->quotacb
T1 drops C1, tries to call the callback which is zeroed, sigsegv.
2020-06-10 11:39:43 -07:00
Witold Kręcicki
7ff1ff88f9 Don't clean quota cb cb_func/data, we don't own it 2020-06-10 17:52:53 +02:00
Witold Kręcicki
31897276d9 Fix 'error: ‘%s’ directive argument is null [-Werror=format-overflow=]' in assertions.c
(cherry picked from commit f4260dc0c5)
2020-06-08 15:57:31 +00:00
Witold Kręcicki
bbf1422614 Fix possible deadlock in unix/socket.c
In process_fd we lock sock->lock and then internal_accept locks mgr->lock,
in isc_sockmgr_render* functions we lock mgr->lock and then lock sock->lock,
that can cause a deadlock when accessing stats. Unlock sock->lock early in
all the internal_{send,recv,connect,accept} functions instead of late
in process_fd.
2020-06-08 15:30:10 +02:00
Witold Kręcicki
c3dcab5f13 Fix a data access race in resolver
We were passing client address to dns_resolver_createfetch as a pointer
and it was saved as a pointer. The client (with its address) could be
gone before the fetch is finished, and in a very odd scenario
log_formerr would call isc_sockaddr_format() which first checks if the
address family is valid (and at this point it still is), then the
sockaddr is cleared, and then isc_netaddr_fromsockaddr is called which
fails an assertion as the address family is now invalid.

(cherry picked from commit 175c4d9055)
2020-06-05 18:58:13 -07:00
Mark Andrews
28a940fe69 Add +yaml support for EDE
(cherry picked from commit 0ec77c2b92)
2020-06-05 10:50:58 +10:00
Michal Nowak
e39685b579
Fix "array subscript is of type 'char'" 2020-06-04 16:27:43 +02:00
Mark Andrews
6ac4e62fbc Ignore attempts to add DS records at zone apex
DS records belong in the parent zone at a zone cut and
are not retrievable with modern recursive servers.

(cherry picked from commit ae55fbbe9c)
2020-06-04 16:06:45 +02:00
Mark Andrews
b17f6eba6a Reject primary zones with an DS record at the zone apex.
DS records only belong at delegation points and if present
at the zone apex are invariably the result of administrative
errors.  Additionally they can't be queried for with modern
resolvers as the parent servers will be queried.

(cherry picked from commit 35a58d30c9)
2020-06-04 16:06:07 +02:00
Ondřej Surý
ef50067fd2 Stop building release notes as a separate sphinx-doc document
The release notes were previously built as a separate document
(including the PDF version).  It was agreed that this doesn't make much
sense, so the release notes are now included only as an appendix to the
BIND 9 ARM.

(cherry picked from commit 8eb2323ec3)
2020-06-04 11:24:53 +02:00
Witold Kręcicki
091117b7ae isc_uv_import must pass UV__IPC_SOCKET_XFER_TCP_CONNECTION, not SERVER.
As a leftover from old TCP accept code isc_uv_import passed TCP_SERVER
flag when importing a socket on Windows.
Since now we're importing/exporting accepted connections it needs to
pass TCP_CONNECTION flag.

(cherry picked from commit 801f7af6e9)
2020-06-03 23:27:24 +02:00
Witold Kręcicki
c4f91575ca Clean quota callback after calling it
(cherry picked from commit 2f252a1068)
2020-06-03 23:00:52 +02:00
Witold Kręcicki
818afe613f Redesigned TCP accepting: one listen/accept loop, passing the connected socket.
Instead of using bind() and passing the listening socket to the children
threads using uv_export/uv_import use one thread that does the accepting,
and then passes the connected socket using uv_export/uv_import to a random
worker. The previous solution had thundering herd problems (all workers
waking up on one connection and trying to accept()), this one avoids this
and is simpler.
The tcp clients quota is simplified with isc_quota_attach_cb - a callback
is issued when the quota is available.

(cherry picked from commit 60629e5b0b)
2020-06-03 23:00:52 +02:00