Commit graph

14377 commits

Author SHA1 Message Date
Ondřej Surý
39d3e2a8ec
Add a limit to the number of RR types for single name
Previously, the number of RR types for a single owner name was limited
only by the maximum number of the types (64k).  As the data structure
that holds the RR types for the database node is just a linked list, and
there are places where we just walk through the whole list (again and
again), adding a large number of RR types for a single owner named with
would slow down processing of such name (database node).

Add a configurable limit to cap the number of the RR types for a single
owner.  This is enforced at the database (rbtdb, qpzone, qpcache) level
and configured with new max-types-per-name configuration option that
can be configured globally, per-view and per-zone.

(cherry picked from commit 00d16211d6368b99f070c1182d8c76b3798ca1db)
2024-06-10 18:50:06 +02:00
Ondřej Surý
e699ef939e
Add a limit to the number of RRs in RRSets
Previously, the number of RRs in the RRSets were internally unlimited.
As the data structure that holds the RRs is just a linked list, and
there are places where we just walk through all of the RRs, adding an
RRSet with huge number of RRs inside would slow down processing of said
RRSets.

Add a configurable limit to cap the number of the RRs in a single RRSet.
This is enforced at the database (rbtdb, qpzone, qpcache) level and
configured with new max-records-per-type configuration option that can
be configured globally, per-view and per-zone.

(cherry picked from commit 3fbd21f69a1bcbd26c4c00920e7b0a419e8762fc)
2024-06-10 18:50:03 +02:00
Ondřej Surý
964891a794
Limit the number of DNS message processed from a single TCP read
The single TCP read can create as much as 64k divided by the minimum
size of the DNS message.  This can clog the processing thread and trash
the memory allocator because we need to do as much as ~20k allocations in
a single UV loop tick.

Limit the number of the DNS messages processed in a single UV loop tick
to just single DNS message and limit the number of the outstanding DNS
messages back to 23.  This effectively limits the number of pipelined
DNS messages to that number (this is the limit we already had before).

This reverts commit 780a89012d.
2024-06-10 18:43:46 +02:00
Ondřej Surý
0b1d70ed2a
Remove the extra memory context with own arena for sending
(cherry picked from commit 8d4cc41c291f8a77a723ae8e62533538b3632d50)
2024-06-10 18:43:46 +02:00
Ondřej Surý
3f6b7f57a6
Replace the tcp_buffers memory pool with static per-loop buffer
As a single thread can process only one TCP send at the time, we don't
really need a memory pool for the TCP buffers, but it's enough to have
a single per-loop (client manager) static buffer that's being used to
assemble the DNS message and then it gets copied into own sending
buffer.

In the future, this should get optimized by exposing the uv_try API
from the network manager, and first try to send the message directly
and allocate the sending buffer only if we need to send the data
asynchronously.

(cherry picked from commit 297cc840fbaf34b9dfa1d02d88a023cd5bf5dc4a)
2024-06-10 18:43:46 +02:00
Aram Sargsyan
4e70342142
ns_client: reuse TCP send buffers
Constantly allocating, reallocating and deallocating 64K TCP send
buffers by 'ns_client' instances takes too much CPU time.

There is an existing mechanism to reuse the ns_clent_t structure
associated with the handle using 'isc_nmhandle_getdata/_setdata'
(see ns_client_request()), but it doesn't work with TCP, because
every time ns_client_request() is called it gets a new handle even
for the same TCP connection, see the comments in
streamdns_on_complete_dnsmessage().

To solve the problem, we introduce an array of available (unused)
TCP buffers stored in ns_clientmgr_t structure so that a 'client'
working via TCP can have a chance to reuse one (if there is one)
instead of allocating a new one every time.
2024-06-10 18:43:45 +02:00
Ondřej Surý
c6f13f12cd
Throttle reading from TCP if the sends are not getting through
When TCP client would not read the DNS message sent to them, the TCP
sends inside named would accumulate and cause degradation of the
service.  Throttle the reading from the TCP socket when we accumulate
enough DNS data to be sent.  Currently this is limited in a way that a
single largest possible DNS message can fit into the buffer.

(cherry picked from commit 26006f7b44474819fac2a76dc6cd6f69f0d76828)
2024-06-10 18:43:44 +02:00
Artem Boldariev
998522e68e
Keep the endpoints set reference within an HTTP/2 socket
This commit ensures that an HTTP endpoints set reference is stored in
a socket object associated with an HTTP/2 stream instead of
referencing the global set stored inside a listener.

This helps to prevent an issue like follows:

1. BIND is configured to serve DoH clients;
2. A client is connected and one or more HTTP/2 stream is
created. Internal pointers are now pointing to the data on the
associated HTTP endpoints set;
3. BIND is reconfigured - the new endpoints set object is created and
promoted to all listeners;
4. The old pointers to the HTTP endpoints set data are now invalid.

