2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 22:15:20 +00:00
Commit Graph

9452 Commits

Author SHA1 Message Date
Matthijs Mekking
042c89ac69 Obsolete dnssec-update-mode
We no longer support 'no-resign' and thus the configuration option
becomes obsolete. Remove the corresponding dnssec system test cases.
2023-07-20 12:44:19 +02:00
Matthijs Mekking
3bcb096a0e Tiny refactor revoked key check
This makes the code flow a bit more readable.
2023-07-20 12:44:19 +02:00
Matthijs Mekking
3e49223a67 Obsolete dnssec-dnskey-kskonly update-check-ksk
These two configuration options worked in conjunction with 'auto-dnssec'
to determine KSK usage, and thus are now obsoleted.

However, in the code we keep KSK processing so that when a zone is
reconfigured from using 'dnssec-policy' immediately to 'none' (without
going through 'insecure'), the zone is not immediately made bogus.

Add one more test case for going straight to none, now with a dynamic
zone (no inline-signing).
2023-07-20 12:40:54 +02:00
Matthijs Mekking
a8f71f67ac Refactor KSK processing
There are multiple almost identical code blocks, time to make a
function.
2023-07-20 12:40:52 +02:00
Matthijs Mekking
f0c164954e Copy DNSKEY record from unsigned zone db
Since external DNSKEY records may exist in the unsigned version of the
zone (for example DNSKEY records from other providers), handle these
RRsets also when copying non DNSSEC records from the unsigned zone
database to the signed version.
2023-07-20 11:04:23 +02:00
Evan Hunt
6ac8723611 use isc_loop_now() for dispentry timeouts
store a pointer to the running loop when creating a dispatch entry
with dns_dispatch_add(), and use isc_loop_now() to get the timestamp for
the current event loop tick when we initialize the dispentry start time
and check for timeouts.
2023-07-19 15:32:21 +02:00
Ondřej Surý
fb13b439bc Add missing headers to <dns/rdataslab.h>
The new header was not self-contained and required extra headers to be
included before including <dns/rdataslah.h>; rectify that.
2023-07-19 09:28:53 +02:00
Evan Hunt
5a85135c1e split out cache-specific functions
move cache-specific functions from rbtdb.c to rbt-cachedb.c.
2023-07-17 14:50:25 +02:00
Evan Hunt
9a1a1293c0 split out zone-specific functions
move zone-specific functions from rbtdb.c to rbt-zonedb.c.
2023-07-17 14:50:25 +02:00
Evan Hunt
445ef1d033 move slab rdataset implementation to rdataslab.c
ultimately we want the slab implementation of dns_rdataset to
be usable by more database implementaions than just rbtdb. this
commit moves rdataset_methods to rdataslab.c, renamed
dns_rdataslab_rdatasetmethods.

new database methods have been added: locknode, unlocknode,
addglue, expiredata, and deletedata, allowing external functions to
perform functions that previously required internal access to the
database implementation.

database and heap pointers are now stored in the dns_slabheader object
so that header is the only thing that needs to be passed to some
functions; this will simplify moving functions that process slabheaders
out of rbtdb.c so they can be used by other database implementations.
2023-07-17 14:50:25 +02:00
Evan Hunt
17f85f6c93 move prototypes for common functions to rbtdb_p.h
rename the existing rbtdb.h to rbtdb_p.h, and start putting
macros and declarations of dns__rbtdb functions into it.
2023-07-17 14:50:25 +02:00
Evan Hunt
4db150437e clean up unused dns_db methods
to reduce the amount of common code that will need to be shared
between the separated cache and zone database implementations,
clean up unused portions of dns_db.

the methods dns_db_dump(), dns_db_isdnssec(), dns_db_printnode(),
dns_db_resigned(), dns_db_expirenode() and dns_db_overmem() were
either never called or were only implemented as nonoperational stub
functions: they have now been removed.

dns_db_nodefullname() was only used in one place, which turned out
to be unnecessary, so it has also been removed.

dns_db_ispersistent() and dns_db_transfernode() are used, but only
the default implementation in db.c was ever actually called. since
they were never overridden by database methods, there's no need to
retain methods for them.

