From 833c4a988fb3a4268f05565bdfe3dade5f672ade Mon Sep 17 00:00:00 2001 From: Toka Date: Sat, 11 Jan 2025 15:33:27 +0100 Subject: [PATCH] rem --- MIGRATION.md | 2 +- libafl/src/events/broker_hooks/mod.rs | 1 - libafl/src/events/centralized.rs | 26 ++---------- libafl/src/events/llmp/mgr.rs | 33 ++------------- libafl/src/events/llmp/mod.rs | 21 +--------- libafl/src/events/llmp/restarting.rs | 23 +++-------- libafl/src/events/mod.rs | 58 +-------------------------- libafl/src/events/simple.rs | 45 +-------------------- libafl/src/events/tcp.rs | 31 ++------------ 9 files changed, 20 insertions(+), 220 deletions(-) diff --git a/MIGRATION.md b/MIGRATION.md index 44a50abde9..8897eb3d4c 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -10,7 +10,7 @@ - `Qemu` cannot be used to initialize `Emulator` directly anymore. Instead, `Qemu` should be initialized through `Emulator` systematically if `Emulator` should be used. - Related: `EmulatorBuilder` uses a single function to provide a `Qemu` initializer: `EmulatorBuilder::qemu_parameters`. For now, it can be either a `Vec` or a `QemuConfig` instance. - Related: Qemu's `AsanModule` does not need any special call to `Qemu` init methods anymore. It is now possible to simply initialize `AsanModule` (or `AsanGuestModule`) with a reference to the environment as parameter. - + - `CustomBufHandlers` has been deleted. Please use `EventManagerHooksTuple` from now on. # 0.14.0 -> 0.14.1 - Removed `with_observers` from `Executor` trait. - `MmapShMemProvider::new_shmem_persistent` has been removed in favour of `MmapShMem::persist`. You probably want to do something like this: `let shmem = MmapShMemProvider::new()?.new_shmem(size)?.persist()?;` diff --git a/libafl/src/events/broker_hooks/mod.rs b/libafl/src/events/broker_hooks/mod.rs index cc3d470b9d..ee58aa4d36 100644 --- a/libafl/src/events/broker_hooks/mod.rs +++ b/libafl/src/events/broker_hooks/mod.rs @@ -194,7 +194,6 @@ where log::log!((*severity_level).into(), "{message}"); Ok(BrokerEventResult::Handled) } - Event::CustomBuf { .. } => Ok(BrokerEventResult::Forward), Event::Stop => Ok(BrokerEventResult::Forward), //_ => Ok(BrokerEventResult::Forward), } diff --git a/libafl/src/events/centralized.rs b/libafl/src/events/centralized.rs index d61dc76172..409c574bba 100644 --- a/libafl/src/events/centralized.rs +++ b/libafl/src/events/centralized.rs @@ -7,7 +7,7 @@ // 3. The "main evaluator", the evaluator node that will evaluate all the testcases pass by the centralized event manager to see if the testcases are worth propagating // 4. The "main broker", the gathers the stats from the fuzzer clients and broadcast the newly found testcases from the main evaluator. -use alloc::{boxed::Box, string::String, vec::Vec}; +use alloc::{string::String, vec::Vec}; use core::{fmt::Debug, time::Duration}; use std::{marker::PhantomData, process}; @@ -30,9 +30,9 @@ use crate::events::llmp::COMPRESS_THRESHOLD; use crate::{ corpus::Corpus, events::{ - AdaptiveSerializer, CustomBufEventResult, Event, EventConfig, EventFirer, EventManager, - EventManagerHooksTuple, EventManagerId, EventProcessor, EventRestarter, - HasCustomBufHandlers, HasEventManagerId, LogSeverity, ProgressReporter, + AdaptiveSerializer, Event, EventConfig, EventFirer, EventManager, EventManagerHooksTuple, + EventManagerId, EventProcessor, EventRestarter, HasEventManagerId, LogSeverity, + ProgressReporter, }, executors::{Executor, HasObservers}, fuzzer::{EvaluatorObservers, ExecutionProcessor}, @@ -417,24 +417,6 @@ where { } -impl HasCustomBufHandlers for CentralizedEventManager -where - EM: HasCustomBufHandlers, - EMH: EventManagerHooksTuple, - S: State, - SP: ShMemProvider, -{ - /// Adds a custom buffer handler that will run for each incoming `CustomBuf` event. - fn add_custom_buf_handler( - &mut self, - handler: Box< - dyn FnMut(&mut Self::State, &str, &[u8]) -> Result, - >, - ) { - self.inner.add_custom_buf_handler(handler); - } -} - impl ProgressReporter for CentralizedEventManager where EM: AdaptiveSerializer + ProgressReporter + HasEventManagerId, diff --git a/libafl/src/events/llmp/mgr.rs b/libafl/src/events/llmp/mgr.rs index ef3d514ca5..d6a6b806cb 100644 --- a/libafl/src/events/llmp/mgr.rs +++ b/libafl/src/events/llmp/mgr.rs @@ -3,7 +3,7 @@ #[cfg(feature = "std")] use alloc::string::ToString; -use alloc::{boxed::Box, vec::Vec}; +use alloc::vec::Vec; use core::{marker::PhantomData, time::Duration}; #[cfg(feature = "std")] use std::net::TcpStream; @@ -33,9 +33,8 @@ use crate::{ corpus::Corpus, events::{ llmp::{LLMP_TAG_EVENT_TO_BOTH, _LLMP_TAG_EVENT_TO_BROKER}, - AdaptiveSerializer, CustomBufEventResult, CustomBufHandlerFn, Event, EventConfig, - EventFirer, EventManager, EventManagerHooksTuple, EventManagerId, EventProcessor, - EventRestarter, HasCustomBufHandlers, HasEventManagerId, ProgressReporter, + AdaptiveSerializer, Event, EventConfig, EventFirer, EventManager, EventManagerHooksTuple, + EventManagerId, EventProcessor, EventRestarter, HasEventManagerId, ProgressReporter, }, executors::{Executor, HasObservers}, fuzzer::{Evaluator, EvaluatorObservers, ExecutionProcessor}, @@ -64,8 +63,6 @@ where hooks: EMH, /// The LLMP client for inter process communication llmp: LlmpClient, - /// The custom buf handler - custom_buf_handlers: Vec>>, #[cfg(feature = "llmp_compression")] compressor: GzipCompressor, /// The configuration defines this specific fuzzer. @@ -168,7 +165,6 @@ impl LlmpEventManagerBuilder { should_serialize_cnt: 0, time_ref, phantom: PhantomData, - custom_buf_handlers: vec![], event_buffer: Vec::with_capacity(INITIAL_EVENT_BUFFER_SIZE), }) } @@ -203,7 +199,6 @@ impl LlmpEventManagerBuilder { should_serialize_cnt: 0, time_ref, phantom: PhantomData, - custom_buf_handlers: vec![], event_buffer: Vec::with_capacity(INITIAL_EVENT_BUFFER_SIZE), }) } @@ -238,7 +233,6 @@ impl LlmpEventManagerBuilder { should_serialize_cnt: 0, time_ref, phantom: PhantomData, - custom_buf_handlers: vec![], event_buffer: Vec::with_capacity(INITIAL_EVENT_BUFFER_SIZE), }) } @@ -271,7 +265,6 @@ impl LlmpEventManagerBuilder { should_serialize_cnt: 0, time_ref, phantom: PhantomData, - custom_buf_handlers: vec![], event_buffer: Vec::with_capacity(INITIAL_EVENT_BUFFER_SIZE), }) } @@ -469,13 +462,6 @@ where } } } - Event::CustomBuf { tag, buf } => { - for handler in &mut self.custom_buf_handlers { - if handler(state, &tag, &buf)? == CustomBufEventResult::Handled { - break; - } - } - } Event::Stop => { state.request_stop(); } @@ -679,19 +665,6 @@ where { } -impl HasCustomBufHandlers for LlmpEventManager -where - S: State, - SP: ShMemProvider, -{ - fn add_custom_buf_handler( - &mut self, - handler: Box Result>, - ) { - self.custom_buf_handlers.push(handler); - } -} - impl ProgressReporter for LlmpEventManager where S: State + HasExecutions + HasMetadata + HasLastReportTime, diff --git a/libafl/src/events/llmp/mod.rs b/libafl/src/events/llmp/mod.rs index 147a41ae65..8d4111beed 100644 --- a/libafl/src/events/llmp/mod.rs +++ b/libafl/src/events/llmp/mod.rs @@ -1,6 +1,5 @@ //! LLMP-backed event manager for scalable multi-processed fuzzing -use alloc::{boxed::Box, vec::Vec}; use core::{marker::PhantomData, time::Duration}; #[cfg(feature = "llmp_compression")] @@ -17,7 +16,7 @@ use serde::Deserialize; use crate::{ corpus::Corpus, - events::{CustomBufEventResult, CustomBufHandlerFn, Event, EventFirer}, + events::{Event, EventFirer}, executors::{Executor, HasObservers}, fuzzer::{EvaluatorObservers, ExecutionProcessor}, inputs::{Input, InputConverter, NopInput, NopInputConverter, UsesInput}, @@ -96,8 +95,6 @@ where throttle: Option, llmp: LlmpClient, last_sent: Duration, - /// The custom buf handler - custom_buf_handlers: Vec>>, #[cfg(feature = "llmp_compression")] compressor: GzipCompressor, converter: Option, @@ -165,7 +162,6 @@ impl LlmpEventConverterBuilder { converter, converter_back, phantom: PhantomData, - custom_buf_handlers: vec![], }) } @@ -195,7 +191,6 @@ impl LlmpEventConverterBuilder { converter, converter_back, phantom: PhantomData, - custom_buf_handlers: vec![], }) } @@ -225,7 +220,6 @@ impl LlmpEventConverterBuilder { converter, converter_back, phantom: PhantomData, - custom_buf_handlers: vec![], }) } } @@ -324,14 +318,6 @@ where } Ok(()) } - Event::CustomBuf { tag, buf } => { - for handler in &mut self.custom_buf_handlers { - if handler(state, &tag, &buf)? == CustomBufEventResult::Handled { - break; - } - } - Ok(()) - } Event::Stop => Ok(()), _ => Err(Error::unknown(format!( "Received illegal message that message should not have arrived: {:?}.", @@ -449,7 +435,6 @@ where #[cfg(all(unix, feature = "std", feature = "multi_machine"))] node_id, }, - Event::CustomBuf { buf, tag } => Event::CustomBuf { buf, tag }, _ => { return Ok(()); } @@ -506,10 +491,6 @@ where #[cfg(all(unix, feature = "std", feature = "multi_machine"))] node_id, }, - Event::CustomBuf { buf, tag } => Event::CustomBuf { buf, tag }, - _ => { - return Ok(()); - } }; let serialized = postcard::to_allocvec(&converted_event)?; self.llmp.send_buf(LLMP_TAG_EVENT_TO_BOTH, &serialized)?; diff --git a/libafl/src/events/llmp/restarting.rs b/libafl/src/events/llmp/restarting.rs index 1a0734ebd1..5a4c0a33e0 100644 --- a/libafl/src/events/llmp/restarting.rs +++ b/libafl/src/events/llmp/restarting.rs @@ -3,7 +3,7 @@ //! When the target crashes, a watch process (the parent) will //! restart/refork it. -use alloc::{boxed::Box, vec::Vec}; +use alloc::vec::Vec; use core::{ marker::PhantomData, num::NonZeroUsize, @@ -34,10 +34,10 @@ use crate::events::EVENTMGR_SIGHANDLER_STATE; use crate::{ corpus::Corpus, events::{ - launcher::ClientDescription, AdaptiveSerializer, CustomBufEventResult, Event, EventConfig, - EventFirer, EventManager, EventManagerHooksTuple, EventManagerId, EventProcessor, - EventRestarter, HasCustomBufHandlers, HasEventManagerId, LlmpEventManager, - LlmpShouldSaveState, ProgressReporter, StdLlmpEventHook, + launcher::ClientDescription, AdaptiveSerializer, Event, EventConfig, EventFirer, + EventManager, EventManagerHooksTuple, EventManagerId, EventProcessor, EventRestarter, + HasEventManagerId, LlmpEventManager, LlmpShouldSaveState, ProgressReporter, + StdLlmpEventHook, }, executors::{Executor, HasObservers}, fuzzer::{Evaluator, EvaluatorObservers, ExecutionProcessor}, @@ -246,19 +246,6 @@ where } } -impl HasCustomBufHandlers for LlmpRestartingEventManager -where - S: State, - SP: ShMemProvider, -{ - fn add_custom_buf_handler( - &mut self, - handler: Box Result>, - ) { - self.llmp_mgr.add_custom_buf_handler(handler); - } -} - /// The llmp connection from the actual fuzzer to the process supervising it const _ENV_FUZZER_SENDER: &str = "_AFL_ENV_FUZZER_SENDER"; const _ENV_FUZZER_RECEIVER: &str = "_AFL_ENV_FUZZER_RECEIVER"; diff --git a/libafl/src/events/mod.rs b/libafl/src/events/mod.rs index 93dddc4f07..e5fba9eb2a 100644 --- a/libafl/src/events/mod.rs +++ b/libafl/src/events/mod.rs @@ -19,7 +19,7 @@ pub use llmp::*; pub mod tcp; pub mod broker_hooks; -use alloc::{borrow::Cow, boxed::Box, string::String, vec::Vec}; +use alloc::{borrow::Cow, string::String, vec::Vec}; use core::{ fmt, hash::{BuildHasher, Hasher}, @@ -154,15 +154,6 @@ impl fmt::Display for LogSeverity { } } -/// The result of a custom buf handler added using [`HasCustomBufHandlers::add_custom_buf_handler`] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum CustomBufEventResult { - /// Exit early from event handling - Handled, - /// Call the next handler, if available - Next, -} - /// Indicate if an event worked or not #[derive(Serialize, Deserialize, Debug, Copy, Clone)] pub enum BrokerEventResult { @@ -337,13 +328,6 @@ where /// `PhantomData` phantom: PhantomData, }, - /// Sends a custom buffer to other clients - CustomBuf { - /// The buffer - buf: Vec, - /// Tag of this buffer - tag: String, - }, /// Exit gracefully Stop, /*/// A custom type @@ -367,7 +351,6 @@ where Event::UpdatePerfMonitor { .. } => "PerfMonitor", Event::Objective { .. } => "Objective", Event::Log { .. } => "Log", - Event::CustomBuf { .. } => "CustomBuf", /*Event::Custom { sender_id: _, /*custom_event} => custom_event.name()*/ } => "todo",*/ @@ -387,7 +370,6 @@ where Event::UpdatePerfMonitor { .. } => Cow::Borrowed("PerfMonitor"), Event::Objective { .. } => Cow::Borrowed("Objective"), Event::Log { .. } => Cow::Borrowed("Log"), - Event::CustomBuf { .. } => Cow::Borrowed("CustomBuf"), Event::Stop => Cow::Borrowed("Stop"), /*Event::Custom { sender_id: _, /*custom_event} => custom_event.name()*/ @@ -598,15 +580,6 @@ where { } -/// The handler function for custom buffers exchanged via [`EventManager`] -type CustomBufHandlerFn = dyn FnMut(&mut S, &str, &[u8]) -> Result; - -/// Supports custom buf handlers to handle `CustomBuf` events. -pub trait HasCustomBufHandlers: UsesState { - /// Adds a custom buffer handler that will run for each incoming `CustomBuf` event. - fn add_custom_buf_handler(&mut self, handler: Box>); -} - /// An eventmgr for tests, and as placeholder if you really don't need an event manager. #[derive(Copy, Clone, Debug)] pub struct NopEventManager { @@ -678,19 +651,6 @@ impl EventManager for NopEventManager where { } -impl HasCustomBufHandlers for NopEventManager -where - S: State, -{ - fn add_custom_buf_handler( - &mut self, - _handler: Box< - dyn FnMut(&mut Self::State, &str, &[u8]) -> Result, - >, - ) { - } -} - impl ProgressReporter for NopEventManager where S: State + HasExecutions + HasLastReportTime + HasMetadata { @@ -815,22 +775,6 @@ where { } -impl HasCustomBufHandlers for MonitorTypedEventManager -where - Self: UsesState, - EM: HasCustomBufHandlers, -{ - #[inline] - fn add_custom_buf_handler( - &mut self, - handler: Box< - dyn FnMut(&mut Self::State, &str, &[u8]) -> Result, - >, - ) { - self.inner.add_custom_buf_handler(handler); - } -} - impl ProgressReporter for MonitorTypedEventManager where Self: UsesState, diff --git a/libafl/src/events/simple.rs b/libafl/src/events/simple.rs index 122bdd3fb6..a491af1a1c 100644 --- a/libafl/src/events/simple.rs +++ b/libafl/src/events/simple.rs @@ -1,6 +1,6 @@ //! A very simple event manager, that just supports log outputs, but no multiprocessing -use alloc::{boxed::Box, vec::Vec}; +use alloc::vec::Vec; use core::{fmt::Debug, marker::PhantomData}; #[cfg(feature = "std")] use core::{ @@ -20,7 +20,7 @@ use libafl_bolts::{os::CTRL_C_EXIT, shmem::ShMemProvider, staterestore::StateRes #[cfg(feature = "std")] use serde::{de::DeserializeOwned, Serialize}; -use super::{CustomBufEventResult, CustomBufHandlerFn, HasCustomBufHandlers, ProgressReporter}; +use super::ProgressReporter; #[cfg(all(unix, feature = "std", not(miri)))] use crate::events::EVENTMGR_SIGHANDLER_STATE; use crate::{ @@ -54,8 +54,6 @@ where monitor: MT, /// The events that happened since the last `handle_in_broker` events: Vec>, - /// The custom buf handler - custom_buf_handlers: Vec>>, phantom: PhantomData, } @@ -139,22 +137,6 @@ where { } -impl HasCustomBufHandlers for SimpleEventManager -where - MT: Monitor, //CE: CustomEvent, - S: State, -{ - /// Adds a custom buffer handler that will run for each incoming `CustomBuf` event. - fn add_custom_buf_handler( - &mut self, - handler: Box< - dyn FnMut(&mut Self::State, &str, &[u8]) -> Result, - >, - ) { - self.custom_buf_handlers.push(handler); - } -} - impl ProgressReporter for SimpleEventManager where MT: Monitor, @@ -194,7 +176,6 @@ where Self { monitor, events: vec![], - custom_buf_handlers: vec![], phantom: PhantomData, } } @@ -267,7 +248,6 @@ where log::log!((*severity_level).into(), "{message}"); Ok(BrokerEventResult::Handled) } - Event::CustomBuf { .. } => Ok(BrokerEventResult::Forward), Event::Stop => Ok(BrokerEventResult::Forward), } } @@ -275,12 +255,6 @@ where // Handle arriving events in the client fn handle_in_client(&mut self, state: &mut S, event: Event) -> Result<(), Error> { match event { - Event::CustomBuf { buf, tag } => { - for handler in &mut self.custom_buf_handlers { - handler(state, &tag, &buf)?; - } - Ok(()) - } Event::Stop => { state.request_stop(); Ok(()) @@ -394,21 +368,6 @@ where { } -#[cfg(feature = "std")] -impl HasCustomBufHandlers for SimpleRestartingEventManager -where - MT: Monitor, - S: State, - SP: ShMemProvider, -{ - fn add_custom_buf_handler( - &mut self, - handler: Box Result>, - ) { - self.simple_event_mgr.add_custom_buf_handler(handler); - } -} - #[cfg(feature = "std")] impl ProgressReporter for SimpleRestartingEventManager where diff --git a/libafl/src/events/tcp.rs b/libafl/src/events/tcp.rs index 53d1df1f00..a553b3a390 100644 --- a/libafl/src/events/tcp.rs +++ b/libafl/src/events/tcp.rs @@ -1,6 +1,6 @@ //! TCP-backed event manager for scalable multi-processed fuzzing -use alloc::{boxed::Box, vec::Vec}; +use alloc::vec::Vec; use core::{ marker::PhantomData, num::NonZeroUsize, @@ -38,15 +38,13 @@ use tokio::{ }; use typed_builder::TypedBuilder; -use super::{CustomBufEventResult, CustomBufHandlerFn}; #[cfg(all(unix, not(miri)))] use crate::events::EVENTMGR_SIGHANDLER_STATE; use crate::{ corpus::Corpus, events::{ BrokerEventResult, Event, EventConfig, EventFirer, EventManager, EventManagerHooksTuple, - EventManagerId, EventProcessor, EventRestarter, HasCustomBufHandlers, HasEventManagerId, - ProgressReporter, + EventManagerId, EventProcessor, EventRestarter, HasEventManagerId, ProgressReporter, }, executors::{Executor, HasObservers}, fuzzer::{EvaluatorObservers, ExecutionProcessor}, @@ -399,7 +397,7 @@ where log::log!((*severity_level).into(), "{message}"); Ok(BrokerEventResult::Handled) } - Event::CustomBuf { .. } | Event::Stop => Ok(BrokerEventResult::Forward), + Event::Stop => Ok(BrokerEventResult::Forward), //_ => Ok(BrokerEventResult::Forward), } } @@ -420,8 +418,6 @@ where tcp: TcpStream, /// Our `CientId` client_id: ClientId, - /// The custom buf handler - custom_buf_handlers: Vec>>, #[cfg(feature = "tcp_compression")] compressor: GzipCompressor, /// The configuration defines this specific fuzzer. @@ -519,7 +515,6 @@ where compressor: GzipCompressor::new(), configuration, phantom: PhantomData, - custom_buf_handlers: vec![], }) } @@ -643,13 +638,6 @@ where log::info!("Added received Testcase as item #{item}"); } } - Event::CustomBuf { tag, buf } => { - for handler in &mut self.custom_buf_handlers { - if handler(state, &tag, &buf)? == CustomBufEventResult::Handled { - break; - } - } - } Event::Stop => { state.request_stop(); } @@ -826,19 +814,6 @@ where { } -impl HasCustomBufHandlers for TcpEventManager -where - EMH: EventManagerHooksTuple, - S: State, -{ - fn add_custom_buf_handler( - &mut self, - handler: Box Result>, - ) { - self.custom_buf_handlers.push(handler); - } -} - impl ProgressReporter for TcpEventManager where EMH: EventManagerHooksTuple,