Skip to content

Commit

Permalink
abcde
Browse files Browse the repository at this point in the history
  • Loading branch information
tokatoka committed Jul 12, 2024
1 parent a660ddb commit a16111d
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 77 deletions.
2 changes: 1 addition & 1 deletion libafl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ all-features = true
rustc-args = ["--cfg", "docsrs"]

[features]
default = ["std", "derive", "llmp_compression", "llmp_small_maps", "llmp_broker_timeouts", "rand_trait", "fork", "prelude", "gzip", "regex", "serdeany_autoreg", "tui_monitor", "libafl_bolts/xxh3"]
default = ["std", "derive", "llmp_compression", "llmp_small_maps", "llmp_broker_timeouts", "rand_trait", "fork", "prelude", "gzip", "regex", "serdeany_autoreg", "tui_monitor", "libafl_bolts/xxh3", "tcp_manager"]
document-features = ["dep:document-features"]

#! # Feature Flags
Expand Down
9 changes: 5 additions & 4 deletions libafl/src/events/llmp/mgr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use crate::{
fuzzer::{Evaluator, EvaluatorObservers, ExecutionProcessor},
inputs::{NopInput, UsesInput},
observers::{ObserversTuple, TimeObserver, UsesObservers},
state::{HasExecutions, HasLastReportTime, NopState, State, UsesState},
state::{HasExecutions, HasImported, HasLastReportTime, NopState, State, UsesState},
Error, HasMetadata,
};

