|
|
2 éve | |
|---|---|---|
| .. | ||
| README.md | 2 éve | |
| extract_fuzzer_dictionary.py | 2 éve | |
| extract_fuzzer_dictionary.sh | 2 éve | |
| fuzzer.c | 2 éve | |
| sanitizer_ignorelist.txt | 2 éve | |
Selected functions can be fuzzed via specific libFuzzer harnesses for increased test coverage and issue detection.
Note: the following commands are relative to the trezor-crypto main directory.
A modern C compiler with built-in libFuzzer support is required. The build process will use clang by default.
Set the CC= environment variable if you want to use a special compiler variant.
make clean
FUZZER=1 make fuzzer -j$(nproc)
Recommended: ASAN / UBSAN / MSAN flags for error detection can be specified via the special SANFLAGS.
Examples:
SANFLAGS="-fsanitize=address,undefined"SANFLAGS="-fsanitize=memory -fsanitize-memory-track-origins"Override OPTFLAGS to test the library at different optimization levels or simplify the debugging of detected issues.
Examples:
OPTFLAGS="-O0 -ggdb3"OPTFLAGS="-O3 -march=native -fno-omit-frame-pointer -gline-tables-only"To be determined:
-fsanitize-ignorelist to reduce sanitizer overhead on hot functions-flto and -flto=thin link time optimizationAdvanced usage:
-DFUZZ_ALLOW_SLOW to enable optional fuzzing targets of slow functions-DFUZZER_EXCLUSIVE_TARGET= to disable the use of all other targetsTo be determined:
-DNDEBUG-DUSE_BIP39_CACHE=0 -DUSE_BIP32_CACHE=0 to explicitly disable the cache, a workaround for automatic cache clearing is used otherwise-D_FORTIFY_SOURCE=2 together with optimization flag -O2 or above-fstack-protector-strong or -fstack-protector-all-m32 to closer emulate the 32-bit environment present on microcontroller platforms
DSECP256K1_CONTEXT_SIZE= for 32-bit values, see legacy/firmware/Makefile-DSHA2_UNROLL_TRANSFORM SHA2 optimization flags-fsanitize-coverage=edge,trace-cmp,trace-div,indirect-calls,trace-gep,no-prune to add program counter granularitytrace-loads and trace-stores sanitizer coverage options are also availableSee the libFuzzer documentation for valid options and usage. Detailed fuzzer usage and relevant considerations are out of scope of this document.
Warning: fuzzing is resource-intensive and can have a negative impact on your system stability.
Basic fuzzer call:
./fuzzer/fuzzer
Here is a more sophisticated multithreading example with a persistent input corpus and other optimizations:
mkdir fuzzer/fuzzer_corpus
./fuzzer/fuzzer -max_len=2048 -use_value_profile=1 -workers=16 -jobs=16 -timeout=1 -reload=5 -print_pcs=1 -print_funcs=42 fuzzer/fuzzer_corpus
Hint: for more permanent setups, consider invoking the fuzzer from outside of the source directory to avoid cluttering it with logfiles and crash inputs. Similarly, it is recommended to store the fuzzer corpus in another location.
Dictionaries are a useful mechanism to augment the capabilities of the fuzzer. Specify them via the -dict= flag.
cd fuzzer
./extract_fuzzer_dictionary.sh fuzzer_crypto_tests_strings_dictionary1.txt
The resulting file can be used as a fuzzer dictionary.
CFLAGS="-fprofile-instr-generate -fcoverage-mapping"-runs= or -max_total_time= limitsllvm-profdata merge -output=default.profdata -instr default.profrawllvm-cov show fuzzer/fuzzer -instr-profile=default.profdata -format=html -output-dir=coverage-reportcoverage-report/index.htmlrm default.profraw default.profdata && rm -r coverage-reportAlthough this code is designed primarily for libFuzzer, it can also be used with Honggfuzz. However, the usage details are out of scope of this document.