diff options
author | Christian Holler (:decoder) <choller@mozilla.com> | 2023-04-25 16:03:21 +0200 |
---|---|---|
committer | Christian Holler (:decoder) <choller@mozilla.com> | 2023-04-25 16:27:25 +0200 |
commit | f94a7e88902f1589b105e74ec1a36e3e3bf01f9e (patch) | |
tree | 8ca4a4491e6d5293a2025ceab0a6a85fc46f64fa | |
parent | dbb317162415a28e3fd2ff4c574292c924493a00 (diff) | |
download | afl++-f94a7e88902f1589b105e74ec1a36e3e3bf01f9e.tar.gz |
Add env var to ignore coverage from dynamically loaded code after forkserver.
When using TRACEPC instrumentation, loading code dynamically (e.g. through dlopen()) it can be useful to completely ignore the loaded code, esp. when it cannot be preloaded and is not the target to be tested. This patch allows setting AFL_LLVM_IGNORE_PROBLEMS_COVERAGE=1 to do so.
-rw-r--r-- | instrumentation/afl-compiler-rt.o.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/instrumentation/afl-compiler-rt.o.c b/instrumentation/afl-compiler-rt.o.c index e0e40983..74506e4c 100644 --- a/instrumentation/afl-compiler-rt.o.c +++ b/instrumentation/afl-compiler-rt.o.c @@ -1563,17 +1563,27 @@ void __sanitizer_cov_trace_pc_guard_init(uint32_t *start, uint32_t *stop) { "[-] FATAL: forkserver is already up, but an instrumented dlopen() " "library loaded afterwards. You must AFL_PRELOAD such libraries to " "be able to fuzz them or LD_PRELOAD to run outside of afl-fuzz.\n" - "To ignore this set AFL_IGNORE_PROBLEMS=1 but this will be bad for " - "coverage.\n"); + "To ignore this set AFL_IGNORE_PROBLEMS=1 but this will lead to " + "ambiguous coverage data.\n" + "In addition, you can set AFL_LLVM_IGNORE_PROBLEMS_COVERAGE=1 to " + "ignore the additional coverage instead (use with caution!).\n"); abort(); } else { + u8 ignore_dso_after_fs = !!getenv("AFL_LLVM_IGNORE_PROBLEMS_COVERAGE"); + if (__afl_debug && ignore_dso_after_fs) { + + fprintf(stderr, "Ignoring coverage from dynamically loaded code\n"); + + } + static u32 offset = 5; while (start < stop) { - if (likely(inst_ratio == 100) || R(100) < inst_ratio) { + if (!ignore_dso_after_fs && + (likely(inst_ratio == 100) || R(100) < inst_ratio)) { *(start++) = offset; |