Full name: AFL plus plus, where AFL stands for American Fuzzy Lop, the breed of rabbit after which Michał Zalewski named the original fuzzer.
Definition
AFL++ is a coverage-guided fuzzer: a tool that runs a target program on very many generated inputs, keeps each input that reaches code no earlier input reached, mutates kept inputs into new ones, and saves the inputs that crash the program or make it hang. It continues the fuzzer AFL (American Fuzzy Lop) and adds many instrumentation §14.24 and mutation methods. To cut the cost of each run, AFL++ runs each input in a child process copied from a prepared process, or runs many inputs in one process, called persistent mode.
The idea
Running a program afresh for each input repeats all the work done before the program reads its input: the operating system creates the process, the dynamic linker §12.49 connects the shared libraries, the C library initializes, and the program reads its configuration. For a small parser this can take milliseconds while the parse takes a tenth of a millisecond, so most of the fuzzer’s time goes to start-up.
AFL++ skips the repeated work, and each way of skipping it also skips some cleaning. A fresh process starts clean because the operating system builds it from nothing. A forked child starts from a copy of a prepared process: its memory is clean, but files, sockets and everything else outside its memory are shared with earlier children. A persistent loop reuses one process, so nothing is cleaned unless the harness cleans it. Rinsing laboratory glassware instead of taking a new beaker is a fair picture: faster, and valid only if the rinse removes every residue that could affect the next measurement. The picture stops in one respect: a fuzzer reports the effects of residue as findings, under the name of an innocent input.
How it works
Instrument. Compile the target with an AFL++ compiler wrapper such as
afl-clang-fast. Each edge of the control flow, a possible jump from one block of straight-line code to another, gets a counter in a shared memory area, the coverage map, which the fuzzer reads after every run. Counts are sorted into the ranges 1, 2, 3, 4–7, 8–15, 16–31, 32–127 and 128 or more, and an input is new when some edge reaches a new range. A program without source code can run under an emulator instead, for example in QEMU (Quick Emulator) mode.Fuzz. The program
afl-fuzztakes an input from its queue, mutates it, runs the target, and queues the mutated input if the coverage map shows something new. Crashing inputs go to the output directorycrashes, inputs over the time limit tohangs.Run each input, in one of three ways.
Fresh process: the operating system resets everything, and everything is paid for again.
Fork server: the program starts once and stops at a fixed point §3.22, by default just before
main, or later at a call to__AFL_INIT(), which is called deferred initialization. For each input it callsfork, the operating-system call that creates a child process as a copy of the caller. The child runs the input and exits, and the fork server reports its exit status §13.24. The copy uses copy-on-write §8.11: parent and child share memory pages until one of them writes a page, which is then duplicated. Every child starts from the same memory snapshot, and its changes vanish when it exits.Persistent mode: inside the forked child, a loop
while (__AFL_LOOP(1000)) { ... }processes up to 1000 inputs, each iteration reading an input, calling the code under test and resetting the state; then a fresh child is forked. The maintainers’ documentation calls 1000 a good starting point and reports usual speed gains of 10 to 20 times.
The documentation warns against placing a deferred __AFL_INIT() after the creation of threads or child processes, which fork does not copy; after timers are set; after temporary files, network sockets or offset-sensitive file descriptors §15.21 are created, if their state affects later behavior (a file descriptor is the number by which a process refers to an open file, and its offset is the current read or write position); or after any access to the input. afl-fuzz also shows a value called stability: the percentage of coverage-map entries that stay the same when one input is rerun. The documentation names a drop in stability under persistent mode as a sign that the target keeps state between iterations.
Worked example
Assume these invented costs: start-up ms, covering process creation, loading and the program’s own initialization; one fork of the initialized program ms; processing one input ms.
Fresh process: ms per input, so inputs per second.
Fork server after initialization: ms per input, so inputs per second.
Persistent mode with 1000 inputs per child: ms per input, so inputs per second, about 90 times the fresh-process rate.
Hygiene has its own costs. If the parser leaks a 1 KiB buffer per input, a fork server discards the leak with each child, while in persistent mode one child leaks KiB, about 0.98 MiB, before it is replaced. If the parser sets a global flag on accepting a header and never clears it, input 501 in a persistent loop can crash only because input 500 set the flag. afl-fuzz saves input 501, which does not crash when run alone. Under a fork server, each child starts with the flag clear and this misleading crash cannot occur.
A fork server still shares what lies outside process memory. A log file opened before __AFL_INIT() is shared by all children, with one write position. At 2000 inputs per second and 100 bytes per input, it grows by bytes per second, which is bytes per hour; if the program reads that file back, earlier inputs influence later ones.
Stated precisely
Split the state that can influence one run into three parts: process memory (global variables, heap, stacks); kernel resources held by the process (file descriptors with their read and write positions, sockets, timers, child processes); and external state (files on disk, devices, other processes, network peers). Then:
a fresh process resets , resets except for descriptors inherited from the fuzzer, and resets nothing in ;
a forked child starts with equal to the parent’s memory at the fork point, holds copies of the parent’s descriptors that share position and open file with the parent’s, contains only the thread that called
fork, does not inherit the parent’s timers, and resets nothing in ;a persistent iteration resets nothing; after iterations, the next child resets and as any forked child does.
A saved input is guaranteed to reproduce its result alone when every part of , and that influences its run has, at the start of that run in the campaign, the same value as at the start of a fresh run. Persistent mode moves the duty of meeting this condition for and from the operating system to the harness. No mode meets the condition for by itself.
Limits and common mistakes
Speed figures belong to one target. The factor of 10 to 20 in the documentation and the factor of 90 in the example are not bounds for another program.
A high execution rate with state carried between inputs buys crashes that do not reproduce, corpus entries credited with coverage they did not cause, and coverage noise that misleads the search. Rerun every saved crash alone in a fresh process before trusting it; the AFL++ tool afl-tmin can then shrink it.
Stability below 100% has other causes too, such as timers, random numbers and threads, so a low value calls for investigation, not a conclusion. A high value does not prove that no state is carried over: carried state that changes no edge count is invisible to it.
A forked child that writes a file, sends a network message or changes a device changes it for all later children. Isolating those effects needs a fresh temporary directory, a fake network or a reset of the device, not a different fork point.
Firmware for a microcontroller §6.1 can be fuzzed with AFL++ only through a host build or an emulator; peripheral timing, interrupts §6.11 and power failures then lie outside what the campaign tests.
Questions answered
How do persistent execution and fork-based isolation trade speed against state hygiene?
Fork-based isolation gives each input a fresh copy of a prepared process, so the operating system cleans process memory between inputs at the cost of one fork per input; persistent execution runs many inputs in one process, which removes that cost but leaves all cleaning to the harness. In AFL++ (a fuzzer descended from AFL, American Fuzzy Lop) the trade works out as follows.
Fork server. Each child starts from the same memory snapshot, and its changes to global variables, heap and stack vanish when it exits, so in-memory state cannot pass from one input to the next. Effects outside process memory survive: files written, the shared position of inherited file descriptors, sockets, devices. Threads and timers created before the fork point do not exist in the child, so that point must come before them.
Persistent mode. Skipping the fork usually makes fuzzing §10.9 10 to 20 times faster, according to the maintainers’ documentation. Every global variable, allocation, descriptor and cache survives into the next iteration, so the harness must reset all state that affects behavior. Otherwise crashes do not reproduce from their saved input, coverage is credited to the wrong input, and leaks accumulate. The loop count, with 1000 as the suggested start, bounds how much can accumulate before a fresh child takes over.
Use persistent mode when the code under test can be reset cheaply and completely, such as a parser without global state; use a fork server with deferred initialization when the state is hard to reset. In both cases, watch the stability value and rerun every saved crash alone in a fresh process.
Related entries: Coverage-guided fuzzing (§10.12), Fuzz harness (§10.13), Deterministic replay (§10.37), libFuzzer (§10.26), Copy-on-write (§8.11). Further reading: [107, 183].