Expand description
libafl_targets contains runtime code, injected in the target itself during compilation.
§LibAFL_Targets: Runtime Components for Instrumented Fuzzing Targets
The libafl_targets crate provides the essential runtime components that are injected into a target program during its compilation for fuzzing with LibAFL.
This crate contains the code that runs inside the fuzzed program, communicating with the LibAFL fuzzer to provide coverage information, comparison data, and other feedback.
§Features
libafl_targets is highly modular and uses a feature-based system to allow users to select the specific instrumentation and runtime components needed for their fuzzing campaign. This ensures that only the necessary code is included in the target, minimizing overhead.
A non-exhaustive list of features includes:
- Coverage Tracking: Different strategies for tracking code coverage are available:
sancov_pcguard: Implements coverage tracking using__sanitizer_cov_pc_guard, which can be used for edge coverage (sancov_pcguard_edges) or hit count tracking (sancov_pcguard_hitcounts).sancov_ngram: Supports N-gram coverage to track sequences of executed basic blocks.sancov_ctx: Provides context-sensitive coverage.- …
- Comparison and Value Profiling:
sancov_cmplog: Instruments compare instructions andmemcmp/strcmpcalls to log interesting values, which can be used by theCmpLogfeedback mechanism inLibAFLand solve comparisons during fuzzing.sancov_value_profile: Gathers information about values observed at compare sites.
LibFuzzerCompatibility Layer:libfuzzer: A set of features to provide compatibility with theLibFuzzerfuzzing engine, allowingLibAFLto be used forLibFuzzerharnesses.
- Forkserver:
forkserver: Includes the client-side implementation of a forkserver, which can significantly speed up the fuzzing of programs that have a slow initialization phase.
- Dynamic Analysis:
drcov: Support fordrcovoutput format (DynamoRIOcode coverage) for coverage visualizations.
- …
§The LibAFL Project
The LibAFL project is part of AFLplusplus and maintained by
- Andrea Fioraldi andrea@aflplus.plus
- Dominik Maier dominik@aflplus.plus
- s1341 github@shmarya.net
- Dongjia Zhang toka@aflplus.plus
- Addison Crump me@addisoncrump.info
§Contributing
For bugs, feel free to open issues or contact us directly. Thank you for your support. <3
Even though we will gladly assist you in finishing up your PR, try to
- keep all the crates compiling with stable rust (hide the eventual non-stable code under
cfgs.) - run
cargo nightly fmton your code before pushing - check the output of
cargo clippy --allor./clippy.sh - run
cargo build --no-default-featuresto check forno_stdcompatibility (and possibly add#[cfg(feature = "std")]) to hide parts of your code.
Some parts in this list may sound hard, but don’t be afraid to open a PR if you cannot fix them by yourself. We will gladly assist.
§License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Dependencies under more restrictive licenses, such as GPL or AGPL, can be enabled using the respective feature in each crate when it is present, such as the 'agpl' feature of the libafl crate.
§Feature Flags
§General Features
std(enabled by default) — Enables features that need rust’sstdlib to work, like print, env, … supportintrospection— Collects performance statistics of the fuzzing pipeline and displays it onMonitorcomponentssancov_8bit— Support for thesancov8-bit counters. This feature enables the8-bit-countersruntime forLibAFL, which uses a globalCOUNTERS_MAPSto store coverage maps. It is compatible with LLVM’sSanitizerCoverage8-bit counters instrumentation.sancov_pcguard_edges— Support forsancovpcguard edge coverage. This feature enables thepcguardruntime forLibAFL, specifically for edge coverage. It instruments edges by writing a1to the coverage map at the corresponding index. This is non-colliding coverage. Mutually exclusive withsancov_pcguard_hitcounts.sancov_pcguard_hitcounts— Support forsancovpcguard hitcounts coverage. This feature enables thepcguardruntime forLibAFL, specifically for hitcounts coverage. It instruments edges by incrementing the counter in the coverage map at the corresponding index. This is non-colliding coverage. Mutually exclusive withsancov_pcguard_edges.sancov_value_profile— Support forsancovvalue profile. This feature enables value profiling in thesancovruntime. It compilessancov_cmp.cwithSANCOV_VALUE_PROFILEdefined, enabling tracing of comparisons.sancov_ngram4— Support forsancovngram4 coverage. This feature enables NGRAM-4 instrumentation in thesancovruntime. It maintains a history of the last 4 locations to provide context-sensitive coverage.sancov_ngram8— Support forsancovngram8 coverage. This feature enables NGRAM-8 instrumentation in thesancovruntime. It maintains a history of the last 8 locations to provide context-sensitive coverage.sancov_ctx— Support forsancovcontext coverage. This feature enables context-sensitive coverage in thesancovruntime. It XORs the current position with the previous context ID to distinguish paths based on calling context.sancov_cmplog— Support forsancov-based cmplog. This feature enables comparison logging using the LLVMsancovruntime. It compilessancov_cmp.cwithSANCOV_CMPLOGdefined and links against weak symbols for comparison hooks. This allows tracing of comparison operands for advanced fuzzing techniques like RedQueen. Defines cmp and __sanitizer_weak_hook functions. Use libfuzzer_interceptors to define interceptors (only compatible with Linux)sancov_pcguard— Support forsancovpcguard. This is an alias forsancov_pcguard_hitcounts, enabling hitcounts coverage by default.sancov_pcguard_dump_cov— Support forsancovpcguard dump cov. This uses pcguard to be able to dump lcov-compatible .info files.common(enabled by default) — Compile common C code defining sanitizer options and cross-platform intrinsics. This feature compilescommon.candcommon.h, which are used by many other features.coverage(enabled by default) — Compile C code definining coverage maps. This feature compilescoverage.c, which defines the edge coverage map (EDGES_MAP) and related variables.cmplog(enabled by default) — Compile C code defining cmp log maps. This feature compilescmplog.candcmplog.h, which define the comparison logging map and related structures.forkserver(enabled by default) — Compile C code for forkserver support. This feature compilesforkserver.rsand enables the forkserver protocol for communicating with the fuzzer. It allows the target to be spawned and controlled by a parent fuzzer process.windows_asan(enabled by default) — Compile C code for ASan on Windows. This feature compileswindows_asan.candwindows_asan.rsto provide AddressSanitizer support on Windows.whole_archive— use +whole-archive to ensure the presence of weak symbols. This feature adds the+whole-archivemodifier to linked libraries inbuild.rs. This is important for ensuring that weak symbols (like sanitizer hooks) are included in the final binary.cmplog_extended_instrumentation— This feature enables extendedCmpLoginstrumentation, compatible withAFL++. It compilescmplog.cwithCMPLOG_EXTENDEDdefined.function-logging— Support for function logging. This feature enables thecallmodule, which provides hooks for function calls. It allows tracing function entries and exits.track_hit_feedbacks— Tracks the Feedbacks and the Objectives that were interesting for a Testcase. This feature enables tracking of hit feedbacks in thelibfuzzerOOM observer.
§Libfuzzer-compatibility Features
libfuzzer— Libfuzzer compatibility mode. This feature compileslibfuzzer.cand enables Libfuzzer compatibility. It allowsLibAFLto be used as a drop-in replacement for Libfuzzer.libfuzzer_no_link_main— Libfuzzer mode without linking main. This feature definesFUZZER_NO_LINK_MAINwhen compilinglibfuzzer.c. It prevents the definition of amainfunction, which is useful when the target already has amain.libfuzzer_define_run_driver— Libfuzzer mode defining run driver. This feature definesFUZZER_DEFINE_RUN_DRIVERwhen compilinglibfuzzer.c. It defines therun_driversymbol, which is used by some Libfuzzer targets.libfuzzer_interceptors— Libfuzzer interceptors. This feature compilesFuzzerInterceptors.cpp, which defines interceptors for common library functions (e.g.,malloc,free). It is used to track memory allocations and other events in Libfuzzer compatibility mode.libfuzzer_oom— Libfuzzer OOM handling. This feature enables Out-Of-Memory (OOM) handling in Libfuzzer compatibility mode. It registers a handler to catch OOM errors and report them to the fuzzer.
§Sanitizer Features
sanitizers_flags(enabled by default) — Sanitizer flags. This feature definesDEFAULT_SANITIZERS_OPTIONSincommon.c. It sets default options for sanitizers (e.g., ASAN, MSAN) to be compatible with fuzzing.pointer_maps— Pointer maps. This feature changes the way coverage maps are accessed. Instead of using fixed-size arrays, it uses pointers to access the maps. This is useful when the map location is not known at compile time or when using shared memory.sanitizer_interfaces— Sanitizer interfaces. This feature generates Rust bindings for sanitizer interface headers (sanitizer_interfaces.h). It allows accessing sanitizer functions and structures from Rust code.clippy— Ignore compiler warnings during clippy. This feature suppresses clippy warnings in generated code or specific modules.observers— Observers. This feature enables observer implementations insancov_8bitandcmps. It allows using these observers to track coverage and comparison values.document-features— Document all features of this crate (forcargo doc)
Re-exports§
pub use sancov_pcguard::*;pub use sancov_cmp::*;pub use libfuzzer::*;pub use sancov_8bit::*;pub use coverage::*;pub use value_profile::*;pub use call::*;pub use cmps::*;pub use forkserver::*;
Modules§
- call
- The module to hook call instructions
- cmps
- runtime related to comparisons
- coverage
- Coverage maps as static mut array
- drcov
DrCovsupport forLibAFLFRIDAmode.- forkserver
- Forkserver logic into targets
- libfuzzer
Libfuzzer-style runtime wrapper forLibAFL.- sancov_
8bit LLVM8-bit-countersruntime forLibAFL.- sancov_
cmp - Sanitizer Coverage comparison functions
- sancov_
pcguard LLVMPcGuardruntime forLibAFL.- sancov_
pcguard_ dump_ cov - Dump coverage to
gcov/lcov.infofiles. Use them withgenhtmlto generate HTML coverage reports. - sanitizer_
ifaces - Module containing bindings to the various sanitizer interface headers
- value_
profile - Value profile support for
LibAFL
Constants§
- ACCOUNTING_
MAP_ SIZE - The size of the accounting maps
- CMPLOG_
MAP_ H - The height of the
CmpLogmap - CMPLOG_
MAP_ W - The width of the
CmpLogmap - CMP_
MAP_ SIZE - The size of the cmps map
- EDGES_
MAP_ ALLOCATED_ SIZE - The real allocated size of the edges map
- EDGES_
MAP_ DEFAULT_ SIZE - The default size of the edges map the fuzzer uses