in rbtdb.c, beginload() and endload() methods are no longer defined for
the cache database, because that was never used (except in a few unit
tests which can easily be modified to use the zone implementation
instead).  issecure() is also no longer defined for the cache database,
as the cache is always insecure and the default implementation of
dns_db_issecure() returns false.

for similar reasons, hashsize() is no longer defined for zone databases.

implementation functions that are shared between zone and cache are now
prepended with 'dns__rbtdb_' so they can become nonstatic.

serve_stale_ttl is now a common member of dns_db.
2023-07-17 14:50:25 +02:00
Evan Hunt
1c21e50953 clean up rbtdb.c
in preparation for splitting up rbtdb.c, rename some types so they
can be defined in dns/types.h instead of only locally. these include:

- struct noqname, which is used to hold no-qname and closest-encloser
  proofs, and is now named dns_proof_t;
- rbtdb_rdatatype_t, which is used to hold a pair of rdatatypes and
  is now called dns_typepair_t and defined in rdatatype.h;
- rbtdb_serial_t, which is now just a uint32_t;
- rdatasetheader_t and rdatasetheaderlist_t, now called
  dns_slabheader_t and dns_slabheaderlist_t;
- rbtdb_version_t, now called dns_rbtdb_version_t.

the helper functions header_from_raw() and raw_from_header() are
renamed dns_slabheader_fromrdataset() and dns_slabheader_raw().

also made further style changes:
- fixing uninitialized pointer variables throughout rbtdb.c;
- switching some initializations to struct literals;
- renaming some functions and struct members more descriptively;
- replacing dns_db_secure_t with a simple bool since it no longer needs
  to be tri-valued.
2023-07-17 14:50:25 +02:00
Evan Hunt
d25d0af7f5 remove unused DNS_DBFIND options
the DNS_DBFIND_VALIDATEGLUE and DNS_DBFIND_FORCENSEC options
were never set, so the code implementing them (which in the case
of _VALIDATEGLUE appears to have been quite outdated anyway) was
never reached. they have now been removed.
2023-07-17 14:50:25 +02:00
Tony Finch
856a6e4afb Give the rdataset->privateN fields more helpful names
BIND's rdataset structure is a view of some DNS records. It is
polymorphic, so the details of how the records are stored can vary.
For instance, the records can be held in an rdatalist, or in an
rdataslab in the rbtdb.

The dns_rdataset structure previously had a number of fields called
`private1` up to `private7`, which were used by the various rdataset
implementations. It was not at all clear what these fields were for,
without reading the code and working it out from context.

