diff options
author | Andrea Fioraldi <andreafioraldi@gmail.com> | 2020-02-11 21:29:36 +0100 |
---|---|---|
committer | Andrea Fioraldi <andreafioraldi@gmail.com> | 2020-02-11 21:29:36 +0100 |
commit | e22ba031f552bf41fb24286b54c0417d5ddd464a (patch) | |
tree | 944e0878e5e90b7d2c4774f630e5f17c6a302648 /qemu_mode/patches | |
parent | 1bb6e1911b4a983687de09b39072638c0c001d3e (diff) | |
download | afl++-e22ba031f552bf41fb24286b54c0417d5ddd464a.tar.gz |
AFL_ENTRYPOINT instruction granularity
Diffstat (limited to 'qemu_mode/patches')
-rw-r--r-- | qemu_mode/patches/afl-qemu-common.h | 5 | ||||
-rw-r--r-- | qemu_mode/patches/afl-qemu-cpu-inl.h | 23 | ||||
-rw-r--r-- | qemu_mode/patches/cpu-exec.diff | 15 | ||||
-rw-r--r-- | qemu_mode/patches/tcg-runtime-head.diff | 10 | ||||
-rw-r--r-- | qemu_mode/patches/tcg-runtime.diff | 24 | ||||
-rw-r--r-- | qemu_mode/patches/translator.diff | 25 |
6 files changed, 68 insertions, 34 deletions
diff --git a/qemu_mode/patches/afl-qemu-common.h b/qemu_mode/patches/afl-qemu-common.h index 4303a5e6..f2a44ba3 100644 --- a/qemu_mode/patches/afl-qemu-common.h +++ b/qemu_mode/patches/afl-qemu-common.h @@ -69,7 +69,7 @@ typedef void (*afl_persistent_hook_fn)(uint64_t *regs, uint64_t guest_base); extern unsigned char *afl_area_ptr; extern unsigned int afl_inst_rms; -extern abi_ulong afl_start_code, afl_end_code; +extern abi_ulong afl_entry_point, afl_start_code, afl_end_code; extern abi_ulong afl_persistent_addr; extern abi_ulong afl_persistent_ret_addr; extern u8 afl_compcov_level; @@ -88,6 +88,9 @@ extern __thread abi_ulong afl_prev_loc; extern struct cmp_map *__afl_cmp_map; extern __thread u32 __afl_cmp_counter; +void afl_setup(void); +void afl_forkserver(CPUState *cpu); + void afl_debug_dump_saved_regs(); void afl_persistent_loop(); diff --git a/qemu_mode/patches/afl-qemu-cpu-inl.h b/qemu_mode/patches/afl-qemu-cpu-inl.h index 5e155c74..28fa1ab6 100644 --- a/qemu_mode/patches/afl-qemu-cpu-inl.h +++ b/qemu_mode/patches/afl-qemu-cpu-inl.h @@ -42,22 +42,6 @@ * VARIOUS AUXILIARY STUFF * ***************************/ -/* This snippet kicks in when the instruction pointer is positioned at - _start and does the usual forkserver stuff, not very different from - regular instrumentation injected via afl-as.h. */ - -#define AFL_QEMU_CPU_SNIPPET2 \ - do { \ - \ - if (itb->pc == afl_entry_point) { \ - \ - afl_setup(); \ - afl_forkserver(cpu); \ - \ - } \ - \ - } while (0) - /* We use one additional file descriptor to relay "needs translation" messages between the child and the fork server. */ @@ -107,9 +91,6 @@ unsigned int afl_inst_rms = MAP_SIZE; /* Exported for afl_gen_trace */ /* Function declarations. */ -static void afl_setup(void); -static void afl_forkserver(CPUState *); - static void afl_wait_tsl(CPUState *, int); static void afl_request_tsl(target_ulong, target_ulong, uint32_t, uint32_t, TranslationBlock *, int); @@ -155,7 +136,7 @@ static inline void tb_add_jump(TranslationBlock *tb, int n, /* Set up SHM region and initialize other stuff. */ -static void afl_setup(void) { +void afl_setup(void) { char *id_str = getenv(SHM_ENV_VAR), *inst_r = getenv("AFL_INST_RATIO"); @@ -310,7 +291,7 @@ static void print_mappings(void) { /* Fork server logic, invoked once we hit _start. */ -static void afl_forkserver(CPUState *cpu) { +void afl_forkserver(CPUState *cpu) { static unsigned char tmp[4]; diff --git a/qemu_mode/patches/cpu-exec.diff b/qemu_mode/patches/cpu-exec.diff index cd35eef6..844be58c 100644 --- a/qemu_mode/patches/cpu-exec.diff +++ b/qemu_mode/patches/cpu-exec.diff @@ -1,5 +1,5 @@ diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c -index 870027d4..841ba557 100644 +index 870027d4..0bc87dfc 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -36,6 +36,8 @@ @@ -11,16 +11,7 @@ index 870027d4..841ba557 100644 /* -icount align implementation. */ typedef struct SyncClocks { -@@ -144,6 +146,8 @@ static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, TranslationBlock *itb) - int tb_exit; - uint8_t *tb_ptr = itb->tc.ptr; - -+ AFL_QEMU_CPU_SNIPPET2; -+ - qemu_log_mask_and_addr(CPU_LOG_EXEC, itb->pc, - "Trace %d: %p [" - TARGET_FMT_lx "/" TARGET_FMT_lx "/%#x] %s\n", -@@ -397,11 +401,13 @@ static inline TranslationBlock *tb_find(CPUState *cpu, +@@ -397,11 +399,13 @@ static inline TranslationBlock *tb_find(CPUState *cpu, TranslationBlock *tb; target_ulong cs_base, pc; uint32_t flags; @@ -34,7 +25,7 @@ index 870027d4..841ba557 100644 mmap_unlock(); /* We add the TB in the virtual pc hash table for the fast lookup */ atomic_set(&cpu->tb_jmp_cache[tb_jmp_cache_hash_func(pc)], tb); -@@ -418,6 +424,10 @@ static inline TranslationBlock *tb_find(CPUState *cpu, +@@ -418,6 +422,10 @@ static inline TranslationBlock *tb_find(CPUState *cpu, /* See if we can patch the calling TB. */ if (last_tb) { tb_add_jump(last_tb, tb_exit, tb); diff --git a/qemu_mode/patches/tcg-runtime-head.diff b/qemu_mode/patches/tcg-runtime-head.diff new file mode 100644 index 00000000..d2deafaa --- /dev/null +++ b/qemu_mode/patches/tcg-runtime-head.diff @@ -0,0 +1,10 @@ +diff --git a/accel/tcg/tcg-runtime.h b/accel/tcg/tcg-runtime.h +index 1bd39d13..944997ee 100644 +--- a/accel/tcg/tcg-runtime.h ++++ b/accel/tcg/tcg-runtime.h +@@ -260,3 +260,5 @@ DEF_HELPER_FLAGS_4(gvec_leu8, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) + DEF_HELPER_FLAGS_4(gvec_leu16, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) + DEF_HELPER_FLAGS_4(gvec_leu32, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) + DEF_HELPER_FLAGS_4(gvec_leu64, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) ++ ++DEF_HELPER_FLAGS_1(afl_entry_routine, TCG_CALL_NO_RWG, void, env) diff --git a/qemu_mode/patches/tcg-runtime.diff b/qemu_mode/patches/tcg-runtime.diff new file mode 100644 index 00000000..54a62ba8 --- /dev/null +++ b/qemu_mode/patches/tcg-runtime.diff @@ -0,0 +1,24 @@ +diff --git a/accel/tcg/tcg-runtime.c b/accel/tcg/tcg-runtime.c +index d0d44844..46154af1 100644 +--- a/accel/tcg/tcg-runtime.c ++++ b/accel/tcg/tcg-runtime.c +@@ -31,6 +31,8 @@ + #include "disas/disas.h" + #include "exec/log.h" + ++#include "../../../patches/afl-qemu-common.h" ++ + /* 32-bit helpers */ + + int32_t HELPER(div_i32)(int32_t arg1, int32_t arg2) +@@ -167,3 +169,10 @@ void HELPER(exit_atomic)(CPUArchState *env) + { + cpu_loop_exit_atomic(ENV_GET_CPU(env), GETPC()); + } ++ ++ ++void HELPER(afl_entry_routine)(CPUArchState *env) { ++ ++ afl_forkserver(ENV_GET_CPU(env)); ++ ++} diff --git a/qemu_mode/patches/translator.diff b/qemu_mode/patches/translator.diff new file mode 100644 index 00000000..842e861d --- /dev/null +++ b/qemu_mode/patches/translator.diff @@ -0,0 +1,25 @@ +diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c +index afd0a49e..773ea712 100644 +--- a/accel/tcg/translator.c ++++ b/accel/tcg/translator.c +@@ -18,6 +18,8 @@ + #include "exec/log.h" + #include "exec/translator.h" + ++#include "../../../patches/afl-qemu-common.h" ++ + /* Pairs with tcg_clear_temp_count. + To be called by #TranslatorOps.{translate_insn,tb_stop} if + (1) the target is sufficiently clean to support reporting, +@@ -92,6 +94,11 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db, + break; + } + } ++ ++ if (db->pc_next == afl_entry_point) { ++ afl_setup(); ++ gen_helper_afl_entry_routine(cpu_env); ++ } + + /* Disassemble one instruction. The translate_insn hook should + update db->pc_next and db->is_jmp to indicate what should be |