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

35772 Commits

Author SHA1 Message Date
Ondřej Surý
8495edc31d 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
2022-03-17 07:35:00 +00:00
Ondřej Surý
5ccb28d6d8 Add CHANGES note for [GL #3212] 2022-03-17 08:16:24 +01:00
Ondřej Surý
cd52953f8a 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
2022-03-17 08:16:24 +01:00
Ondřej Surý
e42cb1f198 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.
2022-03-17 08:16:24 +01:00
Michał Kępień
7ba3a06935 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
2022-03-16 22:05:26 +00:00
Michał Kępień
71dd44339f 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
2022-03-16 21:42:28 +00:00
Michał Kępień
ae7fa0a308 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
2022-03-16 21:36:53 +00:00
Michał Kępień
9c27a3b0e2 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
2022-03-16 21:30:34 +00:00
Aram Sargsyan
9241363f36 Add CHANGES and release note for [GL #3129] 2022-03-16 22:11:49 +01:00
Mark Andrews
c9f28777f6 Add CHANGES and release note for [GL #3158] 2022-03-16 22:11:49 +01:00
Ondřej Surý
dcb6a0c4f8 Add CHANGES and release note for [GL #3112] 2022-03-16 22:11:49 +01:00
Petr Špaček
51546e8892 Add Release Note for [GL #2950] 2022-03-16 22:11:49 +01:00
Aram Sargsyan
f0f3370e14 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].
2022-03-16 22:11:49 +01:00
Mark Andrews
9fcc028f5c 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.
2022-03-16 22:11:49 +01:00
Ondřej Surý
bfa4b9c141 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.
2022-03-16 22:11:49 +01:00
Petr Špaček
612f277877 Add CHANGES note for [GL #2950] 2022-03-16 22:11:49 +01:00
Mark Andrews
5c271f91e1 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.
2022-03-16 22:11:49 +01:00
Mark Andrews
fe1bbba259 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.
2022-03-16 22:11:49 +01:00
Mark Andrews
c289913e5c 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.
2022-03-16 22:11:49 +01:00
Mark Andrews
7e37b5e379 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.
2022-03-16 22:11:49 +01:00
Mark Andrews
5dc3b25d03 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.
2022-03-16 22:11:49 +01:00
Matthijs Mekking
fd8dd9841d 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
2022-03-15 13:14:25 +00:00
Matthijs Mekking
01b125ff05 Fix named.conf man page documentation
Commit 4ca74eee49 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.
2022-03-15 14:13:45 +01:00
Ondřej Surý
13b20ef411 Merge branch '3202-cleanup-isc_timer-API' into 'main'
Refactor and simplify isc_timer API

See merge request isc-projects/bind9!5966
2022-03-14 21:13:24 +00:00
Ondřej Surý
7f91f1ecaa Add CHANGES note for [GL #3202] 2022-03-14 13:00:05 -07:00
Ondřej Surý
79b5ccbf34 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.
2022-03-14 13:00:05 -07:00
Ondřej Surý
e6ca2a651f 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.
2022-03-14 13:00:05 -07:00
Ondřej Surý
6437bcc488 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.
2022-03-14 13:00:05 -07:00
Ondřej Surý
27850a5ad2 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.
2022-03-14 13:00:05 -07:00
Ondřej Surý
c259cecc90 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.
2022-03-14 13:00:05 -07:00
Ondřej Surý
514053f244 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.
2022-03-14 13:00:05 -07:00
Ondřej Surý
8fbb42c49c 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.
2022-03-14 13:00:05 -07:00
Ondřej Surý
f4751a91f7 Remove unused isc_timer_touch() function
The isc_timer_touch() was unused, just remove it.
2022-03-14 13:00:05 -07:00
Ondřej Surý
bbe1c06a8b 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.
2022-03-14 13:00:05 -07:00
Petr Špaček
c752dff3b4 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
2022-03-14 12:38:30 +00:00
Petr Špaček
f98a6a5308 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 4daef4a2a7)
2022-03-14 13:22:40 +01:00
Petr Špaček
49d2a12e7c Merge branch 'pspacek/manpage-hyperlinks' into 'main'
Add hyperlinks to manual pages

See merge request isc-projects/bind9!5934
2022-03-14 09:53:02 +00:00
Tony Finch
ad5b0402c9 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.
2022-03-14 10:47:45 +01:00
Petr Špaček
1d4d008fc9 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.
2022-03-14 10:46:36 +01:00
Petr Špaček
420a71df57 Remove reference to ndc utility from BIND 8 2022-03-14 10:46:36 +01:00
Petr Špaček
53a5776025 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.
2022-03-14 10:46:36 +01:00
Petr Špaček
c7085be211 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"
2022-03-14 10:46:36 +01:00
Petr Špaček
7e7a946d44 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.
2022-03-14 10:46:36 +01:00
Tony Finch
ccc6378355 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.
2022-03-14 10:46:36 +01:00
Petr Špaček
a85df3ff9c 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.
2022-03-14 10:46:36 +01:00
Petr Špaček
5f0ee7c303 Fix rndc command in release notes for 9.17.12
rndc checkds does not exist, it should have been rndc dnssec

Related: #2488, !4813
2022-03-14 10:46:36 +01:00
Petr Špaček
8537878c01 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.
2022-03-14 10:46:36 +01:00
Petr Špaček
ec30944aa4 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.
2022-03-14 10:46:32 +01:00
Michał Kępień
e9f4d00bf0 Merge branch 'michal/tidy-setup-of-python-based-tests' into 'main'
Tidy setup of Python-based tests

See merge request isc-projects/bind9!5960
2022-03-14 08:30:05 +00:00
Michał Kępień
173ad9cf46 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").
2022-03-14 08:59:32 +01:00