2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 05:57:52 +00:00

30988 Commits

Author SHA1 Message Date
Ondřej Surý
3832e3ecc9 Fixup the missing clang-format bits 2020-02-16 17:34:24 +01:00
Ondřej Surý
cbb127eb43 Switch to clang-format-10 that's more accessible on more platforms 2020-02-16 17:34:05 +01:00
Diego dos Santos Fronza
718ec80ed3 Merge branch '1472-threadsanitizer-lock-order-inversion-potential-deadlock-dns_resolver_createfetch-vs' into 'master'
Resolve "ThreadSanitizer: lock-order-inversion (potential deadlock) - dns_resolver_createfetch vs. dns_resolver_prime"

Closes #1472

See merge request isc-projects/bind9!3020
2020-02-14 18:21:12 +00:00
Diego Fronza
45543da802 Fixed disposing of resolver->references in destroy() function 2020-02-14 14:28:31 -03:00
Diego Fronza
e7b36924e2 Fixed potential-lock-inversion
This commit simplifies a bit the lock management within dns_resolver_prime()
and prime_done() functions by means of turning resolver's attribute
"priming" into an atomic_bool and by creating only one dependent object on the
lock "primelock", namely the "primefetch" attribute.

By having the attribute "priming" as an atomic type, it save us from having to
use a lock just to test if priming is on or off for the given resolver context
object, within "dns_resolver_prime" function.

The "primelock" lock is still necessary, since dns_resolver_prime() function
internally calls dns_resolver_createfetch(), and whenever this function
succeeds it registers an event in the task manager which could be called by
another thread, namely the "prime_done" function, and this function is
responsible for disposing the "primefetch" attribute in the resolver object,
also for resetting "priming" attribute to false.

It is important that the invariant "priming == false AND primefetch == NULL"
remains constant, so that any thread calling "dns_resolver_prime" knows for sure
that if the "priming" attribute is false, "primefetch" attribute should also be
NULL, so a new fetch context could be created to fulfill this purpose, and
assigned to "primefetch" attribute under the lock protection.

To honor the explanation above, dns_resolver_prime is implemented as follow:
	1. Atomically checks the attribute "priming" for the given resolver context.
	2. If "priming" is false, assumes that "primefetch" is NULL (this is
           ensured by the "prime_done" implementation), acquire "primelock"
	   lock and create a new fetch context, update "primefetch" pointer to
	   point to the newly allocated fetch context.
	3. If "priming" is true, assumes that the job is already in progress,
	   no locks are acquired, nothing else to do.

To keep the previous invariant consistent, "prime_done" is implemented as follow:
	1. Acquire "primefetch" lock.
	2. Keep a reference to the current "primefetch" object;
	3. Reset "primefetch" attribute to NULL.
	4. Release "primefetch" lock.
	5. Atomically update "priming" attribute to false.
	6. Destroy the "primefetch" object by using the temporary reference.

This ensures that if "priming" is false, "primefetch" was already reset to NULL.

It doesn't make any difference in having the "priming" attribute not protected
by a lock, since the visible state of this variable would depend on the calling
order of the functions "dns_resolver_prime" and "prime_done".

As an example, suppose that instead of using an atomic for the "priming" attribute
we employed a lock to protect it.
Now suppose that "prime_done" function is called by Thread A, it is then preempted
before acquiring the lock, thus not reseting "priming" to false.
In parallel to that suppose that a Thread B is scheduled and that it calls
"dns_resolver_prime()", it then acquires the lock and check that "priming" is true,
thus it will consider that this resolver object is already priming and it won't do
any more job.
Conversely if the lock order was acquired in the other direction, Thread B would check
that "priming" is false (since prime_done acquired the lock first and set "priming" to false)
and it would initiate a priming fetch for this resolver.

An atomic variable wouldn't change this behavior, since it would behave exactly the
same, depending on the function call order, with the exception that it would avoid
having to use a lock.

