diff --git a/libafl_frida/Cargo.toml b/libafl_frida/Cargo.toml index 8aa72e75781..44a13ebb1d2 100644 --- a/libafl_frida/Cargo.toml +++ b/libafl_frida/Cargo.toml @@ -25,6 +25,7 @@ frida-gum = { version = "0.4.0", git = "https://github.com/s1341/frida-rust", fe frida-gum-sys = { version = "0.2.4", git = "https://github.com/s1341/frida-rust", features = [ "auto-download", "event-sink", "invocation-listener"] } #frida-gum = { version = "0.4.0", path = "../../frida-rust/frida-gum", features = [ "auto-download", "backtrace", "event-sink", "invocation-listener"] } #frida-gum-sys = { version = "0.2.4", path = "../../frida-rust/frida-gum-sys", features = [ "auto-download", "event-sink", "invocation-listener"] } +core_affinity = { version = "0.5", git = "https://github.com/s1341/core_affinity_rs" } regex = "1.4" dynasmrt = "1.0.1" capstone = "0.8.0" diff --git a/libafl_frida/src/lib.rs b/libafl_frida/src/lib.rs index b3ae390ac8d..95641acd9e9 100644 --- a/libafl_frida/src/lib.rs +++ b/libafl_frida/src/lib.rs @@ -5,8 +5,12 @@ It can report coverage and, on supported architecutres, even reports memory acce /// The frida address sanitizer runtime pub mod asan_rt; -/// The `LibAFL` firda helper +/// The `LibAFL` frida helper pub mod helper; +// for parsing asan cores +use libafl::utils::parse_core_bind_arg; +// for getting current core_id +use core_affinity; /// A representation of the various Frida options #[derive(Clone, Debug)] @@ -31,6 +35,7 @@ impl FridaOptions { #[must_use] pub fn parse_env_options() -> Self { let mut options = Self::default(); + let mut asan_cores = None; if let Ok(env_options) = std::env::var("LIBAFL_FRIDA_OPTIONS") { for option in env_options.trim().split(':') { @@ -40,7 +45,6 @@ impl FridaOptions { match name { "asan" => { options.enable_asan = value.parse().unwrap(); - #[cfg(not(target_arch = "aarch64"))] if options.enable_asan { panic!("ASAN is not currently supported on targets other than aarch64"); @@ -55,6 +59,9 @@ impl FridaOptions { "asan-allocation-backtraces" => { options.enable_asan_allocation_backtraces = value.parse().unwrap(); } + "asan-cores" => { + asan_cores = parse_core_bind_arg(value); + } "instrument-suppress-locations" => { options.instrument_suppress_locations = Some( value @@ -92,6 +99,16 @@ impl FridaOptions { panic!("unknown FRIDA option: '{}'", option); } } + } // end of for loop + if options.enable_asan && asan_cores.is_some() { + let core_ids = core_affinity::get_core_ids().unwrap(); + assert_eq!( + core_ids.len(), + 1, + "Client should only be enabled on one core" + ); + let core_id = core_ids[0].id; + options.enable_asan = asan_cores.unwrap().contains(&core_id); } }