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

267 Commits

Author SHA1 Message Date
Mark Andrews
a6dba44b65 Use clang-format-20 to update formatting
(cherry picked from commit 422b9118e878d3106c84b2eac44371f7143f320b)
2025-06-25 13:59:44 +10:00
Evan Hunt
90989bfdfb prevent a reference leak from the ns_query_done hooks
if the NS_QUERY_DONE_BEGIN or NS_QUERY_DONE_SEND hook is
used in a plugin and returns NS_HOOK_RETURN, some of the
cleanup in ns_query_done() can be skipped over, leading
to reference leaks that can cause named to hang on shut
down.

this has been addressed by adding more housekeeping
code after the cleanup: tag in ns_query_done().

(cherry picked from commit c2e43582678ec5d0c40e19c671d60012b36ac312)
2025-02-25 22:41:27 +00:00
Aram Sargsyan
f1ec774f9a Fix RPZ bug when resuming a query during a reconfiguration
After a reconfiguration the old view can be left without a valid
'rpzs' member, because when the RPZ is not changed during the named
reconfiguration 'rpzs' "migrate" from the old view into the new
view, so when a query resumes it can find that 'qctx->view->rpzs'
is NULL which query_resume() currently doesn't expect to happen if
it's recursing and 'qctx->rpz_st' is not NULL.

Fix the issue by adding a NULL-check. In order to not split the log
message to two different log messages depending on whether
'qctx->view->rpzs' is NULL or not, change the message to not log
the RPZ policy's "version" which is just a runtime counter and is
most likely not very useful for the users.

(cherry picked from commit 3ea2fbc238e0d933b9f87dfd8fdab9233d978e33)
2025-02-21 11:45:52 +00:00
Ondřej Surý
fa7b7973e3 Limit the additional processing for large RDATA sets
When answering queries, don't add data to the additional section if
the answer has more than 13 names in the RDATA.  This limits the
number of lookups into the database(s) during a single client query,
reducing query processing load.

Also, don't append any additional data to type=ANY queries. The
answer to ANY is already big enough.

(cherry picked from commit a1982cf1bb95c818aa7b58988b5611dec80f2408)
2025-01-15 14:13:45 +01:00
Matthijs Mekking
a0ce89bc15 Implement global limit for outgoing queries
This global limit is not reset on query restarts and is a hard limit
for any client request.

Note: This commit has been significantly modified because of many
merge conflicts due to the dns_resolver_createfetch api changes.

(cherry picked from commit 16b3bd1cc743d3519a91edae896f394a689b0f0f)
2024-12-06 15:17:53 +00:00
Aram Sargsyan
b91b7093f2 Fix error path bugs in the "recursing-clients" list management
In two places, after linking the client to the manager's
"recursing-clients" list using the check_recursionquota()
function, the query.c module fails to unlink it on error
paths. Fix the bugs by unlinking the client from the list.

Also make sure that unlinking happens before detaching the
client's handle, as it is the logically correct order, e.g.
in case if it's the last handle and ns__client_reset_cb()
can be called because of the detachment.

(cherry picked from commit 36c4808903088fd547a09ddd79c35169387d4581)
2024-11-26 12:40:04 +00:00
Ondřej Surý
c5bac96fd0
Remove redundant parentheses from the return statement
(cherry picked from commit 0258850f202b7a46b52f3e3a4968c3fc68fe9a45)
2024-11-19 16:06:16 +01:00
Matthijs Mekking
ff53fd3951 Revert "Use a binary search to find the NSEC3 closest encloser"
This reverts commit 94f665591546fb064acd30b58026af3d3e671b1f.
2024-11-15 13:14:30 +00:00
Mark Andrews
94f6655915 Use a binary search to find the NSEC3 closest encloser
maxlabels is the suffix length that corresponds to the latest
NXDOMAIN response.  minlabels is the suffix length that corresponds
to longest found existing name.