There should be no side effects resulting from this change, since the previous
implementation employed use of the more general resolver's "lock" mutex, which
is used in far more contexts, but in the specifics of the "dns_resolver_prime"
and "prime_done" it was only used to protect "primefetch" and "priming" attributes,
which are not used in any of the other critical sections protected by the same lock,
thus having zero dependency on those variables.
2020-02-14 14:28:31 -03:00
Diego Fronza
c210413a8a Added atomic_compare_exchange_strong_acq_rel macro
It is much better to read than:
atomic_compare_exchange_strong_explicit() with 5 arguments.
2020-02-14 11:41:36 -03:00
Ondřej Surý
a04cdde45d Merge branch '46-enforce-clang-format-rules' into 'master'
Start enforcing the clang-format rules on changed files

Closes #46

See merge request isc-projects/bind9!3063
2020-02-14 08:45:45 +00:00
Ondřej Surý
60d29f695b Don't enforce copyrights on .clang-format 2020-02-14 09:43:13 +01:00
Ondřej Surý
5777c44ad0 Reformat using the new rules 2020-02-14 09:31:05 +01:00
Ondřej Surý
654927c871 Add separate .clang-format files for headers 2020-02-14 09:31:05 +01:00
Ondřej Surý
618947c63b Switch AlwaysBreakAfterReturnType from TopLevelDefinitions to All
The AlwaysBreakAfterReturnType: TopLevelDefinitions was unwrapping
the declarations of the functions in the header files.
2020-02-14 09:07:46 +01:00
Ondřej Surý
d2b5853b8e Start enforcing the clang-format rules on changed files 2020-02-14 09:07:46 +01:00
Ondřej Surý
d3b49b6675 Merge branch 'each-style-tweak' into 'master'
adjust clang-format options to get closer to ISC style

See merge request isc-projects/bind9!3061
2020-02-14 05:35:17 +00:00
Evan Hunt
e851ed0bb5 apply the modified style 2020-02-13 15:05:06 -08:00
Evan Hunt
0255a97473 revise .clang-format and add a C formatting script in util
- add util/cformat.sh, which runs clang-format on all C files with
  the default .clang-format, and on all header files with a slightly
  modified version.
- use correct bracing after multi-line control statements
- stop aligning variable declarations to avoid problems with pointer
  alignment, but retain aligned declarations in header files so that
  struct definitions look cleaner.
- static function prototypes in C files can skip the line break after
  the return type, but function prototypes in header files still have
  the line break.
- don't break-before-brace in function definitions. ISC style calls
  for braces on the same line when function parameters fit on a single
  line, and a line break if they don't, but clang-format doesn't yet
  support that distinction. one-line function definitions are about
  four times more common than multi-line, so let's use the option that
  deviates less.
2020-02-13 15:04:36 -08:00
Ondřej Surý
67b68e06ad Merge branch '46-add-curly-braces' into 'master'
Add curly braces using uncrustify and then reformat with clang-format back

Closes #46

See merge request isc-projects/bind9!3057
2020-02-13 21:28:07 +00:00
Ondřej Surý
056e133c4c Use clang-tidy to add curly braces around one-line statements
The command used to reformat the files in this commit was:

./util/run-clang-tidy \
	-clang-tidy-binary clang-tidy-11
	-clang-apply-replacements-binary clang-apply-replacements-11 \
	-checks=-*,readability-braces-around-statements \
	-j 9 \
	-fix \
	-format \
	-style=file \
	-quiet
clang-format -i --style=format $(git ls-files '*.c' '*.h')
uncrustify -c .uncrustify.cfg --replace --no-backup $(git ls-files '*.c' '*.h')
clang-format -i --style=format $(git ls-files '*.c' '*.h')
2020-02-13 22:07:21 +01:00
Ondřej Surý
d14bb71319 Add copy of run-clang-tidy that can fixup the filepaths 2020-02-13 22:06:05 +01:00
Ondřej Surý
36c6105e4f Use coccinelle to add braces to nested single line statement
Both clang-tidy and uncrustify chokes on statement like this:

for (...)
	if (...)
		break;

This commit uses a very simple semantic patch (below) to add braces around such
statements.

Semantic patch used:

@@
statement S;
expression E;
@@

while (...)
- if (E) S
+ { if (E) { S } }

