aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorvan Hauser <vh@thc.org>2021-03-10 15:45:14 +0100
committerGitHub <noreply@github.com>2021-03-10 15:45:14 +0100
commit2d92bb483ec3a3c0c30d568b432d15e971fc7015 (patch)
tree5066235cea9d80c5996ab44fa2f6eaddb5656f43 /src
parent976cb3e36c130dc31fb189e9bb4f036730fca7ee (diff)
parent071edb1a2ddcf787680ca5096ddc1d6e28addd0b (diff)
downloadafl++-2d92bb483ec3a3c0c30d568b432d15e971fc7015.tar.gz
Merge pull request #786 from AFLplusplus/dev
push to stable
Diffstat (limited to 'src')
-rw-r--r--src/afl-cc.c119
-rw-r--r--src/afl-common.c1
-rw-r--r--src/afl-forkserver.c25
-rw-r--r--src/afl-fuzz-init.c15
-rw-r--r--src/afl-fuzz.c39
5 files changed, 163 insertions, 36 deletions
diff --git a/src/afl-cc.c b/src/afl-cc.c
index ab794877..44654de0 100644
--- a/src/afl-cc.c
+++ b/src/afl-cc.c
@@ -22,7 +22,7 @@
#include "types.h"
#include "debug.h"
#include "alloc-inl.h"
-#include "llvm-ngram-coverage.h"
+#include "llvm-alternative-coverage.h"
#include <stdio.h>
#include <unistd.h>
@@ -50,7 +50,7 @@ static u8 **cc_params; /* Parameters passed to the real CC */
static u32 cc_par_cnt = 1; /* Param count, including argv0 */
static u8 clang_mode; /* Invoked as afl-clang*? */
static u8 llvm_fullpath[PATH_MAX];
-static u8 instrument_mode, instrument_opt_mode, ngram_size, lto_mode;
+static u8 instrument_mode, instrument_opt_mode, ngram_size, ctx_k, lto_mode;
static u8 compiler_mode, plusplus_mode, have_instr_env = 0;
static u8 have_gcc, have_llvm, have_gcc_plugin, have_lto, have_instr_list = 0;
static u8 * lto_flag = AFL_CLANG_FLTO, *argvnull;
@@ -75,6 +75,7 @@ enum {
INSTRUMENT_OPT_CTX = 8,
INSTRUMENT_OPT_NGRAM = 16,
INSTRUMENT_OPT_CALLER = 32,
+ INSTRUMENT_OPT_CTX_K = 64,
};
@@ -939,7 +940,10 @@ static void edit_params(u32 argc, char **argv, char **envp) {
}
- if (preprocessor_only) {
+ // prevent unnecessary build errors
+ cc_params[cc_par_cnt++] = "-Wno-unused-command-line-argument";
+
+ if (preprocessor_only || have_c) {
/* In the preprocessor_only case (-E), we are not actually compiling at
all but requesting the compiler to output preprocessed sources only.
@@ -1000,18 +1004,15 @@ static void edit_params(u32 argc, char **argv, char **envp) {
}
#if !defined(__APPLE__) && !defined(__sun)
- if (!shared_linking && !have_c)
+ if (!shared_linking)
cc_params[cc_par_cnt++] =
alloc_printf("-Wl,--dynamic-list=%s/dynamic_list.txt", obj_path);
#endif
#if defined(USEMMAP) && !defined(__HAIKU__)
- if (!have_c) cc_params[cc_par_cnt++] = "-lrt";
+ cc_params[cc_par_cnt++] = "-lrt";
#endif
- // prevent unnecessary build errors
- cc_params[cc_par_cnt++] = "-Wno-unused-command-line-argument";
-
}
#endif
@@ -1024,7 +1025,7 @@ static void edit_params(u32 argc, char **argv, char **envp) {
int main(int argc, char **argv, char **envp) {
- int i;
+ int i, passthrough = 0;
char *callname = argv[0], *ptr = NULL;
if (getenv("AFL_DEBUG")) {
@@ -1044,6 +1045,13 @@ int main(int argc, char **argv, char **envp) {
}
+ if (getenv("AFL_PASSTHROUGH") || getenv("AFL_NOOPT")) {
+
+ passthrough = 1;
+ if (!debug) { be_quiet = 1; }
+
+ }
+
if ((ptr = strrchr(callname, '/')) != NULL) callname = ptr + 1;
argvnull = (u8 *)argv[0];
check_environment_vars(envp);
@@ -1288,6 +1296,26 @@ int main(int argc, char **argv, char **envp) {
}
+ if (getenv("AFL_LLVM_CTX_K")) {
+
+ ctx_k = atoi(getenv("AFL_LLVM_CTX_K"));
+ if (ctx_k < 1 || ctx_k > CTX_MAX_K)
+ FATAL("K-CTX instrumentation mode must be between 1 and CTX_MAX_K (%u)",
+ CTX_MAX_K);
+ if (ctx_k == 1) {
+
+ setenv("AFL_LLVM_CALLER", "1", 1);
+ unsetenv("AFL_LLVM_CTX_K");
+ instrument_opt_mode |= INSTRUMENT_OPT_CALLER;
+
+ } else {
+
+ instrument_opt_mode |= INSTRUMENT_OPT_CTX_K;
+
+ }
+
+ }
+
if (getenv("AFL_LLVM_INSTRUMENT")) {
u8 *ptr2 = strtok(getenv("AFL_LLVM_INSTRUMENT"), ":,;");
@@ -1383,6 +1411,44 @@ int main(int argc, char **argv, char **envp) {
}
+ if (strncasecmp(ptr2, "ctx-", strlen("ctx-")) == 0) {
+
+ u8 *ptr3 = ptr2 + strlen("ctx-");
+ while (*ptr3 && (*ptr3 < '0' || *ptr3 > '9'))
+ ptr3++;
+
+ if (!*ptr3) {
+
+ if ((ptr3 = getenv("AFL_LLVM_CTX_K")) == NULL)
+ FATAL(
+ "you must set the K-CTX K with (e.g. for value 2) "
+ "AFL_LLVM_INSTRUMENT=ctx-2");
+
+ }
+
+ ctx_k = atoi(ptr3);
+ if (ctx_k < 1 || ctx_k > CTX_MAX_K)
+ FATAL(
+ "K-CTX instrumentation option must be between 1 and CTX_MAX_K "
+ "(%u)",
+ CTX_MAX_K);
+
+ if (ctx_k == 1) {
+
+ instrument_opt_mode |= INSTRUMENT_OPT_CALLER;
+ setenv("AFL_LLVM_CALLER", "1", 1);
+ unsetenv("AFL_LLVM_CTX_K");
+
+ } else {
+
+ instrument_opt_mode |= (INSTRUMENT_OPT_CTX_K);
+ u8 *ptr4 = alloc_printf("%u", ctx_k);
+ setenv("AFL_LLVM_CTX_K", ptr4, 1);
+
+ }
+
+ }
+
if (strncasecmp(ptr2, "ctx", strlen("ctx")) == 0) {
instrument_opt_mode |= INSTRUMENT_OPT_CTX;
@@ -1437,6 +1503,20 @@ int main(int argc, char **argv, char **envp) {
}
+ if ((instrument_opt_mode & INSTRUMENT_OPT_CTX) &&
+ (instrument_opt_mode & INSTRUMENT_OPT_CTX_K)) {
+
+ FATAL("you cannot set CTX and K-CTX together");
+
+ }
+
+ if ((instrument_opt_mode & INSTRUMENT_OPT_CALLER) &&
+ (instrument_opt_mode & INSTRUMENT_OPT_CTX_K)) {
+
+ FATAL("you cannot set CALLER and K-CTX together");
+
+ }
+
if (instrument_opt_mode && instrument_mode == INSTRUMENT_DEFAULT &&
(compiler_mode == LLVM || compiler_mode == UNSET)) {
@@ -1613,6 +1693,8 @@ int main(int argc, char **argv, char **envp) {
" AFL_DONT_OPTIMIZE: disable optimization instead of -O3\n"
" AFL_NO_BUILTIN: no builtins for string compare functions (for "
"libtokencap.so)\n"
+ " AFL_NOOP: behave like a normal compiler (to pass configure "
+ "tests)\n"
" AFL_PATH: path to instrumenting pass and runtime "
"(afl-compiler-rt.*o)\n"
" AFL_IGNORE_UNKNOWN_ENVS: don't warn on unknown env vars\n"
@@ -1803,13 +1885,17 @@ int main(int argc, char **argv, char **envp) {
} else {
char *ptr2 = alloc_printf(" + NGRAM-%u", ngram_size);
+ char *ptr3 = alloc_printf(" + K-CTX-%u", ctx_k);
+
ptr = alloc_printf(
- "%s%s%s%s", instrument_mode_string[instrument_mode],
+ "%s%s%s%s%s", instrument_mode_string[instrument_mode],
(instrument_opt_mode & INSTRUMENT_OPT_CTX) ? " + CTX" : "",
(instrument_opt_mode & INSTRUMENT_OPT_CALLER) ? " + CALLER" : "",
- (instrument_opt_mode & INSTRUMENT_OPT_NGRAM) ? ptr2 : "");
+ (instrument_opt_mode & INSTRUMENT_OPT_NGRAM) ? ptr2 : "",
+ (instrument_opt_mode & INSTRUMENT_OPT_CTX_K) ? ptr3 : "");
ck_free(ptr2);
+ ck_free(ptr3);
}
@@ -1921,7 +2007,16 @@ int main(int argc, char **argv, char **envp) {
}
- execvp(cc_params[0], (char **)cc_params);
+ if (passthrough) {
+
+ argv[0] = cc_params[0];
+ execvp(cc_params[0], (char **)argv);
+
+ } else {
+
+ execvp(cc_params[0], (char **)cc_params);
+
+ }
FATAL("Oops, failed to execute '%s' - check your PATH", cc_params[0]);
diff --git a/src/afl-common.c b/src/afl-common.c
index a306fe5e..68f82a5e 100644
--- a/src/afl-common.c
+++ b/src/afl-common.c
@@ -682,6 +682,7 @@ void check_environment_vars(char **envp) {
env[strlen(afl_environment_variables[i])] == '=') {
match = 1;
+
if ((val = getenv(afl_environment_variables[i])) && !*val) {
WARNF(
diff --git a/src/afl-forkserver.c b/src/afl-forkserver.c
index 6f08f9f4..68995388 100644
--- a/src/afl-forkserver.c
+++ b/src/afl-forkserver.c
@@ -481,11 +481,11 @@ void afl_fsrv_start(afl_forkserver_t *fsrv, char **argv,
/* This should improve performance a bit, since it stops the linker from
doing extra work post-fork(). */
- if (!getenv("LD_BIND_LAZY")) { setenv("LD_BIND_NOW", "1", 0); }
+ if (!getenv("LD_BIND_LAZY")) { setenv("LD_BIND_NOW", "1", 1); }
/* Set sane defaults for ASAN if nothing else specified. */
- if (fsrv->debug == true && !getenv("ASAN_OPTIONS"))
+ if (!getenv("ASAN_OPTIONS"))
setenv("ASAN_OPTIONS",
"abort_on_error=1:"
"detect_leaks=0:"
@@ -498,11 +498,11 @@ void afl_fsrv_start(afl_forkserver_t *fsrv, char **argv,
"handle_abort=0:"
"handle_sigfpe=0:"
"handle_sigill=0",
- 0);
+ 1);
/* Set sane defaults for UBSAN if nothing else specified. */
- if (fsrv->debug == true && !getenv("UBSAN_OPTIONS"))
+ if (!getenv("UBSAN_OPTIONS"))
setenv("UBSAN_OPTIONS",
"halt_on_error=1:"
"abort_on_error=1:"
@@ -514,7 +514,7 @@ void afl_fsrv_start(afl_forkserver_t *fsrv, char **argv,
"handle_abort=0:"
"handle_sigfpe=0:"
"handle_sigill=0",
- 0);
+ 1);
/* Envs for QASan */
setenv("QASAN_MAX_CALL_STACK", "0", 0);
@@ -523,7 +523,7 @@ void afl_fsrv_start(afl_forkserver_t *fsrv, char **argv,
/* MSAN is tricky, because it doesn't support abort_on_error=1 at this
point. So, we do this in a very hacky way. */
- if (fsrv->debug == true && !getenv("MSAN_OPTIONS"))
+ if (!getenv("MSAN_OPTIONS"))
setenv("MSAN_OPTIONS",
"exit_code=" STRINGIFY(MSAN_ERROR) ":"
"symbolize=0:"
@@ -536,7 +536,7 @@ void afl_fsrv_start(afl_forkserver_t *fsrv, char **argv,
"handle_abort=0:"
"handle_sigfpe=0:"
"handle_sigill=0",
- 0);
+ 1);
fsrv->init_child_func(fsrv, argv);
@@ -821,7 +821,7 @@ void afl_fsrv_start(afl_forkserver_t *fsrv, char **argv,
" - The target binary requires a large map and crashes before "
"reporting.\n"
- " Set a high value (e.g. AFL_MAP_SIZE=1024000) or use "
+ " Set a high value (e.g. AFL_MAP_SIZE=8000000) or use "
"AFL_DEBUG=1 to see the\n"
" message from the target binary\n\n"
@@ -848,7 +848,7 @@ void afl_fsrv_start(afl_forkserver_t *fsrv, char **argv,
" - The target binary requires a large map and crashes before "
"reporting.\n"
- " Set a high value (e.g. AFL_MAP_SIZE=1024000) or use "
+ " Set a high value (e.g. AFL_MAP_SIZE=8000000) or use "
"AFL_DEBUG=1 to see the\n"
" message from the target binary\n\n"
@@ -914,7 +914,7 @@ void afl_fsrv_start(afl_forkserver_t *fsrv, char **argv,
"handshake with the injected code.\n"
"Most likely the target has a huge coverage map, retry with setting"
" the\n"
- "environment variable AFL_MAP_SIZE=4194304\n"
+ "environment variable AFL_MAP_SIZE=8000000\n"
"Otherwise there is a horrible bug in the fuzzer.\n"
"Poke <afl-users@googlegroups.com> for troubleshooting tips.\n");
@@ -931,8 +931,9 @@ void afl_fsrv_start(afl_forkserver_t *fsrv, char **argv,
"%s"
- " - Most likely the target has a huge coverage map, retry with setting the\n"
- " environment variable AFL_MAP_SIZE=4194304\n\n"
+ " - Most likely the target has a huge coverage map, retry with "
+ "setting the\n"
+ " environment variable AFL_MAP_SIZE=8000000\n\n"
" - The current memory limit (%s) is too restrictive, causing an "
"OOM\n"
diff --git a/src/afl-fuzz-init.c b/src/afl-fuzz-init.c
index 3dbc4c65..ca2f75f1 100644
--- a/src/afl-fuzz-init.c
+++ b/src/afl-fuzz-init.c
@@ -828,7 +828,7 @@ void perform_dry_run(afl_state_t *afl) {
for (idx = 0; idx < afl->queued_paths; idx++) {
q = afl->queue_buf[idx];
- if (unlikely(q->disabled)) { continue; }
+ if (unlikely(!q || q->disabled)) { continue; }
u8 res;
s32 fd;
@@ -1069,7 +1069,7 @@ void perform_dry_run(afl_state_t *afl) {
}
afl->max_depth = 0;
- for (i = 0; i < afl->queued_paths; i++) {
+ for (i = 0; i < afl->queued_paths && likely(afl->queue_buf[i]); i++) {
if (!afl->queue_buf[i]->disabled &&
afl->queue_buf[i]->depth > afl->max_depth)
@@ -1136,10 +1136,11 @@ void perform_dry_run(afl_state_t *afl) {
for (idx = 0; idx < afl->queued_paths; idx++) {
q = afl->queue_buf[idx];
- if (q->disabled || q->cal_failed || !q->exec_cksum) { continue; }
+ if (!q || q->disabled || q->cal_failed || !q->exec_cksum) { continue; }
u32 done = 0;
- for (i = idx + 1; i < afl->queued_paths && !done; i++) {
+ for (i = idx + 1;
+ i < afl->queued_paths && !done && likely(afl->queue_buf[i]); i++) {
struct queue_entry *p = afl->queue_buf[i];
if (p->disabled || p->cal_failed || !p->exec_cksum) { continue; }
@@ -1191,7 +1192,7 @@ void perform_dry_run(afl_state_t *afl) {
for (idx = 0; idx < afl->queued_paths; idx++) {
- if (!afl->queue_buf[idx]->disabled &&
+ if (afl->queue_buf[idx] && !afl->queue_buf[idx]->disabled &&
afl->queue_buf[idx]->depth > afl->max_depth)
afl->max_depth = afl->queue_buf[idx]->depth;
@@ -1247,7 +1248,7 @@ void pivot_inputs(afl_state_t *afl) {
ACTF("Creating hard links for all input files...");
- for (i = 0; i < afl->queued_paths; i++) {
+ for (i = 0; i < afl->queued_paths && likely(afl->queue_buf[i]); i++) {
q = afl->queue_buf[i];
@@ -2457,7 +2458,7 @@ void check_asan_opts(afl_state_t *afl) {
}
- if (!strstr(x, "symbolize=0")) {
+ if (!afl->debug && !strstr(x, "symbolize=0")) {
FATAL("Custom MSAN_OPTIONS set without symbolize=0 - please fix!");
diff --git a/src/afl-fuzz.c b/src/afl-fuzz.c
index 09aff4fb..8364c1c2 100644
--- a/src/afl-fuzz.c
+++ b/src/afl-fuzz.c
@@ -1403,6 +1403,15 @@ int main(int argc, char **argv_orig, char **envp) {
set_scheduler_mode(SCHEDULER_MODE_LOW_LATENCY);
#endif
+ #ifdef __APPLE__
+ if (pthread_set_qos_class_self_np(QOS_CLASS_USER_INTERACTIVE, 0) != 0) {
+
+ WARNF("general thread priority settings failed");
+
+ }
+
+ #endif
+
init_count_class16();
if (afl->is_main_node && check_main_node_exists(afl) == 1) {
@@ -1560,13 +1569,21 @@ int main(int argc, char **argv_orig, char **envp) {
if (!afl->non_instrumented_mode && !afl->fsrv.qemu_mode &&
!afl->unicorn_mode) {
- afl->fsrv.map_size = 4194304; // dummy temporary value
- setenv("AFL_MAP_SIZE", "4194304", 1);
+ u32 set_env = 0;
+ if (!getenv("AFL_MAP_SIZE")) {
+
+ afl->fsrv.map_size = 8000000; // dummy temporary value
+ setenv("AFL_MAP_SIZE", "8000000", 1);
+ set_env = 1;
+
+ }
+
+ u32 prev_map_size = afl->fsrv.map_size;
u32 new_map_size = afl_fsrv_get_mapsize(
&afl->fsrv, afl->argv, &afl->stop_soon, afl->afl_env.afl_debug_child);
- if (new_map_size && new_map_size != 4194304) {
+ if (new_map_size && new_map_size != prev_map_size) {
// only reinitialize when it makes sense
if (map_size < new_map_size ||
@@ -1598,6 +1615,7 @@ int main(int argc, char **argv_orig, char **envp) {
}
map_size = new_map_size;
+ if (set_env) { unsetenv("AFL_MAP_SIZE"); }
}
@@ -1615,13 +1633,22 @@ int main(int argc, char **argv_orig, char **envp) {
afl->cmplog_fsrv.cmplog_binary = afl->cmplog_binary;
afl->cmplog_fsrv.init_child_func = cmplog_exec_child;
- afl->cmplog_fsrv.map_size = 4194304;
+ u32 set_env = 0;
+ if (!getenv("AFL_MAP_SIZE")) {
+
+ afl->fsrv.map_size = 8000000; // dummy temporary value
+ setenv("AFL_MAP_SIZE", "8000000", 1);
+ set_env = 1;
+
+ }
+
+ u32 prev_map_size = afl->fsrv.map_size;
u32 new_map_size =
afl_fsrv_get_mapsize(&afl->cmplog_fsrv, afl->argv, &afl->stop_soon,
afl->afl_env.afl_debug_child);
- if (new_map_size && new_map_size != 4194304) {
+ if (new_map_size && new_map_size != prev_map_size) {
// only reinitialize when it needs to be larger
if (map_size < new_map_size) {
@@ -1658,6 +1685,8 @@ int main(int argc, char **argv_orig, char **envp) {
}
+ if (set_env) { unsetenv("AFL_MAP_SIZE"); }
+
}
afl->cmplog_fsrv.map_size = map_size;