From be4ed416117bb155aae899cdeb644a8fd4e6457f Mon Sep 17 00:00:00 2001
From: Mark Andrews <marka@isc.org>
Date: Thu, 27 Aug 2020 18:53:06 +1000
Subject: [PATCH] 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)
Conflict: NA
Reference: https://gitlab.isc.org/isc-projects/bind9/-/commit/be4ed416117bb155aae899cdeb644a8fd4e6457f
---
 bin/named/server.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/bin/named/server.c b/bin/named/server.c
index 6aca0224c7..1ece13b31e 100644
--- a/bin/named/server.c
+++ b/bin/named/server.c
@@ -10931,9 +10931,11 @@ ns_server_status(ns_server_t *server, isc_buffer_t **text) {
 		     server->log_queries ? "ON" : "OFF");
 	CHECK(putstr(text, line));
 
+	LOCK(&server->recursionquota.lock);
 	snprintf(line, sizeof(line), "recursive clients: %d/%d/%d\n",
 		     server->recursionquota.used, server->recursionquota.soft,
 		     server->recursionquota.max);
+	UNLOCK(&server->recursionquota.lock);
 	CHECK(putstr(text, line));
 
 	snprintf(line, sizeof(line), "tcp clients: %d/%d\n",
-- 
2.23.0