@@
statement S;
expression E;
@@

for (...;...;...)
- if (E) S
+ { if (E) { S } }

@@
statement S;
expression E;
@@

if (...)
- if (E) S
+ { if (E) { S } }
2020-02-13 21:58:55 +01:00
Michal Nowak
c823ed4f07 Merge branch 'mnowak/coverity-disable-web-tag' into 'master'
Run Coverity Scan only when specific variables are present

See merge request isc-projects/bind9!3050
2020-02-12 14:44:56 +00:00
Michal Nowak
eec29e3477 Run Coverity Scan only when specific variables are present
Submissions to Coverity Scan should be limited to those originated from
release branches and only from a specific schedule which holds
COVERITY_SCAN_PROJECT_NAME and COVERITY_SCAN_TOKEN variables.
2020-02-12 14:44:55 +00:00
Ondřej Surý
7099e79a9b Merge branch '46-just-use-clang-format-to-reformat-sources' into 'master'
Reformat source code with clang-format

Closes #46

See merge request isc-projects/bind9!2156
2020-02-12 14:33:32 +00:00
Ondřej Surý
df6c1f76ad Remove tkey_test (which is no-op anyway) 2020-02-12 15:04:17 +01:00
Ondřej Surý
11341c7688 Update the definition files for Windows 2020-02-12 15:04:17 +01:00
Ondřej Surý
f50b1e0685 Use clang-format to reformat the source files 2020-02-12 15:04:17 +01:00
Ondřej Surý
4c3b063ef8 Import Linux kernel .clang-format with small modifications 2020-02-12 14:01:08 +01:00
Michał Kępień
118692e949 Merge branch 'michal/minor-README-tweaks' into 'master'
Minor README tweaks

See merge request isc-projects/bind9!3036
2020-02-12 10:37:53 +00:00
Michał Kępień
a0349b18e0 Minor CHANGES tweaks 2020-02-12 11:23:48 +01:00
Mark Andrews
677aa65aad Merge branch '1616-autosign-not-waiting-long-enough-for-zone-to-be-signed-v9_11-and-maybe-others-master' into 'master'
wait for apex NSEC3 to be generated

Closes #1616

See merge request isc-projects/bind9!3043
2020-02-12 10:07:27 +00:00
Mark Andrews
dd2830eb97 wait for apex NSEC3 to be generated
(cherry picked from commit c99ad5c8c7d24f7faa339fe86e8ed1515b4a24ce)
2020-02-12 10:02:14 +00:00
Michal Nowak
c380e32e9a Merge branch 'mnowak/coverity2' into 'master'
Add Coverity Scan to CI

See merge request isc-projects/bind9!2979
2020-02-12 09:45:27 +00:00
Michal Nowak
c209ec90f3 Add Coverity Scan to CI
This job requires two CI variables to be set:

  - COVERITY_SCAN_PROJECT_NAME: project name, which is associated with
    the BIND branch for which this job is executed, e.g. "bind-master",

  - COVERITY_SCAN_TOKEN: project token.
2020-02-12 09:45:27 +00:00
Mark Andrews
f16738bae2 Merge branch '1602-rpz-system-test-failed-because-protoype-responses-timed-out' into 'master'
Resolve "rpz system test failed because protoype responses timed out."

Closes #1602

See merge request isc-projects/bind9!3040
2020-02-12 08:32:54 +00:00
Mark Andrews
c38752b07c spin waiting for prototype dig responses 2020-02-12 08:12:02 +00:00
Witold Krecicki
de16ce0581 Merge branch 'wpk/netmgr-pools-unlimited' into 'master'
Don't limit the size of uvreq/nmhandle pool artificially.

See merge request isc-projects/bind9!3031
2020-02-12 08:10:31 +00:00
Stephen Morris
bc539d48e7 Minor README tweaks 2020-02-11 15:14:50 +01:00
Witold Kręcicki
a133239698 Don't limit the size of uvreq/nmhandle pool artificially.
There was a hard limit set on number of uvreq and nmhandles
that can be allocated by a pool, but we don't handle a situation
where we can't get an uvreq. Don't limit the number at all,
let the OS deal with it.
2020-02-11 12:10:57 +00:00
Ondřej Surý
d3843161ab Merge branch '1428-possible-data-race-in-rbtdb-happens-occasionally-on-ppc64le' into 'master'
Convert all atomic operations in isc_rwlock to release-acquire memory ordering

