Commit graph

32845 commits

Author SHA1 Message Date
Ondřej Surý
2011efa99d Disable safe-guard assertion in DLL_THREAD_ATTACH/DLL_THREAD_DETACH
The BIND 9 libraries on Windows define DllMain() optional entry point
into a dynamic-link library (DLL).  When the system starts or terminates
a process or thread, it calls the entry-point function for each loaded
DLL using the first thread of the process.

When the DLL is being loaded into the virtual address space of the
current process as a result of the process starting up, we make a call
to DisableThreadLibraryCalls() which should disable the
DLL_THREAD_ATTACH and DLL_THREAD_DETACH notifications for the specified
dynamic-link library (DLL).

This seems not be the case because we never check the return value of
the DisableThreadLibraryCalls() call, and it could in fact fail.  The
DisableThreadLibraryCalls() function fails if the DLL specified by
hModule has active static thread local storage, or if hModule is an
invalid module handle.

In this commit, we remove the safe-guard assertion put in place for the
DLL_THREAD_ATTACH and DLL_THREAD_DETACH events and we just ignore them.
BIND 9 doesn't create/destroy enough threads for it actually to make any
difference, and in fact we do use static thread local storage in the
code.
2021-02-26 17:18:06 +01:00
Ondřej Surý
2f0f531ee8 Use library constructor/destructor to initialize OpenSSL
Instead of calling isc_tls_initialize()/isc_tls_destroy() explicitly use
gcc/clang attributes on POSIX and DLLMain on Windows to initialize and
shutdown OpenSSL library.

This resolves the issue when isc_nm_create() / isc_nm_destroy() was
called multiple times and it would call OpenSSL library destructors from
isc_nm_destroy().

At the same time, since we now have introduced the ctor/dtor for libisc,
this commit moves the isc_mem API initialization (the list of the
contexts) and changes the isc_mem_checkdestroyed() to schedule the
checking of memory context on library unload instead of executing the
code immediately.
2021-02-26 17:18:06 +01:00
Ondřej Surý
59d51cdeb6 Disable calling DllMain() on thread creation/destruction
Disables the DLL_THREAD_ATTACH and DLL_THREAD_DETACH notifications for
the specified dynamic-link library (DLL).  This can reduce the size of
the working set for some applications.
2021-02-26 17:07:15 +01:00
Ondřej Surý
6883d4bd08 Fix the invalid condition variable
Although harmless, the memmove() in tlsdns and tcpdns was guarded by a
current message length variable that was always bigger than 0 instead of
correct current buffer length remainder variable.
2021-02-26 17:07:09 +01:00
Ondřej Surý
6da91bf16c Move most of the OpenSSL initialization to isc_tls
Since we now require both libcrypto and libssl to be initialized for
netmgr, we move all the OpenSSL initialization code except the engine
initialization to isc_tls API.

The isc_tls_initialize() and isc_tls_destroy() has been made idempotent,
so they could be called multiple time.  However when isc_tls_destroy()
has been called, the isc_tls_initialize() could not be called again.
2021-02-26 17:07:01 +01:00
Ondřej Surý
19fb228782 Merge branch '2335-tlsdns-refactoring-v9_16' into 'v9_16'
Resolve "TLSDNS refactoring"

See merge request isc-projects/bind9!4754
2021-02-26 16:03:41 +00:00
Evan Hunt
e9abe76117 Add CHANGES note for #2335
(cherry picked from commit f472390bc2)
2021-02-26 16:14:50 +01:00
Ondřej Surý
effe3ee595 Refactor TLSDNS module to work with libuv/ssl directly
* Following the example set in 634bdfb16d, the tlsdns netmgr
  module now uses libuv and SSL primitives directly, rather than
  opening a TLS socket which opens a TCP socket, as the previous
  model was difficult to debug.  Closes #2335.

* Remove the netmgr tls layer (we will have to re-add it for DoH)