(cherry picked from commit 67f31c504679dfcd9f1231037afa56da01e40d36)
2024-10-14 23:55:13 +00:00
Matthijs Mekking
60bd3bc051 Revert "fix: chg: Improve performance when looking for the closest encloser"
The 9.18 code does not have the rbtdb refactoring. Rather than
backporting from MR !9611, this reverts directly from commit
5d81a258e3c7988c9505bba9071e6db9ff327399.
2024-10-10 14:26:13 +02:00
Mark Andrews
5d81a258e3 Return partial match when requested
Return partial match from dns_db_find/dns_db_find when requested
to short circuit the closest encloser discover process.  Most of the
time this will be the actual closest encloser but may not be when
there yet to be committed / cleaned up versions of the zone with
names below the actual closest encloser.

(cherry picked from commit d42ea08f16bc6fc4b401f6b6f45a387cfb7f5d73)
2024-08-29 21:05:54 +00:00
Aram Sargsyan
30238a6172 Process also the ISC_R_CANCELED result code in rpz_rewrite()
Log  canceled queries (e.g. when shutting down a hung fetch)
in DEBUG3 level instead of DEBUG1 which is used for the
"unrecognized" result codes.

(cherry picked from commit 8bb9568467500cb80329972c92b1d53b9f9d0672)
2024-08-19 11:45:44 +00:00
Evan Hunt
bfbc6a6c84 make "max_restarts" a configurable value
MAX_RESTARTS is no longer hard-coded; ns_server_setmaxrestarts()
and dns_client_setmaxrestarts() can now be used to modify the
max-restarts value at runtime. in both cases, the default is 11.

(cherry picked from commit c5588babaf89f3e3ad2edccaada716e55c135dd3)
2024-08-07 15:36:15 -07:00
Evan Hunt
dd88a4cdfc reduce MAX_RESTARTS to 11
the number of steps that can be followed in a CNAME chain
before terminating the lookup has been reduced from 16 to 11.
(this is a hard-coded value, but will be made configurable later.)

(cherry picked from commit 05d78671bb6a5ba63d78d77339e17cbc73f18188)
2024-08-07 15:36:14 -07:00
Aram Sargsyan
946931ccb7 Return SERVFAIL for a too long CNAME chain
Due to the maximum query restart limitation a long CNAME chain
it is cut after 16 queries but named still returns NOERROR.

Return SERVFAIL instead and the partial answer.

(cherry picked from commit b621f1d88e2a8a4e22d871e90e58ef4bd4b6050f)
2024-07-31 15:14:43 +00:00
Mark Andrews
9cfd20cd90
Clear qctx->zversion
Clear qctx->zversion when clearing qctx->zrdataset et al in
lib/ns/query.c:qctx_freedata.  The uncleared pointer could lead to
an assertion failure if zone data needed to be re-saved which could
happen with stale data support enabled.