Closes #1428

See merge request isc-projects/bind9!2985
2020-02-11 10:42:52 +00:00
Ondřej Surý
b43f5e0238 Convert all atomic operations in isc_rwlock to release-acquire memory 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.

  Release-Acquire ordering

  If an atomic store in thread A is tagged memory_order_release and an
  atomic load in thread B from the same variable is tagged
  memory_order_acquire, all memory writes (non-atomic and relaxed atomic)
  that happened-before the atomic store from the point of view of thread
  A, become visible side-effects in thread B. That is, once the atomic
  load is completed, thread B is guaranteed to see everything thread A
  wrote to memory.

  The synchronization is established only between the threads releasing
  and acquiring the same atomic variable. Other threads can see different
  order of memory accesses than either or both of the synchronized
  threads.

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.
2020-02-11 11:10:55 +01:00
Evan Hunt
3116a1c2f1 Merge branch '1598-dnssec-policy-doc' into 'master'
Resolve "Improve dnssec-policy documentation"

Closes #1598

See merge request isc-projects/bind9!3023
2020-02-11 09:01:36 +00:00
Evan Hunt
c7866acbf7 revise dnssec-policy documentation 2020-02-11 01:00:17 -08:00
Ondřej Surý
c72d37f3d5 Merge branch 'ondrej/remove-OpenSSL-engine-specification-in-label' into 'master'
Cleanup support for specifying PKCS#11 engine as part of the label

See merge request isc-projects/bind9!2943
2020-02-10 16:02:23 +00:00
Ondřej Surý
33fa3d5eb1 Remove reference to prepending label with engine in manpage 2020-02-10 07:30:19 -08:00
Ondřej Surý
a5c87d9d18 Cleanup support for specifying PKCS#11 engine as part of the label
The code for specifying OpenSSL PKCS#11 engine as part of the label
(e.g. -l "pkcs11:token=..." instead of -E pkcs11 -l "token=...")
was non-functional.  This commit just cleans the related code.
2020-02-10 07:30:19 -08:00
Ondřej Surý
497c797762 Merge branch 'ondrej/null-the-destroyed-pointer-early' into 'master'
NULL the destroyed pointer early

See merge request isc-projects/bind9!3026
2020-02-10 05:23:38 +00:00
Ondřej Surý
bc1d4c9cb4 Clear the pointer to destroyed object early using the semantic patch
Also disable the semantic patch as the code needs tweaks here and there because
some destroy functions might not destroy the object and return early if the
object is still in use.
2020-02-09 18:00:17 -08:00
Ondřej Surý
b97d003033 Add semantic patch to NULL the destroyed pointer early
Our destroy functions usually look like this:

    void
    foo_destroy(foo_t **foop) {
        foo_t foo = *foop;
        ...destroy the contents of foo...
        *foop = NULL;
    }

nulling the pointer should be done as soon as possible which is
not always the case.  This commit adds simple semantic patch that
changes the example function to:

    void
    foo_destroy(foo_t **foop) {
        foo_t foo = *foop;
        *foop = NULL;
        ...destroy the contents of foo...
    }
2020-02-09 18:00:16 -08:00
Evan Hunt
d4f7603af2 Merge branch '932-doc-query-error-logging' into 'master'
improve documentation of query logging

Closes #932

See merge request isc-projects/bind9!2976
2020-02-09 00:06:24 +00:00
Evan Hunt
21bb9fa77f improve documentation of query logging 2020-02-08 16:05:46 -08:00
Ondřej Surý
e557894717 Merge branch 'michal/fix-the-pipelined-system-test-on-openbsd' into 'master'
Fix the "pipelined" system test on OpenBSD

See merge request isc-projects/bind9!3011
2020-02-08 22:46:26 +00:00