Skip to content

Commit dda096d

Browse files
committed
allow -L -1 to enable mopt in parallel to classic mutation
1 parent 5daec43 commit dda096d

File tree

7 files changed

+56
-35
lines changed

7 files changed

+56
-35
lines changed

docs/Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ sending a mail to <[email protected]>.
1717
- afl-fuzz:
1818
- variable map size support added (only LTO mode can use this)
1919
- snapshot feature usage now visible in UI
20+
- Now setting "-L -1" will enable MOpt in parallel to normal mutation.
21+
Additionally this allows to run dictionaries, radamsa and cmplog.
2022
- compare-transform/AFL_LLVM_LAF_TRANSFORM_COMPARES now transforms also
2123
static global and local variable comparisons (cannot find all though)
2224
- extended forkserver: map_size and more information is communicated to

docs/README.MOpt.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ enter the pacemaker fuzzing mode.
3636
Setting 0 will enter the pacemaker fuzzing mode at first, which is
3737
recommended in a short time-scale evaluation.
3838

39+
Setting -1 will enable both pacemaker mode and normal aflmutation fuzzing in
40+
parallel.
41+
3942
Other important parameters can be found in afl-fuzz.c, for instance,
4043

4144
'swarm_num': the number of the PSO swarms used in the fuzzing process.