(cherry picked from commit 179fb3532ab8d4898ab070b2db54c0ce872ef709)
2024-06-10 19:20:06 +02: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 5d7e613e8103b81cf47a22c72310a38737fbe3c6)
2024-05-06 12:18:08 +02: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 40816e4e35a413d3241fed794afc16ce6db06c76)
2024-03-14 15:33:25 +11:00
Michał Kępień
4ad3c694f1 BIND 9.18.24
-----BEGIN PGP SIGNATURE-----
 
 iQJDBAABCgAtFiEENKwGS3ftSQfs1TU17QVz/8hFYQUFAmXIo/4PHG1pY2hhbEBp
 c2Mub3JnAAoJEO0Fc//IRWEFEe0QAJGj+gBVSNYgTM/ay4tbtmoTbJvmHbIcsRJn
 5ANQD5TPCm+tJCJ4ZFFFmdRiyP/ConXAms2UnyCPggd6hl4av9C32q1Wses9Qr1O
 ZOsgJ1tSuvCCihLTlRIZKdK3/J/fn/iLobgqTZfN6O06Voq6spjJwA7CMktwWr8f
 FsDiZVjnPZJhpnKkGJe3Nk6hsSJuTkF76tJgWSjg44q2PsQXVCUg5AfZBoWmrST0
 OHdhXCirTO1YbFBKL7444O+c/jV54/U+6dr8ofoWX/CRG1kkoQXy1eIdEMnbaruN
 3inzgxCJFiN8ZwwmqFjDmYsGD6jt7E11seBSE9nqX7JczDVOx6umwjNMM5AsCvaW
 BH9PZOli/AKyVXHia7WEpiVlFqsHCh10WvNFhCCv8Jqecy7HeKgQirW5SZUkHs4D
 y5/dzG+dSq3yX+mIM7s/5NyWEIWhsx7Q6m1FEY4uCyk8Z38YYeT0XzmRs62nXoa2
 KqdKUuNzZgBne5ECHRM6h2mA0luOIEJuj8t4xqqsOuPOzfkONJp8PSyStgktJwnf
 jAqZhSWQLF2222kowkCjDDJDqbIGulThntMo8VNRjSDuKgFDHJyk/j3cU0QLYGE9
 ZHc0KxjZbAmYQpCFwxETXPgl6i4VY4ax7yHi0mB7VqsG+5/djZarZObotYDp23yf
 VWzlqkac
 =BLMg
 -----END PGP SIGNATURE-----
gpgsig -----BEGIN SSH SIGNATURE-----
 U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAg25GGAuUyFX1gxo7QocNm8V6J/8
 frHSduYX7Aqk4iJLwAAAADZ2l0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5
 AAAAQPSjqDoHAxyeh5X6uWwlLa+g4ElTZhkKmKru+61PbSiGGZacV2z3fap5FAyyQz5oLS
 2Qn3cmhvo0jEeaIMOauwM=
 -----END SSH SIGNATURE-----

Merge tag 'v9.18.24' into bind-9.18

BIND 9.18.24
2024-02-14 13:35:19 +01:00
Aram Sargsyan
cbc0357881 Improve the definition of the DNS_GETDB_* flags
Use the (1 << N) form for defining the flags, in order to avoid
errors like the one fixed in the previous commit.

Also convert the definitions to an enum, as done in some of our
recent refactoring work.

(cherry picked from commit 0d7c7777da160ff0fc1fd2e4942826d8af50f1bf)
2024-02-02 15:06:48 +00:00
Aram Sargsyan
2bcd6c2fd3 Fix the DNS_GETDB_STALEFIRST flag
The DNS_GETDB_STALEFIRST flag is defined as 0x0C, which is the
combination of the DNS_GETDB_PARTIAL (0x04) and the
DNS_GETDB_IGNOREACL (0x08) flags (0x04 | 0x08 == 0x0C) , which is
an obvious error.

All the flags should be power of two, so they don't interfere with
each other. Fix the DNS_GETDB_STALEFIRST flag by setting it to 0x10.

(cherry picked from commit be7d8fafe292424ba0fdecf6687c5c72f85a25d1)
2024-02-02 15:06:43 +00:00
Matthijs Mekking
0d36d98791 Add new dns_rdatatype_iskeymaterial() function
The following code block repeats quite often:

    if (rdata.type == dns_rdatatype_dnskey ||
        rdata.type == dns_rdatatype_cdnskey ||
        rdata.type == dns_rdatatype_cds)

Introduce a new function to reduce the repetition.

(cherry picked from commit ef58f2444f4bc76891f89ad3344348232994a4df)
2024-01-12 19:56:54 +11:00
Mark Andrews
f7e137f321
Restore dns64 state during serve-stale processing
If we are in the process of looking for the A records as part of
dns64 processing and the server-stale timeout triggers, redo the
dns64 changes that had been made to the orignal qctx.

(cherry picked from commit 1fcc483df13e049b96f620e515f0d4d45f3680b7)
2024-01-05 12:20:25 +01:00
Mark Andrews
b42b1fe051
Save the correct result value to resume with nxdomain-redirect
The wrong result value was being saved for resumption with
nxdomain-redirect when performing the fetch.  This lead to an assert
when checking that RFC 1918 reverse queries where not leaking to
the global internet.