* Add isc_tls API to wrap the OpenSSL SSL_CTX object into libisc
  library; move the OpenSSL initialization/deinitialization from dstapi
  needed for OpenSSL 1.0.x to the isc_tls_{initialize,destroy}()

* Add couple of new shims needed for OpenSSL 1.0.x

* When LibreSSL is used, require at least version 2.7.0 that
  has the best OpenSSL 1.1.x compatibility and auto init/deinit

* Enforce OpenSSL 1.1.x usage on Windows

(cherry picked from commit e493e04c0f)
2021-02-26 16:14:50 +01:00
Matthijs Mekking
7537430847 Merge branch '2503-stale-answer-client-timeout-crash-v9_16' into 'v9_16'
Resolve "New stale-answer-client-timeout crashes BIND 9.16 and 9.17"

See merge request isc-projects/bind9!4747
2021-02-25 11:48:18 +00:00
Matthijs Mekking
bcadb31f44 Add CHANGES and release notes for GL #2503
(cherry picked from commit a404eaaffd)
2021-02-25 12:07:43 +01:00
Matthijs Mekking
acc95d4e1d Don't servfail on staleonly lookups
When a staleonly lookup doesn't find a satisfying answer, it should
not try to respond to the client.

This is not true when the initial lookup is staleonly (that is when
'stale-answer-client-timeout' is set to 0), because no resolver fetch
has been created at this point. In this case continue with the lookup
normally.

(cherry picked from commit f8b7b597e9)
2021-02-25 12:07:34 +01:00
Matthijs Mekking
84deb57bc3 Don't allow recursion on staleonly lookups
Fix a crash that can happen in the following scenario:

A client request is received. There is no data for it in the cache,
(not even stale data). A resolver fetch is created as part of
recursion.

Some time later, the fetch still hasn't completed, and
stale-answer-client-timeout is triggered. A staleonly lookup is
started. It will also find no data in the cache.

So 'query_lookup()' will call 'query_gotanswer()' with ISC_R_NOTFOUND,
so this will call 'query_notfound()' and this will start recursion.

We will eventually end up in 'ns_query_recurse()' and that requires
the client query fetch to be NULL:

    REQUIRE(client->query.fetch == NULL);

If the previously started fetch is still running this assertion
fails.

The crash is easily prevented by not requiring recursion for
staleonly lookups.

Also remove a redundant setting of the staleonly flag at the end of
'query_lookup_staleonly()' before destroying the query context.

Add a system test to catch this case.

(cherry picked from commit 9e061faaae)
2021-02-25 12:07:27 +01:00
Matthijs Mekking
c4c8f78b0a Merge branch '2498-nsec3-dynamic-update-dnssec-policy-v9_16' into 'v9_16'
Resolve "Regression in BIND 9.16.10, DNSSEC fails due to improper NSEC3 creation witihin named"