Instead referencing a global object that is updated on
re-configurations we now store a local reference which prevents the
endpoints set objects to go out of scope prematurely.

(cherry picked from commit b9b5d0c01a3a546c4a6a8b3bff8ae9dd31fee224)
2024-06-10 18:35:18 +02:00
Artem Boldariev
b601a5b781
DoH: avoid potential use after free for HTTP/2 session objects
It was reported that HTTP/2 session might get closed or even deleted
before all async. processing has been completed.

This commit addresses that: now we are avoiding using the object when
we do not need it or specifically check if the pointers used are not
'NULL' and by ensuring that there is at least one reference to the
session object while we are doing incoming data processing.

This commit makes the code more resilient to such issues in the
future.

(cherry picked from commit 0cca550dff403c6100b7c0da8f252e7967765ba7)
2024-06-10 18:35:16 +02:00
Mark Andrews
6455527830
Clear DNS_FETCHOPT_TRYSTALE_ONTIMEOUT
When calling dns_resolver_createfetch in resolver.c with a callback
of resume_dslookup, clear DNS_FETCHOPT_TRYSTALE_ONTIMEOUT from
options as DNS_EVENT_TRYSTALE is not an expected event type and
triggers a REQUIRE.
2024-06-06 07:48:49 +02:00
Mark Andrews
13be6cd991 Pass a memory context in to dns_cache_create
(cherry picked from commit 87e3b9dbf3)
2024-06-04 12:42:05 +00:00
Mark Andrews
26ad166a05 Use a new memory context when flushing the cache
When the cache's memory context was in over memory state when the
cache was flushed it resulted in LRU cleaning removing newly entered
data in the new cache straight away until the old cache had been
destroyed enough to take it out of over memory state.  When flushing
the cache create a new memory context for the new db to prevent this.

(cherry picked from commit 5e77edd074)
2024-06-04 12:42:05 +00:00
Mark Andrews
d3f708ba56 Update resquery_senddone handling of ISC_R_TIMEDOUT
Treat timed out as an address specific error.

(cherry picked from commit 56c3dcc5d7)
2024-06-04 07:38:40 +00:00
Mark Andrews
99d2b4079f Update resquery_senddone handling of ISC_R_CONNECTIONRESET
Treat connection reset as an address specific error.

(cherry picked from commit 4e3dd85b8d)
2024-06-04 07:38:40 +00:00
Mark Andrews
e87a5e7bff Handle ISC_R_HOSTDOWN and ISC_R_NETDOWN in resolver.c
These error codes should be treated like other unreachable error
codes.

(cherry picked from commit 180b1e7939)
2024-06-04 07:38:40 +00:00
Mark Andrews
69dde597b9 Don't do DS checks over disabled address families
(cherry picked from commit 05472e63e8)
2024-06-03 13:52:37 +00:00
Mark Andrews
542e891287 Don't forward UPDATE messages over disabled address families
(cherry picked from commit d026dbe536)
2024-06-03 13:52:37 +00:00
Mark Andrews
c6a207c710 Don't send NOTIFY over disabled address families
(cherry picked from commit 5d99625515)
2024-06-03 13:52:37 +00:00
Mark Andrews
96754276a7 Report non-effective primaries
When named is started with -4 or -6 and the primaries for a zone
do not have an IPv4 or IPv6 address respectively issue a log message.

(cherry picked from commit 2cd4303249)
2024-06-03 13:52:37 +00:00
Mark Andrews
7a9ac0491f Zone transfers should honour -4 and -6 options
Check if the address family has been disabled when transferring
zones.

(cherry picked from commit ecdde04e63)
2024-06-03 13:52:37 +00:00
Mark Andrews
e0af62deac Add helper function isc_sockaddr_disabled
(cherry picked from commit 9be1873ef3)
2024-06-03 13:52:37 +00:00
Matthijs Mekking
e1a49ee6d4 Call reset_shutdown if uv_tcp_close_reset failed
If uv_tcp_close_reset() returns an error code, this means the
reset_shutdown callback has not been issued, so do it now.

(cherry picked from commit c40e5c8653)
2024-06-03 08:16:32 +00:00
Matthijs Mekking
6f6d90fd51 Do not runtime check uv_tcp_close_reset
When we reset a TCP connection by sending a RST packet, do not bother
requiring the result is a success code.

(cherry picked from commit 5b94bb2129)
2024-06-03 08:16:32 +00:00
Aydın Mercan
dc9f55da5b
increase TCP4Clients/TCP6Clients after point of no failure
Failing to accept TCP/TLS connections in 9.18 detaches the quota in
isc__nm_failed_accept_cb, causing TCP4Clients and TCP6Clients statistics
to not decrease inside cleanup.

