mirror of
https://github.com/AFLplusplus/AFLplusplus.git
synced 2025-06-13 02:28:09 +00:00
format
This commit is contained in:
@ -653,7 +653,8 @@ extern u8* cmplog_binary;
|
||||
extern s32 cmplog_forksrv_pid;
|
||||
|
||||
void init_cmplog_forkserver(char** argv);
|
||||
u8 input_to_state_stage(char** argv, u8* orig_buf, u8* buf, u32 len, u32 exec_cksum);
|
||||
u8 input_to_state_stage(char** argv, u8* orig_buf, u8* buf, u32 len,
|
||||
u32 exec_cksum);
|
||||
|
||||
/**** Inline routines ****/
|
||||
|
||||
|
@ -47,3 +47,4 @@ struct cmp_map {
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -200,7 +200,8 @@ static void edit_params(u32 argc, char** argv) {
|
||||
if (getenv("AFL_CMPLOG"))
|
||||
cc_params[cc_par_cnt++] = "-fsanitize-coverage=trace-pc-guard,trace-cmp";
|
||||
else
|
||||
cc_params[cc_par_cnt++] = "-fsanitize-coverage=trace-pc-guard"; // edge coverage by default
|
||||
cc_params[cc_par_cnt++] =
|
||||
"-fsanitize-coverage=trace-pc-guard"; // edge coverage by default
|
||||
// cc_params[cc_par_cnt++] = "-mllvm";
|
||||
// cc_params[cc_par_cnt++] =
|
||||
// "-fsanitize-coverage=trace-cmp,trace-div,trace-gep";
|
||||
|
@ -325,7 +325,9 @@ __attribute__((constructor(CONST_PRIO))) void __afl_auto_init(void) {
|
||||
///// CmpLog instrumentation
|
||||
|
||||
void __sanitizer_cov_trace_cmp1(uint8_t Arg1, uint8_t Arg2) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
void __sanitizer_cov_trace_cmp2(uint16_t Arg1, uint16_t Arg2) {
|
||||
@ -419,7 +421,6 @@ void __sanitizer_cov_trace_switch(uint64_t Val, uint64_t* Cases) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* The following stuff deals with supporting -fsanitize-coverage=trace-pc-guard.
|
||||
It remains non-operational in the traditional, plugin-backed LLVM mode.
|
||||
For more info about 'trace-pc-guard', see README.llvm.
|
||||
|
@ -524,7 +524,12 @@ u8 save_if_interesting(char** argv, void* mem, u32 len, u8 fault) {
|
||||
struct queue_entry* q = queue;
|
||||
while (q) {
|
||||
|
||||
if (q->exec_cksum == cksum) { q->n_fuzz = q->n_fuzz + 1; break ; }
|
||||
if (q->exec_cksum == cksum) {
|
||||
|
||||
q->n_fuzz = q->n_fuzz + 1;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
q = q->next;
|
||||
|
||||
|
@ -25,9 +25,11 @@ char** its_argv;
|
||||
///// Colorization
|
||||
|
||||
struct range {
|
||||
|
||||
u32 start;
|
||||
u32 end;
|
||||
struct range* next;
|
||||
|
||||
};
|
||||
|
||||
struct range* add_range(struct range* ranges, u32 start, u32 end) {
|
||||
@ -49,21 +51,28 @@ struct range* pop_biggest_range(struct range** ranges) {
|
||||
u32 max_size = 0;
|
||||
|
||||
while (r) {
|
||||
|
||||
u32 s = r->end - r->start;
|
||||
if (s >= max_size) {
|
||||
|
||||
max_size = s;
|
||||
prev_rmax = prev;
|
||||
rmax = r;
|
||||
|
||||
}
|
||||
|
||||
prev = r;
|
||||
r = r->next;
|
||||
|
||||
}
|
||||
|
||||
if (rmax) {
|
||||
|
||||
if (prev_rmax)
|
||||
prev_rmax->next = rmax->next;
|
||||
else
|
||||
*ranges = rmax->next;
|
||||
|
||||
}
|
||||
|
||||
return rmax;
|
||||
@ -72,8 +81,7 @@ struct range* pop_biggest_range(struct range** ranges) {
|
||||
|
||||
u8 get_exec_checksum(u8* buf, u32 len, u32* cksum) {
|
||||
|
||||
if (unlikely(common_fuzz_stuff(its_argv, buf, len)))
|
||||
return 1;
|
||||
if (unlikely(common_fuzz_stuff(its_argv, buf, len))) return 1;
|
||||
|
||||
*cksum = hash32(trace_bits, MAP_SIZE, HASH_CONST);
|
||||
return 0;
|
||||
@ -109,8 +117,7 @@ u8 colorization(u8* buf, u32 len, u32 exec_cksum) {
|
||||
rand_replace(buf + rng->start, s);
|
||||
|
||||
u32 cksum;
|
||||
if (unlikely(get_exec_checksum(buf, len, &cksum)))
|
||||
return 1;
|
||||
if (unlikely(get_exec_checksum(buf, len, &cksum))) return 1;
|
||||
|
||||
if (cksum != exec_cksum) {
|
||||
|
||||
@ -130,9 +137,11 @@ u8 colorization(u8* buf, u32 len, u32 exec_cksum) {
|
||||
stage_cycles[STAGE_COLORIZATION] += stage_max - stage_cur;
|
||||
|
||||
while (ranges) {
|
||||
|
||||
rng = ranges;
|
||||
ranges = ranges->next;
|
||||
ck_free(rng);
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -147,8 +156,7 @@ u8 its_fuzz(u32 idx, u32 size, u8* buf, u32 len, u8* status) {
|
||||
|
||||
orig_hit_cnt = queued_paths + unique_crashes;
|
||||
|
||||
if (unlikely(common_fuzz_stuff(its_argv, buf, len)))
|
||||
return 1;
|
||||
if (unlikely(common_fuzz_stuff(its_argv, buf, len))) return 1;
|
||||
|
||||
new_hit_cnt = queued_paths + unique_crashes;
|
||||
|
||||
@ -169,7 +177,8 @@ u8 its_fuzz(u32 idx, u32 size, u8* buf, u32 len, u8* status) {
|
||||
}
|
||||
|
||||
u8 cmp_extend_encoding(struct cmp_header* h, u64 pattern, u64 repl, u32 idx,
|
||||
u8* orig_buf, u8* buf, u32 len, u8 do_reverse, u8* status) {
|
||||
u8* orig_buf, u8* buf, u32 len, u8 do_reverse,
|
||||
u8* status) {
|
||||
|
||||
u64* buf_64 = (u64*)&buf[idx];
|
||||
u32* buf_32 = (u32*)&buf[idx];
|
||||
@ -184,54 +193,70 @@ u8 cmp_extend_encoding(struct cmp_header* h, u64 pattern, u64 repl, u32 idx,
|
||||
*status = 0;
|
||||
|
||||
if (SHAPE_BYTES(h->shape) == 8) {
|
||||
|
||||
if (its_len >= 8 && *buf_64 == pattern && *o_buf_64 == pattern) {
|
||||
|
||||
*buf_64 = repl;
|
||||
if (unlikely(its_fuzz(idx, 8, buf, len, status)))
|
||||
return 1;
|
||||
if (unlikely(its_fuzz(idx, 8, buf, len, status))) return 1;
|
||||
*buf_64 = pattern;
|
||||
|
||||
}
|
||||
|
||||
// reverse encoding
|
||||
if (do_reverse)
|
||||
if (unlikely(cmp_extend_encoding(h, SWAP64(pattern), SWAP64(repl), idx,
|
||||
orig_buf, buf, len, 0, status)))
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
if (SHAPE_BYTES(h->shape) == 4 || *status == 2) {
|
||||
|
||||
if (its_len >= 4 && *buf_32 == (u32)pattern && *o_buf_32 == (u32)pattern) {
|
||||
|
||||
*buf_32 = (u32)repl;
|
||||
if (unlikely(its_fuzz(idx, 4, buf, len, status)))
|
||||
return 1;
|
||||
if (unlikely(its_fuzz(idx, 4, buf, len, status))) return 1;
|
||||
*buf_32 = pattern;
|
||||
|
||||
}
|
||||
|
||||
// reverse encoding
|
||||
if (do_reverse)
|
||||
if (unlikely(cmp_extend_encoding(h, SWAP32(pattern), SWAP32(repl), idx,
|
||||
orig_buf, buf, len, 0, status)))
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
if (SHAPE_BYTES(h->shape) == 2 || *status == 2) {
|
||||
|
||||
if (its_len >= 2 && *buf_16 == (u16)pattern && *o_buf_16 == (u16)pattern) {
|
||||
|
||||
*buf_16 = (u16)repl;
|
||||
if (unlikely(its_fuzz(idx, 2, buf, len, status)))
|
||||
return 1;
|
||||
if (unlikely(its_fuzz(idx, 2, buf, len, status))) return 1;
|
||||
*buf_16 = (u16)pattern;
|
||||
|
||||
}
|
||||
|
||||
// reverse encoding
|
||||
if (do_reverse)
|
||||
if (unlikely(cmp_extend_encoding(h, SWAP16(pattern), SWAP16(repl), idx,
|
||||
orig_buf, buf, len, 0, status)))
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
/*if (SHAPE_BYTES(h->shape) == 1 || *status == 2) {
|
||||
|
||||
if (its_len >= 2 && *buf_8 == (u8)pattern && *o_buf_8 == (u8)pattern) {
|
||||
|
||||
*buf_8 = (u8)repl;
|
||||
if (unlikely(its_fuzz(idx, 1, buf, len, status)))
|
||||
return 1;
|
||||
*buf_16 = (u16)pattern;
|
||||
|
||||
}
|
||||
|
||||
}*/
|
||||
|
||||
return 0;
|
||||
@ -244,8 +269,7 @@ u8 cmp_fuzz(u32 key, u8* orig_buf, u8* buf, u32 len) {
|
||||
u32 i, j, idx;
|
||||
|
||||
u32 loggeds = h->hits;
|
||||
if (h->hits > CMP_MAP_H)
|
||||
loggeds = CMP_MAP_H;
|
||||
if (h->hits > CMP_MAP_H) loggeds = CMP_MAP_H;
|
||||
|
||||
u8 status;
|
||||
// opt not in the paper
|
||||
@ -262,15 +286,21 @@ u8 cmp_fuzz(u32 key, u8* orig_buf, u8* buf, u32 len) {
|
||||
|
||||
for (idx = 0; idx < len && fails < 8; ++idx) {
|
||||
|
||||
if (unlikely(cmp_extend_encoding(h, o->v0, o->v1, idx, orig_buf, buf, len, 1, &status)))
|
||||
if (unlikely(cmp_extend_encoding(h, o->v0, o->v1, idx, orig_buf, buf, len,
|
||||
1, &status)))
|
||||
return 1;
|
||||
if (status == 2) ++fails;
|
||||
else if (status == 1) break;
|
||||
if (status == 2)
|
||||
++fails;
|
||||
else if (status == 1)
|
||||
break;
|
||||
|
||||
if (unlikely(cmp_extend_encoding(h, o->v1, o->v0, idx, orig_buf, buf, len, 1, &status)))
|
||||
if (unlikely(cmp_extend_encoding(h, o->v1, o->v0, idx, orig_buf, buf, len,
|
||||
1, &status)))
|
||||
return 1;
|
||||
if (status == 2) ++fails;
|
||||
else if (status == 1) break;
|
||||
if (status == 2)
|
||||
++fails;
|
||||
else if (status == 1)
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
@ -286,18 +316,17 @@ cmp_fuzz_next_iter:
|
||||
///// Input to State stage
|
||||
|
||||
// queue_cur->exec_cksum
|
||||
u8 input_to_state_stage(char** argv, u8* orig_buf, u8* buf, u32 len, u32 exec_cksum) {
|
||||
u8 input_to_state_stage(char** argv, u8* orig_buf, u8* buf, u32 len,
|
||||
u32 exec_cksum) {
|
||||
|
||||
its_argv = argv;
|
||||
|
||||
if (unlikely(colorization(buf, len, exec_cksum)))
|
||||
return 1;
|
||||
if (unlikely(colorization(buf, len, exec_cksum))) return 1;
|
||||
|
||||
// do it manually, forkserver clear only trace_bits
|
||||
memset(cmp_map->headers, 0, sizeof(cmp_map->headers));
|
||||
|
||||
if (unlikely(common_fuzz_cmplog_stuff(argv, buf, len)))
|
||||
return 1;
|
||||
if (unlikely(common_fuzz_cmplog_stuff(argv, buf, len))) return 1;
|
||||
|
||||
u64 orig_hit_cnt, new_hit_cnt;
|
||||
u64 orig_execs = total_execs;
|
||||
@ -311,8 +340,7 @@ u8 input_to_state_stage(char** argv, u8* orig_buf, u8* buf, u32 len, u32 exec_ck
|
||||
u32 k;
|
||||
for (k = 0; k < CMP_MAP_W; ++k) {
|
||||
|
||||
if (!cmp_map->headers[k].hits)
|
||||
continue;
|
||||
if (!cmp_map->headers[k].hits) continue;
|
||||
if (cmp_map->headers[k].hits > CMP_MAP_H)
|
||||
stage_max += CMP_MAP_H;
|
||||
else
|
||||
@ -322,8 +350,7 @@ u8 input_to_state_stage(char** argv, u8* orig_buf, u8* buf, u32 len, u32 exec_ck
|
||||
|
||||
for (k = 0; k < CMP_MAP_W; ++k) {
|
||||
|
||||
if (!cmp_map->headers[k].hits)
|
||||
continue;
|
||||
if (!cmp_map->headers[k].hits) continue;
|
||||
cmp_fuzz(k, orig_buf, buf, len);
|
||||
|
||||
}
|
||||
@ -338,13 +365,9 @@ u8 input_to_state_stage(char** argv, u8* orig_buf, u8* buf, u32 len, u32 exec_ck
|
||||
|
||||
}
|
||||
|
||||
|
||||
//// CmpLog forkserver
|
||||
|
||||
s32 cmplog_forksrv_pid,
|
||||
cmplog_child_pid,
|
||||
cmplog_fsrv_ctl_fd,
|
||||
cmplog_fsrv_st_fd;
|
||||
s32 cmplog_forksrv_pid, cmplog_child_pid, cmplog_fsrv_ctl_fd, cmplog_fsrv_st_fd;
|
||||
|
||||
void init_cmplog_forkserver(char** argv) {
|
||||
|
||||
@ -519,7 +542,9 @@ void init_cmplog_forkserver(char **argv) {
|
||||
}
|
||||
|
||||
if (child_timed_out)
|
||||
FATAL("Timeout while initializing cmplog fork server (adjusting -t may help)");
|
||||
FATAL(
|
||||
"Timeout while initializing cmplog fork server (adjusting -t may "
|
||||
"help)");
|
||||
|
||||
if (waitpid(cmplog_forksrv_pid, &status, 0) <= 0) PFATAL("waitpid() failed");
|
||||
|
||||
@ -781,18 +806,21 @@ u8 run_cmplog_target(char** argv, u32 timeout) {
|
||||
if ((res = write(cmplog_fsrv_ctl_fd, &prev_timed_out, 4)) != 4) {
|
||||
|
||||
if (stop_soon) return 0;
|
||||
RPFATAL(res, "Unable to request new process from cmplog fork server (OOM?)");
|
||||
RPFATAL(res,
|
||||
"Unable to request new process from cmplog fork server (OOM?)");
|
||||
|
||||
}
|
||||
|
||||
if ((res = read(cmplog_fsrv_st_fd, &cmplog_child_pid, 4)) != 4) {
|
||||
|
||||
if (stop_soon) return 0;
|
||||
RPFATAL(res, "Unable to request new process from cmplog fork server (OOM?)");
|
||||
RPFATAL(res,
|
||||
"Unable to request new process from cmplog fork server (OOM?)");
|
||||
|
||||
}
|
||||
|
||||
if (cmplog_child_pid <= 0) FATAL("Cmplog fork server is misbehaving (OOM?)");
|
||||
if (cmplog_child_pid <= 0)
|
||||
FATAL("Cmplog fork server is misbehaving (OOM?)");
|
||||
|
||||
}
|
||||
|
||||
@ -804,7 +832,8 @@ u8 run_cmplog_target(char** argv, u32 timeout) {
|
||||
|
||||
setitimer(ITIMER_REAL, &it, NULL);
|
||||
|
||||
/* The SIGALRM handler simply kills the cmplog_child_pid and sets child_timed_out. */
|
||||
/* The SIGALRM handler simply kills the cmplog_child_pid and sets
|
||||
* child_timed_out. */
|
||||
|
||||
if (dumb_mode == 1 || no_forkserver) {
|
||||
|
||||
@ -948,3 +977,4 @@ u8 common_fuzz_cmplog_stuff(char** argv, u8* out_buf, u32 len) {
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
@ -598,7 +598,8 @@ void show_stats(void) {
|
||||
|
||||
sprintf(tmp, "%s/%s, %s/%s, %s/%s, %s/%s", DI(stage_finds[STAGE_PYTHON]),
|
||||
DI(stage_cycles[STAGE_PYTHON]), DI(stage_finds[STAGE_CUSTOM_MUTATOR]),
|
||||
DI(stage_cycles[STAGE_CUSTOM_MUTATOR]), DI(stage_finds[STAGE_COLORIZATION]),
|
||||
DI(stage_cycles[STAGE_CUSTOM_MUTATOR]),
|
||||
DI(stage_finds[STAGE_COLORIZATION]),
|
||||
DI(stage_cycles[STAGE_COLORIZATION]), DI(stage_finds[STAGE_ITS]),
|
||||
DI(stage_cycles[STAGE_ITS]));
|
||||
|
||||
|
@ -96,8 +96,7 @@ void remove_shm(void) {
|
||||
|
||||
#else
|
||||
shmctl(shm_id, IPC_RMID, NULL);
|
||||
if (cmplog_mode)
|
||||
shmctl(cmplog_shm_id, IPC_RMID, NULL);
|
||||
if (cmplog_mode) shmctl(cmplog_shm_id, IPC_RMID, NULL);
|
||||
#endif
|
||||
|
||||
}
|
||||
@ -158,7 +157,8 @@ void setup_shm(unsigned char dumb_mode) {
|
||||
|
||||
if (cmplog_mode) {
|
||||
|
||||
cmplog_shm_id = shmget(IPC_PRIVATE, sizeof(struct cmp_map), IPC_CREAT | IPC_EXCL | 0600);
|
||||
cmplog_shm_id = shmget(IPC_PRIVATE, sizeof(struct cmp_map),
|
||||
IPC_CREAT | IPC_EXCL | 0600);
|
||||
|
||||
if (cmplog_shm_id < 0) PFATAL("shmget() failed");
|
||||
|
||||
@ -189,8 +189,7 @@ void setup_shm(unsigned char dumb_mode) {
|
||||
|
||||
trace_bits = shmat(shm_id, NULL, 0);
|
||||
|
||||
if (cmplog_mode)
|
||||
cmp_map = shmat(cmplog_shm_id, NULL, 0);
|
||||
if (cmplog_mode) cmp_map = shmat(cmplog_shm_id, NULL, 0);
|
||||
|
||||
if (!trace_bits) PFATAL("shmat() failed");
|
||||
|
||||
|
Reference in New Issue
Block a user