11489 Commits
Author SHA1 Message Date
Tinderbox User c06787e095 prep 9.11.29 2021-03-09 12:49:04 +00:00
Mark Andrews dc88bd641d Address unchecked returns leading to NULL pointer dereferences
on out of memory conditions.
2021-02-25 11:44:28 +11:00
Michal Nowak b9ef330fbe Initialize checknames field in dns_view_create()
The 'checknames' field wasn't initialized in dns_view_create(), but it
should otherwise AddressSanitizer identifies the following runtime error
in query_test.c.

    runtime error: load of value 190, which is not a valid value for type '_Bool'

(cherry picked from commit 0c6fa16477)
2021-02-23 16:48:10 +01:00
Mark Andrews 0ee76590d6 Correctly detect when get_direction failed
(cherry picked from commit 009358d77d)
2021-02-19 11:40:05 +11:00
Mark Andrews 4af7a5f1b1 Test a LOC record with an invalid direction field
(cherry picked from commit 07902d9f9d)
2021-02-19 11:40:04 +11:00
Tinderbox UserandMichał Kępień 43ef3488bf prep 9.11.28 2021-02-17 22:46:14 +01:00
Ondřej SurýandMichał Kępień abed9404d1 Fix off-by-one bug in ISC SPNEGO implementation
The ISC SPNEGO implementation is based on mod_auth_kerb code.  When
CVE-2006-5989 was disclosed, the relevant fix was not applied to the
BIND 9 codebase, making the latter vulnerable to the aforementioned flaw
when "tkey-gssapi-keytab" or "tkey-gssapi-credential" is set in
named.conf.

The original description of CVE-2006-5989 was:

    Off-by-one error in the der_get_oid function in mod_auth_kerb 5.0
    allows remote attackers to cause a denial of service (crash) via a
    crafted Kerberos message that triggers a heap-based buffer overflow
    in the component array.

Later research revealed that this flaw also theoretically enables remote
code execution, though achieving the latter in real-world conditions is
currently deemed very difficult.

