]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Add a fuzzing target for the Proxy Protocol v2 parser
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 13 Mar 2020 18:07:02 +0000 (19:07 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 17 Mar 2020 13:12:56 +0000 (14:12 +0100)
fuzzing/README.md
fuzzing/corpus/proxy-protocol-raw-packets/proxy-protocol-local-header [new file with mode: 0644]
fuzzing/corpus/proxy-protocol-raw-packets/proxy-protocol-v4-with-tlvs [new file with mode: 0644]
pdns/Makefile.am
pdns/fuzz_proxyprotocol.cc [new file with mode: 0644]

index c42c5c12f1539e898867ca35b3b244ea8ae72e2b..055c44883008d0b5e78b7a573a31c4c5417430db 100644 (file)
@@ -12,6 +12,7 @@ The current targets cover:
 - the auth, dnsdist and rec packet caches (fuzz_target_packetcache and
   fuzz_target_dnsdistcache) ;
 - MOADNSParser (fuzz_target_moadnsparser) ;
+- the Proxy Protocol parser (fuzz_target_proxyprotocol) ;
 - ZoneParserTNG (fuzz_target_zoneparsertng).
 
 By default the targets are linked against a standalone target,
@@ -38,7 +39,9 @@ Corpus
 This directory contains a few files used for continuous fuzzing
 of the PowerDNS products.
 
-The 'corpus' directory contains two sub-directories:
+The 'corpus' directory contains three sub-directories:
+- proxy-protocol-raw-packets/ contains DNS queries prefixed with a Proxy
+  Protocol v2 header, used by fuzz_target_proxyprotocol ;
 - raw-dns-packets/ contains DNS queries and responses as captured on
   the wire. These are used by the fuzz_target_dnsdistcache,
   fuzz_target_moadnsparser and fuzz_target_packetcache targets ;
diff --git a/fuzzing/corpus/proxy-protocol-raw-packets/proxy-protocol-local-header b/fuzzing/corpus/proxy-protocol-raw-packets/proxy-protocol-local-header
new file mode 100644 (file)
index 0000000..f2f8264
Binary files /dev/null and b/fuzzing/corpus/proxy-protocol-raw-packets/proxy-protocol-local-header differ
diff --git a/fuzzing/corpus/proxy-protocol-raw-packets/proxy-protocol-v4-with-tlvs b/fuzzing/corpus/proxy-protocol-raw-packets/proxy-protocol-v4-with-tlvs
new file mode 100644 (file)
index 0000000..250bed2
Binary files /dev/null and b/fuzzing/corpus/proxy-protocol-raw-packets/proxy-protocol-v4-with-tlvs differ
index 64d3ad8fad0d636ba093e2d804cfd9871971412f..524110a07be8a0035da66cc314e16456fd9b19b5 100644 (file)
@@ -1423,6 +1423,7 @@ fuzz_targets_programs =  \
        fuzz_target_dnsdistcache \
        fuzz_target_moadnsparser \
        fuzz_target_packetcache \
+       fuzz_target_proxyprotocol \
        fuzz_target_zoneparsertng
 
 fuzz_targets: $(fuzz_targets_programs)
@@ -1479,6 +1480,16 @@ fuzz_target_packetcache_DEPENDENCIES = $(fuzz_targets_deps)
 fuzz_target_packetcache_LDFLAGS = $(fuzz_targets_ldflags)
 fuzz_target_packetcache_LDADD = $(fuzz_targets_libs)
 
+fuzz_target_proxyprotocol_SOURCES = \
+       fuzz_proxyprotocol.cc \
+       iputils.hh \
+       proxy-protocol.cc \
+       proxy-protocol.hh
+
+fuzz_target_proxyprotocol_DEPENDENCIES = $(fuzz_targets_deps)
+fuzz_target_proxyprotocol_LDFLAGS = $(fuzz_targets_ldflags)
+fuzz_target_proxyprotocol_LDADD = $(fuzz_targets_libs)
+
 fuzz_target_dnsdistcache_SOURCES = \
        fuzz_dnsdistcache.cc \
        dnsdist-cache.cc dnsdist-cache.hh \
diff --git a/pdns/fuzz_proxyprotocol.cc b/pdns/fuzz_proxyprotocol.cc
new file mode 100644 (file)
index 0000000..d138d6f
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * This file is part of PowerDNS or dnsdist.
+ * Copyright -- PowerDNS.COM B.V. and its contributors
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * In addition, for the avoidance of any doubt, permission is granted to
+ * link this program with OpenSSL and to (re)distribute the binaries
+ * produced as the result of such linking.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "proxy-protocol.hh"
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
+
+  std::vector<ProxyProtocolValue> values;
+  ComboAddress source;
+  ComboAddress destination;
+  bool proxy = false;
+  bool tcp = false;  
+
+  try {
+    parseProxyHeader(std::string(reinterpret_cast<const char*>(data), size), proxy, source, destination, tcp, values);
+  }
+  catch(const std::exception& e) {
+  }
+  catch(const PDNSException& e) {
+  }
+
+  return 0;
+}