Commit Graph
1162 Commits
Author SHA1 Message Date
Evan Hunt 400171aee8 update all copyright headers to eliminate the typo 2020-09-14 17:00:40 -07: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 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 fb8a3c9ab2 Remove optimisation on obtaining a headlock as it triggers a tsan.
WARNING: ThreadSanitizer: data race (pid=15898)
  Write of size 8 at 0x7b6400011818 by thread T9 (mutexes: write M1597):
    #0 get_client /builds/isc-projects/bind9/bin/named/client.c:3876:3 (named+0x4db171)
    #1 ns_client_replace /builds/isc-projects/bind9/bin/named/client.c:3710:12 (named+0x4d737b)
    #2 query_recurse /builds/isc-projects/bind9/bin/named/query.c:4325:13 (named+0x4ff469)
    #3 query_find /builds/isc-projects/bind9/bin/named/query.c (named+0x4fb949)
    #4 ns_query_start /builds/isc-projects/bind9/bin/named/query.c:9675:8 (named+0x4f37cb)
    #5 client_request /builds/isc-projects/bind9/bin/named/client.c:3112:3 (named+0x4de9ef)
    #6 dispatch /builds/isc-projects/bind9/lib/isc/task.c:1157:7 (libisc.so.1107+0x50845)
    #7 run /builds/isc-projects/bind9/lib/isc/task.c:1331:2 (libisc.so.1107+0x4d799)

  Previous read of size 8 at 0x7b6400011818 by thread T2:
    #0 exit_check /builds/isc-projects/bind9/bin/named/client.c:698:5 (named+0x4d5d22)
    #1 ns_client_detach /builds/isc-projects/bind9/bin/named/client.c:3687:8 (named+0x4d7762)
    #2 query_find /builds/isc-projects/bind9/bin/named/query.c (named+0x4f9021)
    #3 query_resume /builds/isc-projects/bind9/bin/named/query.c:4164:12 (named+0x509b68)
    #4 dispatch /builds/isc-projects/bind9/lib/isc/task.c:1157:7 (libisc.so.1107+0x50845)
    #5 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 bf0bac4068 isc_refcount_current should be memory_order_acquire 2020-09-08 09:25:43 +10:00
Mark Andrews 30013c3794 Use memory_order_acq_rel in isc_refcount_decrement.
While

if (isc_refcount_decrement() == 1) {	// memory_order_release
	isc_refcount_destroy();		// memory_order_acquire
	...
}

is theoretically the most efficent in practice, using
memory_order_acq_rel produces the same code on x86_64 and doesn't
trigger tsan data races (which use a idealistic model) if
isc_refcount_destroy() is not called immediately.  In fact
isc_refcount_destroy() could be removed if we didn't want
to check for the count being 0 when isc_refcount_destroy() is
called.

https://stackoverflow.com/questions/49112732/memory-order-in-shared-pointer-destructor
(cherry picked from commit 6278899a38)
2020-09-01 22:31:52 +10:00
Ondřej SurýandMichał Kępień 8d807cc216 Fix crash in pk11_numbits() when native-pkcs11 is used
When pk11_numbits() is passed a user provided input that contains all
zeroes (via crafted DNS message), it would crash with assertion
failure.  Fix that by properly handling such input.
2020-08-05 15:51:50 +02:00
Mark Andrews 1f1209e1f6 Add +yaml support for EDE
(cherry picked from commit 0ec77c2b92)
2020-06-05 12:10:53 +10:00
Mark Andrews c0d34e8b05 Report Extended DNS Error codes
(cherry picked from commit b144ae1bb0)
(cherry picked from commit eed4fab37b)
2020-05-13 12:18:55 +10:00
Mark Andrews 8fce52189e Fix lists of installed header files 2020-03-06 13:09:47 +11:00
Michał Kępień ae7c0cca89 Fix cppcheck 1.89 warnings
cppcheck 1.89 enabled certain value flow analysis mechanisms [1] which
trigger null pointer dereference false positives that were previously
not reported.  It seems that cppcheck no longer treats at least some
REQUIRE() assertion failures as fatal, so add extra assertion macro
definitions to lib/isc/include/isc/util.h that are only used when the
CPPCHECK preprocessor macro is defined; these definitions make cppcheck
1.89 behave as expected.

