Blame SOURCES/bind-9.16-CVE-2022-2795.patch

b47298
From bf2ea6d8525bfd96a84dad221ba9e004adb710a8 Mon Sep 17 00:00:00 2001
b47298
From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= <michal@isc.org>
b47298
Date: Thu, 8 Sep 2022 11:11:30 +0200
b47298
Subject: [PATCH] Bound the amount of work performed for delegations
b47298
b47298
Limit the amount of database lookups that can be triggered in
b47298
fctx_getaddresses() (i.e. when determining the name server addresses to
b47298
query next) by setting a hard limit on the number of NS RRs processed
b47298
for any delegation encountered.  Without any limit in place, named can
b47298
be forced to perform large amounts of database lookups per each query
b47298
received, which severely impacts resolver performance.
b47298
b47298
The limit used (20) is an arbitrary value that is considered to be big
b47298
enough for any sane DNS delegation.
b47298
b47298
(cherry picked from commit 3a44097fd6c6c260765b628cd1d2c9cb7efb0b2a)
b47298
---
b47298
 lib/dns/resolver.c | 12 ++++++++++++
b47298
 1 file changed, 12 insertions(+)
b47298
b47298
diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c
b47298
index d2cf14bbc8..73a0ee9f77 100644
b47298
--- a/lib/dns/resolver.c
b47298
+++ b/lib/dns/resolver.c
b47298
@@ -195,6 +195,12 @@
b47298
  */
b47298
 #define NS_FAIL_LIMIT 4
b47298
 #define NS_RR_LIMIT   5
b47298
+/*
b47298
+ * IP address lookups are performed for at most NS_PROCESSING_LIMIT NS RRs in
b47298
+ * any NS RRset encountered, to avoid excessive resource use while processing
b47298
+ * large delegations.
b47298
+ */
b47298
+#define NS_PROCESSING_LIMIT 20
b47298
 
b47298
 /* Number of hash buckets for zone counters */
b47298
 #ifndef RES_DOMAIN_BUCKETS
b47298
@@ -3711,6 +3717,7 @@ fctx_getaddresses(fetchctx_t *fctx, bool badcache) {
b47298
 	bool need_alternate = false;
b47298
 	bool all_spilled = true;
b47298
 	unsigned int no_addresses = 0;
b47298
+	unsigned int ns_processed = 0;
b47298
 
b47298
 	FCTXTRACE5("getaddresses", "fctx->depth=", fctx->depth);
b47298
 
b47298
@@ -3902,6 +3909,11 @@ normal_nses:
b47298
 
b47298
 		dns_rdata_reset(&rdata);
b47298
 		dns_rdata_freestruct(&ns);
b47298
+
b47298
+		if (++ns_processed >= NS_PROCESSING_LIMIT) {
b47298
+			result = ISC_R_NOMORE;
b47298
+			break;
b47298
+		}
b47298
 	}
b47298
 	if (result != ISC_R_NOMORE) {
b47298
 		return (result);
b47298
-- 
b47298
2.37.3
b47298