Hi,
I have been digging through the libFuzzer code and have some questions around the CMP instruction tracing that is done.
Afaict, LLVM's code coverage instrumentation (SanitizerCoverage) is used to trace CMP instructions as well as memcmp/strcmp calls. There are three tables that store recent compares (i.e. TracePC::TORC4, TracePC::TORC8 and TracePC::TORCW), which are used to (sometimes) fill the auto dictionary (i.e. MutationDispatcher::PersitentAutoDictionary) as part of the default mutations. If I am not misreading the code, then all tables can only hold 32 compares, meaning some compares get overwritten while a fuzz target is running (makes sense since we want to store *recent* compares).
Questions:
1. From what I gathered, tracing for memcmp and strcmp only happens while
the actual fuzz target (user callback) is running (because libFuzzer
options were otherwise leaking into the auto dict
https://bugs.llvm.org/show_bug.cgi?id=37047). Wouldn't the same make sense for CMP instruction tracing?
2. If I am using a custom mutator, are compares from my mutator stored in the TORC* tables? If yes, then that could be counter productive if my mutator also uses "LLVMFuzzerMutate", right?
3. Since only 32 compares can be stored in each table, isn't there a risk that a target like the one below would end up overwriting all the interesting compares of "fuzz_me", if "cleanup" for some reason is doing a bunch of CMP instructions?
```
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
setup();
fuzz_me(data, size);
cleanup();
return 0;
}
```
4. More generally, how "bad" is it if compares from code unrelated to the code that should be fuzzed, leak into the three tables of recent compares?
Thanks,
Niklas