Skip to content

Commit 7a9cca9

Browse files
authored
Expose AFL++ style extended cmplog for unicornafl (#3238)
* expose afl++ style extended cmplog for unicornafl * also update map ptr * fix imports * fix naming * feature dep
1 parent 8b0fc8c commit 7a9cca9

File tree

6 files changed

+33
-1
lines changed

6 files changed

+33
-1
lines changed

libafl_cc/src/no-link-rt.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ void __libafl_targets_cmplog_instructions(uintptr_t k, uint8_t shape,
1616
(void)arg2;
1717
}
1818

19+
void __libafl_targets_cmplog_instructions_extended(uintptr_t k, uint8_t shape,
20+
uint64_t arg1,
21+
uint64_t arg2) {
22+
(void)k;
23+
(void)shape;
24+
(void)arg1;
25+
(void)arg2;
26+
}
27+
1928
void __cmplog_ins_hook1_extended(uint8_t arg1, uint8_t arg2, uint8_t attr) {
2029
(void)arg1;
2130
(void)arg2;

libafl_targets/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ forkserver = [
6767
windows_asan = ["common"] # Compile C code for ASAN on Windows
6868
whole_archive = [] # use +whole-archive to ensure the presence of weak symbols
6969
cmplog_extended_instrumentation = [
70+
"cmplog", # without `cmplog`, extended instrumentation won't compile
7071
] # support for aflpp cmplog map, we will remove this once aflpp and libafl cmplog shares the same LLVM passes.
7172
function-logging = ["common"]
7273
track_hit_feedbacks = ["libafl/track_hit_feedbacks"]

libafl_targets/src/cmplog.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ void __libafl_targets_cmplog_instructions(uintptr_t k, uint8_t shape,
102102
cmplog_instructions_checked(k, shape, arg1, arg2, 0);
103103
}
104104

105+
// Very generic afl++ style cmplog instructions callback
106+
void __libafl_targets_cmplog_instructions_extended(uintptr_t k, uint8_t shape,
107+
uint64_t arg1, uint64_t arg2) {
108+
cmplog_instructions_extended_checked(k, shape, arg1, arg2, 0);
109+
}
110+
105111
// Very generic cmplog routines callback
106112
void __libafl_targets_cmplog_routines(uintptr_t k, const uint8_t *ptr1,
107113
const uint8_t *ptr2) {

libafl_targets/src/cmplog.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ static inline void cmplog_routines_checked_extended(uintptr_t k,
234234

235235
void __libafl_targets_cmplog_instructions(uintptr_t k, uint8_t shape,
236236
uint64_t arg1, uint64_t arg2);
237-
237+
void __libafl_targets_cmplog_instructions_extended(uintptr_t k, uint8_t shape,
238+
uint64_t arg1, uint64_t arg2);
238239
void __libafl_targets_cmplog_routines(uintptr_t k, const uint8_t *ptr1,
239240
const uint8_t *ptr2);
240241

libafl_targets/src/cmps/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,23 @@ unsafe extern "C" {
5151
/// Logs an instruction for feedback during fuzzing
5252
pub fn __libafl_targets_cmplog_instructions(k: usize, shape: u8, arg1: u64, arg2: u64);
5353

54+
/// Logs an AFL++ style instruction for feedback during fuzzing
55+
pub fn __libafl_targets_cmplog_instructions_extended(k: usize, shape: u8, arg1: u64, arg2: u64);
56+
5457
/// Logs a routine for feedback during fuzzing
5558
pub fn __libafl_targets_cmplog_routines(k: usize, ptr1: *const u8, ptr2: *const u8);
5659

5760
/// Pointer to the `CmpLog` map
5861
pub static mut libafl_cmplog_map_ptr: *mut CmpLogMap;
62+
63+
/// Pointer to the extended `CmpLog` map
64+
pub static mut libafl_cmplog_map_extended_ptr: *mut CmpLogMap;
5965
}
6066

6167
#[cfg(feature = "cmplog")]
6268
pub use libafl_cmplog_map_ptr as CMPLOG_MAP_PTR;
69+
#[cfg(feature = "cmplog_extended_instrumentation")]
70+
pub use libafl_cmplog_map_extended_ptr as EXTENDED_CMPLOG_MAP_PTR;
6371

6472
/// Value indicating if cmplog is enabled.
6573
#[unsafe(no_mangle)]

libafl_targets/src/forkserver.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ use nix::{
2222

2323
#[cfg(feature = "cmplog")]
2424
use crate::cmps::CMPLOG_MAP_PTR;
25+
#[cfg(feature = "cmplog_extended_instrumentation")]
26+
use crate::cmps::EXTENDED_CMPLOG_MAP_PTR;
27+
2528
use crate::coverage::{__afl_map_size, EDGES_MAP_PTR, INPUT_LENGTH_PTR, INPUT_PTR, SHM_FUZZING};
2629
#[cfg(any(target_os = "linux", target_vendor = "apple"))]
2730
use crate::coverage::{__token_start, __token_stop};
@@ -201,6 +204,10 @@ fn map_cmplog_shared_memory_internal() -> Result<(), Error> {
201204
unsafe {
202205
CMPLOG_MAP_PTR = map.cast();
203206
}
207+
#[cfg(feature = "cmplog_extended_instrumentation")]
208+
unsafe {
209+
EXTENDED_CMPLOG_MAP_PTR = map.cast();
210+
}
204211
Ok(())
205212
}
206213

0 commit comments

Comments
 (0)