Skip to content

Commit d536ddc

Browse files
committed
change: slaves only sync from masters
1 parent 564399b commit d536ddc

File tree

9 files changed

+89
-45
lines changed

9 files changed

+89
-45
lines changed

TODO.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
## Roadmap 2.65+
44

5-
- sync_fuzzers(): only masters sync from all, slaves only sync from master
6-
(@andrea: be careful, often people run all slaves)
75
- AFL_MAP_SIZE for qemu_mode and unicorn_mode
86
- random crc32 HASH_CONST per run? because with 65536 paths we have collisions
97
- namespace for targets? e.g. network

docs/Changelog.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ Want to stay in the loop on major new features? Join our mailing list by
99
sending a mail to <[email protected]>.
1010

1111

12-
### Version ++2.6d (dev)
13-
- ...
12+
### Version ++2.65d (dev)
13+
- afl-fuzz:
14+
- -S slaves now only sync from the master to increase performance,
15+
the -M master stilly syncs from everyone. Added checks that exactly
16+
one master is present
1417

1518

1619
### Version ++2.65c (release):

docs/parallel_fuzzing.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,14 @@ Each fuzzer will keep its state in a separate subdirectory, like so:
5757
Each instance will also periodically rescan the top-level sync directory
5858
for any test cases found by other fuzzers - and will incorporate them into
5959
its own fuzzing when they are deemed interesting enough.
60+
For performance reasons only -M masters sync the queue with everyone, the
61+
-S slaves will only sync from the master.
6062

6163
The difference between the -M and -S modes is that the master instance will
6264
still perform deterministic checks; while the secondary instances will
63-
proceed straight to random tweaks. If you don't want to do deterministic
64-
fuzzing at all, it's OK to run all instances with -S. With very slow or complex
65-
targets, or when running heavily parallelized jobs, this is usually a good plan.
65+
proceed straight to random tweaks.
66+
67+
Note that you must always have one -M master instance!
6668

6769
Note that running multiple -M instances is wasteful, although there is an
6870
experimental support for parallelizing the deterministic checks. To leverage

include/afl-fuzz.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,7 @@ u32 find_start_position(afl_state_t *);
913913
void find_timeout(afl_state_t *);
914914
double get_runnable_processes(void);
915915
void nuke_resume_dir(afl_state_t *);
916+
int check_master_exists(afl_state_t *);
916917
void setup_dirs_fds(afl_state_t *);
917918
void setup_cmdline_file(afl_state_t *, char **);
918919
void setup_stdio_file(afl_state_t *);

