]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
fix a TSAN bug in "rndc fetchlimit"
authorEvan Hunt <each@isc.org>
Wed, 28 Jun 2023 21:52:53 +0000 (14:52 -0700)
committerEvan Hunt <each@isc.org>
Fri, 30 Jun 2023 06:52:01 +0000 (06:52 +0000)
fctx counters could be accessed without locking when
"rndc fetchlimit" is called; while this is probably harmless
in production, it triggered TSAN reports in system tests.

lib/dns/resolver.c

index 1e31cf5d34f2526a8f368f88a522b3c96b40c510..477f6b9519381166eccb20d24f2ac99ac9d056e0 100644 (file)
@@ -11175,11 +11175,19 @@ dns_resolver_dumpquota(dns_resolver_t *res, isc_buffer_t **buf) {
             result = isc_hashmap_iter_next(it))
        {
                fctxcount_t *counter = NULL;
+               uint_fast32_t count, dropped, allowed;
+               char nb[DNS_NAME_FORMATSIZE];
+               char text[DNS_NAME_FORMATSIZE + BUFSIZ];
+
                isc_hashmap_iter_current(it, (void **)&counter);
-               char nb[DNS_NAME_FORMATSIZE],
-                       text[DNS_NAME_FORMATSIZE + BUFSIZ];
 
-               if (counter->count < spill) {
+               LOCK(&counter->lock);
+               count = counter->count;
+               dropped = counter->dropped;
+               allowed = counter->allowed;
+               UNLOCK(&counter->lock);
+
+               if (count < spill) {
                        continue;
                }
 
@@ -11187,8 +11195,7 @@ dns_resolver_dumpquota(dns_resolver_t *res, isc_buffer_t **buf) {
                snprintf(text, sizeof(text),
                         "\n- %s: %" PRIuFAST32 " active (allowed %" PRIuFAST32
                         " spilled %" PRIuFAST32 ")",
-                        nb, counter->count, counter->allowed,
-                        counter->dropped);
+                        nb, count, allowed, dropped);
 
                result = isc_buffer_reserve(*buf, strlen(text));
                if (result != ISC_R_SUCCESS) {