Fix by increasing the counter after the point of no failure but before
handling statistics through the client's socket is no longer valid.
2024-05-30 13:39:23 +03:00
Ondřej Surý
7c275be420
Create the new database for AXFR from the dns_zone API
The `axfr_makedb()` didn't set the loop on the newly created database,
effectively killing delayed cleaning on such database.  Move the
database creation into dns_zone API that knows all the gory details of
creating new database suitable for the zone.

(cherry picked from commit 3310cac2b0)
2024-05-29 08:56:38 +02:00
Mark Andrews
26b6ce9a56 Clang-format header file changes 2024-05-17 16:21:35 -07:00
Aram Sargsyan
0a48252b53 Fix a data race in isc_task_purgeevent()
When isc_task_purgeevent() is called for and 'event', the event, in
the meanwhile, could in theory get processed, unlinked, and freed.
So when the function then operates on the 'event', it causes a
segmentation fault.

The only place where isc_task_purgeevent() is called is from
timer_purge().

In order to resolve the data race, call isc_task_purgeevent() inside
the 'timer->lock' locked block, so that timerevent_destroy() won't
be able to destroy the event if it was processed in the meanwhile,
before isc_task_purgeevent() had a chance to purge it.

In order to be able to do that, move the responsibility of calling
isc_event_free() (upon a successful purge) out from the
isc_task_purgeevent() function to its caller instead, so that it can
be called outside of the timer->lock locked block.
2024-05-17 12:08:27 +00:00
Aram Sargsyan
857f6adaec Test a race condition between isc_timer_purge() and isc_event_free()
Let basic_tick() of 'task1' and 'basic_quick' of 'task4' run in
different threads, and insert an artificial delay in timer_purge()
to cause an existing race condition to appear.
2024-05-17 10:49:57 +00:00
Aram Sargsyan
c7b15f1f5a Expose internal timer_purge() as isc_timer_purge()
This function is used in a unit test to check for data races.
2024-05-17 10:49:57 +00:00
Mark Andrews
f7fb020b6e add test cases for several FORMERR code paths:
- duplicated question
  - duplicated answer
  - qtype as an answer
  - two question types
  - question names
  - nsec3 bad owner name
  - short record
  - short question
  - mismatching question class
  - bad record owner name
  - mismatched class in record
  - mismatched KEY class
  - OPT wrong owner name
  - invalid RRSIG "covers" type
  - UPDATE malformed delete type
  - TSIG wrong class
  - TSIG not the last record

(cherry picked from commit 6e9ed4983e)
2024-05-17 15:34:07 +10:00
Mark Andrews
29292902c0 Properly build the NSEC/NSEC3 type bit map
DNSKEY was incorrectly being added to the NESC/NSEC3 type bit map
when it was obscured by the delegation.  This lead to zone verification
failures.

(cherry picked from commit ec3c624814)
2024-05-16 01:53:39 +00:00
Mark Andrews
32589b2be7 Properly update 'maxtype'
'maxtype' should be checked to see if it should be updated whenever
a type is added to the type map.

(cherry picked from commit e84615629f)
2024-05-16 01:53:39 +00:00
Michał Kępień
df346b0088
Prevent passing NULL to dns_dispatch_resume()
If a query sent using the dns_request API times out when the view it was
associated with gets torn down, the dns_dispatch_resume() call in
req_response() may be issued with the 'resp' argument set to NULL,
triggering an assertion failure.  Consider the following scenario ([A]
and [B] are thread identifiers):

 1. [A] Read timeout for a dispatch query fires.

 2. [A] udp_recv() is called.  It locks the dispatch, determines it
    timed out, prepares for calling the higher-level callback with
    ISC_R_TIMEDOUT, and unlocks the dispatch (lib/dns/dispatch.c:633).

 3. [B] The last reference to a view is released.
    dns_requestmgr_shutdown() is called, canceling all in-flight
    requests for that view.  (Note that udp_recv() in thread [A] already
    unlocked the dispatch, so its state can be modified.)  As a part of
    this process, request_cancel() calls dns_dispatch_done() on
    request->dispentry, setting it to NULL.

 4. [A] udp_recv() calls the higher-level callback (req_response()) with
    ISC_R_TIMEDOUT.

 5. [A] Since the request timed out, req_response() retries sending it.
    In the process, it calls dns_dispatch_resume(), passing
    request->dispentry as the 'resp' argument.

 6. [A] Since 'resp' is NULL, the REQUIRE(VALID_RESPONSE(resp));
    assertion in dns_dispatch_resume() fails.

