Merge pull request #1576 from AFLplusplus/persistent_mode_always

Persistent mode always
This commit is contained in:
van Hauser
2022-11-10 14:46:01 +01:00
committed by GitHub
3 changed files with 27 additions and 27 deletions

View File

@ -8,6 +8,7 @@
"__afl_auto_first"; "__afl_auto_first";
"__afl_auto_init"; "__afl_auto_init";
"__afl_auto_second"; "__afl_auto_second";
"__afl_connected";
"__afl_coverage_discard"; "__afl_coverage_discard";
"__afl_coverage_interesting"; "__afl_coverage_interesting";
"__afl_coverage_off"; "__afl_coverage_off";

View File

@ -105,6 +105,9 @@ u32 __afl_dictionary_len;
u64 __afl_map_addr; u64 __afl_map_addr;
u32 __afl_first_final_loc; u32 __afl_first_final_loc;
/* 1 if we are running in afl, and the forkserver was stared, else 0 */
u32 __afl_connected = 0;
// for the __AFL_COVERAGE_ON/__AFL_COVERAGE_OFF features to work: // for the __AFL_COVERAGE_ON/__AFL_COVERAGE_OFF features to work:
int __afl_selective_coverage __attribute__((weak)); int __afl_selective_coverage __attribute__((weak));
int __afl_selective_coverage_start_off __attribute__((weak)); int __afl_selective_coverage_start_off __attribute__((weak));
@ -1049,7 +1052,11 @@ static void __afl_start_forkserver(void) {
/* Phone home and tell the parent that we're OK. If parent isn't there, /* Phone home and tell the parent that we're OK. If parent isn't there,
assume we're not running in forkserver mode and just execute program. */ assume we're not running in forkserver mode and just execute program. */
if (write(FORKSRV_FD + 1, tmp, 4) != 4) { return; } if (write(FORKSRV_FD + 1, tmp, 4) != 4) {
return;
}
__afl_connected = 1;
if (__afl_sharedmem_fuzzing || (__afl_dictionary_len && __afl_dictionary)) { if (__afl_sharedmem_fuzzing || (__afl_dictionary_len && __afl_dictionary)) {
@ -1261,13 +1268,9 @@ int __afl_persistent_loop(unsigned int max_cnt) {
iteration, it's our job to erase any trace of whatever happened iteration, it's our job to erase any trace of whatever happened
before the loop. */ before the loop. */
if (is_persistent) { memset(__afl_area_ptr, 0, __afl_map_size);
__afl_area_ptr[0] = 1;
memset(__afl_area_ptr, 0, __afl_map_size); memset(__afl_prev_loc, 0, NGRAM_SIZE_MAX * sizeof(PREV_LOC_T));
__afl_area_ptr[0] = 1;
memset(__afl_prev_loc, 0, NGRAM_SIZE_MAX * sizeof(PREV_LOC_T));
}
cycle_cnt = max_cnt; cycle_cnt = max_cnt;
first_pass = 0; first_pass = 0;
@ -1275,34 +1278,28 @@ int __afl_persistent_loop(unsigned int max_cnt) {
return 1; return 1;
} } else if (--cycle_cnt) {
if (is_persistent) { raise(SIGSTOP);
if (--cycle_cnt) { __afl_area_ptr[0] = 1;
memset(__afl_prev_loc, 0, NGRAM_SIZE_MAX * sizeof(PREV_LOC_T));
__afl_selective_coverage_temp = 1;
raise(SIGSTOP); return 1;
__afl_area_ptr[0] = 1; } else {
memset(__afl_prev_loc, 0, NGRAM_SIZE_MAX * sizeof(PREV_LOC_T));
__afl_selective_coverage_temp = 1;
return 1; /* When exiting __AFL_LOOP(), make sure that the subsequent code that
follows the loop is not traced. We do that by pivoting back to the
dummy output region. */
} else { __afl_area_ptr = __afl_area_ptr_dummy;
/* When exiting __AFL_LOOP(), make sure that the subsequent code that return 0;
follows the loop is not traced. We do that by pivoting back to the
dummy output region. */
__afl_area_ptr = __afl_area_ptr_dummy;
}
} }
return 0;
} }
/* This one can be called from user code when deferred forkserver mode /* This one can be called from user code when deferred forkserver mode

View File

@ -1166,6 +1166,7 @@ static void edit_params(u32 argc, char **argv, char **envp) {
"({ static volatile char *_B __attribute__((used,unused)); " "({ static volatile char *_B __attribute__((used,unused)); "
" _B = (char*)\"" PERSIST_SIG " _B = (char*)\"" PERSIST_SIG
"\"; " "\"; "
"extern int __afl_connected;"
#ifdef __APPLE__ #ifdef __APPLE__
"__attribute__((visibility(\"default\"))) " "__attribute__((visibility(\"default\"))) "
"int _L(unsigned int) __asm__(\"___afl_persistent_loop\"); " "int _L(unsigned int) __asm__(\"___afl_persistent_loop\"); "
@ -1173,7 +1174,8 @@ static void edit_params(u32 argc, char **argv, char **envp) {
"__attribute__((visibility(\"default\"))) " "__attribute__((visibility(\"default\"))) "
"int _L(unsigned int) __asm__(\"__afl_persistent_loop\"); " "int _L(unsigned int) __asm__(\"__afl_persistent_loop\"); "
#endif /* ^__APPLE__ */ #endif /* ^__APPLE__ */
"_L(_A); })"; // if afl is connected, we run _A times, else once.
"_L(__afl_connected ? _A : 1); })";
cc_params[cc_par_cnt++] = cc_params[cc_par_cnt++] =
"-D__AFL_INIT()=" "-D__AFL_INIT()="