diff --git a/crates/libafl/src/executors/command.rs b/crates/libafl/src/executors/command.rs index 5c00c522a0e..a7743dfb3bf 100644 --- a/crates/libafl/src/executors/command.rs +++ b/crates/libafl/src/executors/command.rs @@ -388,7 +388,6 @@ where ) -> Result { use wait_timeout::ChildExt; - self.observers_mut().pre_exec_all(state, input)?; *state.executions_mut() += 1; let mut child = self .configurator @@ -427,8 +426,6 @@ where self.observers_mut().index_mut(&stdout_handle).observe(buf); } - self.observers_mut() - .post_exec_child_all(state, input, &exit_kind)?; Ok(exit_kind) } } @@ -484,8 +481,8 @@ where /// Linux specific low level implementation, to directly handle `fork`, `exec` and use linux /// `ptrace` /// - /// Hooks' `pre_exec` and observers' `pre_exec_child` are called with the child process stopped - /// just before the `exec` return (after forking). + /// Hooks' `pre_exec` is called with the child process stopped just before the `exec` return + /// (after forking). fn run_target( &mut self, fuzzer: &mut Z, @@ -519,7 +516,6 @@ where ))); } - self.observers.pre_exec_child_all(state, input)?; if *state.executions() == 1 { self.hooks.init_all(state); } @@ -546,7 +542,6 @@ where }; self.hooks.post_exec_all(state, input); - self.observers.post_exec_child_all(state, input, &res)?; Ok(res) } } @@ -898,7 +893,10 @@ mod tests { state::NopState, }; #[cfg(unix)] - use crate::{executors::StdChildArgs, observers::StdOutObserver}; + use crate::{ + executors::{HasObservers, StdChildArgs}, + observers::{ObserversTuple, StdOutObserver}, + }; #[test] #[cfg_attr(miri, ignore)] @@ -944,13 +942,19 @@ mod tests { let mut executor = executor.unwrap(); let mut fuzzer: NopFuzzer = NopFuzzer::new(); + let mut state = NopState::::new(); + let input = BytesInput::new(b".".to_vec()); + executor - .run_target( - &mut fuzzer, - &mut NopState::::new(), - &mut mgr, - &BytesInput::new(b".".to_vec()), - ) + .observers_mut() + .pre_exec_all(&mut state, &input) + .unwrap(); + let exit_kind = executor + .run_target(&mut fuzzer, &mut state, &mut mgr, &input) + .unwrap(); + executor + .observers_mut() + .post_exec_all(&mut state, &input, &exit_kind) .unwrap(); assert!(executor.observers.0.output.is_some()); diff --git a/crates/libafl/src/executors/differential.rs b/crates/libafl/src/executors/differential.rs index c636cb43f6a..aa1a77cf880 100644 --- a/crates/libafl/src/executors/differential.rs +++ b/crates/libafl/src/executors/differential.rs @@ -168,20 +168,6 @@ where ) -> Result<(), Error> { self.differential.post_exec_all(state, input, exit_kind) } - - fn pre_exec_child_all(&mut self, state: &mut S, input: &I) -> Result<(), Error> { - self.differential.pre_exec_child_all(state, input) - } - - fn post_exec_child_all( - &mut self, - state: &mut S, - input: &I, - exit_kind: &ExitKind, - ) -> Result<(), Error> { - self.differential - .post_exec_child_all(state, input, exit_kind) - } } impl Deref for ProxyObserversTuple { diff --git a/crates/libafl/src/executors/forkserver.rs b/crates/libafl/src/executors/forkserver.rs index b95d2123071..963e555f736 100644 --- a/crates/libafl/src/executors/forkserver.rs +++ b/crates/libafl/src/executors/forkserver.rs @@ -1534,10 +1534,7 @@ where input: &I, ) -> Result { let bytes = fuzzer.convert_to_target_bytes(state, input); - self.observers_mut().pre_exec_child_all(state, input)?; let exit = self.execute_input(state, bytes.as_slice())?; - self.observers_mut() - .post_exec_child_all(state, input, &exit)?; Ok(exit) } } diff --git a/crates/libafl/src/executors/inprocess_fork/inner.rs b/crates/libafl/src/executors/inprocess_fork/inner.rs index 08d5b5aacbd..3c4e9cb8c04 100644 --- a/crates/libafl/src/executors/inprocess_fork/inner.rs +++ b/crates/libafl/src/executors/inprocess_fork/inner.rs @@ -124,8 +124,8 @@ where self.hooks.pre_exec_all(state, input); self.observers - .pre_exec_child_all(state, input) - .expect("Failed to run post_exec on observers"); + .pre_exec_all(state, input) + .expect("Failed to run pre_exec on observers"); #[cfg(target_os = "linux")] { @@ -156,7 +156,7 @@ where ) { unsafe { self.observers - .post_exec_child_all(state, input, &ExitKind::Ok) + .post_exec_all(state, input, &ExitKind::Ok) .expect("Failed to run post_exec on observers"); self.hooks.post_exec_all(state, input); diff --git a/crates/libafl/src/executors/inprocess_fork/mod.rs b/crates/libafl/src/executors/inprocess_fork/mod.rs index ec4eaaa9cbe..1481df5489e 100644 --- a/crates/libafl/src/executors/inprocess_fork/mod.rs +++ b/crates/libafl/src/executors/inprocess_fork/mod.rs @@ -217,7 +217,7 @@ pub mod child_signal_handlers { observers::ObserversTuple, }; - /// invokes the `post_exec_child` hook on all observer in case the child process panics + /// invokes the `post_exec` hook on all observer in case the child process panics pub fn setup_child_panic_hook() where E: HasObservers, @@ -234,7 +234,7 @@ pub mod child_signal_handlers { // Invalidate data to not execute again the observer hooks in the crash handler let input = (*data).take_current_input::(); observers - .post_exec_child_all(state, input, &ExitKind::Crash) + .post_exec_all(state, input, &ExitKind::Crash) .expect("Failed to run post_exec on observers"); // std::process::abort(); @@ -266,7 +266,7 @@ pub mod child_signal_handlers { let state = data.state_mut::(); let input = data.take_current_input::(); observers - .post_exec_child_all(state, input, &ExitKind::Crash) + .post_exec_all(state, input, &ExitKind::Crash) .expect("Failed to run post_exec on observers"); } @@ -292,7 +292,7 @@ pub mod child_signal_handlers { let state = data.state_mut::(); let input = data.take_current_input::(); observers - .post_exec_child_all(state, input, &ExitKind::Timeout) + .post_exec_all(state, input, &ExitKind::Timeout) .expect("Failed to run post_exec on observers"); } libc::_exit(128 + (_signal as i32)); diff --git a/crates/libafl/src/observers/map/hitcount_map.rs b/crates/libafl/src/observers/map/hitcount_map.rs index 32bfe77343a..88f88c1d48e 100644 --- a/crates/libafl/src/observers/map/hitcount_map.rs +++ b/crates/libafl/src/observers/map/hitcount_map.rs @@ -134,21 +134,6 @@ where classify_counts(&mut self.as_slice_mut()); self.base.post_exec(state, input, exit_kind) } - - #[inline] - fn pre_exec_child(&mut self, state: &mut S, input: &I) -> Result<(), Error> { - self.base.pre_exec_child(state, input) - } - - #[inline] - fn post_exec_child( - &mut self, - state: &mut S, - input: &I, - exit_kind: &ExitKind, - ) -> Result<(), Error> { - self.base.post_exec_child(state, input, exit_kind) - } } impl Named for HitcountsMapObserver @@ -370,21 +355,6 @@ where self.base.post_exec(state, input, exit_kind) } - - #[inline] - fn pre_exec_child(&mut self, state: &mut S, input: &I) -> Result<(), Error> { - self.base.pre_exec_child(state, input) - } - - #[inline] - fn post_exec_child( - &mut self, - state: &mut S, - input: &I, - exit_kind: &ExitKind, - ) -> Result<(), Error> { - self.base.post_exec_child(state, input, exit_kind) - } } impl Named for HitcountsIterableMapObserver diff --git a/crates/libafl/src/observers/map/mod.rs b/crates/libafl/src/observers/map/mod.rs index 02e5a0a0dc2..b633f513044 100644 --- a/crates/libafl/src/observers/map/mod.rs +++ b/crates/libafl/src/observers/map/mod.rs @@ -150,19 +150,6 @@ where fn post_exec(&mut self, state: &mut S, input: &I, exit_kind: &ExitKind) -> Result<(), Error> { self.0.post_exec(state, input, exit_kind) } - - fn pre_exec_child(&mut self, state: &mut S, input: &I) -> Result<(), Error> { - self.0.pre_exec_child(state, input) - } - - fn post_exec_child( - &mut self, - state: &mut S, - input: &I, - exit_kind: &ExitKind, - ) -> Result<(), Error> { - self.0.post_exec_child(state, input, exit_kind) - } } impl DifferentialObserver diff --git a/crates/libafl/src/observers/mod.rs b/crates/libafl/src/observers/mod.rs index 5c77036a81e..9a188f6dc99 100644 --- a/crates/libafl/src/observers/mod.rs +++ b/crates/libafl/src/observers/mod.rs @@ -60,23 +60,6 @@ pub trait Observer: Named { ) -> Result<(), Error> { Ok(()) } - - /// Called right before execution starts in the child process, if any. - #[inline] - fn pre_exec_child(&mut self, _state: &mut S, _input: &I) -> Result<(), Error> { - Ok(()) - } - - /// Called right after execution finishes in the child process, if any. - #[inline] - fn post_exec_child( - &mut self, - _state: &mut S, - _input: &I, - _exit_kind: &ExitKind, - ) -> Result<(), Error> { - Ok(()) - } } /// A haskell-style tuple of observers @@ -91,17 +74,6 @@ pub trait ObserversTuple: MatchName { input: &I, exit_kind: &ExitKind, ) -> Result<(), Error>; - - /// This is called right before the next execution in the child process, if any. - fn pre_exec_child_all(&mut self, state: &mut S, input: &I) -> Result<(), Error>; - - /// This is called right after the last execution in the child process, if any. - fn post_exec_child_all( - &mut self, - state: &mut S, - input: &I, - exit_kind: &ExitKind, - ) -> Result<(), Error>; } impl ObserversTuple for () { @@ -117,19 +89,6 @@ impl ObserversTuple for () { ) -> Result<(), Error> { Ok(()) } - - fn pre_exec_child_all(&mut self, _state: &mut S, _input: &I) -> Result<(), Error> { - Ok(()) - } - - fn post_exec_child_all( - &mut self, - _state: &mut S, - _input: &I, - _exit_kind: &ExitKind, - ) -> Result<(), Error> { - Ok(()) - } } impl ObserversTuple for (Head, Tail) @@ -151,21 +110,6 @@ where self.0.post_exec(state, input, exit_kind)?; self.1.post_exec_all(state, input, exit_kind) } - - fn pre_exec_child_all(&mut self, state: &mut S, input: &I) -> Result<(), Error> { - self.0.pre_exec_child(state, input)?; - self.1.pre_exec_child_all(state, input) - } - - fn post_exec_child_all( - &mut self, - state: &mut S, - input: &I, - exit_kind: &ExitKind, - ) -> Result<(), Error> { - self.0.post_exec_child(state, input, exit_kind)?; - self.1.post_exec_child_all(state, input, exit_kind) - } } /// A trait for [`Observer`]`s` with a hash field diff --git a/crates/libafl/src/observers/stacktrace.rs b/crates/libafl/src/observers/stacktrace.rs index 85f2988efa7..c2cd86056eb 100644 --- a/crates/libafl/src/observers/stacktrace.rs +++ b/crates/libafl/src/observers/stacktrace.rs @@ -228,15 +228,6 @@ impl Observer for BacktraceObserver<'_> { } Ok(()) } - - fn post_exec_child( - &mut self, - state: &mut S, - input: &I, - exit_kind: &ExitKind, - ) -> Result<(), Error> { - self.post_exec(state, input, exit_kind) - } } impl Named for BacktraceObserver<'_> { diff --git a/crates/libafl/src/observers/stdio.rs b/crates/libafl/src/observers/stdio.rs index bf5c96e5bde..cc291a93597 100644 --- a/crates/libafl/src/observers/stdio.rs +++ b/crates/libafl/src/observers/stdio.rs @@ -292,7 +292,7 @@ impl Observer for OutputObserver where T: 'static, { - fn pre_exec_child(&mut self, _state: &mut S, _input: &I) -> Result<(), Error> { + fn pre_exec(&mut self, _state: &mut S, _input: &I) -> Result<(), Error> { if let Some(file) = self.file.as_mut() { file.seek(SeekFrom::Start(0))?; } @@ -300,11 +300,7 @@ where Ok(()) } - fn pre_exec(&mut self, _state: &mut S, _input: &I) -> Result<(), Error> { - self.pre_exec_child(_state, _input) - } - - fn post_exec_child( + fn post_exec( &mut self, _state: &mut S, _input: &I, @@ -324,15 +320,6 @@ where } Ok(()) } - - fn post_exec( - &mut self, - _state: &mut S, - _input: &I, - _exit_kind: &crate::executors::ExitKind, - ) -> Result<(), Error> { - self.post_exec_child(_state, _input, _exit_kind) - } } impl AsRef for OutputObserver { diff --git a/crates/libafl_targets/src/libfuzzer/observers/oom.rs b/crates/libafl_targets/src/libfuzzer/observers/oom.rs index 4bdfe2676c0..062d969471a 100644 --- a/crates/libafl_targets/src/libfuzzer/observers/oom.rs +++ b/crates/libafl_targets/src/libfuzzer/observers/oom.rs @@ -112,19 +112,6 @@ impl Observer for OomObserver { self.oomed = OOMED.load(Ordering::Relaxed); Ok(()) } - - fn pre_exec_child(&mut self, state: &mut S, input: &I) -> Result<(), Error> { - self.pre_exec(state, input) - } - - fn post_exec_child( - &mut self, - state: &mut S, - input: &I, - exit_kind: &ExitKind, - ) -> Result<(), Error> { - self.post_exec(state, input, exit_kind) - } } /// Feedback for the similarly named [`OomObserver`] to detect if the target crashed due to an observed OOM