]> git.ipfire.org Git - thirdparty/bind9.git/log
thirdparty/bind9.git
4 years agoPut some missing dns_rdata_freestruct() calls in catz.c
Aram Sargsyan [Thu, 17 Mar 2022 14:09:21 +0000 (14:09 +0000)] 
Put some missing dns_rdata_freestruct() calls in catz.c

A successful call to `dns_rdata_tostruct()` expects an accompanying
call to `dns_rdata_freestruct()` to free up any memory that could have
been allocated during the first call.

In catz.c there are several places where `dns_rdata_freestruct()` call
is skipped.

Add the missing cleanup routines.

4 years agoCleanup the code to remove unnecessary indentation
Aram Sargsyan [Tue, 8 Feb 2022 12:01:51 +0000 (12:01 +0000)] 
Cleanup the code to remove unnecessary indentation

Because of the "goto" in the "if" body the "else" part is unnecessary
and adds another level of indentation.

Cleanup the code to not have the "else" part.

4 years agoLog a warning when catz is told to modify a zone not added by catz
Aram Sargsyan [Tue, 8 Feb 2022 11:47:48 +0000 (11:47 +0000)] 
Log a warning when catz is told to modify a zone not added by catz

Catz logs a warning message when it is told to modify a zone which was
not added by the current catalog zone.

When logging a warning, distinguish the two cases when the zone
was not added by a catalog zone at all, and when the zone was
added by a different catalog zone.

4 years agoFix invalid function name in the error log
Aram Sargsyan [Tue, 8 Feb 2022 11:24:18 +0000 (11:24 +0000)] 
Fix invalid function name in the error log

The current function's name in one of the error logs in
catz_addmodzone_taskaction() function is invalid.

Fix the name.

4 years agoMerge branch 'u/fanf2/dnssec-settime-ctime' into 'main'
Ondřej Surý [Fri, 25 Mar 2022 15:13:28 +0000 (15:13 +0000)] 
Merge branch 'u/fanf2/dnssec-settime-ctime' into 'main'

Teach dnssec-settime to read times that it writes

See merge request isc-projects/bind9!2947

4 years agoAdd CHANGES note for [GL !2947]
Tony Finch [Mon, 29 Apr 2019 12:56:05 +0000 (13:56 +0100)] 
Add CHANGES note for [GL !2947]

4 years agoTeach dnssec-settime to read times that it writes
Tony Finch [Mon, 29 Apr 2019 12:56:05 +0000 (13:56 +0100)] 
Teach dnssec-settime to read times that it writes

The dnssec-settime -p and -up options print times in asctime() and
UNIX time_t formats, respectively. The asctime() format can also be
found inside K*.key public key files. Key files also contain times in
the YYYYMMDDHHMMSS format that can be used in timing parameter
options.

The dnssec-settime -p and -up time formats are now acceptable in
timing parameter options to dnssec-settime and dnssec-keygen, so it is
no longer necessary to parse key files to retrieve times that are
acceptable in timing parameter options.

4 years agoMerge branch '3210-dns64-errors' into 'main'
Ondřej Surý [Fri, 25 Mar 2022 10:38:59 +0000 (10:38 +0000)] 
Merge branch '3210-dns64-errors' into 'main'

More explicit dns64 prefix errors

Closes #3210

See merge request isc-projects/bind9!5985

