]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Fix building our fuzzing targets from a dist tarball
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 16 Aug 2023 13:16:33 +0000 (15:16 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 16 Aug 2023 13:53:34 +0000 (15:53 +0200)
Until now all of our fuzzing targets where built with the authoritative
server, even though one of them is specific to dnsdist.
This made it easy to build all of them at once, especially for OSS-Fuzz
and CI-Fuzz, but had the unfortunate drawback of pulling several
dnsdist-specific files into the main pdns/ directory for no good
reason. It also prevented building the fuzzing targets from a dist
tarball/directory.
This commit moves the dnsdist-specific fuzzing target to the dnsdist
build process, and ensure that the standalone_fuzz_target_runner.cc
file is part of the dist tarball, making it possible to build the
fuzzing targets from the dist.
It does not move the dnsdist-specific files to the pdns/dnsdistdist/
directory yet because this would conflict with existing PRs.

fuzzing/README.md
pdns/Makefile.am
pdns/dnsdistdist/Makefile.am
pdns/dnsdistdist/configure.ac
pdns/dnsdistdist/fuzz_dnsdistcache.cc [moved from pdns/fuzz_dnsdistcache.cc with 100% similarity]
pdns/dnsdistdist/fuzz_target_dnsdistcache [new file with mode: 0755]
pdns/dnsdistdist/m4/pdns_enable_fuzz_targets.m4 [new symlink]
pdns/dnsdistdist/standalone_fuzz_target_runner.cc [new symlink]
tasks.py

index c2637d433830e7dfce36a529138e07255399a3a1..f8ec89d190670a46270f139147aad8eb0e0fa45d 100644 (file)
@@ -5,21 +5,24 @@ This repository contains several fuzzing targets that can be used with generic
 fuzzing engines like AFL and libFuzzer.
 
 These targets are built by passing the --enable-fuzz-targets option to the
-configure, then building as usual. You can also build only these targets
-by going into the pdns/ directory and issuing a 'make fuzz_targets' command.
+configure of the authoritative server and dnsdist, then building them as usual.
+You can also build only these targets manually by going into the pdns/ directory
+and issuing a 'make fuzz_targets' command for the authoritative server,
+or going into the pdns/dnsdistdist and issuing a 'make fuzz_targets' command for
+dnsdist.
 
 The current targets cover:
-- the auth, dnsdist and rec packet caches (fuzz_target_packetcache and
-  fuzz_target_dnsdistcache) ;
+- the auth and rec packet cache (fuzz_target_packetcache) ;
 - MOADNSParser (fuzz_target_moadnsparser) ;
 - the Proxy Protocol parser (fuzz_target_proxyprotocol) ;
 - the HTTP parser we use (YaHTTP, fuzz_target_yahttp) ;
 - ZoneParserTNG (fuzz_target_zoneparsertng).
 - Parts of the ragel-generated parser (parseRFC1035CharString in
-  fuzz_target_dnslabeltext)
+  fuzz_target_dnslabeltext) ;
+- the dnsdist packet cache (fuzz_target_dnsdistcache).
 
 By default the targets are linked against a standalone target,
-pdns/standalone_fuzz_target_runner.cc, which does no fuzzing but makes it easy
+standalone_fuzz_target_runner.cc, which does no fuzzing but makes it easy
 to check a given test file, or just that the fuzzing targets can be built properly.
 
 This behaviour can be changed via the LIB_FUZZING_ENGINE variable, for example
@@ -59,7 +62,7 @@ in the fuzzing/corpus/zones/ directory.
 
 Quickly getting started (using clang 11)
 ----------------------------------------
-First, confgure:
+First, configure the authoritative server:
 
 ```
 LIB_FUZZING_ENGINE="/usr/lib/clang/11.0.1/lib/linux/libclang_rt.fuzzer-x86_64.a" \
@@ -70,6 +73,12 @@ LIB_FUZZING_ENGINE="/usr/lib/clang/11.0.1/lib/linux/libclang_rt.fuzzer-x86_64.a"
   ./configure --without-dynmodules --with-modules= --disable-lua-records --disable-ixfrdist --enable-fuzz-targets --disable-dependency-tracking --disable-silent-rules --enable-asan --enable-ubsan
 ```
 
