Commit Graph
8941 Commits
Author SHA1 Message Date
Diego FronzaandOndřej Surý 79c62017eb Properly handling dns_message_t shared references
This commit fix the problems that arose when moving the dns_message_t
object from fetchctx_t to the query structure.

Since the lifetime of query objects are different than that of a
fetchctx and the dns_message_t object held by the query may be being
used by some external module, e.g. validator, even after the query may
have been destroyed, propery handling of the references to the message
were added in this commit to avoid accessing an already destroyed
object.

Specifically, in resquery_response(), a reference to the message is
attached at the beginning of the function and detached at the end, since
a possible call to fctx_cancelquery() would release the dns_message_t
object, and in the next lines of code a call to add_bad() would require
a valid pointer to the same object.

In valcreate() a new reference is attached to the message object, this
ensures that if the corresponding query object is destroyed before the
validator attempts to access it, no invalid pointer access occurs.

In validated() we have to attach a new reference to the message, since
we destroy the validator object at the beginning of the function, and we
need access to the message in the next lines of the same function.
2020-09-30 14:04:04 +02:00
Diego FronzaandOndřej Surý 8781aef52e Refactored dns_message_t for using attach/detach semantics
This commit will be used as a base for the next code updates in order
to have a better control of dns_message_t objects' lifetime.
2020-09-30 13:33:43 +02:00
Mark Andrews d95a18711b Break lock order loop by sending TAT in an event
The dotat() function has been changed to send the TAT
query asynchronously, so there's no lock order loop
because we initialize the data first and then we schedule
the TAT send to happen asynchronously.

This breaks following lock-order loops:

zone->lock (dns_zone_setviewcommit) while holding view->lock
(dns_view_setviewcommit)

keytable->lock (dns_keytable_find) while holding zone->lock
(zone_asyncload)

view->lock (dns_view_findzonecut) while holding keytable->lock
(dns_keytable_forall)

(cherry picked from commit 3c4b68af7c)
2020-09-22 23:35:39 +10:00
Mark Andrews 7247df0fcf Lock access to control->symtab to prevent data race
WARNING: ThreadSanitizer: data race
    Read of size 8 at 0x000000000001 by thread T1:
    #0 isccc_symtab_foreach lib/isccc/symtab.c:277:14
    #1 isccc_cc_cleansymtab lib/isccc/cc.c:954:2
    #2 control_recvmessage bin/named/controlconf.c:477:2
    #3 recv_data lib/isccc/ccmsg.c:110:2
    #4 read_cb lib/isc/netmgr/tcp.c:769:4
    #5 <null> <null>

    Previous write of size 8 at 0x000000000001 by thread T2:
    #0 isccc_symtab_define lib/isccc/symtab.c:242:2
    #1 isccc_cc_checkdup lib/isccc/cc.c:1026:11
    #2 control_recvmessage bin/named/controlconf.c:478:11
    #3 recv_data lib/isccc/ccmsg.c:110:2
    #4 read_cb lib/isc/netmgr/tcp.c:769:4
    #5 <null> <null>

    Location is heap block of size 190352 at 0x000000000011 allocated by main thread:
    #0 malloc <null>
    #1 isccc_symtab_create lib/isccc/symtab.c:76:18
    #2 isccc_cc_createsymtab lib/isccc/cc.c:948:10
    #3 named_controls_create bin/named/controlconf.c:1483:11
    #4 named_server_create bin/named/server.c:10057:2
    #5 setup bin/named/main.c:1256:2
    #6 main bin/named/main.c:1523:2

    Thread T1 (running) created by main thread at:
    #0 pthread_create <null>
    #1 isc_thread_create lib/isc/pthreads/thread.c:73:8
    #2 isc_nm_start lib/isc/netmgr/netmgr.c:215:3
    #3 create_managers bin/named/main.c:909:15
    #4 setup bin/named/main.c:1223:11
    #5 main bin/named/main.c:1523:2

    Thread T2 (running) created by main thread at:
    #0 pthread_create <null>
    #1 isc_thread_create lib/isc/pthreads/thread.c:73:8
    #2 isc_nm_start lib/isc/netmgr/netmgr.c:215:3
    #3 create_managers bin/named/main.c:909:15
    #4 setup bin/named/main.c:1223:11
    #5 main bin/named/main.c:1523:2

    SUMMARY: ThreadSanitizer: data race lib/isccc/symtab.c:277:14 in isccc_symtab_foreach

