Blame SOURCES/bind-9.16-CVE-2022-3094-1.patch

bd9435
From 18036bb3f435eaa20d60093738c61e5da42a6cfe Mon Sep 17 00:00:00 2001
bd9435
From: Evan Hunt <each@isc.org>
bd9435
Date: Thu, 1 Sep 2022 16:05:04 -0700
bd9435
Subject: [PATCH] add an update quota
bd9435
bd9435
limit the number of simultaneous DNS UPDATE events that can be
bd9435
processed by adding a quota for update and update forwarding.
bd9435
this quota currently, arbitrarily, defaults to 100.
bd9435
bd9435
also add a statistics counter to record when the update quota
bd9435
has been exceeded.
bd9435
bd9435
(cherry picked from commit 7c47254a140c3e9cf383cda73c7b6a55c4782826)
bd9435
---
bd9435
 bin/named/bind9.xsl        |  4 +++-
bd9435
 bin/named/bind9.xsl.h      |  6 +++++-
bd9435
 bin/named/statschannel.c   |  5 +++--
bd9435
 doc/arm/reference.rst      |  5 +++++
bd9435
 lib/ns/include/ns/server.h |  1 +
bd9435
 lib/ns/include/ns/stats.h  |  4 +++-
bd9435
 lib/ns/server.c            |  2 ++
bd9435
 lib/ns/update.c            | 37 ++++++++++++++++++++++++++++++++++++-
bd9435
 8 files changed, 58 insertions(+), 6 deletions(-)
bd9435
bd9435
diff --git a/bin/named/bind9.xsl b/bin/named/bind9.xsl
bd9435
index 5078115..194625b 100644
bd9435
--- a/bin/named/bind9.xsl
bd9435
+++ b/bin/named/bind9.xsl
bd9435
@@ -12,7 +12,9 @@
bd9435
 
bd9435
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="1.0">
bd9435
   <xsl:output method="html" indent="yes" version="4.0"/>
bd9435
-  <xsl:template match="statistics[@version="3.11"]">
bd9435
+  
bd9435
+  
bd9435
+  <xsl:template match="statistics[@version="3.11.1"]">
bd9435
     <html>
bd9435
       <head>
bd9435
         <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
bd9435
diff --git a/bin/named/bind9.xsl.h b/bin/named/bind9.xsl.h
bd9435
index e30f7f5..b182742 100644
bd9435
--- a/bin/named/bind9.xsl.h
bd9435
+++ b/bin/named/bind9.xsl.h
bd9435
@@ -20,7 +20,11 @@ static char xslmsg[] =
bd9435
 	"
bd9435
 	"xmlns=\"http://www.w3.org/1999/xhtml\" version=\"1.0\">\n"
bd9435
 	" <xsl:output method=\"html\" indent=\"yes\" version=\"4.0\"/>\n"
bd9435
-	" <xsl:template match=\"statistics[@version="3.11"]\">\n"
bd9435
+	" 
bd9435
+	"bin/named/statschannel.c -->\n"
bd9435
+	" 
bd9435
+	"the HTTP endpoints listed below -->\n"
bd9435
+	" <xsl:template match=\"statistics[@version="3.11.1"]\">\n"
bd9435
 	" <html>\n"
bd9435
 	" <head>\n"
bd9435
 	" 
bd9435
diff --git a/bin/named/statschannel.c b/bin/named/statschannel.c
bd9435
index 832ce93..7361ead 100644
bd9435
--- a/bin/named/statschannel.c
bd9435
+++ b/bin/named/statschannel.c
bd9435
@@ -335,6 +335,7 @@ init_desc(void) {
bd9435
 	SET_NSSTATDESC(reclimitdropped,
bd9435
 		       "queries dropped due to recursive client limit",
bd9435
 		       "RecLimitDropped");
bd9435
+	SET_NSSTATDESC(updatequota, "Update quota exceeded", "UpdateQuota");
bd9435
 
bd9435
 	INSIST(i == ns_statscounter_max);
bd9435
 
bd9435
@@ -2007,7 +2008,7 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
bd9435
 					      "href=\"/bind9.xsl\""));
bd9435
 	TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "statistics"));
bd9435
 	TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "version",
bd9435
-					 ISC_XMLCHAR "3.11"));
bd9435
+					 ISC_XMLCHAR "3.11.1"));
bd9435
 
bd9435
 	/* Set common fields for statistics dump */
bd9435
 	dumparg.type = isc_statsformat_xml;
