To report security bugs, see ‘SECURITY.md’ in the top source directory.


Fuzzing nbdkit using the American Fuzzy Lop (AFL++) persistent mode fuzzer
==========================================================================

You can fuzz nbdkit with AFL++ (https://aflplus.plus/) persistent mode.

Using clang:

  export AFL_USE_ASAN=1
  ./configure \
     --enable-fuzzing \
     --disable-linker-script \
     CC=/usr/bin/afl-clang-fast \
     CXX=/usr/bin/afl-clang-fast \
     --disable-golang \
     --disable-lua \
     --disable-ocaml \
     --disable-perl \
     --disable-python \
     --disable-rust \
     --disable-tcl
  make clean
  make

The fuzzing/testcase_dir directory contains some initial testcases
that AFL can use.

Run multiple copies of afl-fuzz.  Usually you should run 1 master (-M)
and as many slaves (-S) as you can.

Master:

  mkdir -p fuzzing/sync_dir
  export AFL_PRELOAD=./plugins/null/.libs/nbdkit-null-plugin.so
  afl-fuzz -i fuzzing/testcase_dir -o fuzzing/sync_dir -M fuzz01 \
      ./server/nbdkit -t 1 \
          ./plugins/null/.libs/nbdkit-null-plugin.so 1M

Slaves:

  # replace fuzzNN with fuzz02, fuzz03, etc.
  export AFL_PRELOAD=./plugins/null/.libs/nbdkit-null-plugin.so
  afl-fuzz -i fuzzing/testcase_dir -o fuzzing/sync_dir -S fuzzNN \
      ./server/nbdkit -t 1 \
          ./plugins/null/.libs/nbdkit-null-plugin.so 1M

Notes
-----

We only have testcases for the newstyle fixed protocol so far, but if
people report that they are exposing the oldstyle protocol to the
internet / untrusted clients then we could extend the testing for
that.

We have only fuzzed a handful of plugins.  Since plugins can have bugs
as well as the core server, it may be productive to test other plugins
and filters.