include/afl-fuzz.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,14 +354,14 @@ typedef struct afl_state {
354354
/* MOpt:
355355
Lots of globals, but mostly for the status UI and other things where it
356356
really makes no sense to haul them around as function parameters. */
357-
u64 limit_time_puppet, orig_hit_cnt_puppet, last_limit_time_start,
358-
tmp_pilot_time, total_pacemaker_time, total_puppet_find, temp_puppet_find,
359-
most_time_key, most_time, most_execs_key, most_execs, old_hit_count,
360-
force_ui_update;
357+
u64 orig_hit_cnt_puppet, last_limit_time_start, tmp_pilot_time,
358+
total_pacemaker_time, total_puppet_find, temp_puppet_find, most_time_key,
359+
most_time, most_execs_key, most_execs, old_hit_count, force_ui_update;
361360

362361
MOpt_globals_t mopt_globals_core, mopt_globals_pilot;
363362

364-
s32 SPLICE_CYCLES_puppet, limit_time_sig, key_puppet, key_module;
363+
s32 limit_time_puppet, SPLICE_CYCLES_puppet, limit_time_sig, key_puppet,
364+
key_module;
365365

366366
double w_init, w_end, w_now;
367367

src/afl-forkserver.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,9 @@ void afl_fsrv_start(afl_forkserver_t *fsrv, char **argv,
365365
kill(fsrv->fsrv_pid, SIGKILL);
366366

367367
} else {
368-
368+
369369
rlen = 4;
370-
370+
371371
}
372372

373373
} else {
@@ -631,9 +631,9 @@ void afl_fsrv_start(afl_forkserver_t *fsrv, char **argv,
631631

632632
static void afl_fsrv_kill(afl_forkserver_t *fsrv) {
633633

634-
if (fsrv->child_pid > 0) kill(fsrv->child_pid, SIGKILL);
635-
if (fsrv->fsrv_pid > 0) kill(fsrv->fsrv_pid, SIGKILL);
636-
if (waitpid(fsrv->fsrv_pid, NULL, 0) <= 0) { WARNF("error waitpid\n"); }
634+
if (fsrv->child_pid > 0) kill(fsrv->child_pid, SIGKILL);
635+
if (fsrv->fsrv_pid > 0) kill(fsrv->fsrv_pid, SIGKILL);
636+
if (waitpid(fsrv->fsrv_pid, NULL, 0) <= 0) { WARNF("error waitpid\n"); }
637637

638638
}
639639

src/afl-fuzz-one.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4377,7 +4377,7 @@ void pso_updating(afl_state_t *afl) {
43774377

43784378
u8 fuzz_one(afl_state_t *afl) {
43794379

4380-
int key_val_lv = 0;
4380+
int key_val_lv_1 = 0, key_val_lv_2 = 0;
43814381

43824382
#ifdef _AFL_DOCUMENT_MUTATIONS
43834383

@@ -4397,22 +4397,22 @@ u8 fuzz_one(afl_state_t *afl) {
43974397

43984398
#endif
43994399

4400-
if (afl->limit_time_sig == 0) {
4400+
// if limit_time_sig == -1 then both are run after each other
44014401

4402-
key_val_lv = fuzz_one_original(afl);
4402+
if (afl->limit_time_sig <= 0) { key_val_lv_1 = fuzz_one_original(afl); }
44034403

4404-
} else {
4404+
if (afl->limit_time_sig != 0) {
44054405

44064406
if (afl->key_module == 0)
4407-
key_val_lv = pilot_fuzzing(afl);
4407+
key_val_lv_2 = pilot_fuzzing(afl);
44084408
else if (afl->key_module == 1)
4409-
key_val_lv = core_fuzzing(afl);
4409+
key_val_lv_2 = core_fuzzing(afl);
44104410
else if (afl->key_module == 2)
44114411
pso_updating(afl);
44124412

44134413
}
44144414

4415-
return key_val_lv;
4415+
return (key_val_lv_1 | key_val_lv_2);
44164416

44174417
#undef BUF_PARAMS
44184418

src/afl-fuzz-run.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ u8 run_target(afl_state_t *afl, afl_forkserver_t *fsrv, u32 timeout) {
4949
memset(fsrv->trace_bits, 0, fsrv->map_size);
5050

5151
MEM_BARRIER();
52-
52+
5353
/* we have the fork server (or faux server) up and running, so simply
5454
tell it to have at it, and then read back PID. */
5555

src/afl-fuzz.c

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ static void usage(afl_state_t *afl, u8 *argv0, int more_help) {
109109
"Mutator settings:\n"
110110
" -R[R] - add Radamsa as mutator, add another -R to exclusivly "
111111
"run it\n"
112-
" -L minutes - use MOpt(imize) mode and set the limit time for "
112+
" -L minutes - use MOpt(imize) mode and set the time limit for "
113113
"entering the\n"
114-
" pacemaker mode (minutes of no new paths, 0 = "
115-
"immediately).\n"
116-
" a recommended value is 10-60. see "
117-
"docs/README.MOpt.md\n"
114+
" pacemaker mode (minutes of no new paths). 0 = "
115+
"immediately,\n"
116+
" -1 = immediately and together with normal mutation).\n"
117+
" See docs/README.MOpt.md\n"
118118
" -c program - enable CmpLog by specifying a binary compiled for "
119119
"it.\n"
120120
" if using QEMU, just use -c 0.\n\n"
@@ -553,20 +553,33 @@ int main(int argc, char **argv_orig, char **envp) {
553553
case 'L': { /* MOpt mode */
554554

555555
if (afl->limit_time_sig) FATAL("Multiple -L options not supported");
556-
afl->limit_time_sig = 1;
557556
afl->havoc_max_mult = HAVOC_MAX_MULT_MOPT;
558557

559-
if (sscanf(optarg, "%llu", &afl->limit_time_puppet) < 1 ||
560-
optarg[0] == '-')
558+
if (sscanf(optarg, "%d", &afl->limit_time_puppet) < 1)
561559
FATAL("Bad syntax used for -L");
562560

561+
if (afl->limit_time_puppet == -1) {
562+
563+
afl->limit_time_sig = -1;
564+
afl->limit_time_puppet = 0;
565+
566+
} else if (afl->limit_time_puppet < 0) {
567+
568+
FATAL("-L value must be between 0 and 2000000 or -1");
569+
570+
} else {
571+
572+
afl->limit_time_sig = 1;
573+
574+
}
575+
563576
u64 limit_time_puppet2 = afl->limit_time_puppet * 60 * 1000;
564577

565578
if (limit_time_puppet2 < afl->limit_time_puppet)
566579
FATAL("limit_time overflow");
567580
afl->limit_time_puppet = limit_time_puppet2;
568581

569-
SAYF("limit_time_puppet %llu\n", afl->limit_time_puppet);
582+
SAYF("limit_time_puppet %d\n", afl->limit_time_puppet);
570583
afl->swarm_now = 0;
571584

572585
if (afl->limit_time_puppet == 0) afl->key_puppet = 1;
@@ -701,11 +714,14 @@ int main(int argc, char **argv_orig, char **envp) {
701714

702715
if (afl->use_radamsa) {
703716

704-
if (afl->limit_time_sig)
717+
if (afl->limit_time_sig > 0)
705718
FATAL(
706-
"MOpt and Radamsa are mutually exclusive. We accept pull requests "
707-
"that integrates MOpt with the optional mutators "
708-
"(custom/radamsa/redquenn/...).");
719+
"MOpt and Radamsa are mutually exclusive unless you specify -L -1. "
720+
"We accept pull requests that integrates MOpt with the optional "
721+
"mutators (custom/radamsa/redqueen/...).");
722+
723+
if (afl->limit_time_sig && afl->use_radamsa > 1)
724+
FATAL("Radamsa in radamsa-only mode can not run together with -L");
709725

710726
OKF("Using Radamsa add-on");
711727

@@ -984,11 +1000,11 @@ int main(int argc, char **argv_orig, char **envp) {
9841000

9851001
if (afl->cmplog_binary) {
9861002

987-
if (afl->limit_time_sig)
1003+
if (afl->limit_time_sig > 0)
9881004
FATAL(
989-
"MOpt and CmpLog are mutually exclusive. We accept pull requests "
990-
"that integrates MOpt with the optional mutators "
991-
"(custom/radamsa/redquenn/...).");
1005+
"MOpt and CmpLog are mutually exclusive unless you specify -L -1. We "
1006+
"accept pull requests that integrates MOpt with the optional "
1007+
"mutators (custom/radamsa/redqueen/...).");
9921008

9931009
if (afl->unicorn_mode)
9941010
FATAL("CmpLog and Unicorn mode are not compatible at the moment, sorry");

0 commit comments

Comments
 (0)