There is an important requirement for these custom definitions to work:
cppcheck must properly treat abort() as a function which does not
return.  In order for that to happen, the __GNUC__ macro must be set to
a high enough number (because system include directories are used and
system headers compile attributes away if __GNUC__ is not high enough).
__GNUC__ is thus set to the major version number of the GCC compiler
used, which is what that latter does itself during compilation.

[1] https://github.com/danmar/cppcheck/commit/aaeec462e6d96bb70c2b1cf030979d09e2d7c959

(cherry picked from commit abfde3d543)
2020-03-04 12:41:01 +01:00
Ondřej SurýandOndřej Surý 4b9cdbaf7e Replace the OASIS PKCS#11 header file with one from p11-kit
The OASIS pkcs11.h header has a restrictive license.  Replace the
pkcs11.h pkcs11f.h and pkcs11t.h headers with pkcs11.h from p11-kit.

For source distribution, the license for the OASIS headers itself
doesn't pose any licensing problem when combined with MPL license, but
it possibly creates problem for downstream distributors of BIND 9.

(cherry picked from commit c47fad2431)
2020-03-02 10:43:45 +01:00
Evan Hunt 191b616579 fix additional spelling errors 2020-02-24 22:04:43 -08:00
Evan Hunt e63223332c fix spelling errors reported by Fossies. 2020-02-21 14:09:59 -08:00
Ondřej SurýandOndřej Surý f71a8d1120 Convert all atomic operations in isc_rwlock to sequentially-consistent ordering
The memory ordering in the rwlock was all wrong, I am copying excerpts
from the https://en.cppreference.com/w/c/atomic/memory_order#Relaxed_ordering
for the convenience of the reader:

  Relaxed ordering

  Atomic operations tagged memory_order_relaxed are not synchronization
  operations; they do not impose an order among concurrent memory
  accesses. They only guarantee atomicity and modification order
  consistency.

  Sequentially-consistent ordering

  Atomic operations tagged memory_order_seq_cst not only order memory
  the same way as release/acquire ordering (everything that
  happened-before a store in one thread becomes a visible side effect in
  the thread that did a load), but also establish a single total
  modification order of all atomic operations that are so tagged.

Which basically means that we had no or weak synchronization between
threads using the same variables in the rwlock structure.  There should
not be a significant performance drop because the critical sections were
already protected by:

  while(1) {
    if (relaxed_atomic_operation) {
      break;
    }
    LOCK(lock);
    if (!relaxed_atomic_operation) {
      WAIT(sem, lock);
    }
    UNLOCK(lock)l
  }

I would add one more thing to "Don't do your own crypto, folks.":

  - Also don't do your own locking, folks.

As part of this commit, I have also cleaned up the #ifdef spaghetti,
and fixed the isc_atomic API usage.
2020-02-11 21:20:14 +01:00
Ondřej SurýandOndřej Surý 542517b194 Make isc_rwlock.c thread-safe
The ThreadSanitizer found several possible data races in our rwlock
implementation.  This commit convert .spins and .write_granted fields
to atomic.

(cherry picked from commit 1da0994ea4)
2020-02-11 20:05:51 +01:00
Ondřej Surý f2c5bdda21 Refactor parts of isc_httpd and isc_httpd for better readability and safety
(cherry picked from commit 9643a62dd5)
2020-02-08 11:46:37 -08:00
Mark AndrewsandOndřej Surý 12cda20aa2 simplify ISC_LIKELY/ISC_UNLIKELY for CPPCHECK
(cherry picked from commit 6c2e138d7a)
2020-02-08 06:32:42 -08:00
Mark AndrewsandOndřej Surý 26caad3c12 simplify RUNTIME_CHECK for cppcheck
(cherry picked from commit 668a972d1e)
2020-02-08 06:32:42 -08:00
Samuel ThibaultandOndřej Surý 88061c2acb hurd: Fix build
Move PATH_MAX, NAME_MAX, IOV_MAX default definitions to the common
<isc/platform.h>.

(cherry picked from commit d10fbdec84)
2019-11-12 09:22:15 +01:00
Ondřej Surý 55b0da1381 Backport isc_quota_getused() function 2019-11-06 12:54:40 +01:00
Diego FronzaandOndřej Surý 5a9c5166ce Add functions for collecting high-water counters
Add {isc,ns}_stats_{update_if_greater,get_counter}() functions that
are used to set and collect high-water type of statistics.