Fix by checking whether the request has been canceled before calling
dns_dispatch_resume(), similarly to how it is done in req_connected()
and req_senddone().
2024-05-15 21:24:24 +02:00
Mark Andrews
35f1e43273 Use dns_view_findzone instead of dns_zt_find
With weak zone attachments being used for catzs, catzs->view->zonetable
may be NULL so we need to account for this which dns_view_findzone
does.  This is already done in main.
2024-05-14 08:46:00 +10:00
Mark Andrews
d12def13f6 catzs->view should maintain a view reference
Use dns_view_weakattach and dns_view_weakdetach to maintain a
reference to the view referenced through catzs->view.

(cherry picked from commit 307e3ed9a6)
2024-05-09 10:22:00 +10:00
Mark Andrews
d1cc8a271d Only check SVBC alias forms at higher levels
Allow SVBC (HTTPS) alias form with parameters to be accepted from
the wire and when transfered.  This is for possible future extensions.

(cherry picked from commit 799046929c)
2024-05-07 02:08:27 +00:00
Mark Andrews
3f25f3349e Remove infinite loop on ISC_R_NOFILE
When parsing a zonefile named-checkzone (and others) could loop
infinitely if a directory was $INCLUDED.  Record the error and treat
as EOF when looking for multiple errors.

This was found by Eric Sesterhenn from X41.

(cherry picked from commit efd27bb82d)
2024-05-07 01:06:14 +00:00
Mark Andrews
58efb2f740 Address infinite loop when processing $GENERATE
In nibble mode if the value to be converted was negative the parser
would loop forever.  Process the value as an unsigned int instead
of as an int to prevent sign extension when shifting.

This was found by Eric Sesterhenn from X41.

(cherry picked from commit 371824f078)
2024-05-06 23:59:06 +00:00
Matthijs Mekking
4ef23ad0ff RPZ response's SOA record is incorrectly set to 1
An RPZ response's SOA record TTL is set to 1 instead of the SOA TTL,
a boolean value is passed on to query_addsoa, which is supposed to be
a TTL value. I don't see what value is appropriate to be used for
overriding, so we will pass UINT32_MAX.

(cherry picked from commit 5d7e613e81)
2024-05-06 12:18:08 +02:00
Mark Andrews
82ca80c2e9
Move onto the next RRSIG on DNS_R_SIGEXPIRED or DNS_R_SIGFUTURE 2024-04-30 17:47:49 +02:00
Michal Nowak
ea413a6fae Update sources to Clang 18 formatting
(cherry picked from commit f454fa6dea)
2024-04-23 12:48:56 +00:00
Matthijs Mekking
0134b91feb If kasp is not used, use legacy signature jitter
If the zone is signed with a different way than 'dnssec-policy', use
the legacy way of jittering signatures, that is calculate jitter by
taking the two values of 'sig-validity-interval' and subtracting the
second value from the first value.
2024-04-18 15:00:07 +00:00
Matthijs Mekking
f211c05990 Add checkconf check for signatures-jitter
Having a value higher than signatures-validity does not make sense
and should be treated as a configuration error.

(cherry picked from commit c3d8932f79)
2024-04-18 15:00:07 +00:00
Matthijs Mekking
2d8ed9d5d2 Implement signature jitter
When calculating the RRSIG validity, jitter is now derived from the
config option rather than from the refresh value.

(cherry picked from commit 67f403a423)
2024-04-18 15:00:07 +00:00
Matthijs Mekking
a1e61f179e Refactor code that calculates signature validity
There are three code blocks that are (almost) similar, refactor it
to one function.

(cherry picked from commit 0438d3655b)
2024-04-18 15:00:07 +00:00
Matthijs Mekking
104eabdc2e Add signatures-jitter option
Add an option to speficy signatures jitter.

(cherry picked from commit 2a4daaedca)
2024-04-18 15:00:07 +00:00
Michał Kępień
0107701681 Merge tag 'v9.18.25' into bind-9.18 2024-03-20 14:34:32 +01:00
Matthijs Mekking
a621e035d4 Detect invalid durations
Be stricter in durations that are accepted. Basically we accept ISO 8601
formats, but fail to detect garbage after the integers in such strings.

For example, 'P7.5D' will be treated as 7 days. Pass 'endptr' to
'strtoll' and check if the endptr is at the correct suffix.

(cherry picked from commit e39de45adc)
2024-03-14 11:40:43 +01:00
Mark Andrews
7498db6366 Don't use static stub when returning best NS
If we find a static stub zone in query_addbestns look for a parent
zone which isn't a static stub.

(cherry picked from commit 40816e4e35)
2024-03-14 15:33:25 +11:00
Evan Hunt
bc237c6f4a remove dead code in rbtdb.c
dns_db_addrdataset() enforces a requirement that version can only be
NULL for a cache database. code that checks for zone semantics and
version == NULL can never be reached.

(cherry picked from commit b3c8b5cfb2)
2024-03-13 18:21:44 -07:00