122de2
From 6fc38d1c75ce5a6172267e6ca162c4fdc09657ad Mon Sep 17 00:00:00 2001
122de2
From: Petr Mensik <pemensik@redhat.com>
122de2
Date: Tue, 27 Apr 2021 10:56:12 +0200
122de2
Subject: [PATCH 2/2] CVE-2021-25215
122de2
122de2
5616.	[security]	named crashed when a DNAME record placed in the ANSWER
122de2
			section during DNAME chasing turned out to be the final
122de2
			answer to a client query. (CVE-2021-25215) [GL #2540]
122de2
---
122de2
 bin/named/query.c | 13 ++++++++++---
122de2
 1 file changed, 10 insertions(+), 3 deletions(-)
122de2
122de2
diff --git a/bin/named/query.c b/bin/named/query.c
122de2
index a95f5ad..11a888e 100644
122de2
--- a/bin/named/query.c
122de2
+++ b/bin/named/query.c
122de2
@@ -9301,10 +9301,17 @@ query_find(ns_client_t *client, dns_fetchevent_t *event, dns_rdatatype_t qtype)
122de2
 		if (noqname != NULL)
122de2
 			query_addnoqnameproof(client, noqname);
122de2
 		/*
122de2
-		 * We shouldn't ever fail to add 'rdataset'
122de2
-		 * because it's already in the answer.
122de2
+		 * 'rdataset' will only be non-NULL here if the ANSWER section
122de2
+		 * of the message to be sent to the client already contains an
122de2
+		 * RRset with the same owner name and the same type as
122de2
+		 * 'rdataset'.  This should never happen, with one exception:
122de2
+		 * when chasing DNAME records, one of the DNAME records placed
122de2
+		 * in the ANSWER section may turn out to be the final answer to
122de2
+		 * the client's query, but we have no way of knowing that until
122de2
+		 * now.  In such a case, 'rdataset' will be freed later, so we
122de2
+		 * do not need to free it here.
122de2
 		 */
122de2
-		INSIST(rdataset == NULL);
122de2
+		INSIST(rdataset == NULL || qtype == dns_rdatatype_dname);
122de2
 	}
122de2
 
122de2
  addauth:
122de2
-- 
122de2
2.26.3
122de2