2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-28 04:58:04 +00:00

109 Commits

Author SHA1 Message Date
Ondřej Surý
2cb5a6210f
Improve the badcache cleaning by adding LRU and using RCU
Instead of cleaning the dns_badcache opportunistically, add per-loop
LRU, so each thread-loop can clean the expired entries.  This also
allows removal of the atomic operations as the badcache entries are now
immutable, instead of updating the badcache entry in place, the old
entry is now deleted from the hashtable and the LRU list, and the new
entry is inserted in the LRU.
2024-11-27 17:44:53 +01:00
Ondřej Surý
0258850f20
Remove redundant parentheses from the return statement 2024-11-19 12:27:22 +01:00
Evan Hunt
5ea1f6390d corrected code style errors
- add missing brackets around one-line statements
- add paretheses around return values
2024-10-18 19:31:27 +00:00
Evan Hunt
642a1b985d remove the "dialup" and "heartbeat-interval" options
mark "dialup" and "heartbeat-interval" options as ancient and
remove the documentation and the code implementing them.
2024-08-22 11:11:10 -07:00
Ondřej Surý
e6f2f2a5e6
Initialize the DST subsystem implicitly
Instead of calling dst_lib_init() and dst_lib_destroy() explicitly by
all the programs, create a separate memory context for the DST subsystem
and use the library constructor and destructor to initialize the DST
internals.
2024-08-07 17:03:27 +02:00
Ondřej Surý
ef7aba7072
Remove OpenSSL Engine support
The OpenSSL 1.x Engines support has been deprecated in the OpenSSL 3.x
and is going to be removed.  Remove the OpenSSL Engine support in favor
of OpenSSL Providers.
2024-08-06 15:17:48 +02:00
Evan Hunt
92b305be4b add a compile-time option to select default zone and cache DB
by default, QPDB is the database used by named and all tools and
unit tests. the old default of RBTDB can now be restored by using
"configure --with-zonedb=rbt --with-cachedb=rbt".

some tests have been fixed so they will work correctly with either
database.

CHANGES and release notes have been updated to reflect this change.
2024-03-06 10:49:02 +01:00
Evan Hunt
bb4464181a switch database defaults from "rbt" to "qp"
replace the string "rbt" throughout BIND with "qp" so that
qpdb databases will be used by default instead of rbtdb.
rbtdb databases can still be used by specifying "database rbt;"
in a zone statement.
2024-03-06 09:57:24 +01:00
Mark Andrews
fd077c2661 NetBSD has added 'hmac' to libc so rename out uses of hmac 2023-12-13 22:27:38 +00:00
Evan Hunt
29cf7dceb7 modify dns_qp_findname_ancestor() to return found name
add a 'foundname' parameter to dns_qp_findname_ancestor(),
and use it to set the found name in dns_nametree.

this required adding a dns_qpkey_toname() function; that was
done by moving qp_test_keytoname() from the test library to qp.c.
added some more test cases and fixed bugs with the handling of
relative and empty names.
2023-09-28 07:01:13 +00:00
Ondřej Surý
f5af981831
Change dns_message_create() function to accept memory pools
Instead of creating new memory pools for each new dns_message, change
dns_message_create() method to optionally accept externally created
dns_fixedname_t and dns_rdataset_t memory pools.  This allows us to
preallocate the memory pools in ns_client and dns_resolver units for the
lifetime of dns_resolver_t and ns_clientmgr_t.
2023-09-24 18:07:40 +02:00
Evan Hunt
a290ed5bd0 remove dns_name_fromstring2()
we don't need two versions of dns_name_fromstring() any longer; we
can just specify an origin value of dns_rootname for absolute names.
2023-08-31 10:29:16 -07:00
Ondřej Surý
d76ab69772 Attach to the dns_dispatchmgr in the dns_view object
The dns_dispatchmgr object was only set in the dns_view object making it
prone to use-after-free in the dns_xfrin unit when shutting down named.

Remove dns_view_setdispatchmgr() and optionally pass the dispatchmgr
directly to dns_view_create() when it is attached and not just assigned,
so the dns_dispatchmgr doesn't cease to exist too early.

The dns_view_getdnsdispatchmgr() is now protected by the RCU lock, the
dispatchmgr reference is incremented, so the caller needs to detach from
it, and the function can return NULL in case the dns_view has been
already shut down.
2023-08-15 10:25:37 -07:00
Tony Finch
b38c71961d
Improve qp-trie leaf return values
Make the `pval_r` and `ival_r` out arguments optional.