(cherry picked from commit a544e2e300)
2019-11-06 12:35:33 +01:00
Diego FronzaandOndřej Surý e4ebeff0e4 Change the isc_statscounter_t type from int to C99 int_fast64_t type
For TCP high-water work, we need to keep the used integer types widths
in sync.

Note: int_fast32_t is used on WIN32 platform
(cherry picked from commit 0fc98ef2d5)
2019-11-06 12:35:33 +01:00
Mark Andrews 42f998ee14 Detect partial prefixes / incomplete IPv4 address in acls.
(cherry picked from commit fb87e669fb)
2019-10-14 22:12:16 +11:00
Ondřej Surý b06f36a726 lib/isc/include/isc/stdatomic.h: Suppress preprocessorErrorDirective error from Cppcheck 2019-10-03 14:21:47 +02:00
Mark Andrews b44ad05d20 implement maxudp under windows
(cherry picked from commit 2f558854b7)
2019-09-04 11:09:31 +10:00
Ondřej Surý 3c85a1f104 Fix alignment issues in the native implementation of isc_siphash24()
The native implementation's conversion from the uint8_t buffers to uint64_t now
follows the reference implementation that doesn't require aligned buffers.
2019-09-02 13:22:40 +02:00
Ondřej Surý 63666fc926 Revise the Windows section of <isc/endian.h>
Add a comment and remove redundant definitions.

(cherry picked from commit 84ff6a6963)
2019-07-22 08:09:48 -04:00
Ondřej Surý 1fd8b2d9f4 Revise the macOS section of <isc/endian.h>
Move the macOS section of <isc/endian.h> to a lower spot as it is
believed not to be the most popular platform for running BIND.  Add a
comment and remove redundant definitions.

(cherry picked from commit c727a31eab)
2019-07-22 08:09:48 -04:00
Ondřej Surý 55a95f7cd7 Make <isc/endian.h> detect GNU rather than Linux
Instead of only supporting Linux, try making <isc/endian.h> support
other GNU platforms as well.  Since some compilers define __GNUC__ on
BSDs (e.g. Clang on FreeBSD), move the relevant section to the bottom of
the platform-specific part of <isc/endian.h>, so that it only gets
evaluated when more specific platform determination criteria are not
met.  Also include <byteswap.h> so that any byte-swapping macros which
may be defined in that file on older platforms are used in the fallback
definitions of the nonstandard hto[bl]e{16,32,64}() and
[bl]e{16,32,64}toh() conversion functions.

(cherry picked from commit a98c7408fc)
2019-07-22 08:09:48 -04:00
Ondřej Surý 7b74cd6231 Add Solaris support for <isc/endian.h>
While Solaris does not support the nonstandard hto[bl]e{16,32,64}() and
[bl]e{16,32,64}toh() conversion functions, it does have some
byte-swapping macros available in <sys/byteorder.h>.  Ensure these
macros are used in the fallback definitions of the aforementioned
nonstandard functions.

(cherry picked from commit 5b0f81e549)
2019-07-22 08:09:48 -04:00
Ondřej Surý d3a8c162d8 Add fallback definitions to <isc/endian.h>
Since the hto[bl]e{16,32,64}() and [bl]e{16,32,64}toh() conversion
functions are nonstandard, add fallback definitions of these functions
to <isc/endian.h>, so that their unavailability does not prevent
compilation from succeeding.

(cherry picked from commit 973d2991a0)
2019-07-22 08:09:48 -04:00
Michał KępieńandOndřej Surý 3c7cab3f22 Fix <isc/endian.h> on BSD systems
Current versions of DragonFly BSD, FreeBSD, NetBSD, and OpenBSD all
support the modern variants of functions converting values between host
and big-endian/little-endian byte order while older ones might not.
Ensure <isc/endian.h> works properly in both cases.