(cherry picked from commit 0450acc1b6)
2020-09-17 20:06:27 +10:00
Tinderbox UserandMichał Kępień e7b0d5de15 prep 9.11.23 2020-09-16 23:00:15 +02:00
Evan Hunt 400171aee8 update all copyright headers to eliminate the typo 2020-09-14 17:00:40 -07:00
Mark Andrews e5ecb7f57d Wait for test instance of named to exit before completing subtest.
(cherry picked from commit dda5b7b0b8)
2020-09-10 20:41:00 +10:00
Mark Andrews 6dcdee08e9 Don't use production address (127.0.0.1) in runtime system test.
(cherry picked from commit 1f14705938)
2020-09-10 20:21:03 +10:00
Mark Andrews dc30a355bd Also wait for 'zone_dump: zone example/IN: enter'
use nextpartpeek as we don't want to reset the starting point

(cherry picked from commit 7b65bea6d2)
2020-09-10 18:48:52 +10:00
Mark Andrews ed0cb2e9e4 Use ns_g_server->recursionquota instead of client->recursionquota
as the later will be NULL on ISC_R_QUOTA.

*** CID 306732:  Null pointer dereferences  (FORWARD_NULL)
/bin/named/query.c: 4359 in query_recurse()
4353     			static _Atomic(isc_stdtime_t) last = 0;
4354     #else
4355     			static isc_stdtime_t last = 0;
4356     #endif
4357     			isc_stdtime_t now;
4358     			isc_stdtime_get(&now);
   CID 306732:  Null pointer dereferences  (FORWARD_NULL)
   Passing "client" to "log_quota", which dereferences null "client->recursionquota".
