rdobuilder cc2e4a
From 51e3c4928d4938beb576eff34f3bf97e6e64e6b4 Mon Sep 17 00:00:00 2001
rdobuilder cc2e4a
From: Kelvin J Li <72498127+kelvin-j-li@users.noreply.github.com>
rdobuilder cc2e4a
Date: Mon, 19 Feb 2024 21:42:27 +0800
rdobuilder cc2e4a
Subject: [PATCH] Dnspython 2.6.1 - Address DoS via the Tudoor mechanism
rdobuilder cc2e4a
 (CVE-2023-29483)
rdobuilder cc2e4a
MIME-Version: 1.0
rdobuilder cc2e4a
Content-Type: text/plain; charset=UTF-8
rdobuilder cc2e4a
Content-Transfer-Encoding: 8bit
rdobuilder cc2e4a
rdobuilder cc2e4a
Fix for (CVE-2023-29483) and handling of truncated exceptions in greendns.py provided by Bob Halley from https://github.com/rthalley/eventlet/tree/tudoor
rdobuilder cc2e4a
rdobuilder cc2e4a
Do not eat legitimate Truncated exceptions.
rdobuilder cc2e4a
---------
rdobuilder cc2e4a
Co-authored-by: Bob Halley <halley@play-bow.org>
rdobuilder cc2e4a
Co-authored-by: Hervé Beraud <hberaud@redhat.com>
rdobuilder cc2e4a
---
rdobuilder cc2e4a
 eventlet/support/greendns.py | 56 ++++++++++++++++++++++++------------
rdobuilder cc2e4a
 1 file changed, 38 insertions(+), 18 deletions(-)