(cherry picked from commit 9d0fa07c5e7a39db89862a4f843d2190059afb4b)
2024-01-05 12:03:59 +01:00
Matthijs Mekking
76c9019403 Don't ignore auth zones when in serve-stale mode
When serve-stale is enabled and recursive resolution fails, the fallback
to lookup stale data always happens in the cache database. Any
authoritative data is ignored, and only information learned through
recursive resolution is examined.

If there is data in the cache that could lead to an answer, and this can
be just the root delegation, the resolver will iterate further, getting
closer to the answer that can be found by recursing down the root, and
eventually puts the final response in the cache.

Change the fallback to serve-stale to use 'query_getdb()', that finds
out the best matching database for the given query.

(cherry picked from commit 2322425016298a39d2e48153285aefdfecc9a510)
2023-10-31 13:52:08 +01:00
Michal Nowak
7c6632e174
Update the source code formatting using clang-format-17 2023-10-18 09:02:57 +02:00
Evan Hunt
07f6c63a80 prevent query_coveringnsec() from running twice
when synthesizing a new CNAME, we now check whether the target
matches the query already being processed. if so, we do not
restart the query; this prevents a waste of resources.

(cherry picked from commit 0ae8b2e056c3e24df0746541c505bc358352f7fa)
2023-08-21 14:31:10 -07:00
Mark Andrews
b3a97da7a7
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.

(cherry picked from commit dd00b3c50b6d173b90208c5f659c9ca55a55dd2e)
2023-06-28 12:31:49 +02:00
Matthijs Mekking
ff5bacf17c
Fix serve-stale hang at shutdown
The 'refresh_rrset' variable is used to determine if we can detach from
the client. This can cause a hang on shutdown. To fix this, move setting
of the 'nodetach' variable up to where 'refresh_rrset' is set (in
query_lookup(), and thus not in ns_query_done()), and set it to false
when actually refreshing the RRset, so that when this lookup is
completed, the client will be detached.
2023-06-09 14:54:48 +02:00
Evan Hunt
240caa32b9
Stale answer lookups could loop when over recursion quota
When a query was aborted because of the recursion quota being exceeded,
but triggered a stale answer response and a stale data refresh query,
it could cause named to loop back where we are iterating and following
a delegation. Having no good answer in cache, we would fall back to
using serve-stale again, use the stale data, try to refresh the RRset,
and loop back again, without ever terminating until crashing due to
stack overflow.

This happens because in the functions 'query_notfound()' and
'query_delegation_recurse()', we check whether we can fall back to
serving stale data. We shouldn't do so if we are already refreshing
an RRset due to having prioritized stale data in cache.

In other words, we need to add an extra check to 'query_usestale()' to
disallow serving stale data if we are currently refreshing a stale
RRset.

As an additional mitigation to prevent looping, we now use the result
code ISC_R_ALREADYRUNNING rather than ISC_R_FAILURE when a recursion
loop is encountered, and we check for that condition in
'query_usestale()' as well.
2023-06-09 14:54:48 +02:00
Matthijs Mekking
b90bad93cb Fix serve-stale bug when cache has no data
We recently fixed a bug where in some cases (when following an
expired CNAME for example), named could return SERVFAIL if the target
record is still valid (see isc-projects/bind9#3678, and
isc-projects/bind9!7096). We fixed this by considering non-stale
RRsets as well during the stale lookup.

However, this triggered a new bug because despite the answer from
cache not being stale, the lookup may be triggered by serve-stale.
If the answer from database is not stale, the fix in
isc-projects/bind9!7096 erroneously skips the serve-stale logic.

Add 'answer_found' checks to the serve-stale logic to fix this issue.

