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