rdobuilder cc2e4a
rdobuilder cc2e4a
diff --git a/eventlet/support/greendns.py b/eventlet/support/greendns.py
rdobuilder cc2e4a
index 62621423..365664f2 100644
rdobuilder cc2e4a
--- a/eventlet/support/greendns.py
rdobuilder cc2e4a
+++ b/eventlet/support/greendns.py
rdobuilder cc2e4a
@@ -713,7 +713,7 @@ except TypeError:
rdobuilder cc2e4a
 def udp(q, where, timeout=DNS_QUERY_TIMEOUT, port=53,
rdobuilder cc2e4a
         af=None, source=None, source_port=0, ignore_unexpected=False,
rdobuilder cc2e4a
         one_rr_per_rrset=False, ignore_trailing=False,
rdobuilder cc2e4a
-        raise_on_truncation=False, sock=None):
rdobuilder cc2e4a
+        raise_on_truncation=False, sock=None, ignore_errors=False):
rdobuilder cc2e4a
     """coro friendly replacement for dns.query.udp
rdobuilder cc2e4a
     Return the response obtained after sending a query via UDP.
rdobuilder cc2e4a
 
rdobuilder cc2e4a
@@ -752,7 +752,10 @@ def udp(q, where, timeout=DNS_QUERY_TIMEOUT, port=53,
rdobuilder cc2e4a
     query.  If None, the default, a socket is created.  Note that
rdobuilder cc2e4a
     if a socket is provided, it must be a nonblocking datagram socket,
rdobuilder cc2e4a
     and the source and source_port are ignored.
rdobuilder cc2e4a
-    @type sock: socket.socket | None"""
rdobuilder cc2e4a
+    @type sock: socket.socket | None
rdobuilder cc2e4a
+    @param ignore_errors: if various format errors or response mismatches occur,
rdobuilder cc2e4a
+    continue listening.
rdobuilder cc2e4a
+    @type ignore_errors: bool"""
rdobuilder cc2e4a
 
rdobuilder cc2e4a
     wire = q.to_wire()
rdobuilder cc2e4a
     if af is None:
rdobuilder cc2e4a
@@ -816,26 +819,43 @@ def udp(q, where, timeout=DNS_QUERY_TIMEOUT, port=53,
rdobuilder cc2e4a
                 addr = from_address[0]
rdobuilder cc2e4a
                 addr = dns.ipv6.inet_ntoa(dns.ipv6.inet_aton(addr))
rdobuilder cc2e4a
                 from_address = (addr, from_address[1], from_address[2], from_address[3])
rdobuilder cc2e4a
-            if from_address == destination:
rdobuilder cc2e4a
+            if from_address != destination:
rdobuilder cc2e4a
+                if ignore_unexpected:
rdobuilder cc2e4a
+                    continue
rdobuilder cc2e4a
+                else:
rdobuilder cc2e4a
+                    raise dns.query.UnexpectedSource(
rdobuilder cc2e4a
+                        'got a response from %s instead of %s'
rdobuilder cc2e4a
+                        % (from_address, destination))
rdobuilder cc2e4a
+            try:
rdobuilder cc2e4a
+                if _handle_raise_on_truncation:
rdobuilder cc2e4a
+                    r = dns.message.from_wire(wire,
rdobuilder cc2e4a
+                                              keyring=q.keyring,
rdobuilder cc2e4a
+                                              request_mac=q.mac,
rdobuilder cc2e4a
+                                              one_rr_per_rrset=one_rr_per_rrset,
rdobuilder cc2e4a
+                                              ignore_trailing=ignore_trailing,
rdobuilder cc2e4a
+                                              raise_on_truncation=raise_on_truncation)
rdobuilder cc2e4a
+                else:
rdobuilder cc2e4a
+                    r = dns.message.from_wire(wire,
rdobuilder cc2e4a
+                                              keyring=q.keyring,
rdobuilder cc2e4a
+                                              request_mac=q.mac,
rdobuilder cc2e4a
+                                              one_rr_per_rrset=one_rr_per_rrset,
rdobuilder cc2e4a
+                                              ignore_trailing=ignore_trailing)
rdobuilder cc2e4a
+                if not q.is_response(r):
rdobuilder cc2e4a
+                    raise dns.query.BadResponse()
rdobuilder cc2e4a
                 break
rdobuilder cc2e4a
-            if not ignore_unexpected:
rdobuilder cc2e4a
-                raise dns.query.UnexpectedSource(
rdobuilder cc2e4a
-                    'got a response from %s instead of %s'
rdobuilder cc2e4a
-                    % (from_address, destination))
rdobuilder cc2e4a
+            except dns.message.Truncated as e:
rdobuilder cc2e4a
+                if ignore_errors and not q.is_response(e.message()):
rdobuilder cc2e4a
+                    continue
rdobuilder cc2e4a
+                else:
rdobuilder cc2e4a
+                    raise
rdobuilder cc2e4a
+            except Exception:
rdobuilder cc2e4a
+                if ignore_errors:
rdobuilder cc2e4a
+                    continue
rdobuilder cc2e4a
+                else:
rdobuilder cc2e4a
+                    raise
rdobuilder cc2e4a
     finally:
rdobuilder cc2e4a
         s.close()
rdobuilder cc2e4a
 
rdobuilder cc2e4a
-    if _handle_raise_on_truncation:
rdobuilder cc2e4a
-        r = dns.message.from_wire(wire, keyring=q.keyring, request_mac=q.mac,
rdobuilder cc2e4a
-                                  one_rr_per_rrset=one_rr_per_rrset,
rdobuilder cc2e4a
-                                  ignore_trailing=ignore_trailing,
rdobuilder cc2e4a
-                                  raise_on_truncation=raise_on_truncation)
rdobuilder cc2e4a
-    else:
rdobuilder cc2e4a
-        r = dns.message.from_wire(wire, keyring=q.keyring, request_mac=q.mac,
rdobuilder cc2e4a
-                                  one_rr_per_rrset=one_rr_per_rrset,
rdobuilder cc2e4a
-                                  ignore_trailing=ignore_trailing)
rdobuilder cc2e4a
-    if not q.is_response(r):
rdobuilder cc2e4a
-        raise dns.query.BadResponse()
rdobuilder cc2e4a
     return r
rdobuilder cc2e4a
 
rdobuilder cc2e4a
 
rdobuilder cc2e4a
-- 
rdobuilder cc2e4a
2.46.0
rdobuilder cc2e4a