+If you build the fuzzing targets only, you will need to issue the following commands first:
+```
+make -j2 -C ext/arc4random/
+make -j2 -C ext/yahttp/
+```
+
 Then build:
 
 ```
index 625bc1e04414c9ed023016fa54103145dcc4655f..502a2e33a1508fad9ed3e724df6849fcef96fb6d 100644 (file)
@@ -63,6 +63,7 @@ EXTRA_DIST = \
        lua-record.cc \
        minicurl.cc \
        minicurl.hh \
+       standalone_fuzz_target_runner.cc \
        api-swagger.yaml \
        api-swagger.json \
        requirements.txt \
@@ -1527,7 +1528,6 @@ LIB_FUZZING_ENGINE ?= standalone_fuzz_target_runner.o
 standalone_fuzz_target_runner.o: standalone_fuzz_target_runner.cc
 
 fuzz_targets_programs =  \
-       fuzz_target_dnsdistcache \
        fuzz_target_moadnsparser \
        fuzz_target_packetcache \
        fuzz_target_proxyprotocol \
@@ -1601,31 +1601,6 @@ 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 = \
-       channel.hh channel.cc \
-       dns.cc dns.hh \
-       dnsdist-cache.cc dnsdist-cache.hh \
-       dnsdist-ecs.cc dnsdist-ecs.hh \
-       dnsdist-idstate.hh \
-       dnsdist-protocols.cc dnsdist-protocols.hh \
-       dnslabeltext.cc \
-       dnsname.cc dnsname.hh \
-       dnsparser.cc dnsparser.hh \
-       dnswriter.cc dnswriter.hh \
-       doh.hh \
-       ednsoptions.cc ednsoptions.hh \
-       ednssubnet.cc ednssubnet.hh \
-       fuzz_dnsdistcache.cc \
-       iputils.cc iputils.hh \
-       misc.cc misc.hh \
-       packetcache.hh \
-       qtype.cc qtype.hh \
-       svc-records.cc svc-records.hh
-
-fuzz_target_dnsdistcache_DEPENDENCIES = $(fuzz_targets_deps)
-fuzz_target_dnsdistcache_LDFLAGS = $(fuzz_targets_ldflags)
-fuzz_target_dnsdistcache_LDADD = $(fuzz_targets_libs)
-
 fuzz_target_yahttp_SOURCES = \
        fuzz_yahttp.cc
 
index 9b951a58669444df7ef415a935fbd226d0680908..57ecaaa26e536babbf1d8f227552dfd14381d3fd 100644 (file)
@@ -106,6 +106,7 @@ EXTRA_DIST=COPYING \
           kqueuemplexer.cc \
           portsmplexer.cc \
           cdb.cc cdb.hh \
+          standalone_fuzz_target_runner.cc \
           ext/lmdb-safe/lmdb-safe.cc ext/lmdb-safe/lmdb-safe.hh \
           ext/protozero/include/* \
           builder-support/gen-version
@@ -451,6 +452,60 @@ testrunner_SOURCES += \
        portsmplexer.cc
 endif
 
+if FUZZ_TARGETS
+
+LIB_FUZZING_ENGINE ?= standalone_fuzz_target_runner.o
+
+standalone_fuzz_target_runner.o: standalone_fuzz_target_runner.cc
+
+fuzz_targets_programs =  \
+       fuzz_target_dnsdistcache
+
+fuzz_targets: $(ARC4RANDOM_LIBS) $(fuzz_targets_programs)
+
+bin_PROGRAMS += \
+       $(fuzz_targets_programs)
+
+fuzz_targets_libs = \
+       $(LIBCRYPTO_LIBS) \
+       $(LIB_FUZZING_ENGINE)
+
+fuzz_targets_ldflags = \
+       $(AM_LDFLAGS) \
+       $(DYNLINKFLAGS) \
+       $(LIBCRYPTO_LDFLAGS) \
+       $(FUZZING_LDFLAGS)
+
+# we need the mockup runner to be built, but not linked if a real fuzzing engine is used
+fuzz_targets_deps = standalone_fuzz_target_runner.o
+
+fuzz_target_dnsdistcache_SOURCES = \
+       channel.hh channel.cc \
+       dns.cc dns.hh \
+       dnsdist-cache.cc dnsdist-cache.hh \
+       dnsdist-ecs.cc dnsdist-ecs.hh \
+       dnsdist-idstate.hh \
+       dnsdist-protocols.cc dnsdist-protocols.hh \
+       dnslabeltext.cc \
+       dnsname.cc dnsname.hh \
+       dnsparser.cc dnsparser.hh \
+       dnswriter.cc dnswriter.hh \
+       doh.hh \
+       ednsoptions.cc ednsoptions.hh \
+       ednssubnet.cc ednssubnet.hh \
+       fuzz_dnsdistcache.cc \
+       iputils.cc iputils.hh \
+       misc.cc misc.hh \
+       packetcache.hh \
+       qtype.cc qtype.hh \
+       svc-records.cc svc-records.hh
+
+fuzz_target_dnsdistcache_DEPENDENCIES = $(fuzz_targets_deps)
+fuzz_target_dnsdistcache_LDFLAGS = $(fuzz_targets_ldflags)
+fuzz_target_dnsdistcache_LDADD = $(fuzz_targets_libs)
+
+endif
+
 MANPAGES=dnsdist.1
 
 dist_man_MANS=$(MANPAGES)
index aa7ffbf7a44e21f3b0dca476a32779b9dd0cda35..57856ee8e4f08dcd755c5e56570dd501ef349f72 100644 (file)
@@ -35,6 +35,7 @@ AC_FUNC_STRERROR_R
 BOOST_REQUIRE([1.42])
 
 PDNS_ENABLE_UNIT_TESTS
+PDNS_ENABLE_FUZZ_TARGETS
 PDNS_WITH_RE2
 DNSDIST_ENABLE_DNSCRYPT
 PDNS_WITH_EBPF
diff --git a/pdns/dnsdistdist/fuzz_target_dnsdistcache b/pdns/dnsdistdist/fuzz_target_dnsdistcache
new file mode 100755 (executable)
index 0000000..8eb51b8
Binary files /dev/null and b/pdns/dnsdistdist/fuzz_target_dnsdistcache differ
diff --git a/pdns/dnsdistdist/m4/pdns_enable_fuzz_targets.m4 b/pdns/dnsdistdist/m4/pdns_enable_fuzz_targets.m4
new file mode 120000 (symlink)
index 0000000..7bec31c
--- /dev/null
@@ -0,0 +1 @@
+../../../m4/pdns_enable_fuzz_targets.m4
\ No newline at end of file
diff --git a/pdns/dnsdistdist/standalone_fuzz_target_runner.cc b/pdns/dnsdistdist/standalone_fuzz_target_runner.cc
new file mode 120000 (symlink)
index 0000000..61ca1e3
--- /dev/null
@@ -0,0 +1 @@
+../standalone_fuzz_target_runner.cc
\ No newline at end of file
index e78e0a55212ecdee766298922886034b23fff910..0b326ef26c463aacc223652fa79978baf6984f50 100644 (file)
--- a/tasks.py
+++ b/tasks.py
@@ -510,6 +510,7 @@ def ci_dnsdist_configure(c, features):
                           -DDISABLE_FALSE_SHARING_PADDING \
                           -DDISABLE_NPN'
     unittests = ' --enable-unit-tests' if os.getenv('UNIT_TESTS') == 'yes' else ''
+    fuzztargets = '--enable-fuzz-targets' if os.getenv('FUZZING_TARGETS') == 'yes' else ''
     sanitizers = ' '.join('--enable-'+x for x in os.getenv('SANITIZERS').split('+')) if os.getenv('SANITIZERS') != '' else ''
     cflags = '-O1 -Werror=vla -Werror=shadow -Wformat=2 -Werror=format-security -Werror=string-plus-int'
     cxxflags = cflags + ' -Wp,-D_GLIBCXX_ASSERTIONS ' + additional_flags
@@ -524,7 +525,7 @@ def ci_dnsdist_configure(c, features):
                      --enable-fortify-source=auto \
                      --enable-auto-var-init=pattern \
                      --enable-lto=thin \
-                     --prefix=/opt/dnsdist %s %s %s''' % (cflags, cxxflags, features_set, sanitizers, unittests), warn=True)
+                     --prefix=/opt/dnsdist %s %s %s %s''' % (cflags, cxxflags, features_set, sanitizers, unittests, fuzztargets), warn=True)
     if res.exited != 0:
         c.run('cat config.log')
         raise UnexpectedExit(res)