See merge request isc-projects/bind9!4746
2021-02-25 11:02:00 +00:00
Matthijs Mekking
8475d0bd61 Add changes and notes for [#2498]
(cherry picked from commit 89c47b3b42)
2021-02-25 10:56:46 +01:00
Matthijs Mekking
d51df34995 Fix dnssec-policy NSEC3 on dynamic zones
When applying dnssec-policy on a dynamic zone (e.g. that allows Dynamic
Updates), the NSEC3 parameters were put on the queue, but they were
not being processed (until a reload of the zone or reconfiguration).

Process the NSEC3PARAM queue on zone postload when handling a
dynamic zone.

(cherry picked from commit 4b176c850b)
2021-02-25 10:56:00 +01:00
Matthijs Mekking
ddfb9ea8c1 Add tests for NSEC3 on dynamic zones
GitLab issue #2498 is a bug report on NSEC3 with dynamic zones. Tests
for it in the nsec3 system test directory were missing.

(cherry picked from commit 0c0f10b53f)
2021-02-25 10:55:51 +01:00
Michal Nowak
a88846c664 Merge branch '2446-query-c-5430-16-runtime-error-v9_16' into 'v9_16'
[v9_16] Initialize checknames field in dns_view_create()

See merge request isc-projects/bind9!4735
2021-02-23 16:48:35 +00:00
Michal Nowak
b36690e750
Initialize checknames field in dns_view_create()
The 'checknames' field wasn't initialized in dns_view_create(), but it
should otherwise AddressSanitizer identifies the following runtime error
in query_test.c.

    runtime error: load of value 190, which is not a valid value for type '_Bool'

(cherry picked from commit 0c6fa16477)
2021-02-23 16:45:36 +01:00
Michal Nowak
da2a647ee1 Merge branch 'mnowak/alpine-3.13-fix-PLATFORMS' into 'v9_16'
Update Alpine Linux version in PLATFORMS file

See merge request isc-projects/bind9!4734
2021-02-23 15:19:55 +00:00
Michal Nowak
57112addf5
Update Alpine Linux version in PLATFORMS file
Commit 76cfefe3fc updated PLATFORMS.md
file, but failed to update the plain-text PLATFORMS file.
2021-02-23 16:11:13 +01:00
Michal Nowak
6b75d201c4 Merge branch 'mnowak/alpine-3.13-v9_16' into 'v9_16'
[v9_16] Add Alpine Linux 3.13

See merge request isc-projects/bind9!4732
2021-02-23 14:53:37 +00:00
Michal Nowak
76cfefe3fc
Add Alpine Linux 3.13
(cherry picked from commit 909c85f7a9)
2021-02-23 15:46:42 +01:00
Michal Nowak
cc2db3a4a3 Merge branch 'mnowak/pairwise-pict-keep-stderr-v9_16' into 'v9_16'
[v9_16] Do not remove stderr from pict output

See merge request isc-projects/bind9!4730
2021-02-23 14:32:31 +00:00
Michal Nowak
2038d087bf
Do not remove stderr from pict output
Removing stderr from the pict tool serves no purpose and drops valuable
information, we might use when debugging failed pairwise CI job, such
as:

    Input Error: A parameter names must be unique

(cherry picked from commit 079debaa10)
2021-02-23 15:26:19 +01:00
Mark Andrews
a64c68fe9f Merge branch '2508-cid-320481-null-pointer-dereferences-reverse_inull-v9_16' into 'v9_16'
Silence CID 320481: Null pointer dereferences

See merge request isc-projects/bind9!4729
2021-02-23 13:31:25 +00:00
Mark Andrews
c5ad174129 Silence CID 320481: Null pointer dereferences
*** CID 320481:  Null pointer dereferences  (REVERSE_INULL)
    /bin/tests/wire_test.c: 261 in main()
    255     			process_message(input);
    256     		}
    257     	} else {
    258     		process_message(input);
    259     	}
    260
       CID 320481:  Null pointer dereferences  (REVERSE_INULL)
       Null-checking "input" suggests that it may be null, but it has already been dereferenced on all paths leading to the check.
    261     	if (input != NULL) {
    262     		isc_buffer_free(&input);
    263     	}
    264
    265     	if (printmemstats) {
    266     		isc_mem_stats(mctx, stdout);

(cherry picked from commit 658c950d7b)
2021-02-24 00:08:57 +11:00
Matthijs Mekking
cd87bdf77c Merge branch '2408-dnssec-policy-purge-keys-v9_16' into 'v9_16'
Resolve "kasp: Purge deleted keys"

See merge request isc-projects/bind9!4726
2021-02-23 09:31:57 +00:00
Matthijs Mekking
a3e9c05bfb Add changes and notes for [#2408]
(cherry picked from commit 5a99a124fb)
2021-02-23 09:20:20 +01:00
Matthijs Mekking
9b4e067206 Minor kasp test fixes
Two minor fixes in the kasp system test:

1. A wrong comment in ns3/setup.sh (we are subtracting 2 hours, not
   adding them).
2. 'get_keyids' used bad parameters "$1" "$2" when 'check_numkeys'
   failed. Also, 'check_numkeys' can use $DIR, $ZONE, and $NUMKEYS
   directly, no need to pass them.

(cherry picked from commit 5be26898c0)
2021-02-23 09:19:23 +01:00
Matthijs Mekking
fc9dcbf419 Test purge-keys option
Add some more zones to the kasp system test to test the 'purge-keys'
option. Three zones test that the predecessor key files are removed
after the purge keys interval, one test checks that the key files
are retained if 'purge-keys' is disabled. For that, we change the
times to 90 days in the past (the default value for 'purge-keys').

(cherry picked from commit 6333ff15f0)
2021-02-23 09:19:11 +01:00
Matthijs Mekking
8e4d0d51be Purge keys implementation
On each keymgr run, we now also check if key files can be removed.
The 'purge-keys' interval determines how long keys should be retained
after they have become completely hidden.

Key files should not be removed if it has a state that is set to
something else then HIDDEN, if purge-keys is 0 (disabled), if
the key goal is set to OMNIPRESENT, or if the key is unused (a key is
unused if no timing metadata set, and no states are set or if set,
they are set to HIDDEN).

If the last changed timing metadata plus the purge-keys interval is
in the past, the key files may be removed.

Add a dst_key_t variable 'purge' to signal that the key file should
not be written to file again.

(cherry picked from commit 8c526cb67f)
2021-02-23 09:19:03 +01:00
Matthijs Mekking
45dcabf411 Add purge-keys config option
Add a new option 'purge-keys' to 'dnssec-policy' that will purge key
files for deleted keys. The option determines how long key files
should be retained prior to removing the corresponding files from
disk.

If set to 0, the option is disabled and 'named' will not remove key
files from disk.

(cherry picked from commit 313de3a7e2)
2021-02-23 09:18:55 +01:00
Mark Andrews
772cad50a1 Merge branch '2509-cid-281489-resource-leaks-resource_leak-v9_16' into 'v9_16'
Address theoretical resource leak in dns_dt_open()

See merge request isc-projects/bind9!4725
2021-02-22 23:24:14 +00:00
Mark Andrews
4e192d2fe7 Address theoretical resource leak in dns_dt_open()
dns_dt_open() is not currently called with mode dns_dtmode_unix.

    *** CID 281489:  Resource leaks  (RESOURCE_LEAK)
    /lib/dns/dnstap.c: 983 in dns_dt_open()
    977
    978     		if (!dnstap_file(handle->reader)) {
    979     			CHECK(DNS_R_BADDNSTAP);
    980     		}
    981     		break;
    982     	case dns_dtmode_unix:
       CID 281489:  Resource leaks  (RESOURCE_LEAK)
       Variable "handle" going out of scope leaks the storage it points to.
    983     		return (ISC_R_NOTIMPLEMENTED);
    984     	default:
    985     		INSIST(0);
    986     		ISC_UNREACHABLE();
    987     	}
    988

(cherry picked from commit 003dd8cc70)
2021-02-23 09:41:15 +11:00
Mark Andrews
31da81d82b Merge branch '2499-a-loc-record-with-a-invalid-direction-field-triggers-an-insist-v9_16' into 'v9_16'
Resolve "A LOC record with a invalid direction field triggers an INSIST"

See merge request isc-projects/bind9!4711
2021-02-19 01:14:00 +00:00
Mark Andrews
65013e5c32 Add release note for [GL #2499]
(cherry picked from commit 3d340ecfd2)
2021-02-19 11:39:47 +11:00
Mark Andrews
c4f1b8762b Add CHANGES for [GL #2499]
(cherry picked from commit 6f47e0956c)
2021-02-19 11:39:43 +11:00
Mark Andrews
d68b85e555 Correctly detect when get_direction failed
(cherry picked from commit 009358d77d)
2021-02-19 11:39:12 +11:00
Mark Andrews
0cea486327 Test a LOC record with an invalid direction field
(cherry picked from commit 07902d9f9d)
2021-02-19 11:39:12 +11:00
Michal Nowak
6b35244573 Merge branch 'mnowak/fix-feature-test-tool-location-v9_16' into 'v9_16'
[v9_16] Use FEATURETEST variable instead of a path

See merge request isc-projects/bind9!4707
2021-02-18 14:56:58 +00:00
Michal Nowak
5ded078daa
Use FEATURETEST variable instead of a path
feature-test tool location needs to be determined by its associated
variable; otherwise, the tool is not found on Windows:

    setup.sh: line 22: ../feature-test: No such file or directory

(cherry picked from commit 102f012631)
2021-02-18 15:47:57 +01:00
Michal Nowak
e68b63c813 Merge branch 'mnowak/make-kyua-report-html-less-verbose' into 'v9_16'
Make "kyua report-html" less verbose on stdout

See merge request isc-projects/bind9!4688
2021-02-18 14:47:39 +00:00
Michal Nowak
74fa196286
Make "kyua report-html" less verbose on stdout
"kyua report-html" command in CI generates more than two pages of output
to stdout, which is nothing but which HTML pages Kyua generated, e.g.:

  Generating kyua_html/context.html
  Generating kyua_html/lib_dns_tests_acl_test_main.html
  ...
  Generating kyua_html/lib_ns_tests_query_test_main.html
  Generating kyua_html/report.css
  Generating kyua_html/index.html

This is seldomly useful and requires the user to scroll three pages
upwards to get to unit test results.
2021-02-18 15:39:04 +01:00
Matthijs Mekking
ad1e9c3709 Merge branch '1810-followup-9_16' into 'v9_16'
Fix backport "Refactor ecdsa and eddsa tests after testcrypto.sh changes" (9.16)

See merge request isc-projects/bind9!4695
2021-02-18 09:40:59 +00:00
Matthijs Mekking
1ffe0accf5 Fix eddsa system test
Use the correct conf.sh setup commands in ns3/sign.sh
2021-02-18 08:37:48 +00:00
Michal Nowak
61acd2a664 Merge branch 'mnowak/system-test-check-for-file-not-removed-v9_16' into 'v9_16'
[v9_16] Check for "file not removed" in system test output

See merge request isc-projects/bind9!4698
2021-02-18 08:04:17 +00:00
Michal Nowak
c65c3d5153
Prevent Git to expand $systest
CentOS 8 "git status" unexpectedly expands search directory "tsig" to
also search in the "tsiggss" directory, thus incorrectly identifying
files as "not removed" in the "tsig" directory:

$ git status -su --ignored tsig
$ touch tsiggss/ns1/{named.run,named.memstats}
$ git status -su --ignored tsig
!! tsiggss/ns1/named.memstats
!! tsiggss/ns1/named.run

(cherry picked from commit f310b75250)
2021-02-18 08:20:54 +01:00
Michal Nowak
78c5a80817
Clean omitted files from system tests
Any CI job:
- I:dnssec:file dnssec/ns1/trusted.keys not removed
- I:rpzrecurse:file rpzrecurse/ns3/named.run.prev not removed

system:gcc:sid:amd64:
- I🪞file mirror/ns3/_default.nzf not removed

system:gcc:xenial:amd64:
- I:shutdown:file shutdown/.cache/v/cache/lastfailed not removed

(cherry picked from commit 14a104d121)
2021-02-18 08:20:54 +01:00
Michal Nowak
f3f77fa4fc
Check for "file not removed" in system test output
Run this check only when in Git repository, because run.sh produces the
"file not removed" warnings only when in Git repository.

(cherry picked from commit 4a2778abdf)
2021-02-18 08:20:54 +01:00
Michal Nowak
382ace6db6
Add system test name to "file not removed" info
(cherry picked from commit 10bf725ee2)
2021-02-18 08:20:54 +01:00