Add `pval_r` and `ival_r` out arguments to `dns_qp_deletekey()`
and `dns_qp_deletename()`, to return the deleted leaf.
2023-08-15 14:24:39 +02:00
Ondřej Surý
1e3b6d2d83
Don't cleanup the dns_message_checksig fuzzer in atexit handler
After the dns_badcache refactoring, the dns_badcache_destroy() would
call call_rcu().  The dns_message_checksig cleanup which calls
dns_view_detach() happens in the atexit handler, so there might be
call_rcu threads started very late in the process.  The liburcu
registers library destructor that destroys the data structured internal
to liburcu and this clashes with the call_rcu thread that just got
started in the atexit() handler causing either (depending on timing):

 - a normal run
 - a straight segfault
 - an assertion failure from liburcu

Instead of trying to cleanup the dns_message_checksig unit, ignore the
leaked memory as we do with all the other fuzzing tests.
2023-07-31 15:51:15 +02:00
Ondřej Surý
ea2fe8eea4 Refactor dns_zone_create() to return void
After isc_stats_create() change, the dns_zone_create() cannot fail, so
refactor the function to return void and fix all its uses.
2023-07-27 11:37:44 +02:00
Evan Hunt
6105a7d360 convert TSIG keyring storage from RBT to hash table
since it is not necessary to find partial matches when looking
up names in a TSIG keyring, we can use a hash table instead of
an RBT to store them.

the tsigkey object now stores the key name as a dns_fixedname
rather than allocating memory for it.

the `name` parameter to dns_tsigkeyring_add() has been removed;
it was unneeded since the tsigkey object already contains a copy
of the name.

the opportunistic cleanup_ring() function has been removed;
it was only slowing down lookups.
2023-06-14 08:14:38 +00:00
Evan Hunt
ffacf0aec6 use algorithm number instead of name to create TSIG keys
the prior practice of passing a dns_name containing the
expanded name of an algorithm to dns_tsigkey_create() and
dns_tsigkey_createfromkey() is unnecessarily cumbersome;
we can now pass the algorithm number instead.
2023-06-14 08:14:38 +00:00
Evan Hunt
6fa8524bba use ISC_REFCOUNT_IMPL for dns_tsigkey and dns_tsigkeyring
use the ISC_REFCOUNT attach/detach implementation in dns/tsig.c
so that detailed tracing can be used during refactoring.

dns_tsig_keyring_t has been renamed dns_tsigkeyring_t so the type
and the attach/detach function names will match.
2023-06-14 08:14:38 +00:00
Evan Hunt
b1db1c1475 minor tsig.c cleanups
- style cleanups.
- simplify the function parameters to dns_tsigkey_create():
  + remove 'restored' and 'generated', they're only ever set to false.
  + remove 'creator' because it's only ever set to NULL.
  + remove 'inception' and 'expiry' because they're only ever set to
    (0, 0) or (now, now), and either way, this means "never expire".
  + remove 'ring' because we can just use dns_tsigkeyring_add() instead.
- rename dns_keyring_restore() to dns_tsigkeyring_restore() to match the
  rest of the functions operating on dns_tsigkeyring objects.
2023-06-14 08:14:38 +00:00
Tony Finch
c890b9b124
Get the tests working with liburcu
Mostly a few qp-trie details to adjust.
2023-05-12 20:48:31 +01:00
Tony Finch
9882a6ef90
The zone table no longer depends on the loop manager
This reverts some of the changes in commit b171cacf4f0123ba
because now it isn't necessary to pass the loopmgr around.
2023-05-12 20:48:31 +01:00
Tony Finch
b171cacf4f Use a qp-trie for the zone table
This change makes the zone table lock-free for reads. Previously, the
zone table used a red-black tree, which is not thread safe, so the hot
read path acquired both the per-view mutex and the per-zonetable
rwlock. (The double locking was to fix to cleanup races on shutdown.)

One visible difference is that zones are not necessarily shut down
promptly: it depends on when the qp-trie garbage collector cleans up
the zone table. The `catz` system test checks several times that zones
have been deleted; the test now checks for zones to be removed from
the server configuration, instead of being fully shut down. The catz
test does not churn through enough zones to trigger a gc, so the zones
are not fully detached until the server exits.

After this change, it is still possible to improve the way we handle
changes to the zone table, for instance, batching changes, or better
compaction heuristics.
2023-04-05 12:38:11 +01:00
Tony Finch
b3e35fd120 A few qp-trie cleanups
Revert refcount debug tracing (commit a8b29f0365), there are better
ways to do it.

Use the dns_qpmethods_t typedef where appropriate.

