numam-spdk/mk
Jim Harris 050565e5ab test/nvmf: fuzz nvmf target using LLVM's libFuzzer
LLVM provides libFuzzer which does coverage-guided
fuzzing of a library or application under test.  For
SPDK, we can use this as a new and better way to
generate random commands to the SPDK nvmf target.

By default, libFuzzer provides the main() and your
source file just provides the function called by
LLVM for each iteration of random data.  But this
doesn't really work for SPDK since we need to start
the app framework and the nvmf target.  So we
specify -fsanitizer=fuzzer-no-link, explicitly
specify the location of the fuzzer_no_main library
and then call LLVMFuzzerRunDriver to start the
fuzzing process once we are ready.

Since this is all coverage-guided, we invoke the
fuzzer inside the nvmf target application.  So this
patch creates a new target application called
'llvm_nvme_fuzz'. One core is needed to run the
nvmf target, then we spawn a pthread to run the
fuzzer against it.

Currently there are two fuzzers defined.  Fuzzer 0
does random testing of admin commands.  Fuzzer 1
is focused solely on GET_LOG_PAGE and fuzzes a
smaller subset of the bytes in the spdk_nvme_cmd.

Additional fuzzers can be added in the future for
other commands, testing I/O queues, data payloads,
etc.

You do need to specify CC and CXX when running
configure, as well as specify the location of the
special clang_rt.fuzz_no_main library. The path of
that library is dependent on your clang version and
architecture. If using clang-12 on x86_64 platform,
it will look like:

CC=clang-12 CXX=clang++-12 ./configure --with-fuzzer= \
  /usr/lib/llvm-12/lib/clang/12.0.0/lib/linux/libclang_rt.fuzzer_no_main-x86_64.a

Then just do the following to demonstrate the fuzzer
tool.

make
test/nvmf/target/llvm_nvme_fuzz.sh --time=60 --fuzzer=0

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: Iee0997501893ac284a3947a1db7a155c5ceb7849
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/10038
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
2021-12-15 04:32:05 +00:00
..
nvme.libtest.mk build: use DEPDIRS variables to build SPDK_LIB_LIST 2020-12-18 09:40:01 +00:00
spdk_blank.map mk: add a placeholder map file. 2020-05-14 10:37:14 +00:00
spdk.app_cxx.mk mk: support file extension for executables 2021-03-15 09:29:10 +00:00
spdk.app_vars.mk build: use DEPDIRS variables to build SPDK_LIB_LIST 2020-12-18 09:40:01 +00:00
spdk.app.mk build: relink apps when vfio-user library is updated 2021-05-11 12:04:36 +00:00
spdk.common.mk test/nvmf: fuzz nvmf target using LLVM's libFuzzer 2021-12-15 04:32:05 +00:00
spdk.deps.mk build: add copyright header where missing 2016-11-22 16:41:47 -07:00
spdk.fio.mk build/fio: disable warning for fio clang-11 builds 2021-04-08 16:09:00 +00:00
spdk.lib_deps.mk idxd: add trace events for OP_SUBMIT and OP_COMPLETE 2021-11-17 10:58:17 +00:00
spdk.lib.mk make: use CXX to build libraries with C++ code 2021-09-14 07:30:23 +00:00
spdk.mock.unittest.mk ut/rpc: wrap syscalls using spdk.mock.unittest.mk 2021-09-27 20:59:37 +00:00
spdk.modules.mk scheduler: create public API and subsystem for scheduler/governor 2021-09-07 07:33:03 +00:00
spdk.nvmecli.mk vhost: deprecate internal vhost library support 2020-10-20 02:42:16 +00:00
spdk.subdirs.mk Makefile: Add possibility to uninstall spdk. 2019-05-16 20:56:18 +00:00
spdk.unittest.mk usdt: don't emit probes in unit tests 2021-07-09 07:02:28 +00:00