This vulnerability was responsibly reported as ZDI-CAN-12302 ("ISC BIND
TKEY Query Heap-based Buffer Overflow Remote Code Execution
Vulnerability") by Trend Micro Zero Day Initiative.
2021-02-17 22:46:14 +01:00
Tinderbox UserandMichał Kępień 177d66e39f prep 9.11.27 2021-01-21 09:38:24 +01:00
Michal Nowak 187fd98bca update for 2021 2021-01-06 16:55:54 +01:00
Mark Andrews 25150c15e7 Inactive incorrectly incremented
It is possible to have two threads destroying an rbtdb at the same
time when detachnode() executes and removes the last reference to
a node between exiting being set to true for the node and testing
if the references are zero in maybe_free_rbtdb().  Move NODE_UNLOCK()
to after checking if references is zero to prevent detachnode()
changing the reference count too early.

(cherry picked from commit 859d2fdad6)
2021-01-06 19:18:54 +11:00
Mark Andrews f63b2d8fbd update link order of libbind9 2020-12-21 01:10:00 +00:00
Tinderbox UserandMichał Kępień 363a2c3e5e prep 9.11.26 2020-12-16 22:32:08 +01:00
Mark Andrews 042e1e3a44 Lock check of DNS_ZONEFLG_EXITING flag
WARNING: ThreadSanitizer: data race
    Read of size 4 at 0x000000000001 by thread T1 (mutexes: write M1):
    #0 dns_zone_refresh lib/dns/zone.c:10447
    #1 dns_zone_notifyreceive2 lib/dns/zone.c:13646
    #2 dns_zone_notifyreceive2 lib/dns/zone.c:13497
    #3 ns_notify_start bin/named/notify.c:150
    #4 client_request bin/named/client.c:3137
    #5 dispatch lib/isc/task.c:1157
    #6 run lib/isc/task.c:1331
    #7 <null> <null>

    Previous write of size 4 at 0x000000000001 by thread T2 (mutexes: write M2):
    #0 dns_zone_refresh lib/dns/zone.c:10466
    #1 zone_maintenance lib/dns/zone.c:10236
    #2 zone_timer lib/dns/zone.c:13136
    #3 dispatch lib/isc/task.c:1157
    #4 run lib/isc/task.c:1331
    #5 <null> <null>
2020-12-10 06:31:20 +00:00
Mark Andrews 7982767d4a Ignore TSAN errors with getcounter and setcounter
WARNING: ThreadSanitizer: data race
    Read of size 8 at 0x000000000001 by thread T1:
    #0 getcounter lib/isc/stats.c:289:15
    #1 isc_stats_update_if_greater lib/isc/stats.c:464:24
    #2 client_accept bin/named/client.c:3599:2
    #3 client_start bin/named/client.c:833:4
    #4 dispatch lib/isc/task.c:1157:7
    #5 run lib/isc/task.c:1331:2

    Previous write of size 8 at 0x000000000001 by thread T2:
    #0 setcounter lib/isc/stats.c:313:27
    #1 isc_stats_update_if_greater lib/isc/stats.c:466:3
    #2 client_accept bin/named/client.c:3599:2
    #3 client_start bin/named/client.c:833:4
    #4 dispatch lib/isc/task.c:1157:7
    #5 run lib/isc/task.c:1331:2
2020-12-10 06:31:19 +00:00
Ondřej SurýandMark Andrews 761cedc2b4 Don't use rwlocks for reference counting
WARNING: ThreadSanitizer: data race
    Write of size 8 at 0x000000000001 by thread T1 (mutexes: write M1):
    #0 memset <null>
    #1 mem_put lib/isc/mem.c:819
    #2 isc___mem_free lib/isc/mem.c:1662
    #3 isc__mem_free lib/isc/mem.c:3078
    #4 isc___mem_putanddetach lib/isc/mem.c:1221
    #5 isc__mem_putanddetach lib/isc/mem.c:3033
    #6 destroyring lib/dns/tsig.c:494
    #7 dns_tsigkeyring_dumpanddetach lib/dns/tsig.c:665
    #8 destroy lib/dns/view.c:392
    #9 dns_view_weakdetach lib/dns/view.c:704
    #10 zone_free lib/dns/zone.c:1152
    #11 zone_shutdown lib/dns/zone.c:13123
    #12 dispatch lib/isc/task.c:1157
    #13 run lib/isc/task.c:1331
    #14 <null> <null>

    Previous atomic read of size 8 at 0x000000000001 by thread T2:
    #0 __tsan_atomic64_load <null>
    #1 isc_rwlock_unlock lib/isc/rwlock.c:612
    #2 dns_tsigkeyring_dumpanddetach lib/dns/tsig.c:632
    #3 destroy lib/dns/view.c:392
    #4 dns_view_weakdetach lib/dns/view.c:704
    #5 zone_free lib/dns/zone.c:1149
    #6 zone_shutdown lib/dns/zone.c:13123
    #7 dispatch lib/isc/task.c:1157
    #8 run lib/isc/task.c:1331
    #9 <null> <null>
2020-12-10 06:31:19 +00:00
Mark Andrews d85196cdca Ignore TSAN errors accessing init_count and header->count
WARNING: ThreadSanitizer: data race
    Write of size 4 at 0x000000000001 by thread T1 (mutexes: write M1):
    #0 subtractrdataset lib/dns/rbtdb.c:7065:21
    #1 dns_db_subtractrdataset lib/dns/db.c:807:10
    #2 diff_apply lib/dns/diff.c:377:14
    #3 dns_diff_apply lib/dns/diff.c:458:10
    #4 do_one_tuple lib/dns/zone.c:4103:11
    #5 update_one_rr lib/dns/zone.c:4132:10
    #6 keyfetch_done lib/dns/zone.c:9835:4
    #7 dispatch lib/isc/task.c:1157:7
    #8 run lib/isc/task.c:1331:2

    Previous write of size 4 at 0x000000000001 by thread T2 (mutexes: write M2):
    #0 addrdataset lib/dns/rbtdb.c:6869:21
    #1 dns_db_addrdataset lib/dns/db.c:783:10
    #2 addoptout lib/dns/ncache.c:264:10
    #3 dns_ncache_add lib/dns/ncache.c:101:10
    #4 ncache_adderesult lib/dns/resolver.c:5989:12
    #5 ncache_message lib/dns/resolver.c:6165:11
    #6 resquery_response lib/dns/resolver.c:8691:12
    #7 dispatch lib/isc/task.c:1157:7
    #8 run lib/isc/task.c:1331:2
2020-12-10 06:31:19 +00:00
Mark Andrews fdb893ede1 Address data race in dns_stats_detach over references
WARNING: ThreadSanitizer: data race
    Write of size 4 at 0x000000000001 by thread T1 (mutexes: write M1):
    #0 dns_stats_detach lib/dns/stats.c:115:19
    #1 destroy lib/dns/view.c:527:3
    #2 dns_view_weakdetach lib/dns/view.c:704:3
    #3 zone_free lib/dns/zone.c:1149:3
    #4 zone_shutdown lib/dns/zone.c:13123:3
    #5 dispatch lib/isc/task.c:1157:7
    #6 run lib/isc/task.c:1331:2

    Previous read of size 4 at 0x000000000001 by thread T2:
    #0 dns_stats_detach lib/dns/stats.c:118:13
    #1 destroy lib/dns/view.c:527:3
    #2 dns_view_weakdetach lib/dns/view.c:704:3
    #3 zone_free lib/dns/zone.c:1152:3
    #4 zone_shutdown lib/dns/zone.c:13123:3
    #5 dispatch lib/isc/task.c:1157:7
    #6 run lib/isc/task.c:1331:2
2020-12-10 06:31:19 +00:00
Mark Andrews e989ba66f0 Lock access to acache stats when not using atomics
WARNING: ThreadSanitizer: data race
    Write of size 4 at 0x000000000001 by thread T1 (mutexes: write M1):
    #0 dns_acache_getentry lib/dns/acache.c:1549:2
    #1 rdataset_getadditional lib/dns/rbtdb.c:9912:11
    #2 dns_rdataset_getadditional lib/dns/rdataset.c:711:11
    #3 query_addadditional2 bin/named/query.c:1991:11
    #4 additionaldata_ns lib/dns/./rdata/generic/ns_2.c:198:10
    #5 dns_rdata_additionaldata lib/dns/rdata.c:1246:2
    #6 dns_rdataset_additionaldata lib/dns/rdataset.c:629:12
    #7 query_addrdataset bin/named/query.c:2435:8
    #8 query_addrrset bin/named/query.c:2826:2
    #9 query_addbestns bin/named/query.c:3525:2
    #10 query_find bin/named/query.c:9204:4
    #11 query_resume bin/named/query.c:4188:12
    #12 dispatch lib/isc/task.c:1157:7
    #13 run lib/isc/task.c:1331:2

    Previous write of size 4 at 0x000000000001 by thread T2 (mutexes: write M2):
    #0 dns_acache_countquerymiss lib/dns/acache.c:1201:2
    #1 rdataset_getadditional lib/dns/rbtdb.c:9896:4
    #2 dns_rdataset_getadditional lib/dns/rdataset.c:711:11
    #3 query_addadditional2 bin/named/query.c:1991:11
    #4 additionaldata_ns lib/dns/./rdata/generic/ns_2.c:198:10
    #5 dns_rdata_additionaldata lib/dns/rdata.c:1246:2
    #6 dns_rdataset_additionaldata lib/dns/rdataset.c:629:12
    #7 query_addrdataset bin/named/query.c:2435:8
    #8 query_addrrset bin/named/query.c:2826:2
    #9 query_find bin/named/query.c:9176:4
    #10 query_resume bin/named/query.c:4188:12
    #11 dispatch lib/isc/task.c:1157:7
2020-12-10 06:31:19 +00:00
Mark Andrews d4a59f232e Ignore TSAN warnings in state_key_init - deliberate
WARNING: ThreadSanitizer: data race
    Write of size 1 at 0x000000000001 by thread T1 (mutexes: write M1, write M2):
    #0 state_key_init lib/dns/geoip2.c:150:5
    #1 get_entry_for lib/dns/geoip2.c:241:11
    #2 dns_geoip_match lib/dns/geoip2.c:410:10
    #3 dns_aclelement_match2 lib/dns/acl.c:493:11
    #4 dns_acl_match2 lib/dns/acl.c:298:7
    #5 allowed bin/named/client.c:1869:11
    #6 ns_client_isself bin/named/client.c:1934:7
    #7 notify_isself lib/dns/zone.c:11055:11
    #8 notify_send lib/dns/zone.c:11374:7
    #9 notify_find_address lib/dns/zone.c:11178:2
    #10 zone_notify lib/dns/zone.c:11616:3
    #11 zone_maintenance lib/dns/zone.c:10291:4
    #12 zone_timer lib/dns/zone.c:13136:2
    #13 dispatch lib/isc/task.c:1157:7
    #14 run lib/isc/task.c:1331:2

    Previous read of size 1 at 0x000000000001 by thread T2 (mutexes: write M3):
    #0 state_key_init lib/dns/geoip2.c:134:7
    #1 get_entry_for lib/dns/geoip2.c:241:11
    #2 dns_geoip_match lib/dns/geoip2.c:410:10
    #3 dns_aclelement_match2 lib/dns/acl.c:493:11
    #4 dns_acl_match2 lib/dns/acl.c:298:7
    #5 allowed bin/named/client.c:1869:11
    #6 ns_client_isself bin/named/client.c:1934:7
    #7 notify_isself lib/dns/zone.c:11055:11
    #8 notify_send lib/dns/zone.c:11374:7
    #9 notify_find_address lib/dns/zone.c:11178:2
    #10 zone_notify lib/dns/zone.c:11616:3
    #11 zone_maintenance lib/dns/zone.c:10291:4
    #12 zone_timer lib/dns/zone.c:13136:2
    #13 dispatch lib/isc/task.c:1157:7
    #14 run lib/isc/task.c:1331:2
2020-12-10 06:31:19 +00:00
Mark Andrews 5f6ab3512e Silence TSAN warning on spins in isc_rwlock_lock
WARNING: ThreadSanitizer: data race
    Write of size 4 at 0x000000000001 by thread T1:
    #0 isc_rwlock_lock lib/isc/rwlock.c:720:2
    #1 findnodeintree lib/dns/rbtdb.c:3060:2
    #2 findnsec3node lib/dns/rbtdb.c:3164:10
    #3 dns_db_findnsec3node lib/dns/db.c:528:10
    #4 diff_apply lib/dns/diff.c:318:5
    #5 dns_diff_applysilently lib/dns/diff.c:463:10
    #6 signname bin/dnssec/./dnssec-signzone.c:1118:11
    #7 sign bin/dnssec/./dnssec-signzone.c:1599:2
    #8 dispatch lib/isc/task.c:1157:7
    #9 run lib/isc/task.c:1331:2

    Previous read of size 4 at 0x000000000001 by thread T2:
    #0 isc_rwlock_lock lib/isc/rwlock.c:704:25
    #1 addrdataset lib/dns/rbtdb.c:6853:2
    #2 dns_db_addrdataset lib/dns/db.c:783:10
    #3 diff_apply lib/dns/diff.c:370:14
    #4 dns_diff_applysilently lib/dns/diff.c:463:10
    #5 signname bin/dnssec/./dnssec-signzone.c:1118:11
    #6 sign bin/dnssec/./dnssec-signzone.c:1599:2
    #7 dispatch lib/isc/task.c:1157:7
    #8 run lib/isc/task.c:1331:2
2020-12-10 06:31:19 +00:00
Mark Andrews a241c69920 Lock read of refs when atomics are not available.
WARNING: ThreadSanitizer: data race
    Read of size 4 at 0x000000000001 by thread T1 (mutexes: write M1):
    #0 zone_iattach lib/dns/zone.c:5412:2
    #1 soa_query lib/dns/zone.c:12725:2
    #2 dispatch lib/isc/task.c:1157:7
    #3 run lib/isc/task.c:1331:2

    Previous write of size 4 at 0x000000000001 by thread T2 (mutexes: write M2):
    #0 dns_zone_detach lib/dns/zone.c:5346:2
    #1 ns_server_refreshcommand bin/named/./server.c:9880:3
    #2 ns_control_docommand bin/named/control.c:247:12
    #3 control_recvmessage bin/named/controlconf.c:469:13
    #4 dispatch lib/isc/task.c:1157:7
    #5 run lib/isc/task.c:1331:2
2020-12-10 06:31:19 +00:00
Mark Andrews 1caef804d5 Ignore thread sanitizer warnings in stats counters
set ISC_NO_SANITIZE_THREAD for incrementcounter and decrementcounter

    WARNING: ThreadSanitizer: data race
    Write of size 8 at 0x000000000001 by thread T1:
    #0 decrementcounter lib/isc/stats.c:258:26
    #1 isc_stats_decrement lib/isc/stats.c:350:2
    #2 dec_stats lib/isc/unix/socket.c:934:3
    #3 socketclose lib/isc/unix/socket.c:2270:3
    #4 destroy lib/isc/unix/socket.c:2323:3
    #5 isc__socket_detach lib/isc/unix/socket.c:3275:3
    #6 isc_socket_detach lib/isc/unix/./../socket_api.c:128:3
    #7 exit_check bin/named/client.c:593:4
    #8 ns_client_next bin/named/client.c:947:8
    #9 client_request bin/named/client.c
    #10 dispatch lib/isc/task.c:1157:7
    #11 run lib/isc/task.c:1331:2

    Previous write of size 8 at 0x000000000001 by thread T2:
    #0 incrementcounter lib/isc/stats.c:239:26
    #1 isc_stats_increment lib/isc/stats.c:340:2
    #2 inc_stats lib/isc/unix/socket.c:923:3
    #3 internal_accept lib/isc/unix/socket.c:3741:4
    #4 dispatch lib/isc/task.c:1157:7
    #5 run lib/isc/task.c:1331:2
2020-12-10 06:31:19 +00:00
Mark Andrews 0e5a076cc1 Prevent inlining of code with thread sanitiser disabled 2020-12-10 06:31:19 +00:00
Mark Andrews f3c402baed Only lock access to epoll_ctl when using watcher thread 2020-12-10 02:34:36 +00:00
Mark Andrews 7466b505b3 check result 2020-12-10 02:34:36 +00:00
Mark Andrews 136804b1a0 #ifdef protect key_mutex 2020-12-10 02:34:36 +00:00
Petr MensikandMark Andrews 839350f5f6 Pass task_test also with threads disabled
Condition cv is declared only when threads are used. Use it only in that
case. Test compiles and passes without thread support also.
2020-12-01 23:06:19 +00:00
Mark Andrews d09991e4e9 Adjust default value of "max-recursion-queries"
Since the queries sent towards root and TLD servers are now included in
the count (as a result of the fix for CVE-2020-8616),
"max-recursion-queries" has a higher chance of being exceeded by
non-attack queries.  Increase its default value from 75 to 100.

(cherry picked from commit ab0bf49203)
2020-12-01 22:13:05 +00:00
Mark Andrews 0e7a4169bd Fix misplaced declaration
(cherry picked from commit 49b9219bb3)
2020-12-01 23:19:46 +11:00
Michał Kępień dfdd3a8a2f Make DocBook sources namespaced again
Every DocBook source document can be namespaced (DocBook 5) or
non-namespaced (DocBook 4).  The set of XSL stylesheets used for
producing an output document can also be namespaced or non-namespaced.
Namespaced source documents should be used with namespaced stylesheets
and non-namespaced source documents should be used with non-namespaced
stylesheets.  However, both stylesheet flavors contain processing rules
which allow them to be used interchangeably for any type of source
document.

Unfortunately, these processing rules became broken in version 1.79.1 of
the stylesheets, which means that non-namespaced source documents can no
longer be correctly transformed into man pages using namespaced
stylesheets and vice versa.  This problem was fixed upstream [1], but no
released version of the XSL stylesheets contains that fix yet.

Back in 2016, this problem was reported as RT #43831 and allegedly fixed
in commit 1b8ce3b330.  However, that fix
only helped for the non-namespaced version of the stylesheets - while
also breaking man page generation for the namespaced flavor.

Since using namespaced DocBook sources is the current best practice
(DocBook 5), make BIND DocBook sources namespaced again.  When using
version 1.79.1 or 1.79.2 of the XSL stylesheets, care must be taken to
ensure namespaced stylesheets are used for generating BIND
documentation.

[1] https://github.com/docbook/xslt10-stylesheets/issues/109
2020-11-30 09:33:32 +01:00
Mark Andrews 28f1cbb007 Add comment about cookie sizes
(cherry picked from commit 304df53991)
2020-11-27 10:20:40 +11:00
Mark Andrews cdf73095ab Tighten DNS COOKIE response handling
Fallback to TCP when we have already seen a DNS COOKIE response
from the given address and don't have one in this UDP response. This
could be a server that has turned off DNS COOKIE support, a
misconfigured anycast server with partial DNS COOKIE support, or a
spoofed response. Falling back to TCP is the correct behaviour in
all 3 cases.

(cherry picked from commit 0e3b1f5a25)
2020-11-27 09:28:09 +11:00
Michal Nowak bbed152e5d Fix typo in ISC_PLAFORM_HAVESYSUNH
(cherry picked from commit 8885f4a6f7)
2020-11-26 15:09:36 +01:00
Michał Kępień fa989e4236 Use proper cmocka macros for pointer checks
Make sure pointer checks in unit tests use cmocka assertion macros
dedicated for use with pointers instead of those dedicated for use with
integers or booleans.

(cherry picked from commit f440600126)
2020-11-26 13:15:28 +01:00
Tinderbox UserandMichał Kępień 66faf3215c prep 9.11.25 2020-11-26 12:33:58 +01:00
Mark AndrewsandMichał Kępień c5fff690ad Remove now redundant check for state != NULL
(cherry picked from commit ee135d8946)
2020-11-25 13:42:12 +01:00
Michał Kępień 47c206f386 Silence cppcheck 2.2 false positive in udp_recv()
cppcheck 2.2 reports the following false positive:

    lib/dns/dispatch.c:1220:14: warning: Either the condition 'resp==NULL' is redundant or there is possible null pointer dereference: resp. [nullPointerRedundantCheck]
     if (disp != resp->disp) {
                 ^
    lib/dns/dispatch.c:1191:11: note: Assuming that condition 'resp==NULL' is not redundant
     if (resp == NULL) {
              ^
    lib/dns/dispatch.c:1220:14: note: Null pointer dereference
     if (disp != resp->disp) {
                 ^

Apparently this version of cppcheck gets confused about conditional
"goto" statements because line 1220 can never be reached if 'resp' is
NULL.

Move a code block to prevent the above false positive from being
reported without affecting the processing logic.

(cherry picked from commit 0b6216d1c7)
2020-11-25 13:42:12 +01:00
Mark Andrews 62158e1882 Address TSAN error between dns_rbt_findnode() and subtractrdataset().
Having dns_rbt_findnode() in previous_closest_nsec() check of
node->data is a optimisation that triggers a TSAN error with
subtractrdataset().  find_closest_nsec() still needs to check if
the NSEC record are active or not and look for a earlier NSEC records
if it isn't.  Set DNS_RBTFIND_EMPTYDATA so node->data isn't referenced
without the node lock being held.

    WARNING: ThreadSanitizer: data race
    Read of size 8 at 0x000000000001 by thread T1 (mutexes: read M1, read M2):
    #0 dns_rbt_findnode lib/dns/rbt.c:1708
    #1 previous_closest_nsec lib/dns/rbtdb.c:3760
    #2 find_closest_nsec lib/dns/rbtdb.c:3942
    #3 zone_find lib/dns/rbtdb.c:4091
    #4 dns_db_findext lib/dns/db.c:536
    #5 query_lookup lib/ns/query.c:5582
    #6 ns__query_start lib/ns/query.c:5505
    #7 query_setup lib/ns/query.c:5229
    #8 ns_query_start lib/ns/query.c:11380
    #9 ns__client_request lib/ns/client.c:2166
    #10 processbuffer netmgr/tcpdns.c:230
    #11 dnslisten_readcb netmgr/tcpdns.c:309
    #12 read_cb netmgr/tcp.c:832
    #13 <null> <null>
    #14 <null> <null>

    Previous write of size 8 at 0x000000000001 by thread T2 (mutexes: write M3):
    #0 subtractrdataset lib/dns/rbtdb.c:7133
    #1 dns_db_subtractrdataset lib/dns/db.c:742
    #2 diff_apply lib/dns/diff.c:368
    #3 dns_diff_apply lib/dns/diff.c:459
    #4 do_one_tuple lib/dns/update.c:247
    #5 update_one_rr lib/dns/update.c:275
    #6 delete_if_action lib/dns/update.c:689
    #7 foreach_rr lib/dns/update.c:471
    #8 delete_if lib/dns/update.c:716
    #9 dns_update_signaturesinc lib/dns/update.c:1948
    #10 receive_secure_serial lib/dns/zone.c:15637
    #11 dispatch lib/isc/task.c:1152
    #12 run lib/isc/task.c:1344
    #13 <null> <null>

    Location is heap block of size 130 at 0x000000000028 allocated by thread T3:
    #0 malloc <null>
    #1 default_memalloc lib/isc/mem.c:713
    #2 mem_get lib/isc/mem.c:622
    #3 mem_allocateunlocked lib/isc/mem.c:1268
    #4 isc___mem_allocate lib/isc/mem.c:1288
    #5 isc__mem_allocate lib/isc/mem.c:2453
    #6 isc___mem_get lib/isc/mem.c:1037
    #7 isc__mem_get lib/isc/mem.c:2432
    #8 create_node lib/dns/rbt.c:2239
    #9 dns_rbt_addnode lib/dns/rbt.c:1202
    #10 dns_rbtdb_create lib/dns/rbtdb.c:8668
    #11 dns_db_create lib/dns/db.c:118
    #12 receive_secure_db lib/dns/zone.c:16154
    #13 dispatch lib/isc/task.c:1152
    #14 run lib/isc/task.c:1344
    #15 <null> <null>

    Mutex M1 (0x000000000040) created at:
    #0 pthread_rwlock_init <null>
    #1 isc_rwlock_init lib/isc/rwlock.c:39
    #2 dns_rbtdb_create lib/dns/rbtdb.c:8527
    #3 dns_db_create lib/dns/db.c:118
    #4 receive_secure_db lib/dns/zone.c:16154
    #5 dispatch lib/isc/task.c:1152
    #6 run lib/isc/task.c:1344
    #7 <null> <null>

    Mutex M2 (0x000000000044) created at:
    #0 pthread_rwlock_init <null>
    #1 isc_rwlock_init lib/isc/rwlock.c:39
    #2 dns_rbtdb_create lib/dns/rbtdb.c:8600
    #3 dns_db_create lib/dns/db.c:118
    #4 receive_secure_db lib/dns/zone.c:16154
    #5 dispatch lib/isc/task.c:1152
    #6 run lib/isc/task.c:1344
    #7 <null> <null>

    Mutex M3 (0x000000000046) created at:
    #0 pthread_rwlock_init <null>
    #1 isc_rwlock_init lib/isc/rwlock.c:39
    #2 dns_rbtdb_create lib/dns/rbtdb.c:8600
    #3 dns_db_create lib/dns/db.c:118
    #4 receive_secure_db lib/dns/zone.c:16154
    #5 dispatch lib/isc/task.c:1152
    #6 run lib/isc/task.c:1344
    #7 <null> <null>

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

    Thread T2 (running) created by main thread at:
    #0 pthread_create <null>
    #1 isc_thread_create pthreads/thread.c:73
    #2 isc_taskmgr_create lib/isc/task.c:1434
    #3 create_managers bin/named/main.c:915
    #4 setup bin/named/main.c:1223
    #5 main bin/named/main.c:1523

    Thread T3 (running) created by main thread at:
    #0 pthread_create <null>
    #1 isc_thread_create pthreads/thread.c:73
    #2 isc_taskmgr_create lib/isc/task.c:1434
    #3 create_managers bin/named/main.c:915
    #4 setup bin/named/main.c:1223
    #5 main bin/named/main.c:1523

    SUMMARY: ThreadSanitizer: data race lib/dns/rbt.c:1708 in dns_rbt_findnode

(cherry picked from commit 244f84a84b)
2020-11-11 08:25:55 +11:00
Mark Andrews b2bccc68a5 Lock zone before calling zone_namerd_tostr()
WARNING: ThreadSanitizer: data race
    Read of size 8 at 0x000000000001 by thread T1:
    #0 inline_raw lib/dns/zone.c:1375
    #1 zone_namerd_tostr lib/dns/zone.c:15316
    #2 dns_zone_name lib/dns/zone.c:15391
    #3 xfrin_log lib/dns/xfrin.c:1605
    #4 xfrin_destroy lib/dns/xfrin.c:1477
    #5 dns_xfrin_detach lib/dns/xfrin.c:739
    #6 xfrin_connect_done lib/dns/xfrin.c:970
    #7 tcpdnsconnect_cb netmgr/tcpdns.c:786
    #8 tcp_connect_cb netmgr/tcp.c:292
    #9 <null> <null>
    #10 <null> <null>

    Previous write of size 8 at 0x000000000001 by thread T2 (mutexes: write M1):
    #0 zone_shutdown lib/dns/zone.c:14462
    #1 dispatch lib/isc/task.c:1152
    #2 run lib/isc/task.c:1344
    #3 <null> <null>

    Location is heap block of size 2769 at 0x000000000013 allocated by thread T3:
    #0 malloc <null>
    #1 default_memalloc lib/isc/mem.c:713
    #2 mem_get lib/isc/mem.c:622
    #3 mem_allocateunlocked lib/isc/mem.c:1268
    #4 isc___mem_allocate lib/isc/mem.c:1288
    #5 isc__mem_allocate lib/isc/mem.c:2453
    #6 isc___mem_get lib/isc/mem.c:1037
    #7 isc__mem_get lib/isc/mem.c:2432
    #8 dns_zone_create lib/dns/zone.c:984
    #9 configure_zone bin/named/server.c:6502
    #10 do_addzone bin/named/server.c:13391
    #11 named_server_changezone bin/named/server.c:13788
    #12 named_control_docommand bin/named/control.c:207
    #13 control_command bin/named/controlconf.c:392
    #14 dispatch lib/isc/task.c:1152
    #15 run lib/isc/task.c:1344
    #16 <null> <null>

(cherry picked from commit 84f43903da)
2020-11-10 17:16:43 +11:00
Mark Andrews ee53b9558f Call nta_detach() before dns_view_weakdetach() so view is available.
(cherry picked from commit ea956976d1)
2020-11-03 23:50:19 +11:00
Michał Kępień 7f13c427a9 Fix getrbp()
The following compiler warning is emitted for the BACKTRACE_X86STACK
part of lib/isc/backtrace.c:

    backtrace.c: In function ‘getrbp’:
    backtrace.c:139:1: warning: no return statement in function returning non-void [-Wreturn-type]

While getrbp() stores the value of the RBP register in the RAX register
and thus does attempt to return a value, this is not enough for an
optimizing compiler to always produce the expected result.  With -O2,
the following machine code may be generated in isc_backtrace_gettrace():

    0x00007ffff7b0ff7a <+10>:	mov    %rbp,%rax
    0x00007ffff7b0ff7d <+13>:	mov    $0x17,%eax
    0x00007ffff7b0ff82 <+18>:	retq

The above is equivalent to:

    sp = (void **)getrbp();
    return (ISC_R_NOTFOUND);

and results in the backtrace never getting printed.

Fix by using an intermediate variable.  With this change in place, the
machine code generated with -O2 becomes something like:

    0x00007ffff7af5638 <+24>:	mov    $0x17,%eax
    0x00007ffff7af563d <+29>:	mov    %rbp,%rdx
    0x00007ffff7af5640 <+32>:	test   %rdx,%rdx
    0x00007ffff7af5643 <+35>:	je     0x7ffff7af56bd <isc_backtrace_gettrace+157>
    ...
    0x00007ffff7af56bd <+157>:	retq

(Note that this method of grabbing a stack trace is finicky anyway
because in order for RBP to be relied upon, -fno-omit-stack-frame must
be present among CFLAGS.)

(cherry picked from commit 923c443389)
2020-10-30 09:42:24 +01:00
Michał Kępień a51cde6ceb Check for _Unwind_Backtrace() support
Some operating systems (e.g. Linux, FreeBSD) provide the
_Unwind_Backtrace() function in libgcc_s.so, which is automatically
linked into any binary using the functions provided by that library.  On
OpenBSD, though, _Unwind_Backtrace() is provided by libc++abi.so, which
is not automatically linked into binaries produced by the stock system C
compiler.

Meanwhile, lib/isc/backtrace.c assumes that any GNU-compatible toolchain
allows _Unwind_Backtrace() to be used without any extra provisions in
the build system.  This causes build failures on OpenBSD (and possibly
other systems).

Instead of making assumptions, actually check for _Unwind_Backtrace()
support in the toolchain if the backtrace() function is unavailable.

(cherry picked from commit 10d7055791)
2020-10-30 09:42:24 +01:00
Mark Andrews 4a4605fbef Handle DNS_R_NCACHENXRRSET in fetch_callback_{dnskey,validator}()
DNS_R_NCACHENXRRSET can be return when zones are in transition state
from being unsigned to signed and signed to unsigned.  The validation
should be resumed and should result in a insecure answer.

(cherry picked from commit 718e597def)
2020-10-30 08:25:03 +11:00
Mark AndrewsandMichał Kępień adc090a478 address 'make depend' issues
(cherry picked from commit 06fa0d7b4e)
2020-10-28 11:00:34 +01:00
Diego Fronza 6b97de3813 Fix transfer of glue records in stub zones if master has minimal-responses set
Stub zones don't make use of AXFR/IXFR for the transfering of zone
data, instead, a single query is issued to the master asking for
their nameserver records (NS).

That works fine unless master is configured with 'minimal-responses'
set to yes, in which case glue records are not provided by master
in the answer with nameservers authoritative for the zone, leaving
stub zones with incomplete databases.

This commit fix this problem in a simple way, when the answer with
the authoritative nameservers is received from master (stub_callback),
for each nameserver listed (save_nsrrset), a A and AAAA records for
the name is verified in the additional section, and if not present
a query is created to resolve the corresponsing missing glue.

A struct 'stub_cb_args' was added to keep relevant information for
performing a query, like TSIG key, udp size, dscp value, etc, this
information is borrowed from, and created within function 'ns_query',
where the resolving of nameserver from master starts.

A new field was added to the struct 'dns_stub', an atomic integer,
namely pending_requests, which is used to keep how many queries are
created when resolving nameserver addresses that were missing in
the glue.

When the value of pending_requests is zero we know we can release
resources, adjust zone timers, dump to zone file, etc.
2020-10-26 10:45:27 -03:00
Mark Andrews 86d9d04fd8 Hold qid->lock when calling deref_portentry() as
socket_search() need portentry to be unchanging.

    WARNING: ThreadSanitizer: data race
    Write of size 8 at 0x000000000001 by thread T1 (mutexes: write M1):
    #0 deref_portentry lib/dns/dispatch.c:630
    #1 deactivate_dispsocket lib/dns/dispatch.c:861
    #2 udp_recv lib/dns/dispatch.c:1105
    #3 udp_exrecv lib/dns/dispatch.c:1028
    #4 dispatch lib/isc/task.c:1152
    #5 run lib/isc/task.c:1344
    #6 <null> <null>

    Previous read of size 8 at 0x000000000001 by thread T2 (mutexes: write M1, write M2):
    #0 socket_search lib/dns/dispatch.c:661
    #1 get_dispsocket lib/dns/dispatch.c:744
    #2 dns_dispatch_addresponse lib/dns/dispatch.c:3120
    #3 resquery_send lib/dns/resolver.c:2467
    #4 fctx_query lib/dns/resolver.c:2217
    #5 fctx_try lib/dns/resolver.c:4245
    #6 fctx_timeout lib/dns/resolver.c:4570
    #7 dispatch lib/isc/task.c:1152
    #8 run lib/isc/task.c:1344
    #9 <null> <null>

(cherry picked from commit 5c253c416d)
2020-10-24 08:23:31 +11:00
Mark Andrews a2d2161be4 DNS_ZONEFLAG_NOIXFR should be DNS_ZONEFLG_NOIXFR
(cherry picked from commit 3a044444bd)
2020-10-24 00:29:07 +11:00
Tinderbox UserandMichał Kępień 6995173371 prep 9.11.24 2020-10-22 09:22:48 +02:00
Mark Andrews 56e8628e92 Restore the dns_message_reset() call before the dns_dispatch_getnext()
This was accidentally lost in the process of moving rmessage from fctx
to query.  Without this dns_message_setclass() will fail.
2020-10-08 13:10:31 +11:00
Witold KręcickiandMichal Nowak 09a3431069 Fix 'error: ‘%s’ directive argument is null [-Werror=format-overflow=]' in assertions.c
(cherry picked from commit f4260dc0c5)
2020-10-07 10:26:47 +02:00