4359     			log_quota(client, &last, now,
4360     				  "no more recursive clients (%d/%d/%d): %s",
4361     				  isc_result_totext(result));
4362     			ns_client_killoldestquery(client);
4363     		}
4364     		if (result == ISC_R_SUCCESS && !client->mortal &&

** CID 306731:  Program hangs  (LOCK)
/lib/dns/resolver.c: 8943 in spillattimer_countdown()
2020-09-09 06:01:54 +00:00
Mark Andrews d6c727d669 ISC_QUEUE_POP is not tsan safe. Suppress warnings
ret->link.next is tested to see if it is NULL unlocked
to avoid obtaining taillock when it is not nexessary then
retested once the taillock is obtained.
2020-09-08 17:41:33 +10:00
Mark Andrews 6d9b1ed70c Address data race over query_recurse.last
WARNING: ThreadSanitizer: data race
  Read of size 4 at 0x000000000001 by thread T1:
    #0 query_recurse bin/named/query.c:4291:15
    #1 query_find bin/named/query.c
    #2 ns_query_start bin/named/query.c:9675:8
    #3 client_request bin/named/client.c:3133:3
    #4 dispatch lib/isc/task.c:1157:7
    #5 run lib/isc/task.c:1331:2

  Previous write of size 4 at 0x000000000001 by thread T2:
    #0 query_recurse bin/named/query.c:4292:10
    #1 query_find bin/named/query.c
    #2 ns_query_start bin/named/query.c:9675:8
    #3 client_request bin/named/client.c:3133:3
    #4 dispatch lib/isc/task.c:1157:7
    #5 run lib/isc/task.c:1331:2

  Location is global 'query_recurse.last' of size 4 at 0x000000000001
2020-09-08 09:25:43 +10:00
Mark Andrews 72cbe648c4 Test if linked while holding the queue lock
WARNING: ThreadSanitizer: data race
  Read of size 8 at 0x000000000001 by thread T1:
    #0 client_shutdown bin/named/client.c:849:6
    #1 dispatch lib/isc/task.c:1157:7
    #2 run lib/isc/task.c:1331:2

  Previous write of size 8 at 0x000000000001 by thread T2 (mutexes: write M1, write M2):
    #0 client_shutdown bin/named/client.c:850:3
    #1 dispatch lib/isc/task.c:1157:7
    #2 run lib/isc/task.c:1331:2
2020-09-08 09:25:43 +10:00
Mark Andrews be4ed41611 Obtain a lock on the quota structure.
WARNING: ThreadSanitizer: data race (pid=15228)
  Read of size 4 at 0x7b5c00000444 by thread T8:
    #0 ns_server_status /builds/isc-projects/bind9/bin/named/./server.c:10935:31 (named+0x514671)
    #1 ns_control_docommand /builds/isc-projects/bind9/bin/named/control.c:263:12 (named+0x4e4726)
    #2 control_recvmessage /builds/isc-projects/bind9/bin/named/controlconf.c:465:13 (named+0x4e9046)
    #3 dispatch /builds/isc-projects/bind9/lib/isc/task.c:1157:7 (libisc.so.1107+0x50845)
    #4 run /builds/isc-projects/bind9/lib/isc/task.c:1331:2 (libisc.so.1107+0x4d799)

  Previous write of size 4 at 0x7b5c00000444 by thread T9 (mutexes: write M1082):
    #0 isc_quota_release /builds/isc-projects/bind9/lib/isc/quota.c:73:13 (libisc.so.1107+0x3bf10)
    #1 isc_quota_detach /builds/isc-projects/bind9/lib/isc/quota.c:111:2 (libisc.so.1107+0x3c12b)
    #2 ns_client_endrequest /builds/isc-projects/bind9/bin/named/client.c:896:3 (named+0x4dcad1)
    #3 exit_check /builds/isc-projects/bind9/bin/named/client.c:512:3 (named+0x4d570d)
    #4 ns_client_detach /builds/isc-projects/bind9/bin/named/client.c:3687:8 (named+0x4d7732)
    #5 query_find /builds/isc-projects/bind9/bin/named/query.c (named+0x4f8ff1)
    #6 query_resume /builds/isc-projects/bind9/bin/named/query.c:4164:12 (named+0x509b38)
    #7 dispatch /builds/isc-projects/bind9/lib/isc/task.c:1157:7 (libisc.so.1107+0x50845)
    #8 run /builds/isc-projects/bind9/lib/isc/task.c:1331:2 (libisc.so.1107+0x4d799)
2020-09-08 09:25:43 +10:00
Mark Andrews 818520216d Missing locks in ns_lwresd_shutdown.
WARNING: ThreadSanitizer: data race
  Read of size 8 at 0x000000000001 by main thread:
    #0 ns_lwresd_shutdown bin/named/lwresd.c:885:3
    #1 destroy_managers bin/named/./main.c:938:2
    #2 cleanup bin/named/./main.c:1346:2
    #3 main bin/named/./main.c:1594:2

  Previous write of size 8 at 0x000000000001 by thread T1 (mutexes: write M1):
    #0 configure_listener bin/named/lwresd.c:768:2
    #1 ns_lwresd_configure bin/named/lwresd.c:836:5
    #2 load_configuration bin/named/./server.c:8230:2
    #3 run_server bin/named/./server.c
    #4 dispatch lib/isc/task.c:1157:7
    #5 run lib/isc/task.c:1331:2
2020-09-08 09:25:43 +10:00
Mark Andrews 00d315046b Defer read of zl->server and zl->reconfig until
the reference counter has gone to zero and there is
nolonger a possibility of changes in other threads.
2020-09-08 09:25:43 +10:00
Mark Andrews a26d0c5ef3 Access ns_client_requests atomically 2020-09-08 09:25:43 +10:00
Mark Andrews 690f557b09 Don't run dyndb and dlzexternal if running TSAN as
the dlopen flags being used are incompatible with TSAN.

(cherry picked from commit 86316ed29d)
2020-09-08 08:46:14 +10:00
Mark Andrews b66b5a096c alphabetize tests/usage
(cherry picked from commit bbece7389e)
2020-09-08 08:43:45 +10:00
Mark Andrews b1c36e7818 Check 'deny name' + 'grant subdomain' for the same name
(cherry picked from commit a402ffbced)
2020-09-03 16:22:54 +10:00
Mark Andrews b2c93102de Increase zone load timeout in the "rndc" test
The "huge.zone" zone can take longer than 100 seconds to load when
running under a sanitizer.  Increase the relevant zone load timeout to
prevent intermittent failures of the "rndc" system test.

(cherry picked from commit fd08918df5)
2020-09-03 07:15:54 +10:00
Mark Andrews 46dc1c34f9 dig +bufsize=0 failed to disable EDNS as a side effect.
(cherry picked from commit 0dc04cb901)
2020-09-02 20:47:19 +10:00
Mark AndrewsandOndřej Surý c237ca4d43 Dump the returned packet 2020-09-02 08:54:40 +02:00
Ondřej Surý 36ec930560 Add -r <repeats> option to packet.pl
For some tests, we need to send big data streams (for TCP) or repeated
packets (for UDP), this commits adds `-r` option to packet.pl that sends
the same input <repeats> times using the specified protocol.

(cherry picked from commit dd46559a19)
2020-09-02 08:54:40 +02:00
Ondřej Surý abae6c0f95 Properly format 2037-pk11_numbits-crash-test.pkt file
(cherry picked from commit 22e0272063)
2020-09-02 08:54:40 +02:00
Ondřej SurýandOndřej Surý a40151fe76 Add PoC system test for pk11_numbits() assertion
(cherry picked from commit a69433ba40)
2020-08-31 11:49:36 +02:00
Mark AndrewsandOndřej Surý 78d0355f30 check that a malformed truncated response to a TSIG query is handled
(cherry picked from commit 8bbf3eb5f3)
2020-08-31 08:35:10 +02:00
Evan Hunt 15d57a425e Merge tag 'v9_11_22' into v9_11
BIND 9.11.22
2020-08-20 12:10:47 -07:00
Michal Nowak d79c96da01 Make sure .txt files are not identified as crashed test
Previously .txt files with full backtrace may be identified as a
crashed test:

    I:Core dumps were found for the following system tests:
    I:	 core.19948-backtrace.txt
    I:   shutdown

Now .txt files are removed from the list.

Change 'run.sh.in' to match the core matching pattern in
'testsummary.sh'.

(cherry picked from commit c2dcd95966)
(cherry picked from commit 01119ac4f9)
2020-08-12 09:56:16 +02:00
Mark Andrews 1cc06636fc Ensure rl_message() gets prototype.
(cherry picked from commit fd126553d4)
2020-08-12 09:46:31 +10:00
Mark Andrews fd370a250d Stop deprecated functions being defined
(cherry picked from commit 1532a34658)
2020-08-12 09:42:34 +10:00
Mark Andrews f155ff75e4 Check isc_mutex_init() return values 2020-08-11 01:19:02 +00:00
Mark AndrewsandMichał Kępień 58e560beb5 Add a test for update-policy 'zonesub'
The new test checks that 'update-policy zonesub' is properly enforced.
2020-08-05 15:55:14 +02:00
Mark AndrewsandMichał Kępień 393e8f643c Add a test for update-policy 'subdomain'
The new test checks that 'update-policy subdomain' is properly enforced.
2020-08-05 15:55:14 +02:00
Mark AndrewsandMichał Kępień e4cccf9668 Update-policy 'subdomain' was incorrectly treated as 'zonesub'
resulting in names outside the specified subdomain having the wrong
restrictions for the given key.
2020-08-05 15:55:14 +02:00
Mark Andrews d3281b80a9 Check rcode is FORMERR
(cherry picked from commit 88ff6b846c)
2020-08-04 23:08:49 +10:00
Mark Andrews 5770740587 Map DNS_R_BADTSIG to FORMERR
Now that the log message has been printed set the result code to
DNS_R_FORMERR.  We don't do this via dns_result_torcode() as we
don't want upstream errors to produce FORMERR if that processing
end with DNS_R_BADTSIG.

(cherry picked from commit 20488d6ad3)
2020-08-04 23:07:02 +10:00
Michal Nowak fc1e50e73a Fix name of the test directory of stop.pl in masterformat test 2020-07-31 09:26:51 +02:00
Michal Nowak 9470e9e469 Ensure test fails if packet.pl does not work as expected 2020-07-31 09:26:51 +02:00
Michał Kępień 41e2117866 Only run system tests as root in developer mode
Running system tests with root privileges is potentially dangerous.
Only allow it when explicitly requested (by building with
--enable-developer).

(cherry picked from commit 3ef106f69d)
2020-07-31 07:47:49 +02:00
Diego FronzaandEvan Hunt 4bc9ee1844 Update copyrights 2020-07-27 13:40:50 -07:00
Diego FronzaandEvan Hunt 40fd600f25 Add test for RPZ wildcard passthru ignored fix 2020-07-27 13:40:50 -07:00
Mark Andrews b424dfaada Check walking the hip rendezvous servers.
Also fixes extraneous white space at end of record when
there are no rendezvous servers.

(cherry picked from commit 78db46d746)
2020-07-24 15:43:54 +10:00
Petr MenšíkandMark Andrews 35fbfaa498 Prevent crash on dst initialization failure
server might be created, but not yet fully initialized, when fatal
function is called. Check both server and task before attaching
exclusive task.

(cherry picked from commit c5e7152cf0)
2020-07-23 11:29:57 +10:00
Michal Nowak 3745767b2b Check tests for core files regardless of test status
Failed test should be checked for core files et al. and have
backtrace generated.
2020-07-20 17:09:20 +02:00
Michal Nowak 9996811493 Rationalize backtrace logging
GDB backtrace generated via "thread apply all bt full" is too long for
standard output, lets save them to .txt file among other log files.
2020-07-20 17:00:13 +02:00
Evan Hunt 0f7f6201e3 make sure new_zone_lock is locked before unlocking it
it was possible for the count_newzones() function to try to
unlock view->new_zone_lock on return before locking it, which
caused a crash on shutdown.

(cherry picked from commit ed37c63e2b)
2020-07-13 12:32:51 -07:00
Mark Andrews 55f567ab35 Fallback to built in trust-anchors, managed-keys, or trusted-keys
if the bind.keys file cannot be parsed.

(cherry picked from commit d02a14c795)
2020-07-13 15:55:59 +10:00
Michał Kępień 25818ac81f Fix locking for LMDB 0.9.26
When "rndc reconfig" is run, named first configures a fresh set of views
and then tears down the old views.  Consider what happens for a single
view with LMDB enabled; "envA" is the pointer to the LMDB environment
used by the original/old version of the view, "envB" is the pointer to
the same LMDB environment used by the new version of that view:

 1. mdb_env_open(envA) is called when the view is first created.
 2. "rndc reconfig" is called.
 3. mdb_env_open(envB) is called for the new instance of the view.
 4. mdb_env_close(envA) is called for the old instance of the view.

This seems to have worked so far.  However, an upstream change [1] in
LMDB which will be part of its 0.9.26 release prevents the above
sequence of calls from working as intended because the locktable mutexes
will now get destroyed by the mdb_env_close() call in step 4 above,
causing any subsequent mdb_txn_begin() calls to fail (because all of the
above steps are happening within a single named process).

Preventing the above scenario from happening would require either
redesigning the way we use LMDB in BIND, which is not something we can
easily backport, or redesigning the way BIND carries out its
reconfiguration process, which would be an even more severe change.

To work around the problem, set MDB_NOLOCK when calling mdb_env_open()
to stop LMDB from controlling concurrent access to the database and do
the necessary locking in named instead.  Reuse the view->new_zone_lock
mutex for this purpose to prevent the need for modifying struct dns_view
(which would necessitate library API version bumps).  Drop use of
MDB_NOTLS as it is made redundant by MDB_NOLOCK: MDB_NOTLS only affects
where LMDB reader locktable slots are stored while MDB_NOLOCK prevents
the reader locktable from being used altogether.

[1] https://git.openldap.org/openldap/openldap/-/commit/2fd44e325195ae81664eb5dc36e7d265927c5ebc

(cherry picked from commit 53120279b5)
2020-07-10 11:31:43 +02:00
Michał KępieńandMark Andrews 74a738428c Silence PyYAML warning
Make yaml.load_all() use yaml.SafeLoader to address a warning currently
emitted when bin/tests/system/dnstap/ydump.py is run:

    ydump.py:28: YAMLLoadWarning: calling yaml.load_all() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
      for l in yaml.load_all(f.stdout):

(cherry picked from commit 62f631f798)
2020-06-30 11:43:35 +10:00