(cherry picked from commit 588c14d5c9)
2019-07-22 08:09:48 -04:00
Ondřej Surý 91307842b8 Add reference SipHash 2-4 implementation
(cherry picked from commit a197df137a)
(cherry picked from commit 8d87ad53eb)
2019-07-22 08:09:48 -04:00
Ondřej Surý 92a86ac211 Add portable <isc/endian.h> header
(cherry picked from commit 0efc36c19a)
(cherry picked from commit 0b050ad4fd)
2019-07-22 08:09:48 -04:00
Mark Andrews 0c0ddaf3d1 teach cppcheck that _assert_int_equal and _assert_int_not_equal don't return on failure
(cherry picked from commit 5d5d751c7f)
2019-06-04 15:24:18 +10:00
Evan HuntandOndřej Surý c47ccf630f refactor tcpquota and pipeline refs; allow special-case overrun in isc_quota
- if the TCP quota has been exceeded but there are no clients listening
  for new connections on the interface, we can now force attachment to the
  quota using isc_quota_force(), instead of carrying on with the quota not
  attached.
- the TCP client quota is now referenced via a reference-counted
  'ns_tcpconn' object, one of which is created whenever a client begins
  listening for new connections, and attached to by members of that
  client's pipeline group. when the last reference to the tcpconn
  object is detached, it is freed and the TCP quota slot is released.
- reduce code duplication by adding mark_tcp_active() function.
- convert counters to atomic.

(cherry picked from commit 7e8222378ca24f1302a0c1c638565050ab04681b)
(cherry picked from commit 4939451275722bfda490ea86ca13e84f6bc71e46)
(cherry picked from commit 13f7c918b8)
2019-04-25 15:04:26 +02:00
Ondřej Surý de4fe3ed32 On non-GNUC systems, use uintmax_t in the ISC_ALIGN macro
(cherry picked from commit 2e40cc94dc)
2019-04-18 13:18:10 +02:00
Mark AndrewsandEvan Hunt 28ea43ab35 Handle EDQUOT and ENOSPC errors
(cherry picked from commit 435ae2f29a)
2019-03-07 21:29:59 -08:00
Mark AndrewsandEvan Hunt 2671666ef8 improve clang / cmocka integration
(cherry picked from commit cb913177ae)
2019-03-05 11:04:46 -08:00
Mark Andrews 58cc1ee718 Ensure base64/base32/hex fields in DNS records that should be non-empty are.
(cherry picked from commit 5e8b772ad1)
2019-01-09 18:52:50 +11:00
Ondřej Surý 4892b52156 Fix the stdatomic #ifdefs to work with older compilers 2018-12-21 09:29:47 +01:00
Ondřej Surý 074cc75aa7 Add better EMPTY_TRANSLATION_UNIT to isc/util.h 2018-12-21 09:29:47 +01:00
Ondřej Surý c116fb963a Fix ECC algorithms unused constants in PKCS#11 build 2018-12-21 09:29:47 +01:00
Ondřej Surý d0dadf5ac4 __SANITIZE_ADDRESS__ needs to be defined to 1
(cherry picked from commit ff7c868f25)
2018-12-20 00:15:59 +01:00
Ondřej Surý 11cce88a41 gcc defines __SANITIZE_ADDRESS__ and not __ADDRESS_SANITIZER__, use the correct #define
(cherry picked from commit 8903d68d69)
2018-12-19 12:46:05 +01:00
Ondřej Surý 9827b8ade9 Define __ADDRESS_SANITIZER__ if compiling under clang's AddressSanitizer
(cherry picked from commit e1ce3a3d42)
2018-12-19 10:50:54 +01:00
Mark Andrews c0a3c48802 add missing DBC checks for catz and add isc_magic checks; add DBC checks to ht.c
(cherry picked from commit a487473fc5)
(cherry picked from commit 17d9fa3cc7)
2018-11-29 15:05:17 +11:00
Ondřej SurýandMark Andrews 22c0f129ae Add support for cmocka assert testing by overriding REQUIRE/INSIST/... macros when UNIT_TESTING is defined
(cherry picked from commit 52731c000d)
2018-11-12 12:56:15 +11:00
Ondřej Surý 9000f73ba3 Properly use ATOMIC_*_LOCK_FREE preprocessor constants
The ATOMIC_*_LOCK_FREE can evalutate either 0, 1, or 2 which indicate the
lock-free property of the corresponding atomic types (both signed and unsigned).

	Value	Explanation
	-----	--------------------------------------
	  0	The atomic type is never lock-free
	  1	The atomic type is sometimes lock-free
	  2	The atomic type is always lock-free
	-----	--------------------------------------

(cherry picked from commit a5e7901eb9)
2018-11-09 05:00:32 +07:00