Some stylistic improvements.
2023-04-05 12:35:04 +01:00
Tony Finch
906d434aea Fix Coverity complaints in the qp-trie tests
The main problem was `qp_test_keytoname()` not using `qpkey_bit()`
to do bounds checking.
2023-04-03 15:10:47 +00:00
Ondřej Surý
4ec9c4a1db Cleanup the last Windows / MSC ifdefs and comments
Cleanup the remnants of MS Compiler bits from <isc/refcount.h>, printing
the information in named/main.c, and cleanup some comments about Windows
that no longer apply.

The bits in picohttpparser.{h,c} were left out, because it's not our
code.
2023-04-03 09:06:20 +00:00
Ondřej Surý
2c0a9575d7
Replace __attribute__((unused)) with ISC_ATTR_UNUSED attribute macro
Instead of marking the unused entities with UNUSED(x) macro in the
function body, use a `ISC_ATTR_UNUSED` attribute macro that expans to
C23 [[maybe_unused]] or __attribute__((__unused__)) as fallback.
2023-03-30 23:29:25 +02:00
Mark Andrews
64c0065986 Build libtest even if CMOCKA is not available
Be more selective about what is not built when CMOCKA is not available
so that fuzz/dns_qp and fuzz/dns_qpkey_name can link against it.
2023-03-29 02:29:18 +00:00
Evan Hunt
e914c5e194 add basic test for TSIG key dump/restore functionality
stop and restart the server in the 'tsiggss' test, in order
to confirm that GSS negotiated TSIG keys are saved and restored
when named loads.

added logging to dns_tsigkey_createfromkey() to indicate whether
a key has been statically configured, generated via GSS negotiation,
or restored from a file.
2023-03-16 09:55:50 -07:00
Tony Finch
a8b29f0365 Improve qp-trie refcount debugging
Add some qp-trie tracing macros which can be enabled by a
developer. These print a message when a leaf is attached or
detached, indicating which part of the qp-trie implementation
did so. The refcount methods must now return the refcount value
so it can be printed by the trace macros.
2023-02-27 13:47:57 +00:00
Tony Finch
4b5ec07bb7 Refactor qp-trie to use QSBR
The first working multi-threaded qp-trie was stuck with an unpleasant
trade-off:

  * Use `isc_rwlock`, which has acceptable write performance, but
    terrible read scalability because the qp-trie made all accesses
    through a single lock.

  * Use `liburcu`, which has great read scalability, but terrible
    write performance, because I was relying on `rcu_synchronize()`
    which is rather slow. And `liburcu` is LGPL.

To get the best of both worlds, we need our own scalable read side,
which we now have with `isc_qsbr`. And we need to modify the write
side so that it is not blocked by readers.

Better write performance requires an async cleanup function like
`call_rcu()`, instead of the blocking `rcu_synchronize()`. (There
is no blocking cleanup in `isc_qsbr`, because I have concluded
that it would be an attractive nuisance.)

Until now, all my multithreading qp-trie designs have been based
around two versions, read-only and mutable. This is too few to
work with asynchronous cleanup. The bare minimum (as in epoch
based reclamation) is three, but it makes more sense to support an
arbitrary number. Doing multi-version support "properly" makes
fewer assumptions about how safe memory reclamation works, and it
makes snapshots and rollbacks simpler.

To avoid making the memory management even more complicated, I
have introduced a new kind of "packed reader node" to anchor the
root of a version of the trie. This is simpler because it re-uses
the existing chunk lifetime logic - see the discussion under
"packed reader nodes" in `qp_p.h`.

I have also made the chunk lifetime logic simpler. The idea of a
"generation" is gone; instead, chunks are either mutable or
immutable. And the QSBR phase number is used to indicate when a
chunk can be reclaimed.

Instead of the `shared_base` flag (which was basically a one-bit
reference count, with a two version limit) the base array now has a
refcount, which replaces the confusing ad-hoc lifetime logic with
something more familiar and systematic.
2023-02-27 13:47:55 +00:00
Tony Finch
b06f6ef75a Fuzz testing the qp-trie
Ensure dns_qpkey_fromname() and dns_qpkey_toname() are inverses.

Excercise a single-threaded dns_qp_t with a fixed set of random keys
and a small chunk size. Use the table of names to ensure that the trie
is behaving as expected. This is (in effect) randomized testing like
the `qpmulti` unit test, but making use of coverage-guided fuzzing
and (in principle) test case minimization.
2023-02-27 13:47:25 +00:00
Tony Finch
6927a30926 Remove do-nothing header <isc/print.h>
This one really truly did nothing. No lines added!
2023-02-15 16:44:47 +00:00
Tony Finch
50ab648f8a Remove unused support for fromwire(DNS_NAME_DOWNCASE)
Most of this change is fixing dns_rdata_fromwire() so
it does not propagate the unused options variable.
2023-02-06 13:26:36 +00:00
Mark Andrews
897e0cd6f4 Call dst_lib_destroy if we have called dst_lib_init
This returns BIGNUMs to OpenSSL allowing libcrypto to fully clean up.
2023-02-01 00:34:33 +11:00
Ondřej Surý
0c62c0bdb7
Mark setting operating system limits from named.conf as ancient
After deprecating the operating system limits settings (coresize,
datasize, files and stacksize), mark them as ancient and remove the code
that sets the values from config.
2022-12-07 19:40:00 +01:00
Tony Finch
04f3000dfc Fuzzing and benchmarking for dns_name_fromwire()
Since this is very sensitive code which has often had security
problems in many DNS implementations, it needs a decent amount of
validation. This fuzzer ensures that the new code has the same output
as the old code, and that it doesn't take longer than a second.

