Mac OS Autotokens (#723)

* mac_tokens

* more

* win fix

* fmt

* fmt c
This commit is contained in:
Dongjia Zhang 2022-08-13 02:58:22 +02:00 committed by GitHub
parent c1aafe3e98
commit 5d9a19f955
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 33 additions and 21 deletions

View File

@ -21,7 +21,7 @@ pub fn main() {
let mut cc = ClangWrapper::new();
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_vendor = "apple"))]
cc.add_pass(LLVMPasses::AutoTokens);
if let Some(code) = cc

View File

@ -47,7 +47,7 @@ use libafl::{
state::{HasCorpus, HasMetadata, StdState},
Error,
};
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_vendor = "apple"))]
use libafl_targets::autotokens;
use libafl_targets::{
libfuzzer_initialize, libfuzzer_test_one_input, CmpLogObserver, CMPLOG_MAP, EDGES_MAP,
@ -367,7 +367,7 @@ fn fuzz(
if let Some(tokenfile) = tokenfile {
toks.add_from_file(tokenfile)?;
}
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_vendor = "apple"))]
{
toks += autotokens()?;
}

View File

@ -18,7 +18,7 @@ pub fn main() {
let mut cc = ClangWrapper::new();
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_vendor = "apple"))]
cc.add_pass(LLVMPasses::AutoTokens);
if let Some(code) = cc

View File

@ -53,7 +53,7 @@ use libafl::{
state::{HasCorpus, HasMetadata, StdState},
Error,
};
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_vendor = "apple"))]
use libafl_targets::autotokens;
use libafl_targets::{
libfuzzer_initialize, libfuzzer_test_one_input, CmpLogObserver, CMPLOG_MAP, EDGES_MAP,
@ -427,7 +427,7 @@ fn fuzz_binary(
if let Some(tokenfile) = tokenfile {
toks.add_from_file(tokenfile)?;
}
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_vendor = "apple"))]
{
toks += autotokens()?;
}
@ -654,7 +654,7 @@ fn fuzz_text(
if let Some(tokenfile) = tokenfile {
toks.add_from_file(tokenfile)?;
}
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_vendor = "apple"))]
{
toks += autotokens()?;
}

View File

@ -21,7 +21,7 @@ pub fn main() {
let mut cc = ClangWrapper::new();
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_vendor = "apple"))]
cc.add_pass(LLVMPasses::AutoTokens);
if let Some(code) = cc

View File

@ -47,7 +47,7 @@ use libafl::{
state::{HasCorpus, HasMetadata, StdState},
Error,
};
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_vendor = "apple"))]
use libafl_targets::autotokens;
use libafl_targets::{
libfuzzer_initialize, libfuzzer_test_one_input, CmpLogObserver, CMPLOG_MAP, EDGES_MAP,
@ -368,7 +368,7 @@ fn fuzz(
if let Some(tokenfile) = tokenfile {
toks.add_from_file(tokenfile)?;
}
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_vendor = "apple"))]
{
toks += autotokens()?;
}

View File

@ -1,7 +1,7 @@
//! Tokens are what AFL calls extras or dictionaries.
//! They may be inserted as part of mutations during fuzzing.
use alloc::vec::Vec;
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_vendor = "apple"))]
use core::slice::from_raw_parts;
use core::{
mem::size_of,
@ -105,7 +105,7 @@ impl Tokens {
/// # Safety
/// The caller must ensure that the region between `token_start` and `token_stop`
/// is a valid region, containing autotokens in the exepcted format.
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_vendor = "apple"))]
pub unsafe fn from_ptrs(token_start: *const u8, token_stop: *const u8) -> Result<Self, Error> {
let mut ret = Self::default();
if token_start.is_null() || token_stop.is_null() {

View File

@ -665,7 +665,11 @@ bool AutoTokensPass::runOnModule(Module &M) {
ConstantDataArray::get(Ctx,
*(new ArrayRef<char>(ptrhld.get(), offset))),
"libafl_dictionary_" + M.getName());
#if defined(__linux__)
dict->setSection("libafl_token");
#elif defined(__APPLE__)
dict->setSection("__DATA,__libafl_token");
#endif
}
}

View File

@ -15,13 +15,21 @@ extern uint32_t __afl_acc_memop_ptr_local[ACCOUNTING_MAP_SIZE];
uint32_t *__afl_acc_memop_ptr = __afl_acc_memop_ptr_local;
// Weak symbols, LLVM Passes overwrites them if we really use it
#ifdef __linux__
#if defined(__linux__)
extern EXT_VAR(__start_libafl_token, uint8_t);
extern EXT_VAR(__stop_libafl_token, uint8_t);
#elif defined(__APPLE__)
extern uint8_t __start_libafl_token __asm(
"section$start$__DATA$__libafl_token");
extern uint8_t __stop_libafl_token __asm("section$end$__DATA$__libafl_token");
#endif
#if defined(__linux__) || defined(__APPLE__)
// Expose the start of libafl_token section as C symbols
uint8_t *__token_start = &__start_libafl_token;
uint8_t *__token_stop = &__stop_libafl_token;
#endif
//#if defined(__ANDROID__) || defined(__HAIKU__)

View File

@ -1,6 +1,6 @@
//! Coverage maps as static mut array
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_vendor = "apple"))]
use libafl::{mutators::Tokens, Error};
use crate::{ACCOUNTING_MAP_SIZE, EDGES_MAP_SIZE};
@ -26,11 +26,11 @@ extern "C" {
pub static mut __afl_acc_memop_ptr: *mut u32;
/// Start of libafl token section
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_vendor = "apple"))]
pub static __token_start: *const u8;
/// End of libafl token section
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_vendor = "apple"))]
pub static __token_stop: *const u8;
}
pub use __afl_acc_memop_ptr as ACCOUNTING_MEMOP_MAP_PTR;
@ -43,7 +43,7 @@ pub use __afl_area_ptr as EDGES_MAP_PTR;
/// # Safety
///
/// This fn is safe to call, as long as the compilation did not break, previously
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_vendor = "apple"))]
pub fn autotokens() -> Result<Tokens, Error> {
unsafe {
if __token_start.is_null() || __token_stop.is_null() {