(cherry picked from commit bbd163acf67843c76099921e467dd0ef90f3f670)
2023-05-30 13:46:00 +02:00
Evan Hunt
9f1c6d9744 refactor dns_clientinfo_init(); use separate function to set ECS
Instead of using an extra rarely-used paramater to dns_clientinfo_init()
to set ECS information for a client, this commit adds a function
dns_clientinfo_setecs() which can be called only when ECS is needed.

(cherry picked from commit ff3fdaa424824a3fa49651872b4badaed6b1c5f7)
2023-02-08 00:13:12 -08:00
Michał Kępień
8b4dcc27ef BIND 9.18.11
-----BEGIN PGP SIGNATURE-----
 
 iQJDBAABCgAtFiEENKwGS3ftSQfs1TU17QVz/8hFYQUFAmPAh6gPHG1pY2hhbEBp
 c2Mub3JnAAoJEO0Fc//IRWEFyGsQAJuggfdFRAFzH6QTlE+jYPGGPGGAEp9+lFuP
 ufCdlek5FKN/V/NFpuMfNeyQ3NhK93ofMzaluAg47vM5Cj2/lPxUUFea7w20tHVm
 Nqsxk4Lc+RsnngVNUwWtA6CkwAGHDQA0Rwa3OEjqPkm33KLwCeC3w3ufv6KPlT7m
 MubNOd7BogMBxDg63TnOlSBjcKFi/TzGCNmOVj1cyOj9QP52XeIe6iKol4g47mWG
 erQ8ZKV/vWoIRCwLdPheRgCgO/2KyHLGbtI+uJ53OExiYnrKL18wGnt1Foo8Er9V
 hOkBykzgtWTtgrl8Ljd1lbR6FjZvLgcWWIZ6oM2RXjD25942lNgyWYubQHsRHchi
 /vnFD3qg5SBBbCHuzIzy9QCk2YYwJiDpI8t2RngzhJOexHGcCLYyM99yriqNYnFw
 DHoFkcUbJiHGhtEzzGuhz7LrSySclvqQRYbWLh7qcuUIKGdbPiWB8BmZtAkaFyaN
 fOJYwk8pSlpgvFqaAOicG3hAWTUxcJ5U/wWdBFk7Xg3wZ/K2XLuA88QgxePh2S2L
 kYBwwD81amWMEZct1hq9PW42vFFiWjJtZnTceZjCVARQamJ/+QgjUapMfbnYb1jN
 ry4XQoFz3FhfT4Ow2cKfRUzrh8lrNUJNqMoNiXDnj4jjH1YwIN6NqIYqrXJUGeCU
 yaaBGMu/
 =XdZL
 -----END PGP SIGNATURE-----

Merge tag 'v9_18_11' into v9_18

BIND 9.18.11
2023-01-25 21:26:22 +01:00
Aram Sargsyan
8f209c7dcf Refactor isc_nm_xfr_allowed()
Return 'isc_result_t' type value instead of 'bool' to indicate
the actual failure. Rename the function to something not suggesting
a boolean type result. Make changes in the places where the API
function is being used to check for the result code instead of
a boolean value.

(cherry picked from commit 41dc48bfd735b1fc21943bb9a636986cc5278662)
2023-01-19 12:20:10 +00:00
Aram Sargsyan
a4fc5e5158 Cancel all fetch events in dns_resolver_cancelfetch()
Although 'dns_fetch_t' fetch can have two associated events, one for
each of 'DNS_EVENT_FETCHDONE' and 'DNS_EVENT_TRYSTALE' types, the
dns_resolver_cancelfetch() function is designed in a way that it
expects only one existing event, which it must cancel, and when it
happens so that 'stale-answer-client-timeout' is enabled and there
are two events, only one of them is canceled, and it results in an
assertion in dns_resolver_destroyfetch(), when it finds a dangling
event.

Change the logic of dns_resolver_cancelfetch() function so that it
cancels both the events (if they exist), and in the right order.