bd9435
@@ -2876,7 +2877,7 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg,
bd9435
 	/*
bd9435
 	 * These statistics are included no matter which URL we use.
bd9435
 	 */
bd9435
-	obj = json_object_new_string("1.5");
bd9435
+	obj = json_object_new_string("1.5.1");
bd9435
 	CHECKMEM(obj);
bd9435
 	json_object_object_add(bindstats, "json-stats-version", obj);
bd9435
 
bd9435
diff --git a/doc/arm/reference.rst b/doc/arm/reference.rst
bd9435
index 2d05aec..25c20d7 100644
bd9435
--- a/doc/arm/reference.rst
bd9435
+++ b/doc/arm/reference.rst
bd9435
@@ -6705,6 +6705,11 @@ Name Server Statistics Counters
bd9435
 ``UpdateBadPrereq``
bd9435
     This indicates the number of dynamic updates rejected due to a prerequisite failure.
bd9435
 
bd9435
+``UpdateQuota``
bd9435
+    This indicates the number of times a dynamic update or update
bd9435
+    forwarding request was rejected because the number of pending
bd9435
+    requests exceeded the update quota.
bd9435
+
bd9435
 ``RateDropped``
bd9435
     This indicates the number of responses dropped due to rate limits.
bd9435
 
bd9435
diff --git a/lib/ns/include/ns/server.h b/lib/ns/include/ns/server.h
bd9435
index 6a1f345..0abb579 100644
bd9435
--- a/lib/ns/include/ns/server.h
bd9435
+++ b/lib/ns/include/ns/server.h
bd9435
@@ -84,6 +84,7 @@ struct ns_server {
bd9435
 	isc_quota_t recursionquota;
bd9435
 	isc_quota_t tcpquota;
bd9435
 	isc_quota_t xfroutquota;
bd9435
+	isc_quota_t updquota;
bd9435
 
bd9435
 	/*% Test options and other configurables */
bd9435
 	uint32_t options;
bd9435
diff --git a/lib/ns/include/ns/stats.h b/lib/ns/include/ns/stats.h
bd9435
index 3c08799..95b15d0 100644
bd9435
--- a/lib/ns/include/ns/stats.h
bd9435
+++ b/lib/ns/include/ns/stats.h
bd9435
@@ -106,7 +106,9 @@ enum {
bd9435
 
bd9435
 	ns_statscounter_reclimitdropped = 66,
bd9435
 
bd9435
-	ns_statscounter_max = 67,
bd9435
+	ns_statscounter_updatequota = 67,
bd9435
+
bd9435
+	ns_statscounter_max = 68,
bd9435
 };
bd9435
 
bd9435
 void
bd9435
diff --git a/lib/ns/server.c b/lib/ns/server.c
bd9435
index a970a28..540bc2e 100644
bd9435
--- a/lib/ns/server.c
bd9435
+++ b/lib/ns/server.c
bd9435
@@ -52,6 +52,7 @@ ns_server_create(isc_mem_t *mctx, ns_matchview_t matchingview,
bd9435
 	isc_quota_init(&sctx->xfroutquota, 10);
bd9435
 	isc_quota_init(&sctx->tcpquota, 10);
bd9435
 	isc_quota_init(&sctx->recursionquota, 100);
bd9435
+	isc_quota_init(&sctx->updquota, 100);
bd9435
 
bd9435
 	CHECKFATAL(dns_tkeyctx_create(mctx, &sctx->tkeyctx));
bd9435
 
bd9435
@@ -131,6 +132,7 @@ ns_server_detach(ns_server_t **sctxp) {
bd9435
 			isc_mem_put(sctx->mctx, altsecret, sizeof(*altsecret));
bd9435
 		}
bd9435
 
bd9435
+		isc_quota_destroy(&sctx->updquota);
bd9435
 		isc_quota_destroy(&sctx->recursionquota);
bd9435
 		isc_quota_destroy(&sctx->tcpquota);
bd9435
 		isc_quota_destroy(&sctx->xfroutquota);
bd9435
diff --git a/lib/ns/update.c b/lib/ns/update.c
bd9435
index 546b70a..1871438 100644
bd9435
--- a/lib/ns/update.c
bd9435
+++ b/lib/ns/update.c
bd9435
@@ -1544,6 +1544,19 @@ send_update_event(ns_client_t *client, dns_zone_t *zone) {
bd9435
 	update_event_t *event = NULL;
bd9435
 	isc_task_t *zonetask = NULL;
bd9435
 
bd9435
+	result = isc_quota_attach(&client->manager->sctx->updquota,
bd9435
+				  &(isc_quota_t *){ NULL });
bd9435
+	if (result != ISC_R_SUCCESS) {
bd9435
+		update_log(client, zone, LOGLEVEL_PROTOCOL,
bd9435
+			   "update failed: too many DNS UPDATEs queued (%s)",
bd9435
+			   isc_result_totext(result));
bd9435
+		ns_stats_increment(client->manager->sctx->nsstats,
bd9435
+				   ns_statscounter_updatequota);
bd9435
+		ns_client_drop(client, result);
bd9435
+		isc_nmhandle_detach(&client->reqhandle);
bd9435
+		return (DNS_R_DROP);
bd9435
+	}
bd9435
+
bd9435
 	event = (update_event_t *)isc_event_allocate(
bd9435
 		client->mctx, client, DNS_EVENT_UPDATE, update_action, NULL,
bd9435
 		sizeof(*event));
bd9435
@@ -1676,12 +1689,18 @@ failure:
bd9435
 		       dns_zone_gettype(zone) == dns_zone_mirror);
bd9435
 		inc_stats(client, zone, ns_statscounter_updaterej);
bd9435
 	}
bd9435
+
bd9435
 	/*
bd9435
 	 * We failed without having sent an update event to the zone.
bd9435
 	 * We are still in the client task context, so we can
bd9435
 	 * simply give an error response without switching tasks.
bd9435
 	 */
bd9435
-	respond(client, result);
bd9435
+	if (result == DNS_R_DROP) {
bd9435
+		ns_client_drop(client, result);
bd9435
+	} else {
bd9435
+		respond(client, result);
bd9435
+	}
bd9435
+
bd9435
 	if (zone != NULL) {
bd9435
 		dns_zone_detach(&zone);
bd9435
 	}
bd9435
@@ -3489,6 +3508,7 @@ updatedone_action(isc_task_t *task, isc_event_t *event) {
bd9435
 
bd9435
 	respond(client, uev->result);
bd9435
 
bd9435
+	isc_quota_detach(&(isc_quota_t *){ &client->manager->sctx->updquota });
bd9435
 	isc_event_free(&event);
bd9435
 	isc_nmhandle_detach(&client->updatehandle);
bd9435
 }
bd9435
@@ -3505,6 +3525,8 @@ forward_fail(isc_task_t *task, isc_event_t *event) {
bd9435
 	INSIST(client->nupdates > 0);
bd9435
 	client->nupdates--;
bd9435
 	respond(client, DNS_R_SERVFAIL);
bd9435
+
bd9435
+	isc_quota_detach(&(isc_quota_t *){ &client->manager->sctx->updquota });
bd9435
 	isc_event_free(&event);
bd9435
 	isc_nmhandle_detach(&client->updatehandle);
bd9435
 }
bd9435
@@ -3542,6 +3564,8 @@ forward_done(isc_task_t *task, isc_event_t *event) {
bd9435
 	client->nupdates--;
bd9435
 	ns_client_sendraw(client, uev->answer);
bd9435
 	dns_message_detach(&uev->answer);
bd9435
+
bd9435
+	isc_quota_detach(&(isc_quota_t *){ &client->manager->sctx->updquota });
bd9435
 	isc_event_free(&event);
bd9435
 	isc_nmhandle_detach(&client->updatehandle);
bd9435
 }
bd9435
@@ -3576,6 +3600,17 @@ send_forward_event(ns_client_t *client, dns_zone_t *zone) {
bd9435
 	update_event_t *event = NULL;
bd9435
 	isc_task_t *zonetask = NULL;
bd9435
 
bd9435
+	result = isc_quota_attach(&client->manager->sctx->updquota,
bd9435
+				  &(isc_quota_t *){ NULL });
bd9435
+	if (result != ISC_R_SUCCESS) {
bd9435
+		update_log(client, zone, LOGLEVEL_PROTOCOL,
bd9435
+			   "update failed: too many DNS UPDATEs queued (%s)",
bd9435
+			   isc_result_totext(result));
bd9435
+		ns_stats_increment(client->manager->sctx->nsstats,
bd9435
+				   ns_statscounter_updatequota);
bd9435
+		return (DNS_R_DROP);
bd9435
+	}
bd9435
+
bd9435
 	event = (update_event_t *)isc_event_allocate(
bd9435
 		client->mctx, client, DNS_EVENT_UPDATE, forward_action, NULL,
bd9435
 		sizeof(*event));
bd9435
-- 
bd9435
2.39.2
bd9435