Remove CustomBufHandlers (#2829)

* rem

* fix

* fixer
This commit is contained in:
Dongjia "toka" Zhang 2025-01-13 16:00:41 +01:00 committed by GitHub
parent aa0391ef8d
commit fd06e5ced0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 25 additions and 219 deletions

View File

@ -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<String>` 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()?;`

View File

@ -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),
}

View File

@ -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<EM, EMH, S, SP> HasCustomBufHandlers for CentralizedEventManager<EM, EMH, S, SP>
where
EM: HasCustomBufHandlers<State = S>,
EMH: EventManagerHooksTuple<S>,
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<CustomBufEventResult, Error>,
>,
) {
self.inner.add_custom_buf_handler(handler);
}
}
impl<EM, EMH, S, SP> ProgressReporter for CentralizedEventManager<EM, EMH, S, SP>
where
EM: AdaptiveSerializer + ProgressReporter<State = S> + HasEventManagerId,

View File

@ -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<SP>,
/// The custom buf handler
custom_buf_handlers: Vec<Box<CustomBufHandlerFn<S>>>,
#[cfg(feature = "llmp_compression")]
compressor: GzipCompressor,
/// The configuration defines this specific fuzzer.
@ -168,7 +165,6 @@ impl<EMH> LlmpEventManagerBuilder<EMH> {
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<EMH> LlmpEventManagerBuilder<EMH> {
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<EMH> LlmpEventManagerBuilder<EMH> {
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<EMH> LlmpEventManagerBuilder<EMH> {
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<EMH, S, SP> HasCustomBufHandlers for LlmpEventManager<EMH, S, SP>
where
S: State,
SP: ShMemProvider,
{
fn add_custom_buf_handler(
&mut self,
handler: Box<dyn FnMut(&mut S, &str, &[u8]) -> Result<CustomBufEventResult, Error>>,
) {
self.custom_buf_handlers.push(handler);
}
}
impl<EMH, S, SP> ProgressReporter for LlmpEventManager<EMH, S, SP>
where
S: State + HasExecutions + HasMetadata + HasLastReportTime,

View File

@ -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<Duration>,
llmp: LlmpClient<SP>,
last_sent: Duration,
/// The custom buf handler
custom_buf_handlers: Vec<Box<CustomBufHandlerFn<S>>>,
#[cfg(feature = "llmp_compression")]
compressor: GzipCompressor,
converter: Option<IC>,
@ -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,7 +491,6 @@ where
#[cfg(all(unix, feature = "std", feature = "multi_machine"))]
node_id,
},
Event::CustomBuf { buf, tag } => Event::CustomBuf { buf, tag },
_ => {
return Ok(());
}

View File

@ -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<EMH, S, SP> HasCustomBufHandlers for LlmpRestartingEventManager<EMH, S, SP>
where
S: State,
SP: ShMemProvider,
{
fn add_custom_buf_handler(
&mut self,
handler: Box<dyn FnMut(&mut S, &str, &[u8]) -> Result<CustomBufEventResult, Error>>,
) {
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";

View File

@ -19,7 +19,9 @@ pub use llmp::*;
pub mod tcp;
pub mod broker_hooks;
use alloc::{borrow::Cow, boxed::Box, string::String, vec::Vec};
#[cfg(feature = "introspection")]
use alloc::boxed::Box;
use alloc::{borrow::Cow, string::String, vec::Vec};
use core::{
fmt,
hash::{BuildHasher, Hasher},
@ -154,15 +156,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 +330,6 @@ where
/// `PhantomData`
phantom: PhantomData<I>,
},
/// Sends a custom buffer to other clients
CustomBuf {
/// The buffer
buf: Vec<u8>,
/// Tag of this buffer
tag: String,
},
/// Exit gracefully
Stop,
/*/// A custom type
@ -367,7 +353,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 +372,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 +582,6 @@ where
{
}
/// The handler function for custom buffers exchanged via [`EventManager`]
type CustomBufHandlerFn<S> = dyn FnMut(&mut S, &str, &[u8]) -> Result<CustomBufEventResult, Error>;
/// 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<CustomBufHandlerFn<Self::State>>);
}
/// An eventmgr for tests, and as placeholder if you really don't need an event manager.
#[derive(Copy, Clone, Debug)]
pub struct NopEventManager<S> {
@ -678,19 +653,6 @@ impl<E, S, Z> EventManager<E, Z> for NopEventManager<S> where
{
}
impl<S> HasCustomBufHandlers for NopEventManager<S>
where
S: State,
{
fn add_custom_buf_handler(
&mut self,
_handler: Box<
dyn FnMut(&mut Self::State, &str, &[u8]) -> Result<CustomBufEventResult, Error>,
>,
) {
}
}
impl<S> ProgressReporter for NopEventManager<S> where
S: State + HasExecutions + HasLastReportTime + HasMetadata
{
@ -815,22 +777,6 @@ where
{
}
impl<EM, M> HasCustomBufHandlers for MonitorTypedEventManager<EM, M>
where
Self: UsesState,
EM: HasCustomBufHandlers<State = Self::State>,
{
#[inline]
fn add_custom_buf_handler(
&mut self,
handler: Box<
dyn FnMut(&mut Self::State, &str, &[u8]) -> Result<CustomBufEventResult, Error>,
>,
) {
self.inner.add_custom_buf_handler(handler);
}
}
impl<EM, M> ProgressReporter for MonitorTypedEventManager<EM, M>
where
Self: UsesState,

View File

@ -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<Event<S::Input>>,
/// The custom buf handler
custom_buf_handlers: Vec<Box<CustomBufHandlerFn<S>>>,
phantom: PhantomData<S>,
}
@ -122,7 +120,7 @@ where
) -> Result<usize, Error> {
let count = self.events.len();
while let Some(event) = self.events.pop() {
self.handle_in_client(state, event)?;
self.handle_in_client(state, &event)?;
}
Ok(count)
}
@ -139,22 +137,6 @@ where
{
}
impl<MT, S> HasCustomBufHandlers for SimpleEventManager<MT, S>
where
MT: Monitor, //CE: CustomEvent<I, OT>,
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<CustomBufEventResult, Error>,
>,
) {
self.custom_buf_handlers.push(handler);
}
}
impl<MT, S> ProgressReporter for SimpleEventManager<MT, S>
where
MT: Monitor,
@ -194,7 +176,6 @@ where
Self {
monitor,
events: vec![],
custom_buf_handlers: vec![],
phantom: PhantomData,
}
}
@ -267,20 +248,14 @@ where
log::log!((*severity_level).into(), "{message}");
Ok(BrokerEventResult::Handled)
}
Event::CustomBuf { .. } => Ok(BrokerEventResult::Forward),
Event::Stop => Ok(BrokerEventResult::Forward),
}
}
// Handle arriving events in the client
fn handle_in_client(&mut self, state: &mut S, event: Event<S::Input>) -> Result<(), Error> {
#[allow(clippy::unused_self)]
fn handle_in_client(&mut self, state: &mut S, event: &Event<S::Input>) -> 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 +369,6 @@ where
{
}
#[cfg(feature = "std")]
impl<MT, S, SP> HasCustomBufHandlers for SimpleRestartingEventManager<MT, S, SP>
where
MT: Monitor,
S: State,
SP: ShMemProvider,
{
fn add_custom_buf_handler(
&mut self,
handler: Box<dyn FnMut(&mut S, &str, &[u8]) -> Result<CustomBufEventResult, Error>>,
) {
self.simple_event_mgr.add_custom_buf_handler(handler);
}
}
#[cfg(feature = "std")]
impl<MT, S, SP> ProgressReporter for SimpleRestartingEventManager<MT, S, SP>
where

View File

@ -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<Box<CustomBufHandlerFn<S>>>,
#[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<EMH, S> HasCustomBufHandlers for TcpEventManager<EMH, S>
where
EMH: EventManagerHooksTuple<S>,
S: State,
{
fn add_custom_buf_handler(
&mut self,
handler: Box<dyn FnMut(&mut S, &str, &[u8]) -> Result<CustomBufEventResult, Error>>,
) {
self.custom_buf_handlers.push(handler);
}
}
impl<EMH, S> ProgressReporter for TcpEventManager<EMH, S>
where
EMH: EventManagerHooksTuple<S>,