fast resume setup detection

This commit is contained in:
vanhauser-thc 2024-06-10 18:22:06 +02:00
parent 8e50c0c103
commit 6ed0a2b4aa
3 changed files with 95 additions and 29 deletions

View File

@ -76,7 +76,13 @@ char *get_fuzzing_state(afl_state_t *afl) {
void write_setup_file(afl_state_t *afl, u32 argc, char **argv) {
u8 fn[PATH_MAX];
u8 fn[PATH_MAX], fn2[PATH_MAX];
snprintf(fn2, PATH_MAX, "%s/target_hash", afl->out_dir);
FILE *f2 = create_ffile(fn2);
fprintf(f2, "%p\n", (void *)get_binary_hash(afl->fsrv.target_path));
fclose(f2);
snprintf(fn, PATH_MAX, "%s/fuzzer_setup", afl->out_dir);
FILE *f = create_ffile(fn);
u32 i;

View File

@ -2101,45 +2101,105 @@ int main(int argc, char **argv_orig, char **envp) {
}
write_setup_file(afl, argc, argv);
setup_cmdline_file(afl, argv + optind);
check_binary(afl, argv[optind]);
read_testcases(afl, NULL);
// read_foreign_testcases(afl, 1); for the moment dont do this
OKF("Loaded a total of %u seeds.", afl->queued_items);
u64 prev_target_hash = 0;
s32 fast_resume = 0, fr_fd = -1;
pivot_inputs(afl);
if (afl->in_place_resume) {
if (!afl->timeout_given) { find_timeout(afl); } // only for resumes!
u8 fn[PATH_MAX], buf[32];
snprintf(fn, PATH_MAX, "%s/target_hash", afl->out_dir);
fr_fd = open(fn, O_RDONLY);
if (fr_fd >= 0) {
if (afl->afl_env.afl_tmpdir && !afl->in_place_resume) {
if (read(fr_fd, buf, 32) >= 16) {
char tmpfile[PATH_MAX];
sscanf(buf, "%p", (void**)&prev_target_hash);
if (afl->file_extension) {
}
snprintf(tmpfile, PATH_MAX, "%s/.cur_input.%s", afl->tmp_dir,
afl->file_extension);
} else {
snprintf(tmpfile, PATH_MAX, "%s/.cur_input", afl->tmp_dir);
}
/* there is still a race condition here, but well ... */
if (access(tmpfile, F_OK) != -1) {
FATAL(
"AFL_TMPDIR already has an existing temporary input file: %s - if "
"this is not from another instance, then just remove the file.",
tmpfile);
close(fr_fd);
}
}
write_setup_file(afl, argc, argv);
if (afl->in_place_resume) {
u64 target_hash = get_binary_hash(afl->fsrv.target_path);
if (!target_hash || prev_target_hash != target_hash) {
ACTF("Target binary is different, cannot perform FAST RESUME!");
} else {
u8 fn[PATH_MAX];
snprintf(fn, PATH_MAX, "%s/fastresume.bin", afl->out_dir);
if ((fr_fd = open(fn, O_RDONLY)) >= 0) {
OKF("Performing FAST RESUME");
// fast_resume = 1;
} else {
ACTF("fastresume.bin not found, cannot perform FAST RESUME!");
}
}
}
if (fast_resume) {
// XXX
} else {
read_testcases(afl, NULL);
pivot_inputs(afl);
if (!afl->timeout_given) { find_timeout(afl); } // only for resumes!
if (afl->afl_env.afl_tmpdir && !afl->in_place_resume) {
char tmpfile[PATH_MAX];
if (afl->file_extension) {
snprintf(tmpfile, PATH_MAX, "%s/.cur_input.%s", afl->tmp_dir,
afl->file_extension);
} else {
snprintf(tmpfile, PATH_MAX, "%s/.cur_input", afl->tmp_dir);
}
/* there is still a race condition here, but well ... */
if (access(tmpfile, F_OK) != -1) {
FATAL(
"AFL_TMPDIR already has an existing temporary input file: %s - if "
"this is not from another instance, then just remove the file.",
tmpfile);
}
}
}
// read_foreign_testcases(afl, 1); for the moment dont do this
OKF("Loaded a total of %u seeds.", afl->queued_items);
/* If we don't have a file name chosen yet, use a safe default. */
if (!afl->fsrv.out_file) {
@ -2196,8 +2256,6 @@ int main(int argc, char **argv_orig, char **envp) {
}
check_binary(afl, argv[optind]);
#ifdef AFL_PERSISTENT_RECORD
if (unlikely(afl->fsrv.persistent_record)) {

View File

@ -99,11 +99,13 @@ inline u64 hash64(u8 *key, u32 len, u64 seed) {
u64 get_binary_hash(u8 *fn) {
if (!fn) { return 0; }
int fd = open(fn, O_RDONLY);
if (fd < 0) { PFATAL("Unable to open '%s'", fn); }
struct stat st;
if (fstat(fd, &st) < 0) { PFATAL("Unable to fstat '%s'", fn); }
u32 f_len = st.st_size;
if (!f_len) { return 0; }
u8 *f_data = mmap(0, f_len, PROT_READ, MAP_PRIVATE, fd, 0);
if (f_data == MAP_FAILED) { PFATAL("Unable to mmap file '%s'", fn); }
close(fd);