Expand Down Expand Up @@ -389,7 +389,7 @@ where
impl<EMH, S, SP> LlmpEventManager<EMH, S, SP>
where
EMH: EventManagerHooksTuple<S>,
S: State + HasExecutions + HasMetadata,
S: State + HasExecutions + HasMetadata + HasImported,
SP: ShMemProvider,
{
// Handle arriving events in the client
Expand Down Expand Up @@ -454,6 +454,7 @@ where
)?
};
if let Some(item) = res.1 {
*state.imported_mut() += 1;
log::debug!("Added received Testcase {evt_name} as item #{item}");
} else {
log::debug!("Testcase {evt_name} was discarded");
Expand Down Expand Up @@ -585,7 +586,7 @@ impl<E, EMH, S, SP, Z> EventProcessor<E, Z> for LlmpEventManager<EMH, S, SP>
where
EMH: EventManagerHooksTuple<S>,
<E as UsesObservers>::Observers: Serialize,
S: State + HasExecutions + HasMetadata,
S: State + HasExecutions + HasMetadata + HasImported,
SP: ShMemProvider,
E: HasObservers<State = S> + Executor<Self, Z>,
for<'a> E::Observers: Deserialize<'a>,
Expand Down Expand Up @@ -639,7 +640,7 @@ where
<E as UsesObservers>::Observers: Serialize,
for<'a> E::Observers: Deserialize<'a>,
EMH: EventManagerHooksTuple<S>,
S: State + HasExecutions + HasMetadata + HasLastReportTime,
S: State + HasExecutions + HasMetadata + HasLastReportTime + HasImported,
SP: ShMemProvider,
Z: ExecutionProcessor<State = S> + EvaluatorObservers<E::Observers> + Evaluator<E, Self>,
{
Expand Down
6 changes: 3 additions & 3 deletions libafl/src/events/llmp/restarting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use crate::{
inputs::UsesInput,
monitors::Monitor,
observers::{ObserversTuple, TimeObserver, UsesObservers},
state::{HasExecutions, HasLastReportTime, State, UsesState},
state::{HasExecutions, HasLastReportTime, State, UsesState, HasImported},
Error, HasMetadata,
};

Expand Down Expand Up @@ -208,7 +208,7 @@ where
<E as UsesObservers>::Observers: Serialize,
for<'a> E::Observers: Deserialize<'a>,
EMH: EventManagerHooksTuple<S>,
S: State + HasExecutions + HasMetadata,
S: State + HasExecutions + HasMetadata + HasImported,
SP: ShMemProvider,
Z: ExecutionProcessor<State = S>
+ EvaluatorObservers<E::Observers>
Expand All @@ -232,7 +232,7 @@ where
<E as UsesObservers>::Observers: Serialize,
for<'a> E::Observers: Deserialize<'a>,
EMH: EventManagerHooksTuple<S>,
S: State + HasExecutions + HasMetadata + HasLastReportTime,
S: State + HasExecutions + HasMetadata + HasLastReportTime + HasImported,
SP: ShMemProvider,
Z: ExecutionProcessor<State = S>
+ EvaluatorObservers<E::Observers>
Expand Down
17 changes: 9 additions & 8 deletions libafl/src/events/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use crate::{
inputs::{Input, UsesInput},
monitors::Monitor,
observers::UsesObservers,
state::{HasExecutions, HasLastReportTime, State, UsesState},
state::{HasExecutions, HasLastReportTime, State, UsesState, HasImported},
Error, HasMetadata,
};

Expand Down Expand Up @@ -592,7 +592,7 @@ where
impl<EMH, S> TcpEventManager<EMH, S>
where
EMH: EventManagerHooksTuple<S>,
S: State + HasExecutions + HasMetadata,
S: State + HasExecutions + HasMetadata + HasImported,
{
/// Write the client id for a client [`EventManager`] to env vars
pub fn to_env(&self, env_name: &str) {
Expand Down Expand Up @@ -649,6 +649,7 @@ where
)?
};
if let Some(item) = _res.1 {
*state.imported_mut() += 1;
log::info!("Added received Testcase as item #{item}");
}
}
Expand Down Expand Up @@ -753,7 +754,7 @@ where
<E as UsesObservers>::Observers: Serialize,
for<'a> E::Observers: Deserialize<'a>,
EMH: EventManagerHooksTuple<S>,
S: State + HasExecutions + HasMetadata,
S: State + HasExecutions + HasMetadata + HasImported,
Z: EvaluatorObservers<E::Observers, State = S> + ExecutionProcessor<State = S>,
{
fn process(
Expand Down Expand Up @@ -827,7 +828,7 @@ where
<E as UsesObservers>::Observers: Serialize,
for<'a> E::Observers: Deserialize<'a>,
EMH: EventManagerHooksTuple<S>,
S: State + HasExecutions + HasMetadata + HasLastReportTime,
S: State + HasExecutions + HasMetadata + HasLastReportTime + HasImported,
Z: EvaluatorObservers<E::Observers, State = S> + ExecutionProcessor<State = S>,
{
}
Expand Down Expand Up @@ -972,7 +973,7 @@ where
for<'a> E::Observers: Deserialize<'a>,
<E as UsesObservers>::Observers: Serialize,
EMH: EventManagerHooksTuple<S>,
S: State + HasExecutions + HasMetadata,
S: State + HasExecutions + HasMetadata + HasImported,
SP: ShMemProvider + 'static,
Z: EvaluatorObservers<E::Observers, State = S> + ExecutionProcessor, //CE: CustomEvent<I>,
{
Expand All @@ -992,7 +993,7 @@ where
<E as UsesObservers>::Observers: Serialize,
for<'a> E::Observers: Deserialize<'a>,
EMH: EventManagerHooksTuple<S>,
S: State + HasExecutions + HasMetadata + HasLastReportTime,
S: State + HasExecutions + HasMetadata + HasLastReportTime + HasImported,
SP: ShMemProvider + 'static,
Z: EvaluatorObservers<E::Observers, State = S> + ExecutionProcessor, //CE: CustomEvent<I>,
{
Expand Down Expand Up @@ -1090,7 +1091,7 @@ pub fn setup_restarting_mgr_tcp<MT, S>(
>
where
MT: Monitor + Clone,
S: State + HasExecutions + HasMetadata,
S: State + HasExecutions + HasMetadata + HasImported,
{
TcpRestartingMgr::builder()
.shmem_provider(StdShMemProvider::new()?)
Expand Down Expand Up @@ -1155,7 +1156,7 @@ impl<EMH, MT, S, SP> TcpRestartingMgr<EMH, MT, S, SP>
where
EMH: EventManagerHooksTuple<S> + Copy + Clone,
SP: ShMemProvider,
S: State + HasExecutions + HasMetadata,
S: State + HasExecutions + HasMetadata + HasImported,
MT: Monitor + Clone,
{
/// Launch the restarting manager
Expand Down
56 changes: 49 additions & 7 deletions libafl/src/executors/inprocess/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,23 @@ use core::{
time::Duration,
};

use libafl_bolts::tuples::{tuple_list, RefIndexable};
use libafl_bolts::{
current_time,
tuples::{tuple_list, RefIndexable},
};

#[cfg(any(unix, feature = "std"))]
use crate::executors::hooks::inprocess::GLOBAL_STATE;
use crate::{
events::{EventFirer, EventRestarter},
corpus::Corpus,
events::{Event, EventFirer, EventRestarter},
executors::{
hooks::{inprocess::InProcessHooks, ExecutorHooksTuple},
inprocess::inner::GenericInProcessExecutorInner,
Executor, ExitKind, HasObservers,
},
feedbacks::Feedback,
fuzzer::HasObjective,
fuzzer::{ExecuteInputResult, HasObjective},
inputs::UsesInput,
observers::{ObserversTuple, UsesObservers},
schedulers::Scheduler,
Expand Down Expand Up @@ -432,7 +436,7 @@ pub fn run_observers_and_save_state<E, EM, OF, Z>(
input: &<E::State as UsesInput>::Input,
fuzzer: &mut Z,
event_mgr: &mut EM,
exitkind: ExitKind,
exit_kind: ExitKind,
) where
E: HasObservers,
EM: EventFirer<State = E::State> + EventRestarter<State = E::State>,
Expand All @@ -447,9 +451,47 @@ pub fn run_observers_and_save_state<E, EM, OF, Z>(

let _ = scheduler.on_evaluation(state, input, &*observers);

let res = fuzzer.check_results(state, event_mgr, input, &*observers, &exitkind);
if let Ok(r) = res {
let _ = fuzzer.process_execution(state, event_mgr, &input, &r, &*observers);
let res = fuzzer.check_results(state, event_mgr, input, &*observers, &exit_kind);
if let Ok(exec_res) = res {
let _ = fuzzer.process_execution(state, event_mgr, input, &exec_res, &*observers);

// Now send off the event
// unlike in fuzzer/mod.rs we never serialize here.
// (because it doesn't work with generics)
match exec_res {
ExecuteInputResult::Corpus => {
if event_mgr.should_send() {
// TODO set None for fast targets
let _ = event_mgr.fire(
state,
Event::NewTestcase {
input: input.clone(),
observers_buf: None,
exit_kind,
corpus_size: state.corpus().count(),
client_config: event_mgr.configuration(),
time: current_time(),
executions: *state.executions(),
forward_id: None,
#[cfg(all(unix, feature = "std", feature = "multi_machine"))]
node_id: None,
},
);
}
}
ExecuteInputResult::Solution => {
let executions = *state.executions();
let _ = event_mgr.fire(
state,
Event::Objective {
objective_size: state.solutions().count(),
executions,
time: current_time(),
},
);
}
ExecuteInputResult::None => (),
}
} else {
log::info!("Faild to check execution result");
}
Expand Down
65 changes: 11 additions & 54 deletions libafl/src/fuzzer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,6 @@ pub trait ExecutionProcessor: UsesState {
EM: EventFirer<State = Self::State>,
OT: ObserversTuple<Self::State>;

/// Send event via the event manager
fn dispatch_event<EM, OT>(
&mut self,
state: &mut Self::State,
manager: &mut EM,
input: <Self::State as UsesInput>::Input,
exec_res: &ExecuteInputResult,
observers: &OT,
exit_kind: &ExitKind,
send_events: bool,
) -> Result<(), Error>
where
EM: EventFirer<State = Self::State>,
OT: ObserversTuple<Self::State> + Serialize;

/// Evaluate if a set of observation channels has an interesting state
fn evaluate_execution<EM, OT>(
&mut self,
Expand Down Expand Up @@ -424,21 +409,23 @@ where
Ok(res)
}

/// Send event via the event manager
fn dispatch_event<EM, OT>(
fn evaluate_execution<EM, OT>(
&mut self,
state: &mut Self::State,
manager: &mut EM,
input: <Self::State as UsesInput>::Input,
exec_res: &ExecuteInputResult,
observers: &OT,
exit_kind: &ExitKind,
send_events: bool,
) -> Result<(), Error>
) -> Result<(ExecuteInputResult, Option<CorpusId>), Error>
where
EM: EventFirer<State = Self::State>,
OT: ObserversTuple<Self::State> + Serialize,
{
let exec_res = self.check_results(state, manager, &input, observers, exit_kind)?;
let corpus_id = self.process_execution(state, manager, &input, &exec_res, observers)?;

// Now send off the event
match exec_res {
ExecuteInputResult::Corpus => {
if send_events && manager.should_send() {
Expand All @@ -463,9 +450,6 @@ where
node_id: None,
},
)?;
} else {
// This testcase is from the other fuzzers.
*state.imported_mut() += 1;
}
}
ExecuteInputResult::Solution => {
Expand All @@ -481,36 +465,9 @@ where
)?;
}
}
_ => (),
ExecuteInputResult::None => (),
}

Ok(())
}

fn evaluate_execution<EM, OT>(
&mut self,
state: &mut Self::State,
manager: &mut EM,
input: <Self::State as UsesInput>::Input,
observers: &OT,
exit_kind: &ExitKind,
send_events: bool,
) -> Result<(ExecuteInputResult, Option<CorpusId>), Error>
where
EM: EventFirer<State = Self::State>,
OT: ObserversTuple<Self::State> + Serialize,
{
let exec_res = self.check_results(state, manager, &input, observers, exit_kind)?;
let corpus_id = self.process_execution(state, manager, &input, &exec_res, observers)?;
self.dispatch_event(
state,
manager,
input,
&exec_res,
observers,
exit_kind,
send_events,
)?;
Ok((exec_res, corpus_id))
}

Expand All @@ -529,13 +486,13 @@ where
{
match exec_res {
ExecuteInputResult::None => {
self.feedback_mut().discard_metadata(state, &input)?;
self.objective_mut().discard_metadata(state, &input)?;
self.feedback_mut().discard_metadata(state, input)?;
self.objective_mut().discard_metadata(state, input)?;
Ok(None)
}
ExecuteInputResult::Corpus => {
// Not a solution
self.objective_mut().discard_metadata(state, &input)?;
self.objective_mut().discard_metadata(state, input)?;

// Add the input to the main corpus
let mut testcase = Testcase::with_executions(input.clone(), *state.executions());
Expand All @@ -551,7 +508,7 @@ where
}
ExecuteInputResult::Solution => {
// Not interesting
self.feedback_mut().discard_metadata(state, &input)?;
self.feedback_mut().discard_metadata(state, input)?;

let executions = *state.executions();
// The input is a solution, add it to the respective corpus
Expand Down

0 comments on commit a16111d

Please sign in to comment.