(cherry picked from commit ec2098ca35039e4f81fd0aa7c525eb960b8f47bf)
2023-01-12 12:54:02 +01:00
Mark Andrews
38323f3b9f Move the mapping of SIG and RRSIG to ANY
dns_db_findext() asserts if RRSIG is passed to it and
query_lookup_stale() failed to map RRSIG to ANY to prevent this.  To
avoid cases like this in the future, move the mapping of SIG and RRSIG
to ANY for qctx->type to qctx_init().

(cherry picked from commit 56eae064183488bcf7ff08c3edf59f2e1742c1b6)
2023-01-12 12:27:28 +01:00
Michał Kępień
90408617d7 Check for NULL before dereferencing qctx->rpz_st
Commit 9ffb4a7ba11fae64a6ce2dd6390cd334372b7ab7 causes Clang Static
Analyzer to flag a potential NULL dereference in query_nxdomain():

    query.c:9394:26: warning: Dereference of null pointer [core.NullDereference]
            if (!qctx->nxrewrite || qctx->rpz_st->m.rpz->addsoa) {
                                    ^~~~~~~~~~~~~~~~~~~
    1 warning generated.

The warning above is for qctx->rpz_st potentially being a NULL pointer
when query_nxdomain() is called from query_resume().  This is a false
positive because none of the database lookup result codes currently
causing query_nxdomain() to be called (DNS_R_EMPTYWILD, DNS_R_NXDOMAIN)
can be returned by a database lookup following a recursive resolution
attempt.  Add a NULL check nevertheless in order to future-proof the
code and silence Clang Static Analyzer.

(cherry picked from commit 07592d1315412c38c978e8d009aace5d0f5bef93)
(cherry picked from commit a4547a109324fff1bdd21032c5c7d8fdeb0e4ad8)
2023-01-09 14:26:02 +01:00
Matthijs Mekking
271bc20b1c Consider non-stale data when in serve-stale mode
With 'stale-answer-enable yes;' and 'stale-answer-client-timeout off;',
consider the following situation:

A CNAME record and its target record are in the cache, then the CNAME
record expires, but the target record is still valid.

When a new query for the CNAME record arrives, and the query fails,
the stale record is used, and then the query "restarts" to follow
the CNAME target. The problem is that the query's multiple stale
options (like DNS_DBFIND_STALEOK) are not reset, so 'query_lookup()'
treats the restarted query as a lookup following a failed lookup,
and returns a SERVFAIL answer when there is no stale data found in the
cache, even if there is valid non-stale data there available.

With this change, query_lookup() now considers non-stale data in the
cache in the first place, and returns it if it is available.

(cherry picked from commit 91a1a8efc5bca44ff3aa6861c31759449ea65ecd)
2023-01-09 14:26:02 +01:00
Tom Krizek
f4d0b2dca9
Revert "Merge branch '3678-serve-stale-servfailing-unexpectedly-v9_18' into 'v9_18'"
This reverts commit 81b6f17e7c26e8c70e21969d971e0d6e7e9a6701, reversing
changes made to ea47a9c100873c522d88e7054353834f4df8cac9.

It also removes release note 6038, since the fix is reverted.
2022-12-08 10:22:33 +01:00
Mark Andrews
6f998bbe51 Extend dns_db_allrdatasets to control interation results
Add an options parameter to control what rdatasets are returned when
iteratating over the node.  Specific modes will be added later.

(cherry picked from commit 7695c36a5de01c441690f2a0e46f176321b58896)
2022-12-07 23:59:36 +00:00
Michał Kępień
a4547a1093 Check for NULL before dereferencing qctx->rpz_st
Commit 9ffb4a7ba11fae64a6ce2dd6390cd334372b7ab7 causes Clang Static
Analyzer to flag a potential NULL dereference in query_nxdomain():

    query.c:9394:26: warning: Dereference of null pointer [core.NullDereference]
            if (!qctx->nxrewrite || qctx->rpz_st->m.rpz->addsoa) {
                                    ^~~~~~~~~~~~~~~~~~~
    1 warning generated.

The warning above is for qctx->rpz_st potentially being a NULL pointer
when query_nxdomain() is called from query_resume().  This is a false
positive because none of the database lookup result codes currently
causing query_nxdomain() to be called (DNS_R_EMPTYWILD, DNS_R_NXDOMAIN)
can be returned by a database lookup following a recursive resolution
attempt.  Add a NULL check nevertheless in order to future-proof the
code and silence Clang Static Analyzer.

(cherry picked from commit 07592d1315412c38c978e8d009aace5d0f5bef93)
2022-12-06 13:47:51 +00:00
Matthijs Mekking
65443cb59f Consider non-stale data when in serve-stale mode
With 'stale-answer-enable yes;' and 'stale-answer-client-timeout off;',
consider the following situation:

A CNAME record and its target record are in the cache, then the CNAME
record expires, but the target record is still valid.

When a new query for the CNAME record arrives, and the query fails,
the stale record is used, and then the query "restarts" to follow
the CNAME target. The problem is that the query's multiple stale
options (like DNS_DBFIND_STALEOK) are not reset, so 'query_lookup()'
treats the restarted query as a lookup following a failed lookup,
and returns a SERVFAIL answer when there is no stale data found in the
cache, even if there is valid non-stale data there available.

With this change, query_lookup() now considers non-stale data in the
cache in the first place, and returns it if it is available.

(cherry picked from commit 86a80e723fc7b6bdd87174f4a48aa702dbe17c5a)
2022-12-06 13:47:22 +00:00
Michal Nowak
1d7d504338
Update sources to Clang 15 formatting 2022-11-29 09:14:07 +01:00
Evan Hunt
2cc8874c90 ensure RPZ lookups handle CD=1 correctly
RPZ rewrites called dns_db_findext() without passing through the
client database options; as as result, if the client set CD=1,
DNS_DBFIND_PENDINGOK was not used as it should have been, and
cache lookups failed, resulting in failure of the rewrite.

(cherry picked from commit 305a50dbe12a43b0ee429c2e9bee04f35a8047c4)
2022-10-19 13:12:31 -07:00
Aram Sargsyan
82991451b4 Fix ns_statscounter_recursclients counting bug
The incrementing and decrementing of 'ns_statscounter_recursclients'
were not properly balanced: for example, it would be incremented for
a prefetch query but not decremented if the query failed.

This commit ensures that the recursion quota and the recursive clients
counter are always in sync with each other.
2022-10-18 08:54:04 +00:00
Michał Kępień
0a53f61727 BIND 9.18.7
-----BEGIN PGP SIGNATURE-----
 
 iQJDBAABCgAtFiEENKwGS3ftSQfs1TU17QVz/8hFYQUFAmMZ4qIPHG1pY2hhbEBp
 c2Mub3JnAAoJEO0Fc//IRWEFpl0QAItVxvXJ2yQw+06QhlmA7l0pmKgAqKzgwzcD
 hpOsYsglMGhkyry+eWr+XOSEyU/MAIHSvhaKvvlicZMrthe4wmip4O0M24BldVmL
 Vvqb8/0vg2/8hom9aJu9NgRaGX/ybewauIG21drPR4O6MnLfX+8m0c0bbO1I60bn
 xSL5OX1DzDYJhMQ+hBlG2hTlEhovtXBFZYpTR2H9ITvXMrDJNbs3VQZLKFrD56Ge
 WitoPeE4lkGpDcPTtFys3siRJjIOAl9jKUZWqfnhmiYGC0USMmXneEEuM9/sMXFv
 jh0AtymJbe0s9bceYD961RE1pd9cdbrUg+6EJIhoGqNL+ANtj61jtdpLtWwWWKgU
 3MiEJF7YQLQ0lWXArUtMTRwWUYeVpxPprzwXIdQfiTp35fTBoOzL3rslq4HdVCxA
 SPtAunI8OFsr2Njglf2VsJfcX0x7V4lbftnmY3e24b+C+YXddRVc+83cGZvh2kvB
 NKY2Y8/Op8BsFyUoJ69Umcrx+xZSmO0ngEA62lKjJ/oAZ/WaQ8bkcajCdtLYKFJd
 rTXw/UsdKQDlUQ/rCU/Ge+Y/BKFRn3f7UA0D0Mvp+DpTus9DYMvy/nWWphVgWNGP
 E2j/1orf/dGdWojvFLGe4zPl8BCRHqgoxfGBaizR4N3eTKHcOS2uVJJ0x4WfY9xe
 nUKGK+iw
 =OVc+
 -----END PGP SIGNATURE-----

Merge tag 'v9_18_7' into v9_18

BIND 9.18.7
2022-09-21 13:13:30 +02:00
Petr Špaček
c095ac9ad1
Log reason why cache peek is not available
Log which ACL caused RD=0 query into cache to be refused.
Expected performance impact is negligible.

(cherry picked from commit fdf74566432a67761bf940224e6145ea435f5edf)
2022-09-15 09:41:01 +02:00
Matthijs Mekking
b9e2f3333d Only refresh RRset once
Don't attempt to resolve DNS responses for intermediate results. This
may create multiple refreshes and can cause a crash.

One scenario is where for the query there is a CNAME and canonical
answer in cache that are both stale. This will trigger a refresh of
the RRsets because we encountered stale data and we prioritized it over
the lookup. It will trigger a refresh of both RRsets. When we start
recursing, it will detect a recursion loop because the recursion
parameters will eventually be the same. In 'dns_resolver_destroyfetch'
the sanity check fails, one of the callers did not get its event back
before trying to destroy the fetch.

Move the call to 'query_refresh_rrset' to 'ns_query_done', so that it
is only called once per client request.

Another scenario is where for the query there is a stale CNAME in the
cache that points to a record that is also in cache but not stale. This
will trigger a refresh of the RRset (because we encountered stale data
and we prioritized it over the lookup).

We mark RRsets that we add to the message with
DNS_RDATASETATTR_STALE_ADDED to prevent adding a duplicate RRset when
a stale lookup and a normal lookup conflict with each other. However,
the other non-stale RRset when following a CNAME chain will be added to
the message without setting that attribute, because it is not stale.

This is a variant of the bug in #2594. The fix covered the same crash
but for stale-answer-client-timeout > 0.

Fix this by clearing all RRsets from the message before refreshing.
This requires the refresh to happen after the query is send back to
the client.

(cherry picked from commit d939d2ecde5639d11acd6eac33a997b3e3c78b02)
2022-09-08 11:50:44 +02:00
Aram Sargsyan
35e37505f0 Fix RRL responses-per-second bypass using wildcard names
It is possible to bypass Response Rate Limiting (RRL)
`responses-per-second` limitation using specially crafted wildcard
names, because the current implementation, when encountering a found
DNS name generated from a wildcard record, just strips the leftmost
label of the name before making a key for the bucket.

While that technique helps with limiting random requests like
<random>.example.com (because all those requests will be accounted
as belonging to a bucket constructed from "example.com" name), it does
not help with random names like subdomain.<random>.example.com.

The best solution would have been to strip not just the leftmost
label, but as many labels as necessary until reaching the suffix part
of the wildcard record from which the found name is generated, however,
we do not have that information readily available in the context of RRL
processing code.

Fix the issue by interpreting all valid wildcard domain names as
the zone's origin name concatenated to the "*" name, so they all will
be put into the same bucket.

(cherry picked from commit baa9698c9d4bed741cdff14a07f1c71c81b21908)
2022-09-08 09:36:50 +02:00
Matthijs Mekking
5e908a988f Don't enable serve-stale on duplicate queries
When checking if we should enable serve-stale, add an early out case
when the result is an error signalling a duplicate query or a query
that would be dropped.

(cherry picked from commit 059a4c2f4d9d3cff371842f43208d021509314fa)
2022-08-09 09:36:11 +02:00