The benchmark uses the fuzzer's copy of the old dns_name_fromwire()
code to compare a number of scenarios: many compression pointers, many
labels, long labels, random data, with/without downcasing.
2022-11-17 08:45:17 +00:00
Evan Hunt
428eac45ba fix build error in fuzz tests
a missing include file caused dns_message_checksig.c to fail
to build on some platforms. this has been fixed.
2022-10-31 04:28:01 -07:00
Ondřej Surý
6ba0a22627
Change the return type of isc_lex_create() to void
The isc_lex_create() cannot fail, so cleanup the return type from
isc_result_t to void.
2022-10-26 12:55:06 +02:00
Tony Finch
45b2d8938b
Simplify and speed up DNS name compression
All we need for compression is a very small hash set of compression
offsets, because most of the information we need (the previously added
names) can be found in the message using the compression offsets.

This change combines dns_compress_find() and dns_compress_add() into
one function dns_compress_name() that both finds any existing suffix,
and adds any new prefix to the table. The old split led to performance
problems caused by duplicate names in the compression context.

Compression contexts are now either small or large, which the caller
chooses depending on the expected size of the message. There is no
dynamic resizing.

There is a behaviour change: compression now acts on all the labels in
each name, instead of just the last few.

A small benchmark suggests this is about 2x faster.
2022-10-17 08:45:44 +02:00
Mark Andrews
033057ba9d Create a key directory in /tmp
Access to the source tree is not available with oss_fuzz.  Have
fuzz/dns_message_checksig build and populate a key directory for
the fuzzer to use.  This contains a key pair and a zone file which
has the public key from the key pair.  Clean it up on shutdown.
2022-09-30 02:19:52 +00:00
Ondřej Surý
16377100ae
Fix stack-use-after-scope in dns_message_checksig test
Previously stack with buffer for test dns message went out of scope
before the message was processed. For fuzz testing its better to avoid
allocation, so let's avoid allocations completely and use simplest
possible static buffer.

Fixes: #3565
2022-09-27 13:06:01 +02:00
Petr Špaček
4108d79c9a
Fix dns_message_checksig in out-of-tree setup
Hardcoded path was missing FUZZDIR prefix.

Related: !5923
2022-09-27 11:21:42 +02:00
Petr Špaček
d102c59b96
Detect errors in fuzzer initialization
Incomplete initialization typically causes mysterious failures later on,
so let's err out early.
2022-09-27 11:21:38 +02:00
Petr Špaček
983822abcf
Add seed to reproduce issue memory leak in dns_message_checktsig
Related: #3547
2022-09-26 16:29:36 +02:00
Mark Andrews
c127a2aefc
Add a SIG(0) request seed 2022-09-26 16:28:23 +02:00
Mark Andrews
3c28608c9f
Add TSIG reply seed 2022-09-26 16:28:23 +02:00
Mark Andrews
f3d47bc8e0
Add TSIG request seed 2022-09-26 16:28:23 +02:00
Ondřej Surý
4da0180ba2
Add dns_message_checksig() fuzzer
dns_message_checksig is called in a number of scenarios

	* on requests and responses
	* on multiple opcodes
	* with and without signatures
	* with TSIG signatures
	* with SIG(0) signatures
	* with and without configured TSIG keys
	* with and without KEY records being present
	* signing performed now, in the future and in the past

we use the first two octets of the seed to configure the calling
environment with the remainder of the seed being the rdata of the
TSIG/SIG(0) record.
2022-09-26 16:28:23 +02:00
Tony Finch
1d807d84f1 Shrink decompression contexts
It's wasteful to use 20 bytes and a pointer indirection to represent
two bits of information, so turn the struct into an enum. And change
the names of the enumeration constants to make the intent more clear.

This change introduces some inline functions into another header,
which confuses `gcovr` when it is trying to collect code coverage
statistics. So, in the CI job, copy more header files into a directory
where `gcovr` looks for them.
2022-06-01 13:00:40 +01:00