llvm_mode/LLVMInsTrim.so.cc

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,21 +160,23 @@ struct InsTrim : public ModulePass {
160160
else
161161
#else
162162
if (ngram_size_str)
163-
#ifdef LLVM_VERSION_STRING
163+
#ifdef LLVM_VERSION_STRING
164164
FATAL(
165165
"Sorry, NGRAM branch coverage is not supported with llvm version %s!",
166166
LLVM_VERSION_STRING);
167-
#else
168-
#ifndef LLVM_VERSION_PATCH
167+
#else
168+
#ifndef LLVM_VERSION_PATCH
169169
FATAL(
170-
"Sorry, NGRAM branch coverage is not supported with llvm version %d.%d.%d!",
170+
"Sorry, NGRAM branch coverage is not supported with llvm version "
171+
"%d.%d.%d!",
171172
LLVM_VERSION_MAJOR, LLVM_VERSION_MINOR, 0);
172-
#else
173+
#else
173174
FATAL(
174-
"Sorry, NGRAM branch coverage is not supported with llvm version %d.%d.%d!",
175+
"Sorry, NGRAM branch coverage is not supported with llvm version "
176+
"%d.%d.%d!",
175177
LLVM_VERSION_MAJOR, LLVM_VERSION_MINOR, LLVM_VERISON_PATCH);
176-
#endif
177-
#endif
178+
#endif
179+
#endif
178180
#endif
179181
PrevLocSize = 1;
180182

llvm_mode/afl-llvm-pass.so.cc

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -211,15 +211,17 @@ bool AFLCoverage::runOnModule(Module &M) {
211211
else
212212
#else
213213
if (ngram_size_str)
214-
#ifndef LLVM_VERSION_PATCH
215-
FATAL("Sorry, NGRAM branch coverage is not supported with llvm version %d.%d.%d!",
216-
LLVM_VERSION_MAJOR, LLVM_VERSION_MINOR,
217-
0);
218-
#else
219-
FATAL("Sorry, NGRAM branch coverage is not supported with llvm version %d.%d.%d!",
220-
LLVM_VERSION_MAJOR, LLVM_VERSION_MINOR,
221-
LLVM_VERSION_PATCH);
222-
#endif
214+
#ifndef LLVM_VERSION_PATCH
215+
FATAL(
216+
"Sorry, NGRAM branch coverage is not supported with llvm version "
217+
"%d.%d.%d!",
218+
LLVM_VERSION_MAJOR, LLVM_VERSION_MINOR, 0);
219+
#else
220+
FATAL(
221+
"Sorry, NGRAM branch coverage is not supported with llvm version "
222+
"%d.%d.%d!",
223+
LLVM_VERSION_MAJOR, LLVM_VERSION_MINOR, LLVM_VERSION_PATCH);
224+
#endif
223225
#endif
224226
PrevLocSize = 1;
225227

src/afl-fuzz-init.c

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,36 @@ static void handle_existing_out_dir(afl_state_t *afl) {
13151315

13161316
}
13171317

1318+
/* If this is a -S slave, ensure a -M master is running */
1319+
1320+
int check_master_exists(afl_state_t *afl) {
1321+
1322+
DIR * sd;
1323+
struct dirent *sd_ent;
1324+
u8 * fn;
1325+
sd = opendir(afl->sync_dir);
1326+
if (!sd) { PFATAL("Unable to open '%s'", afl->sync_dir); }
1327+
while ((sd_ent = readdir(sd))) {
1328+
1329+
/* Skip dot files and our own output directory. */
1330+
1331+
if (sd_ent->d_name[0] == '.' || !strcmp(afl->sync_id, sd_ent->d_name)) {
1332+
1333+
continue;
1334+
1335+
}
1336+
1337+
fn = alloc_printf("%s/%s/is_master", afl->sync_dir, sd_ent->d_name);
1338+
int res = access(fn, F_OK);
1339+
free(fn);
1340+
if (res == 0) return 1;
1341+
1342+
}
1343+
1344+
return 0;
1345+
1346+
}
1347+
13181348
/* Prepare output directories and fds. */
13191349

13201350
void setup_dirs_fds(afl_state_t *afl) {
@@ -1330,18 +1360,15 @@ void setup_dirs_fds(afl_state_t *afl) {
13301360

13311361
}
13321362

1333-
/*
1334-
if (afl->is_master) {
1363+
if (afl->is_master) {
13351364

1336-
u8 *x = alloc_printf("%s/%s/is_master", afl->sync_dir, afl->sync_id);
1337-
int fd = open(x, O_CREAT | O_RDWR, 0644);
1338-
if (fd < 0) FATAL("cannot create %s", x);
1339-
free(x);
1340-
close(fd);
1341-
1342-
}
1365+
u8 *x = alloc_printf("%s/%s/is_master", afl->sync_dir, afl->sync_id);
1366+
int fd = open(x, O_CREAT | O_RDWR, 0644);
1367+
if (fd < 0) FATAL("cannot create %s", x);
1368+
free(x);
1369+
close(fd);
13431370

1344-
*/
1371+
}
13451372

13461373
if (mkdir(afl->out_dir, 0700)) {
13471374

src/afl-fuzz-run.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -401,19 +401,15 @@ void sync_fuzzers(afl_state_t *afl) {
401401

402402
}
403403

404-
/*
405-
// a slave only syncs from a master, a master syncs from everyone
406-
if (likely(afl->is_slave)) {
404+
// a slave only syncs from a master, a master syncs from everyone
405+
if (likely(afl->is_slave)) {
407406

408-
u8 x = alloc_printf("%s/%s/is_master", afl->sync_dir, sd_ent->d_name);
409-
int res = access(x, F_OK);
410-
free(x);
411-
if (res != 0)
412-
continue;
407+
u8 *x = alloc_printf("%s/%s/is_master", afl->sync_dir, sd_ent->d_name);
408+
int res = access(x, F_OK);
409+
free(x);
410+
if (likely(res != 0)) continue;
413411

414-
}
415-
416-
*/
412+
}
417413

418414
/* Skip anything that doesn't have a queue/ subdirectory. */
419415

src/afl-fuzz.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,8 +1065,21 @@ int main(int argc, char **argv_orig, char **envp) {
10651065

10661066
init_count_class16();
10671067

1068+
if (afl->is_master && check_master_exists(afl) == 1) {
1069+
1070+
WARNF("It is wasteful to run more than one master!");
1071+
1072+
}
1073+
10681074
setup_dirs_fds(afl);
10691075

1076+
if (afl->is_slave && check_master_exists(afl) == 0) {
1077+
1078+
WARNF("no -M master found. You need to run one master!");
1079+
sleep(5);
1080+
1081+
}
1082+
10701083
setup_custom_mutators(afl);
10711084

10721085
setup_cmdline_file(afl, argv + optind);

0 commit comments

Comments
 (0)