This change makes the rdataset inheritance hierarchy more clear. The
polymorphic part of a `struct dns_rdataset` is now a union of structs,
each of which is named for the class of implementation using it. The
fields of these structs replace the old `privateN` fields. (Note: the
term "inheritance hierarchy" refers to the fact that the builtin and
SDLZ implementations are based on and inherit from the rdatalist
implementation, which in turn inherits from the generic rdataset.

Most of this change is mechanical, but there are a few extras.

In keynode.c there were a number of REQUIRE()ments that were not
necessary: they had already been checked by the rdataset method
dispatch code. On the other hand, In ncache.c there was a public
function which needed to REQUIRE() that an rdataset was valid.

I have removed lots of "reset iterator state" comments, because it
should now be clear from `target->iter = NULL` where before
`target->private5 = NULL` could have been doing anything.

Initialization is a bit neater in a few places, using C structure
literals where appropriate.

The pointer arithmetic for translating between an rdataslab header and
its raw contents is now fractionally safer.
2023-07-17 14:50:25 +02:00
Evan Hunt
9330fada3a refactor the slab rdataset implementation
- use externally accessible functions for attachnode/detachnode
  so these functions can be moved outside rbtdb.c
- simplify and tidy up some other functions
- use struct initializers when appropriate
- remove the flag RDATASET_ATTR_RETAIN; it was never being set
- renamed the rdataset attributes to
- remove the 'slab_methods' rdataset implementation. this was
  a reduced set of slab rdataset methods, omitting 'setownercase()'
  and 'getownercase()'. we can get the identical result by using
  an DNS_RDATASETATTR_KEEPCASE attribute in rdatasets that
  shouldn't have their case modified, and then we only need one
  set of rdataset methods.
2023-07-17 14:50:25 +02:00
Aram Sargsyan
28bb419edc Add shutdown checks in dns_catz_dbupdate_callback()
When a zone database update callback is called, the 'catzs' object,
extracted from the callback argument, might be already shutting down,
in which case the 'catzs->zones' can be NULL and cause an assertion
failure when calling isc_ht_find().

Add an early return from the callback if 'catzs->shuttingdown' is true.

Also check the validity of 'catzs->zones' after locking 'catzs' in
case there is a race with dns_catz_shutdown_catzs() running in another
thread.
2023-07-06 10:46:46 +00:00
Evan Hunt
0955cf1af5 clean up numbering of FETCHOPT and ADDRINFO flags
in the past there was overlap between the fields used
as resolver fetch options and ADB addrinfo flags. this has
mostly been eliminated; now we can clean up the rest of
it and remove some confusing comments.
2023-07-04 18:23:57 +00:00
Evan Hunt
5ba73c785e fix a TSAN bug in "rndc fetchlimit"
fctx counters could be accessed without locking when
"rndc fetchlimit" is called; while this is probably harmless
in production, it triggered TSAN reports in system tests.
2023-06-30 06:52:01 +00:00
Evan Hunt
352d542d27 minor refactoring of resume_qmin() for clarity
make the code flow clearer by enumerating the result codes that
are treated as success conditions for an intermediate minimized
query (ISC_R_SUCCESS, DNS_R_DELEGATION, DNS_R_NXRRSET, etc), rather
than just folding them all into the 'default' branch of a switch
statement.
2023-06-29 10:14:20 -07:00
Mark Andrews
e3e20ed76e Emit deprecated warning for K* file pairs
We try reading the same file using different methods so only
emit a warning if we successfully read the file.
2023-06-29 08:28:48 +10:00
Mark Andrews
3f93d3f757 Restore the ability to read legacy K*+157+* files
The ability to read legacy HMAC-MD5 K* keyfile pairs using algorithm
number 157 was accidentally lost when the algorithm numbers were
consolidated into a single block, in commit
09f7e0607a.

The assumption was that these algorithm numbers were only known
internally, but they were also used in key files. But since HMAC-MD5
got renumbered from 157 to 160, legacy HMAC-MD5 key files no longer
work.

Move HMAC-MD5 back to 157 and GSSAPI back to 160.  Add exception for
GSSAPI to list_hmac_algorithms.
2023-06-29 08:28:44 +10:00
Mark Andrews
ea11650376 In rctx_answer return DNS_R_DELEGATION on NOFOLLOW
When DNS_FETCHOPT_NOFOLLOW is set DNS_R_DELEGATION needs to be
returned to restart the resolution process rather than converting
it to ISC_R_SUCCESS.
2023-06-28 11:48:32 +10:00
Mark Andrews
80bc0ee075 Skip some QNAME mininisation queries if possible
If we know that the NS RRset for an intermediate label doesn't exist
on cache contents don't query using that name when looking for a
referral.
2023-06-28 11:47:56 +10:00
Mark Andrews
dd00b3c50b Use NS rather than A records for qname-minimization relaxed
Remove all references to DNS_FETCHOPT_QMIN_USE_A and adjust
the expected tests results in the qmin system test.
2023-06-28 11:45:59 +10:00
Ondřej Surý
519481dcdb Use per-loop memory contexts for dns_resolver child objects
The dns_resolver creates a lot of smaller objects (fetch context, fetch
counter, query, response, ...) and those are all loop-bound.
Previously, those objects were allocated from the a single resolver
context, which in turn increases contention between threads - remember
"dead by thousand atomic paper cuts".  Instead of using a single memory
context, use the per-loop memory contexts that are bound to a specific
loop and thus there's no contention between them when doing the memory
accounting.
2023-06-27 10:51:54 +02:00
Michal Nowak
71439d0c3a Merge tag 'v9.19.14'
BIND 9.19.14
2023-06-21 19:31:57 +02:00
Ondřej Surý
b53d1d7069 Refactor how we map isc_result_t <-> dns_rcode_t
The mapping functions between isc_result_t and dns_rcode_t could return
both isc_result_t values not defined in the header and dns_rcode_t
values not defined in the header because it blindly maps anything
withing full 12-bits defined for RCODEs to isc_result_t and back.

Refactor the dns_result_{from,to}rcode() functions to always return
valid isc_result_t and dns_rcode_t values by explicitly mapping the
values to each other and returning DNS_R_SERVFAIL (dns_rcode_servfail)
when encountering value out of the defined range.
2023-06-15 15:32:04 +02:00
Aram Sargsyan
6f1f5fc307 Fix a data race between the dns_zone and dns_catz modules
The dns_zone_catz_enable_db() and dns_zone_catz_disable_db()
functions can race with similar operations in the catz module
because there is no synchronization between the threads.

Add catz functions which use the view's catalog zones' lock
when registering/unregistering the database update notify callback,
and use those functions in the dns_zone module, instead of doing it
directly.
2023-06-15 08:49:20 +00:00
Mark Andrews
971f49b3ad Use RCU for view->adb access
view->adb may be referenced while the view is shutting down as the
zone uses a weak reference to the view and examines view->adb but
dns_view_detach call dns_adb_detach to clear view->adb.
2023-06-14 19:21:28 +10:00
Evan Hunt
885c132f4a improve code flow
the code in dns_tkey_processquery() was unnecessarily hard to follow.
2023-06-14 08:14:38 +00:00
Evan Hunt
f4084ff543 minor tkey-related fixups
- style fixes and general tidying-up in tkey.c
- remove the unused 'intoken' parameter from dns_tkey_buildgssquery()
- remove an unnecessary call to dns_tkeyctx_create() in ns_server_create()
  (the TKEY context that was created there would soon be destroyed and
  another one created when the configuration was loaded).
2023-06-14 08:14:38 +00:00
Evan Hunt
96e8b0e782 rename 'ret' to 'result'
purely to assuage my desire for consistency across modules,
result variables have been renamed to 'result' as they are
throughout most of BIND. there are no other changes.
2023-06-14 08:14:38 +00: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
e64b44a5cb remove dns__tsig_algallocated()
this function was no longer needed, because the algorithm name is no
longer copied into the tsigkey object by dns_tsigkey_createfromkey();
it's always just a pointer to a statically defined name.
2023-06-14 08:14:38 +00:00
Evan Hunt
f2d5782e89 get_key_struct() can no longer fail
remove checks for NULL return values.
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
a6e187a8d5 further dns_tsigkey API tweaks
- remove the 'ring' parameter from dns_tsigkey_createfromkey(),
  and use dns_tsigkeyring_add() to add key objects to a keyring instead.
- add a magic number to dns_tsigkeyring_t
- change dns_tsigkeyring_dumpanddetach() to dns_tsigkeyring_dump();
  we now call dns_tsigkeyring_detach() separately.
- remove 'maxgenerated' from dns_tsigkeyring_t since it never changes.
2023-06-14 08:14:38 +00:00
Evan Hunt
404a13b4dd clean up reference counting in dns_tsigkey
the reference counter in dns_tsigkey was being computed differently
depending on whether there was a keyring or not. this is prone to
error.
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
Matthijs Mekking
e59c6a5adc Update findzonekeys function name in log message
The "dns_dnssec_findzonekeys2" log message is a leftover from when that
was the name of the function. Rename to match the current name of the
function.
2023-06-14 09:08:56 +02:00
Matthijs Mekking
88e5bc0687 Update find_zone_keys for dynamic update
The find_zone_keys() function was not working properly for
inline-signed zones. It only worked if the DNSKEY records were also
published in the unsigned version of the zone. But this is not the
case when you use dnssec-policy, the DNSKEY records will only occur
in the signed version of the zone. Therefor, when looking for keys
to sign the zone, only the newly added keys in the dynamic update
were found (which could be zero), ignoring existing keys.

Also, if a DNSKEY was added, it would try to sign the zone with just
this new key, and this would only work if the key files for that key
were imported into the key-directory.

This is a design error, because the goal is to sign the zone with the
keys for which we actually have key files for. So instead of looking
for DNSKEY records to then search for the matching key files, call
dns_dnssec_findmatchingkeys() which just looks for the keys we have
on disk for the given zone. It will also set the correct DNSSEC
signing hints.
2023-06-14 09:08:56 +02:00
Aram Sargsyan
998765fea5 Fix catz db update callback registration logic error
When a catalog zone is updated using AXFR, the zone database is changed,
so it is required to unregister the update notification callback from
the old database, and register it for the new one.

Currently, here is the order of the steps happening in such scenario:

1. The zone.c:zone_startload() function registers the notify callback
   on the new database using dns_zone_catz_enable_db()
2. The callback, when called, notices that the new 'db' is different
   than 'catz->db', and unregisters the old callback for 'catz->db',
   marks that it's unregistered by setting 'catz->db_registered' to
   false, then it schedules an update if it isn't already scheduled.
3. The offloaded update process, after completing its job, notices that
   'catz->db_registered' is false, and (re)registers the update callback
   for the current database it is working on. There is no harm here even
   if it was registered also on step 1, and we can't skip it, because
   this function can also be called "artificially" during a
   reconfiguration, and in that case the registration step is required
   here.

A problem arises when before step 1 an update process was already
in a running state, operating on the old database, and finishing its
work only after step 2. As described in step 3, dns__catz_update_cb()
notices that 'catz->db_registered' is false and registers the callback
on the current database it is working on, which, at that state, is
already obsolete and unused by the zone. When it detaches the database,
the function which is responsible for its cleanup (e.g. free_rbtdb())
asserts because there is a registered update notify callback there.

To fix the problem, instead of delaying the (re)registration to step 3,
make sure that the new callback is registered and 'catz->db_registered'
is accordingly marked on step 2.
2023-06-13 12:58:13 +00:00
Ondřej Surý
da0eafcdee Improve RBT overmem cache cleaning
When cache memory usage is over the configured cache size (overmem) and
we are cleaning unused entries, it might not be enough to clean just two
entries if the entries to be expired are smaller than the newly added
rdata.  This could be abused by an attacker to cause a remote Denial of
Service by possibly running out of the operating system memory.

Currently, the addrdataset() tries to do a single TTL-based cleaning
considering the serve-stale TTL and then optionally moves to overmem
cleaning if we are in that condition.  Then the overmem_purge() tries to
do another single TTL based cleaning from the TTL heap and then continue
with LRU-based cleaning up to 2 entries cleaned.

Squash the TTL-cleaning mechanism into single call from addrdataset(),
but ignore the serve-stale TTL if we are currently overmem.

Then instead of having a fixed number of entries to clean, pass the size
of newly added rdatasetheader to the overmem_purge() function and
cleanup at least the size of the newly added data.  This prevents the
cache going over the configured memory limit (`max-cache-size`).

Additionally, refactor the overmem_purge() function to reduce for-loop
nesting for readability.
2023-06-08 12:11:09 +02:00
Ondřej Surý
696506e164 Fix extra detach when dns_validator create_fetch() detects deadlock
When create_fetch() in the dns_validator unit detects deadlock, it
returns DNS_R_NOVALIDSIG, but it didn't attach to the validator.  The
other condition to returning result != ISC_R_SUCCESS would be error from
dns_resolver_createfetch().  The caller (in two places out of three)
would detect the error condition and always detach from the validator.

Move the dns_validator_detach() on dns_resolver_createfetch() error
condition to create_fetch() function and cleanup the extra detaches in
seek_dnskey() and get_dsset().
2023-06-06 19:04:17 +02:00
Mark Andrews
783c6a9538 Use dns_view_findzone instead of dns_zt_find
This ensures that rcu locking is properly applied for
view->zonetable.
2023-06-01 16:51:38 +02:00
Mark Andrews
8d86fa7135 Extend dns_view_findzone to take an options argument
This is in preparation to allow the few remaining direct
dns_zt_find(view->zonetable, ...) to use it for rcu mediated
access to view->zonetable.
2023-06-01 16:51:38 +02:00
Mark Andrews
ceb3264082 Add dns_view_apply
Add dns_view_apply to allow dns_zt_apply to be called on
view->zonetable with rcu locking applied.
2023-06-01 16:51:38 +02:00
Mark Andrews
e0f41259bd Add dns_view_delzone
dns_view_delzone performs the rcu locking required around accessing
view->zonetable.
2023-06-01 16:51:38 +02:00