4 years agoAdd CHANGES note for [GL #3210]
Tony Finch [Wed, 16 Mar 2022 17:33:10 +0000 (17:33 +0000)] 
Add CHANGES note for [GL #3210]

4 years agoMore explicit dns64 prefix errors
Tony Finch [Wed, 16 Mar 2022 17:33:10 +0000 (17:33 +0000)] 
More explicit dns64 prefix errors

Quote the dns64 prefix in error messages that complain about
problems with it, to avoid confusion with the following ACLs.

Closes #3210

4 years agoMerge branch 'ondrej-remove-nmhandle-extra' into 'main'
Ondřej Surý [Fri, 25 Mar 2022 09:43:31 +0000 (09:43 +0000)] 
Merge branch 'ondrej-remove-nmhandle-extra' into 'main'

Remove extrahandle size from netmgr

Closes #3227

See merge request isc-projects/bind9!6018

4 years agoMerge branch 'ondrej-cleanup-ns_client-structure' into 'main'
Ondřej Surý [Fri, 25 Mar 2022 09:38:41 +0000 (09:38 +0000)] 
Merge branch 'ondrej-cleanup-ns_client-structure' into 'main'

Remove extra copies and stray members from ns_client_t

See merge request isc-projects/bind9!6017

4 years agoAdd CHANGES note for [GL #3227]
Ondřej Surý [Wed, 23 Mar 2022 13:59:32 +0000 (14:59 +0100)] 
Add CHANGES note for [GL #3227]

4 years agoRemove ns_client_t .shuttingdown member
Ondřej Surý [Wed, 23 Mar 2022 15:16:53 +0000 (16:16 +0100)] 
Remove ns_client_t .shuttingdown member

The way the ns_client_t .shuttingdown member was practically dead code.
The .shuttingdown would be set to true only in ns__client_put() function
meaning that we have detached from all ns_client_t .*handles and the
ns_client_t object being freed:

    client->magic = 0;
    client->shuttingdown = true;
    [...]
    isc_mem_put(manager->ctx, client, sizeof(*client))

Meanwhile the ns_client_t object is accessed like this:

    isc_nmhandle_detach(&client->fetchhandle);

    client->query.attributes &= ~NS_QUERYATTR_RECURSING;
    client->state = NS_CLIENTSTATE_WORKING;

    qctx_init(client, &devent, 0, &qctx);

    client_shuttingdown = ns_client_shuttingdown(client);
    if (fetch_canceled || fetch_answered || client_shuttingdown) {
        [...]
    }

Even if the isc_nmhandle_detach(...) was the last handle detach, it
would mean that immediatelly, after calling the isc_nmhandle_detach(),
we would be causing use-after-free, because the ns_client_t is
immediatelly destroyed after setting .shuttingdown to true.

The similar code in the query_hookresume() already noticed this:

    /*
     * This event is running under a client task, so it's safe to detach
     * the fetch handle.  And it should be done before resuming query
     * processing below, since that may trigger another recursion or
     * asynchronous hook event.
     */

4 years agoRemove extrahandle size from netmgr
Ondřej Surý [Wed, 23 Mar 2022 12:57:15 +0000 (13:57 +0100)] 
Remove extrahandle size from netmgr

Previously, it was possible to assign a bit of memory space in the
nmhandle to store the client data.  This was complicated and prevents
further refactoring of isc_nmhandle_t caching (future work).

Instead of caching the data in the nmhandle, allocate the hot-path
ns_client_t objects from per-thread clientmgr memory context and just
assign it to the isc_nmhandle_t via isc_nmhandle_set().

4 years agoRemove extra copies and stray members from ns_client_t
Ondřej Surý [Wed, 23 Mar 2022 12:57:15 +0000 (13:57 +0100)] 
Remove extra copies and stray members from ns_client_t

The ns_client_t is always attached to ns_clientmgr_t which has
associated memory context, server context, task and threadid.  Use those
directly from the ns_clientmgr_t instead of attaching it to an extra
copy in ns_client_t to make the ns_client_t more sleek and lean.

Additionally, remove some stray ns_client_t struct members that were not
used anywhere.

4 years agoMerge branch 'ondrej/statements-following-return-break-continue-or-goto-will-never...
Ondřej Surý [Fri, 25 Mar 2022 09:07:28 +0000 (09:07 +0000)] 
Merge branch 'ondrej/statements-following-return-break-continue-or-goto-will-never-be-executed' into 'main'

Remove UNREACHABLE() statements after exit()

See merge request isc-projects/bind9!6027

4 years agoRemove UNREACHABLE() statements after exit()
Ondřej Surý [Fri, 25 Mar 2022 08:25:11 +0000 (09:25 +0100)] 
Remove UNREACHABLE() statements after exit()

Couple of UNREACHABLE() statements following exit() were found and
removed.

4 years agoMerge branch 'ondrej/use-newer-compiler-features' into 'main'
Ondřej Surý [Fri, 25 Mar 2022 07:41:05 +0000 (07:41 +0000)] 
Merge branch 'ondrej/use-newer-compiler-features' into 'main'

Use modern C and modern compiler features

See merge request isc-projects/bind9!5480

4 years agoRemove workaround for ancient clang versions (<< 3.2 and << 4.0.1)
Ondřej Surý [Sat, 5 Mar 2022 12:46:52 +0000 (13:46 +0100)] 
Remove workaround for ancient clang versions (<< 3.2 and << 4.0.1)

Some ancient versions of clang reported uninitialized memory use false
positive (see https://bugs.llvm.org/show_bug.cgi?id=14461).  Since clang
4.0.1 has been long obsoleted, just remove the workarounds.

4 years agoRemove use of the inline keyword used as suggestion to compiler
Ondřej Surý [Mon, 11 Oct 2021 11:43:12 +0000 (13:43 +0200)] 
Remove use of the inline keyword used as suggestion to compiler

Historically, the inline keyword was a strong suggestion to the compiler
that it should inline the function marked inline.  As compilers became
better at optimising, this functionality has receded, and using inline
as a suggestion to inline a function is obsolete.  The compiler will
happily ignore it and inline something else entirely if it finds that's
a better optimisation.

Therefore, remove all the occurences of the inline keyword with static
functions inside single compilation unit and leave the decision whether
to inline a function or not entirely on the compiler

NOTE: We keep the usage the inline keyword when the purpose is to change
the linkage behaviour.

4 years agoReplace ISC_NORETURN with C11's noreturn
Ondřej Surý [Mon, 11 Oct 2021 10:57:27 +0000 (12:57 +0200)] 
Replace ISC_NORETURN with C11's noreturn

C11 has builtin support for _Noreturn function specifier with
convenience noreturn macro defined in <stdnoreturn.h> header.

Replace ISC_NORETURN macro by C11 noreturn with fallback to
__attribute__((noreturn)) if the C11 support is not complete.

4 years agoSimplify way we tag unreachable code with only ISC_UNREACHABLE()
Ondřej Surý [Mon, 11 Oct 2021 10:50:17 +0000 (12:50 +0200)] 
Simplify way we tag unreachable code with only ISC_UNREACHABLE()

Previously, the unreachable code paths would have to be tagged with:

    INSIST(0);
    ISC_UNREACHABLE();

There was also older parts of the code that used comment annotation:

    /* NOTREACHED */

Unify the handling of unreachable code paths to just use:

    UNREACHABLE();

The UNREACHABLE() macro now asserts when reached and also uses
__builtin_unreachable(); when such builtin is available in the compiler.

4 years agoAdd FALLTHROUGH macro for __attribute__((fallthrough))
Ondřej Surý [Mon, 11 Oct 2021 10:09:16 +0000 (12:09 +0200)] 
Add FALLTHROUGH macro for __attribute__((fallthrough))

Gcc 7+ and Clang 10+ have implemented __attribute__((fallthrough)) which
is explicit version of the /* FALLTHROUGH */ comment we are currently
using.

Add and apply FALLTHROUGH macro that uses the attribute if available,
but does nothing on older compilers.

In one case (lib/dns/zone.c), using the macro revealed that we were
using the /* FALLTHROUGH */ comment in wrong place, remove that comment.

4 years agoMerge branch 'ondrej-save-tsan-files-with-txt-extension' into 'main'
Ondřej Surý [Wed, 23 Mar 2022 19:31:02 +0000 (19:31 +0000)] 
Merge branch 'ondrej-save-tsan-files-with-txt-extension' into 'main'

Save parsed tsan files with .txt extension

See merge request isc-projects/bind9!6019

4 years agoSave parsed tsan files with .txt extension
Ondřej Surý [Mon, 14 Mar 2022 18:01:43 +0000 (19:01 +0100)] 
Save parsed tsan files with .txt extension

When the parse tsan files have text extension they can be viewed
directly in the GitLab web UI without downloading them locally.

4 years agoMerge branch 'matthijs-engine_pkcs11-save-error-output' into 'main'
Matthijs Mekking [Mon, 21 Mar 2022 09:47:31 +0000 (09:47 +0000)] 
Merge branch 'matthijs-engine_pkcs11-save-error-output' into 'main'

Save keyfromlabel error output

See merge request isc-projects/bind9!6002

4 years agoSave keyfromlabel error output
Matthijs Mekking [Fri, 18 Mar 2022 13:47:13 +0000 (14:47 +0100)] 
Save keyfromlabel error output

Save the error output from pkcs11-tool and dnssec-keyfromlabel in the
engine_pkcs11 system test.

4 years agoMerge branch 'ondrej/add-isc_nm_getnworkers' into 'main'
Ondřej Surý [Fri, 18 Mar 2022 21:21:47 +0000 (21:21 +0000)] 
Merge branch 'ondrej/add-isc_nm_getnworkers' into 'main'

Make netmgr the authority on number of threads running

See merge request isc-projects/bind9!5999

4 years agoMake netmgr the authority on number of threads running
Ondřej Surý [Fri, 18 Mar 2022 08:50:58 +0000 (09:50 +0100)] 
Make netmgr the authority on number of threads running

Instead of passing the "workers" variable back and forth along with
passing the single isc_nm_t instance, add isc_nm_getnworkers() function
that returns the number of netmgr threads are running.

Change the ns_interfacemgr and ns_taskmgr to utilize the newly acquired
knowledge.

4 years agoMerge branch '3201-no-vla' into 'main'
Tony Finch [Fri, 18 Mar 2022 16:02:46 +0000 (16:02 +0000)] 
Merge branch '3201-no-vla' into 'main'

Avoid using C99 variable length arrays

Closes #3201

See merge request isc-projects/bind9!5956

4 years agoAvoid using C99 variable length arrays
Tony Finch [Fri, 18 Mar 2022 14:50:36 +0000 (14:50 +0000)] 
Avoid using C99 variable length arrays

From an attacker's point of view, a VLA declaration is essentially a
primitive for performing arbitrary arithmetic on the stack pointer. If
the attacker can control the size of a VLA they have a very powerful
tool for causing memory corruption.

To mitigate this kind of attack, and the more general class of stack
clash vulnerabilities, C compilers insert extra code when allocating a
VLA to probe the growing stack one page at a time. If these probes hit
the stack guard page, the program will crash.

From the point of view of a C programmer, there are a few things to
consider about VLAs:

  * If it is important to handle allocation failures in a controlled
    manner, don't use VLAs. You can use VLAs if it is OK for
    unreasonable inputs to cause an uncontrolled crash.

  * If the VLA is known to be smaller than some known fixed size,
    use a fixed size array and a run-time check to ensure it is large
    enough. This will be more efficient than the compiler's stack
    probes that need to cope with arbitrary-size VLAs.

  * If the VLA might be large, allocate it on the heap. The heap
    allocator can allocate multiple pages in one shot, whereas the
    stack clash probes work one page at a time.

Most of the existing uses of VLAs in BIND are in test code where they
are benign, but there was one instance in `named`, in the GSS-TSIG
verification code, which has now been removed.

This commit adjusts the style guide and the C compiler flags to allow
VLAs in test code but not elsewhere.

4 years agoRemove a redundant variable-length array
Tony Finch [Thu, 10 Mar 2022 13:04:08 +0000 (13:04 +0000)] 
Remove a redundant variable-length array

In the GSS-TSIG verification code there was an alarming
variable-length array whose size came off the network, from the
signature in the request. It turned out to be safe, because the caller
had previously checked that the signature had a reasonable size.
However, the safety checks are in the generic TSIG implementation, and
the risky VLA usage was in the GSS-specific code, and they are
separated by the DST indirection layer, so it wasn't immediately
obvious that the risky VLA was in fact safe.

In fact this risky VLA was completely unnecessary, because the GSS
signature can be verified in place without being copied to the stack,
like the message covered by the signature. The `REGION_TO_GBUFFER()`
macro backwardly assigns the region in its left argument to the GSS
buffer in its right argument; this is just a pointer and length
conversion, without copying any data. The `gss_verify_mic()` call uses
both message and signature GSS buffers in a read-only manner.

4 years agoMerge branch '3205-dig-tcp-next-server-on-connection-error-crash' into 'main'
Arаm Sаrgsyаn [Fri, 18 Mar 2022 10:55:23 +0000 (10:55 +0000)] 
Merge branch '3205-dig-tcp-next-server-on-connection-error-crash' into 'main'

Fix dig error when trying the next server after a TCP connection failure

Closes #3205

See merge request isc-projects/bind9!5976

4 years agoAdd CHANGES note for [GL #3205]
Aram Sargsyan [Sun, 13 Mar 2022 13:53:50 +0000 (13:53 +0000)] 
Add CHANGES note for [GL #3205]

4 years agoAdd various dig/host tests for TCP/UDP socket error handling cases
Aram Sargsyan [Sun, 13 Mar 2022 13:47:44 +0000 (13:47 +0000)] 
Add various dig/host tests for TCP/UDP socket error handling cases

Rework the "ans8" server in the "digdelv" system test to support various
modes of operations using a control channel.

The supported modes are:

1. `silent` (do not respond)
2. `close` (UDP: same as `silent`; TCP: also close the connection)
3. `servfail` (always respond with `SERVFAIL`)
4. `unstable` (constantly switch between `silent` and `servfail`)

Add multiple tests to check the handling of both TCP and UDP socket
error scenarios in dig/host.

4 years agoFix dig error when trying the next server after a TCP connection failure
Aram Sargsyan [Sun, 13 Mar 2022 13:47:16 +0000 (13:47 +0000)] 
Fix dig error when trying the next server after a TCP connection failure

When encountering a TCP connection error while trying to initiate a
connection to a server, dig erroneously cancels the lookup even when
there are other server(s) to try, which results in an assertion failure.

Cancel the lookup only when there are no more queries left in the
lookup's queries list (i.e. `next` is NULL).

4 years agoMerge branch '3128-dig-does-not-recover-from-a-isc_nm_udpconnect-failure' into 'main'
Arаm Sаrgsyаn [Fri, 18 Mar 2022 10:24:46 +0000 (10:24 +0000)] 
Merge branch '3128-dig-does-not-recover-from-a-isc_nm_udpconnect-failure' into 'main'

After dig request errors, try to use other servers when they exist

Closes #3128

See merge request isc-projects/bind9!5967

4 years agoAdd CHANGES entry for [GL #3128]
Aram Sargsyan [Fri, 11 Mar 2022 21:36:25 +0000 (21:36 +0000)] 
Add CHANGES entry for [GL #3128]

4 years agoAdd digdelv system test to check that dig tries other servers on error
Aram Sargsyan [Fri, 11 Mar 2022 21:29:14 +0000 (21:29 +0000)] 
Add digdelv system test to check that dig tries other servers on error

Add a test to check whether dig tries the next query/server after
a connection error.

Add a test to check whether dig tries the next query/server after
a one or more (default is 3) connection/request timeouts.

4 years agoAfter dig request errors, try to use other servers when they exist
Aram Sargsyan [Fri, 11 Mar 2022 19:37:27 +0000 (19:37 +0000)] 
After dig request errors, try to use other servers when they exist

When timing-out or having other types of socket errors during a query,
dig isn't trying to perform the lookup using other servers which exist
in the lookup's queries list.

After configured amount of timeout retries, or after a socket error,
check if there are other queries/servers in the lookup's queries list,
and start the next one if it exists, instead of unconditionally failing.

4 years agoMerge branch '3020-dighost-servfail-bug' into 'main'
Arаm Sаrgsyаn [Fri, 18 Mar 2022 09:02:40 +0000 (09:02 +0000)] 
Merge branch '3020-dighost-servfail-bug' into 'main'

When resending a UDP request, insert the query to the lookup's list

Closes #3020

See merge request isc-projects/bind9!5954

4 years agoAdd digdelv system test to check timed-out result followed by a SERVFAIL
Aram Sargsyan [Thu, 10 Mar 2022 00:12:37 +0000 (00:12 +0000)] 
Add digdelv system test to check timed-out result followed by a SERVFAIL

This test ensures that `dig` retries with another attempt after a
timed-out request, and that it does not crash when the retried
request returns a SERVFAIL result. See [GL #3020] for the latter
issue.

4 years agoAdd CHANGES note for [GL #3020]
Aram Sargsyan [Wed, 9 Mar 2022 20:17:51 +0000 (20:17 +0000)] 
Add CHANGES note for [GL #3020]

4 years agoWhen resending a UDP request, insert the query to the lookup's list
Aram Sargsyan [Wed, 9 Mar 2022 19:45:54 +0000 (19:45 +0000)] 
When resending a UDP request, insert the query to the lookup's list

When a query times out, and `dig` (or `host`) creates a new query
to resend the request, it is being prepended to the lookup's queries
list, which can cause a confusion later, making `dig` (or `host`)
believe that there is another new query in the list, but that is
actually the old one, which was timed out. That mistake will result
in an assertion failure.

That can happen, in particular, when after a timed out request,
the retried request returns a SERVFAIL result, and the recursion
is enabled, and `+nofail` option was used with `dig` (that is the
default behavior in `host`, unless the `-s` option is provided).

Fix the problem by inserting the query just after the current,
timed-out query, instead of prepending to the list.

Before calling start_udp() detach `l->current_query`, like it is
done in another place in the function.

Slightly update a couple of debug messages to make them more
consistent.

4 years agoFix an issue in dig when retrying with the next server after SERVFAIL
Aram Sargsyan [Thu, 10 Mar 2022 17:30:34 +0000 (17:30 +0000)] 
Fix an issue in dig when retrying with the next server after SERVFAIL

After a query results in a SERVFAIL result, and there is another
registered query in the lookup's queries list, `dig` starts the next
query to try another server, but for some reason, reports about that
also when the current query is in the head of the list, even if there
is no other query in the list to try.

Use the same condition for both decisions, and after starting the next
query, jump to the "detach_query" label instead of "next_lookup",
because there is no need to start the next lookup after we just started
a query in the current lookup.

4 years agoMerge branch '3208-fix-xfrout-maxtimer-timer-log-message-log-level' into 'main'
Ondřej Surý [Thu, 17 Mar 2022 20:34:30 +0000 (20:34 +0000)] 
Merge branch '3208-fix-xfrout-maxtimer-timer-log-message-log-level' into 'main'

Change xfer-out timer message log level to DEBUG(1)

Closes #3208

See merge request isc-projects/bind9!5995

4 years agoChange xfer-out timer message log level to DEBUG(1)
Ondřej Surý [Thu, 17 Mar 2022 20:28:29 +0000 (21:28 +0100)] 
Change xfer-out timer message log level to DEBUG(1)

When max-transfer-*-out timeouts were reintroduced, the log message
about starting the timer was errorneously left as ISC_LOG_ERROR.
Change the log level of said message to ISC_LOG_DEBUG(1).

4 years agoMerge branch 'ondrej/add-missing-braces-clang-format-15' into 'main'
Ondřej Surý [Thu, 17 Mar 2022 17:50:42 +0000 (17:50 +0000)] 
Merge branch 'ondrej/add-missing-braces-clang-format-15' into 'main'

Add couple missing braces around single-line statements

See merge request isc-projects/bind9!5968

4 years agoAdd couple missing braces around single-line statements
Ondřej Surý [Sun, 13 Mar 2022 12:05:27 +0000 (13:05 +0100)] 
Add couple missing braces around single-line statements

The clang-format-15 has new option InsertBraces that could add missing
branches around single line statements.  Use that to our advantage
without switching to not-yet-released LLVM version to add missing braces
in couple of places.

4 years agoMerge branch '3212-implement-incremental-rehashing-for-isc_ht-hashtables' into 'main'
Ondřej Surý [Thu, 17 Mar 2022 07:35:00 +0000 (07:35 +0000)] 
Merge branch '3212-implement-incremental-rehashing-for-isc_ht-hashtables' into 'main'

Implement incremental hash table resizing in isc_ht

Closes #3212

See merge request isc-projects/bind9!5983

4 years agoAdd CHANGES note for [GL #3212]
Ondřej Surý [Tue, 15 Mar 2022 20:59:46 +0000 (21:59 +0100)] 
Add CHANGES note for [GL #3212]

4 years agoUpdate the isc_ht unit test to also tesh rehashing
Ondřej Surý [Wed, 16 Mar 2022 10:11:38 +0000 (11:11 +0100)] 
Update the isc_ht unit test to also tesh rehashing

As incremental rehashing has been added to isc_ht implementation, we
need to test whether the rehashing works.

Update the isc_ht unit test to test:

 * preinitialized hash table large enough to hold all the elements
 * smallest hash table that fully grows to hold all the elements
 * partially preinitialized hash table that grows
 * iterating while rehashing is in progress

4 years agoImplement incremental hash table resizing in isc_ht
Ondřej Surý [Tue, 15 Mar 2022 20:45:33 +0000 (21:45 +0100)] 
Implement incremental hash table resizing in isc_ht

Previously, an incremental hash table resizing was implemented for the
dns_rbt_t hash table implementation.  Using that as a base, also
implement the incremental hash table resizing also for isc_ht API
hashtables:

 1. During the resize, allocate the new hash table, but keep the old
    table unchanged.
 2. In each lookup, delete, or iterator operation, check both tables.
 3. Perform insertion operations only in the new table.
 4. At each insertion also move <r> elements from the old table to
    the new table.
 5. When all elements are removed from the old table, deallocate it.

To ensure that the old table is completely copied over before the new
table itself needs to be enlarged, it is necessary to increase the
size of the table by a factor of at least (<r> + 1)/<r> during resizing.

In our implementation <r> is equal to 1.

The downside of this approach is that the old table and the new table
could stay in memory for longer when there are no new insertions into
the hash table for prolonged periods of time as the incremental
rehashing happens only during the insertions.

4 years agoMerge branch '3129-check-fetch-shutting-down-in-resume_dslookup' into 'main'
Michał Kępień [Wed, 16 Mar 2022 22:05:26 +0000 (22:05 +0000)] 
Merge branch '3129-check-fetch-shutting-down-in-resume_dslookup' into 'main'

[CVE-2022-0667] Check if the fetch is shutting down in resume_dslookup()

See merge request isc-projects/bind9!5989

4 years agoMerge branch '3158-confidential-issue-only-set-foundname-on-success' into 'main'
Michał Kępień [Wed, 16 Mar 2022 21:42:28 +0000 (21:42 +0000)] 
Merge branch '3158-confidential-issue-only-set-foundname-on-success' into 'main'

[CVE-2022-0635] DNAME lookups can trigger INSIST when synth-from-dnssec is enabled

See merge request isc-projects/bind9!5988

4 years agoMerge branch '3112-ensure-correct-ordering-in-isc__nm_process_sock_buffer' into ...
Michał Kępień [Wed, 16 Mar 2022 21:36:53 +0000 (21:36 +0000)] 
Merge branch '3112-ensure-correct-ordering-in-isc__nm_process_sock_buffer' into 'main'

[CVE-2022-0396] Resolve #3112 TCP sockets stuck in CLOSE_WAIT

Closes #3112

See merge request isc-projects/bind9!5987

4 years agoMerge branch '2950-confidential-cache-acceptance-rules' into 'main'
Michał Kępień [Wed, 16 Mar 2022 21:30:34 +0000 (21:30 +0000)] 
Merge branch '2950-confidential-cache-acceptance-rules' into 'main'

[CVE-2021-25220] prevent cache poisoning from forwarder responses

See merge request isc-projects/bind9!5986

4 years agoAdd CHANGES and release note for [GL #3129]
Aram Sargsyan [Thu, 10 Feb 2022 20:40:29 +0000 (20:40 +0000)] 
Add CHANGES and release note for [GL #3129]

4 years agoAdd CHANGES and release note for [GL #3158]
Mark Andrews [Wed, 16 Feb 2022 08:30:19 +0000 (19:30 +1100)] 
Add CHANGES and release note for [GL #3158]

4 years agoAdd CHANGES and release note for [GL #3112]
Ondřej Surý [Thu, 27 Jan 2022 07:44:53 +0000 (08:44 +0100)] 
Add CHANGES and release note for [GL #3112]

4 years agoAdd Release Note for [GL #2950]
Petr Špaček [Fri, 25 Feb 2022 14:14:23 +0000 (15:14 +0100)] 
Add Release Note for [GL #2950]

4 years agoCheck if the fetch is shutting down in resume_dslookup()
Aram Sargsyan [Thu, 10 Feb 2022 20:06:30 +0000 (20:06 +0000)] 
Check if the fetch is shutting down in resume_dslookup()

The fetch can be in the shutting down state when resume_dslookup() is
trying to operate on it.

This is also a security issue, because a malicious actor can set up a
name server which delays certain queries in such a way that the fetch
will time out and shut down, which will cause named to crash.

Add a check to see if the fetch has the shutting down attribute set,
and cancel any further operations on it in such case.

A similar bug had been fixed earlier for the resume_qmin() function,
see [GL #966].

4 years agoSkip calling find_coveringnsec if we found a DNAME
Mark Andrews [Thu, 17 Feb 2022 06:11:26 +0000 (17:11 +1100)] 
Skip calling find_coveringnsec if we found a DNAME

This is an optimisation as we can skip a lot of pointless work when we
know there is a DNAME there.

When we have a partial match and a DNAME above the QNAME, the closest
encloser has the same owner as the DNAME, will have the DNAME bit set
in the type map, and we wouldn't use it as we would return the
DNAME + RRSIG(DNAME) instead.

So there is no point in looking for it nor in attempting to check that
it is valid for the QNAME.

4 years agoRun .closehandle_cb asynchrounosly in nmhandle_detach_cb()
Ondřej Surý [Tue, 8 Feb 2022 11:42:34 +0000 (12:42 +0100)] 
Run .closehandle_cb asynchrounosly in nmhandle_detach_cb()

When sock->closehandle_cb is set, we need to run nmhandle_detach_cb()
asynchronously to ensure correct order of multiple packets processing in
the isc__nm_process_sock_buffer().  When not run asynchronously, it
would cause:

  a) out-of-order processing of the return codes from processbuffer();

  b) stack growth because the next TCP DNS message read callback will
     be called from within the current TCP DNS message read callback.

The sock->closehandle_cb is set to isc__nm_resume_processing() for TCP
sockets which calls isc__nm_process_sock_buffer().  If the read callback
(called from isc__nm_process_sock_buffer()->processbuffer()) doesn't
attach to the nmhandle (f.e. because it wants to drop the processing or
we send the response directly via uv_try_write()), the
isc__nm_resume_processing() (via .closehandle_cb) would call
isc__nm_process_sock_buffer() recursively.

The below shortened code path shows how the stack can grow:

 1: ns__client_request(handle, ...);
 2: isc_nm_tcpdns_sequential(handle);
 3: ns_query_start(client, handle);
 4:   query_lookup(qctx);
 5:     query_send(qctcx->client);
 6:       isc__nmhandle_detach(&client->reqhandle);
 7:         nmhandle_detach_cb(&handle);
 8:           sock->closehandle_cb(sock); // isc__nm_resume_processing
 9:             isc__nm_process_sock_buffer(sock);
10:               processbuffer(sock); // isc__nm_tcpdns_processbuffer
11:                 isc_nmhandle_attach(req->handle, &handle);
12:                 isc__nm_readcb(sock, req, ISC_R_SUCCESS);
13:                   isc__nm_async_readcb(NULL, ...);
14:                     uvreq->cb.recv(...); // ns__client_request

Instead, if 'sock->closehandle_cb' is set, we need to run detach the
handle asynchroniously in 'isc__nmhandle_detach', so that on line 8 in
the code flow above does not start this recursion. This ensures the
correct order when processing multiple packets in the function
'isc__nm_process_sock_buffer()' and prevents the stack growth.

When not run asynchronously, the out-of-order processing leaves the
first TCP socket open until all requests on the stream have been
processed.

If the pipelining is disabled on the TCP via `keep-response-order`
configuration option, named would keep the first socket in lingering
CLOSE_WAIT state when the client sends an incomplete packet and then
closes the connection from the client side.

4 years agoAdd CHANGES note for [GL #2950]
Petr Špaček [Fri, 25 Feb 2022 14:14:10 +0000 (15:14 +0100)] 
Add CHANGES note for [GL #2950]

4 years agoOnly update foundname if returning DNS_R_COVERINGNSEC
Mark Andrews [Wed, 16 Feb 2022 08:20:25 +0000 (19:20 +1100)] 
Only update foundname if returning DNS_R_COVERINGNSEC

'setup_delegation' depends on 'foundname' being the value returned
by 'dns_rbt_findnode' in the cache and 'find_coveringnsec' was
modifying 'foundname' when a covering NSEC was not found.

4 years agoLook for zones deeper than the current domain or forward name
Mark Andrews [Wed, 2 Feb 2022 04:13:39 +0000 (15:13 +1100)] 
Look for zones deeper than the current domain or forward name

When caching glue, we need to ensure that there is no closer
source of truth for the name. If the owner name for the glue
record would be answered by a locally configured zone, do not
cache.

4 years agoCheck cached names for possible "forward only" clause
Mark Andrews [Fri, 21 Jan 2022 04:36:48 +0000 (15:36 +1100)] 
Check cached names for possible "forward only" clause

When caching additional and glue data *not* from a forwarder, we must
check that there is no "forward only" clause covering the owner name
that would take precedence.  Such names would normally be allowed by
baliwick rules, but a "forward only" zone introduces a new baliwick
scope.

4 years agoCheck that the forward declaration is unchanged and not overridden
Mark Andrews [Thu, 20 Jan 2022 23:52:02 +0000 (10:52 +1100)] 
Check that the forward declaration is unchanged and not overridden

If we are using a fowarder, in addition to checking that names to
be cached are subdomains of the forwarded namespace, we must also
check that there are no subsidiary forwarded namespaces which would
take precedence. To be safe, we don't cache any responses if the
forwarding configuration has changed since the query was sent.

4 years agoAdd additional name checks when using a forwarder
Mark Andrews [Wed, 19 Jan 2022 06:38:18 +0000 (17:38 +1100)] 
Add additional name checks when using a forwarder

When using a forwarder, check that the owner name of response
records are within the bailiwick of the forwarded name space.

4 years agoMerge branch '3185-follow-up-fix-zone-documentation' into 'main'
Matthijs Mekking [Tue, 15 Mar 2022 13:14:25 +0000 (13:14 +0000)] 
Merge branch '3185-follow-up-fix-zone-documentation' into 'main'

Fix zone named.conf man page documentation

Closes #3185

See merge request isc-projects/bind9!5977

4 years agoFix named.conf man page documentation
Matthijs Mekking [Mon, 14 Mar 2022 10:32:46 +0000 (11:32 +0100)] 
Fix named.conf man page documentation

Commit 4ca74eee49363a9c24c561a742f0abdd7f71d2a8 update the zone grammar
such that the zone statement is printed with the valid options per
zone type.

This commit is a follow-up, putting back the ZONE heading and adding
a note that these zone statements may also be put inside the view
statement.

It is tricky to actually print the zone statements inside
the view statement, and so we decided that we would add a note to say
that this is possible.

4 years agoMerge branch '3202-cleanup-isc_timer-API' into 'main'
Ondřej Surý [Mon, 14 Mar 2022 21:13:24 +0000 (21:13 +0000)] 
Merge branch '3202-cleanup-isc_timer-API' into 'main'

Refactor and simplify isc_timer API

See merge request isc-projects/bind9!5966

4 years agoAdd CHANGES note for [GL #3202]
Ondřej Surý [Fri, 11 Mar 2022 22:14:06 +0000 (23:14 +0100)] 
Add CHANGES note for [GL #3202]

4 years agoImplement isc_interval_t on top of isc_time_t
Ondřej Surý [Sun, 13 Mar 2022 11:13:11 +0000 (12:13 +0100)] 
Implement isc_interval_t on top of isc_time_t

Change the isc_interval_t implementation from separate data type and
separate implementation to be shim implementation on top of isc_time_t.
The distinction between isc_interval_t and isc_time_t has been kept
because they are semantically different - isc_interval_t is relative and
isc_time_t is absolute, but this allows isc_time_t and isc_interval_t to
be freely interchangeable, f.e. this:

    isc_time_t *t1;
    isc_interval_t *interval;
    isc_time_t *t2;

    isc_interval_set(interval, isc_time_seconds(t2), isc_time_nanoseconds(t2);;
    isc_time_subtract(t1, interval, t2);
    isc_interval_set(interval, isc_time_seconds(t2), isc_time_nanoseconds(t2));

to just:

    isc_time_t *t1;
    isc_interval_t *interval;
    isc_time_t *t2;

    isc_time_subtract(t1, t2, interval);

without introducing a whole set of new functions.

4 years agoRefactor isc_timer_reset() use with semantic patch
Ondřej Surý [Fri, 11 Mar 2022 22:08:17 +0000 (23:08 +0100)] 
Refactor isc_timer_reset() use with semantic patch

Add and apply semantic patch to remove expires argument from the
isc_timer_reset() calls through the codebase.

4 years agoRemove expires argument from isc_timer API
Ondřej Surý [Fri, 11 Mar 2022 22:00:55 +0000 (23:00 +0100)] 
Remove expires argument from isc_timer API

The isc_timer_reset() now works only with intervals for once timers.

This makes the API almost 1:1 compatible with the libuv timers making
the further refactoring possible.

4 years agoChange isc_timer_reset() usage to never use expires argument
Ondřej Surý [Fri, 11 Mar 2022 21:34:45 +0000 (22:34 +0100)] 
Change isc_timer_reset() usage to never use expires argument

There were two places where expires argument (absolute isc_time_t value)
was being used.  Both places has been converted to use relative interval
argument in preparation of simplification and refactoring of isc_timer
API.

4 years agoRefactor isc_timer_create() to just create timer
Ondřej Surý [Fri, 11 Mar 2022 11:09:35 +0000 (12:09 +0100)] 
Refactor isc_timer_create() to just create timer

The isc_timer_create() function was a bit conflated.  It could have been
used to create a timer and start it at the same time.  As there was a
single place where this was done before (see the previous commit for
nta.c), this was cleaned up and the isc_timer_create() function was
changed to only create new timer.

4 years agoChange lib/dns/nta.c to create inactive timer and then reset it
Ondřej Surý [Fri, 11 Mar 2022 10:50:25 +0000 (11:50 +0100)] 
Change lib/dns/nta.c to create inactive timer and then reset it

In nta.c, it was the only place where the active timer was created
directly instead of first creating inactive timer and then starting it
with isc_timer_reset().

Change the code to create inactive timer first, so we can refactor the
isc_timer_create() function.

4 years agoRemove "a temporary hack, 'rndc timerpoke'"
Ondřej Surý [Fri, 11 Mar 2022 10:32:48 +0000 (11:32 +0100)] 
Remove "a temporary hack, 'rndc timerpoke'"

In 2002, "a temporary hack, 'rndc timerpoke'" was added.  It's time
for it to go, so it was removed.

4 years agoRemove unused isc_timer_touch() function
Ondřej Surý [Fri, 11 Mar 2022 10:26:09 +0000 (11:26 +0100)] 
Remove unused isc_timer_touch() function

The isc_timer_touch() was unused, just remove it.

4 years agoRemove isc_timertype_limited from isc_timer API
Ondřej Surý [Fri, 11 Mar 2022 10:19:43 +0000 (11:19 +0100)] 
Remove isc_timertype_limited from isc_timer API

The isc_timertype_limited timer type was never used (not even in tests).
Remove isc_timertype_limited timer type before planned refactoring.

4 years agoMerge branch 'pspacek/manpage-hyperlinks-fix' into 'main'
Petr Špaček [Mon, 14 Mar 2022 12:38:30 +0000 (12:38 +0000)] 
Merge branch 'pspacek/manpage-hyperlinks-fix' into 'main'

Fix dig option hyperlinks in the TSIG section of the ARM

See merge request isc-projects/bind9!5979

4 years agoFix dig option hyperlinks in the TSIG section of the ARM
Petr Špaček [Mon, 14 Mar 2022 10:27:53 +0000 (11:27 +0100)] 
Fix dig option hyperlinks in the TSIG section of the ARM

While backporting !5934 I noticed a copy&paste mistake in TSIG
chapter of the ARM.

The incorrect reference was introduced by "Add hyperlinks from
program options to definition in man pages" commit but it is not
worth creating separate MR for that when the backport is not merged
yet.

(cherry picked from commit 4daef4a2a74278a25f4d9935ffa78b01f44bbd83)

4 years agoMerge branch 'pspacek/manpage-hyperlinks' into 'main'
Petr Špaček [Mon, 14 Mar 2022 09:53:02 +0000 (09:53 +0000)] 
Merge branch 'pspacek/manpage-hyperlinks' into 'main'

Add hyperlinks to manual pages

See merge request isc-projects/bind9!5934

4 years agoRegenerate the named.conf manual with hyperlinks
Tony Finch [Thu, 10 Mar 2022 16:52:12 +0000 (16:52 +0000)] 
Regenerate the named.conf manual with hyperlinks

The named.conf grammar is exported to the manual via
doc/misc/rst-options.pl which is the ultimate source
for the non-grammar parts of the man page.

4 years agoAdd internal hyperlinks to See Also section of manual pages
Petr Špaček [Fri, 4 Mar 2022 12:10:25 +0000 (13:10 +0100)] 
Add internal hyperlinks to See Also section of manual pages

Replace :manpage: with :iscman: to generate internal hyperlinks. That
way reader can use links even when offline, and jumps to man pages
for the same version.

Formerly HTML version of man pages did not have links in See Also
section because :manpage: role in Sphinx can generate only external
hyperlinks - and we do not have that enabled.
Enabling the Sphinx :manpage: linking could reliably create hyperlinks
only to external URLs, but that would take users to another version
of docs.

Generated by:
    find bin -name '*.rst' | xargs sed -i -e 's/:manpage:`\([^(]\+\)(\([0-9]\))`/:iscman:`\1(\2) <\1>`/g'
+ hand-edit to revert change for mmencode reference which is
  not provided in our source tree.

4 years agoRemove reference to ndc utility from BIND 8
Petr Špaček [Thu, 3 Mar 2022 21:27:26 +0000 (22:27 +0100)] 
Remove reference to ndc utility from BIND 8

4 years agoHyperlink program names to their manual pages
Petr Špaček [Thu, 3 Mar 2022 21:17:04 +0000 (22:17 +0100)] 
Hyperlink program names to their manual pages

Use the new role :iscman: to replace all occurences or ``binary``
with :iscman:`binary`, creating a hyperlink to the manual page.

Generated using:
    find bin -name *.rst | xargs fgrep --files-with-matches '.. iscman' | xargs -I{} -n1 basename {} .rst > /tmp/progs
    for PROG in $(cat /tmp/progs); do find -name '*.rst' | xargs sed -i -e "s/\`\`$PROG\`\`/:iscman:\`$PROG\`/g"; done

Additional hand-edits were done mainly around filter-aaaa and
filter-a which are program names and and option names at the
same time. Couple more edits was neede to fix .rst syntax broken by
automatic replacement.

4 years agoUse semantic markup for :program: self-references
Petr Špaček [Thu, 3 Mar 2022 15:00:43 +0000 (16:00 +0100)] 
Use semantic markup for :program: self-references

Sphinx has it's own :program: syntax for refering to program names.
Use it for self-references in manual pages. These self-references are
not clickable and not as eye-cathing as links, which is a good thing.
There is no point in attracting attention to ``dig`` several times on a
single page dedicated to dig itself.

Substituted automatically using:
    find bin  -name *.rst | xargs fgrep --files-with-matches '.. program' | xargs -n1 bash /tmp/repl.sh

With /tmp/repl.sh being:
    BASE=$(basename "$1" .rst)
    sed -i -e "s/\`\`$BASE\`\`/:program:\`$BASE\`/g" "$1"

4 years agoIntroduce new Sphinx role iscman for ISC manual pages
Petr Špaček [Thu, 3 Mar 2022 14:32:35 +0000 (15:32 +0100)] 
Introduce new Sphinx role iscman for ISC manual pages

The new directive and role "iscman" allow to tag & reference man pages in
our source tree. Essentially it is just namespacing for ISC man pages,
but it comes with couple benefits.

Differences from .. _man_program label we formerly used:
- Does not expand :ref:`man_program` into full text of the page header.
- Generates index entry with category "manual page".
- Rendering style is closer to ubiquitous to the one produced
  by ``named`` syntax.

Differences from Sphinx built-in :manpage: role:
- Supports all builders with support for cross-references.
- Generates internal links (unlike :manpage: which generates external
  URLs).
- Checks that target exists withing our source tree.

4 years agoMore man page option hyperlinks
Tony Finch [Thu, 3 Mar 2022 15:02:10 +0000 (15:02 +0000)] 
More man page option hyperlinks

The dig man page wanted -h option hyperlink and anchor, and there
were a couple of missing cross-references in the rndc man page.

4 years agoAdd hyperlinks from program options to definition in man pages
Petr Špaček [Wed, 2 Mar 2022 15:54:31 +0000 (16:54 +0100)] 
Add hyperlinks from program options to definition in man pages

Side-effect of hyperlinking is that typos in program and option names
are now detected by Sphinx.

Candidate -options were detected using:
    find -name *.rst | xargs grep '``-[^`]'
and then modified from ``-o`` to :option:`-o` using regex
    s/``\(-[^`]\+\)``/:option:`\1`/
+ manual modifications where necessary.

Non-hyphenated options were detected by looking at context around
program names:
    find bin -name *.rst | xargs -I{} -n1 basename {} .rst | sort -u
and grepping for program name with trailing whitespace.

Stand-alone program names like ``named`` are not hyperlinked in this
commit.

4 years agoFix rndc command in release notes for 9.17.12
Petr Špaček [Thu, 3 Mar 2022 09:07:10 +0000 (10:07 +0100)] 
Fix rndc command in release notes for 9.17.12

rndc checkds does not exist, it should have been rndc dnssec

Related: #2488, !4813

4 years agoAdd semantic markup for program names into manual pages
Petr Špaček [Wed, 2 Mar 2022 15:36:34 +0000 (16:36 +0100)] 
Add semantic markup for program names into manual pages

It allows to cross-reference options in man pages from other
documents using :option:`named -g` syntax.

4 years agoDenote all command line options using semantic markup (.. option::)
Petr Špaček [Wed, 2 Mar 2022 14:12:17 +0000 (15:12 +0100)] 
Denote all command line options using semantic markup (.. option::)

The markup allows referencing individual options, and also makes them
more legible (no more thin red text on gray background).

Most of the work was done using regexes:
    s/^``-\(.*\)``$/.. option:: -\1\r/
    s/^``+\(.*\)``$/.. option:: +\1\r/
on bin/**/*.rst files along with visual inspection and hand-edits,
mostly for positional arguments.

Regex for rndc.rst:
    s/^``\(.*\)``/.. option:: \1\r/
+ hand edits to remove extra asterisk and whitespace here and there.

4 years agoMerge branch 'michal/tidy-setup-of-python-based-tests' into 'main'
Michał Kępień [Mon, 14 Mar 2022 08:30:05 +0000 (08:30 +0000)] 
Merge branch 'michal/tidy-setup-of-python-based-tests' into 'main'

Tidy setup of Python-based tests

See merge request isc-projects/bind9!5960

4 years agoTweak Automake conditionals for pytest-based tests
Michał Kępień [Mon, 14 Mar 2022 07:59:32 +0000 (08:59 +0100)] 
Tweak Automake conditionals for pytest-based tests

Since pytest itself skips tests using dnspython if the latter is not
available, also using Automake conditionals for silently skipping
pytest-based tests requiring dnspython is redundant and hides
information.  Allow all pytest-based tests requiring dnspython to be run
whenever pytest itself is available, in order to ensure test skipping is
done in a uniform manner.

Note that the above reasoning only applies to pytest-based tests, so
similar adjustments were not made for shell-based tests using Python
scripts that require dnspython ("chain", "cookie", "dnssec", "qmin").