Skip to content

Commit 0f9c82f

Browse files
authored
Add always_interesting option to llmp mgr (#2262)
* always add * change launcher...
1 parent 7b90873 commit 0f9c82f

3 files changed

Lines changed: 82 additions & 31 deletions

File tree

libafl/src/events/launcher.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,9 @@ where
495495
monitor: MT,
496496
/// The configuration
497497
configuration: EventConfig,
498+
/// Consider this testcase as interesting always if true
499+
#[builder(default = false)]
500+
always_interesting: bool,
498501
/// The 'main' function to run for each client forked. This probably shouldn't return
499502
#[builder(default, setter(strip_option))]
500503
run_client: Option<CF>,
@@ -684,6 +687,7 @@ where
684687

685688
// Fuzzer client. keeps retrying the connection to broker till the broker starts
686689
let builder = RestartingMgr::<(), MT, S, SP>::builder()
690+
.always_interesting(self.always_interesting)
687691
.shmem_provider(self.shmem_provider.clone())
688692
.broker_port(self.broker_port)
689693
.kind(ManagerKind::Client {

libafl/src/events/llmp/mgr.rs

Lines changed: 64 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use crate::{
4343
ProgressReporter,
4444
},
4545
executors::{Executor, HasObservers},
46-
fuzzer::{EvaluatorObservers, ExecutionProcessor},
46+
fuzzer::{Evaluator, EvaluatorObservers, ExecutionProcessor},
4747
inputs::{NopInput, UsesInput},
4848
observers::ObserversTuple,
4949
state::{HasExecutions, HasLastReportTime, NopState, State, UsesState},
@@ -59,6 +59,8 @@ where
5959
{
6060
/// We only send 1 testcase for every `throttle` second
6161
pub(crate) throttle: Option<Duration>,
62+
/// Treat the incoming testcase as interesting always without evaluating them
63+
always_interesting: bool,
6264
/// We sent last message at `last_sent`
6365
last_sent: Duration,
6466
hooks: EMH,
@@ -98,6 +100,7 @@ impl LlmpEventManager<(), NopState<NopInput>, NopShMemProvider> {
98100
pub struct LlmpEventManagerBuilder<EMH> {
99101
throttle: Option<Duration>,
100102
hooks: EMH,
103+
always_interesting: bool,
101104
}
102105

103106
impl Default for LlmpEventManagerBuilder<()> {
@@ -113,6 +116,7 @@ impl LlmpEventManagerBuilder<()> {
113116
Self {
114117
throttle: None,
115118
hooks: (),
119+
always_interesting: false,
116120
}
117121
}
118122

@@ -121,6 +125,17 @@ impl LlmpEventManagerBuilder<()> {
121125
LlmpEventManagerBuilder {
122126
throttle: self.throttle,
123127
hooks,
128+
always_interesting: self.always_interesting,
129+
}
130+
}
131+
132+
/// Set `always_interesting`
133+
#[must_use]
134+
pub fn always_interesting(self, always_interesting: bool) -> LlmpEventManagerBuilder<()> {
135+
LlmpEventManagerBuilder {
136+
throttle: self.throttle,
137+
hooks: self.hooks,
138+
always_interesting,
124139
}
125140
}
126141
}
@@ -149,6 +164,7 @@ impl<EMH> LlmpEventManagerBuilder<EMH> {
149164
throttle: self.throttle,
150165
last_sent: Duration::from_secs(0),
151166
hooks: self.hooks,
167+
always_interesting: self.always_interesting,
152168
llmp,
153169
#[cfg(feature = "llmp_compression")]
154170
compressor: GzipCompressor::with_threshold(COMPRESS_THRESHOLD),
@@ -178,6 +194,7 @@ impl<EMH> LlmpEventManagerBuilder<EMH> {
178194
throttle: self.throttle,
179195
last_sent: Duration::from_secs(0),
180196
hooks: self.hooks,
197+
always_interesting: self.always_interesting,
181198
llmp,
182199
#[cfg(feature = "llmp_compression")]
183200
compressor: GzipCompressor::with_threshold(COMPRESS_THRESHOLD),
@@ -208,6 +225,7 @@ impl<EMH> LlmpEventManagerBuilder<EMH> {
208225
throttle: self.throttle,
209226
last_sent: Duration::from_secs(0),
210227
hooks: self.hooks,
228+
always_interesting: self.always_interesting,
211229
llmp,
212230
#[cfg(feature = "llmp_compression")]
213231
compressor: GzipCompressor::with_threshold(COMPRESS_THRESHOLD),
@@ -242,6 +260,7 @@ impl<EMH> LlmpEventManagerBuilder<EMH> {
242260
throttle: self.throttle,
243261
last_sent: Duration::from_secs(0),
244262
hooks: self.hooks,
263+
always_interesting: self.always_interesting,
245264
llmp,
246265
#[cfg(feature = "llmp_compression")]
247266
compressor: GzipCompressor::with_threshold(COMPRESS_THRESHOLD),
@@ -270,6 +289,7 @@ impl<EMH> LlmpEventManagerBuilder<EMH> {
270289
throttle: self.throttle,
271290
last_sent: Duration::from_secs(0),
272291
hooks: self.hooks,
292+
always_interesting: self.always_interesting,
273293
llmp,
274294
#[cfg(feature = "llmp_compression")]
275295
compressor: GzipCompressor::with_threshold(COMPRESS_THRESHOLD),
@@ -302,6 +322,7 @@ impl<EMH> LlmpEventManagerBuilder<EMH> {
302322
throttle: self.throttle,
303323
last_sent: Duration::from_secs(0),
304324
hooks: self.hooks,
325+
always_interesting: self.always_interesting,
305326
llmp,
306327
#[cfg(feature = "llmp_compression")]
307328
compressor: GzipCompressor::with_threshold(COMPRESS_THRESHOLD),
@@ -329,6 +350,7 @@ impl<EMH> LlmpEventManagerBuilder<EMH> {
329350
throttle: self.throttle,
330351
last_sent: Duration::from_secs(0),
331352
hooks: self.hooks,
353+
always_interesting: self.always_interesting,
332354
llmp,
333355
#[cfg(feature = "llmp_compression")]
334356
compressor: GzipCompressor::with_threshold(COMPRESS_THRESHOLD),
@@ -360,6 +382,7 @@ impl<EMH> LlmpEventManagerBuilder<EMH> {
360382
throttle: self.throttle,
361383
last_sent: Duration::from_secs(0),
362384
hooks: self.hooks,
385+
always_interesting: self.always_interesting,
363386
llmp,
364387
#[cfg(feature = "llmp_compression")]
365388
compressor: GzipCompressor::with_threshold(COMPRESS_THRESHOLD),
@@ -506,7 +529,9 @@ where
506529
where
507530
E: Executor<Self, Z> + HasObservers<State = S>,
508531
for<'a> E::Observers: Deserialize<'a>,
509-
Z: ExecutionProcessor<E::Observers, State = S> + EvaluatorObservers<E::Observers>,
532+
Z: ExecutionProcessor<E::Observers, State = S>
533+
+ EvaluatorObservers<E::Observers>
534+
+ Evaluator<E, Self>,
510535
{
511536
if !self.hooks.pre_exec_all(state, client_id, &event)? {
512537
return Ok(());
@@ -524,33 +549,40 @@ where
524549
} => {
525550
log::info!("Received new Testcase from {client_id:?} ({client_config:?}, forward {forward_id:?})");
526551

527-
let res = if client_config.match_with(&self.configuration)
528-
&& observers_buf.is_some()
529-
{
530-
#[cfg(feature = "adaptive_serialization")]
531-
let start = current_time();
532-
let observers: E::Observers =
533-
postcard::from_bytes(observers_buf.as_ref().unwrap())?;
534-
#[cfg(feature = "adaptive_serialization")]
535-
{
536-
self.deserialization_time = current_time() - start;
537-
}
538-
#[cfg(feature = "scalability_introspection")]
539-
{
540-
state.scalability_monitor_mut().testcase_with_observers += 1;
541-
}
542-
fuzzer.execute_and_process(state, self, input, &observers, &exit_kind, false)?
552+
if self.always_interesting {
553+
let item = fuzzer.add_input(state, executor, self, input)?;
554+
log::info!("Added received Testcase as item #{item}");
543555
} else {
544-
#[cfg(feature = "scalability_introspection")]
556+
let res = if client_config.match_with(&self.configuration)
557+
&& observers_buf.is_some()
545558
{
546-
state.scalability_monitor_mut().testcase_without_observers += 1;
559+
#[cfg(feature = "adaptive_serialization")]
560+
let start = current_time();
561+
let observers: E::Observers =
562+
postcard::from_bytes(observers_buf.as_ref().unwrap())?;
563+
#[cfg(feature = "adaptive_serialization")]
564+
{
565+
self.deserialization_time = current_time() - start;
566+
}
567+
#[cfg(feature = "scalability_introspection")]
568+
{
569+
state.scalability_monitor_mut().testcase_with_observers += 1;
570+
}
571+
fuzzer.execute_and_process(
572+
state, self, input, &observers, &exit_kind, false,
573+
)?
574+
} else {
575+
#[cfg(feature = "scalability_introspection")]
576+
{
577+
state.scalability_monitor_mut().testcase_without_observers += 1;
578+
}
579+
fuzzer.evaluate_input_with_observers::<E, Self>(
580+
state, executor, self, input, false,
581+
)?
582+
};
583+
if let Some(item) = res.1 {
584+
log::info!("Added received Testcase as item #{item}");
547585
}
548-
fuzzer.evaluate_input_with_observers::<E, Self>(
549-
state, executor, self, input, false,
550-
)?
551-
};
552-
if let Some(item) = res.1 {
553-
log::info!("Added received Testcase as item #{item}");
554586
}
555587
}
556588
Event::CustomBuf { tag, buf } => {
@@ -686,7 +718,9 @@ where
686718
SP: ShMemProvider,
687719
E: HasObservers<State = S> + Executor<Self, Z>,
688720
for<'a> E::Observers: Deserialize<'a>,
689-
Z: EvaluatorObservers<E::Observers, State = S> + ExecutionProcessor<E::Observers, State = S>,
721+
Z: ExecutionProcessor<E::Observers, State = S>
722+
+ EvaluatorObservers<E::Observers>
723+
+ Evaluator<E, Self>,
690724
{
691725
fn process(
692726
&mut self,
@@ -732,7 +766,9 @@ where
732766
EMH: EventManagerHooksTuple<S>,
733767
S: State + HasExecutions + HasMetadata + HasLastReportTime,
734768
SP: ShMemProvider,
735-
Z: EvaluatorObservers<E::Observers, State = S> + ExecutionProcessor<E::Observers, State = S>,
769+
Z: ExecutionProcessor<E::Observers, State = S>
770+
+ EvaluatorObservers<E::Observers>
771+
+ Evaluator<E, Self>,
736772
{
737773
}
738774

libafl/src/events/llmp/restarting.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ use crate::{
4848
LlmpEventManager, LlmpShouldSaveState, ProgressReporter,
4949
},
5050
executors::{Executor, HasObservers},
51-
fuzzer::{EvaluatorObservers, ExecutionProcessor},
51+
fuzzer::{Evaluator, EvaluatorObservers, ExecutionProcessor},
5252
inputs::UsesInput,
5353
monitors::Monitor,
5454
observers::ObserversTuple,
@@ -219,7 +219,9 @@ where
219219
EMH: EventManagerHooksTuple<S>,
220220
S: State + HasExecutions + HasMetadata,
221221
SP: ShMemProvider + 'static,
222-
Z: EvaluatorObservers<E::Observers, State = S> + ExecutionProcessor<E::Observers>, //CE: CustomEvent<I>,
222+
Z: ExecutionProcessor<E::Observers, State = S>
223+
+ EvaluatorObservers<E::Observers>
224+
+ Evaluator<E, LlmpEventManager<EMH, S, SP>>,
223225
{
224226
fn process(&mut self, fuzzer: &mut Z, state: &mut S, executor: &mut E) -> Result<usize, Error> {
225227
let res = self.llmp_mgr.process(fuzzer, state, executor)?;
@@ -236,7 +238,9 @@ where
236238
EMH: EventManagerHooksTuple<S>,
237239
S: State + HasExecutions + HasMetadata + HasLastReportTime,
238240
SP: ShMemProvider + 'static,
239-
Z: EvaluatorObservers<E::Observers, State = S> + ExecutionProcessor<E::Observers>, //CE: CustomEvent<I>,
241+
Z: ExecutionProcessor<E::Observers, State = S>
242+
+ EvaluatorObservers<E::Observers>
243+
+ Evaluator<E, LlmpEventManager<EMH, S, SP>>,
240244
{
241245
}
242246

@@ -402,6 +406,9 @@ where
402406
/// The shared memory provider to use for the broker or client spawned by the restarting
403407
/// manager.
404408
shmem_provider: SP,
409+
#[builder(default = false)]
410+
/// Consider this testcase as interesting always if true
411+
always_interesting: bool,
405412
/// The configuration
406413
configuration: EventConfig,
407414
/// The monitor to use
@@ -487,10 +494,12 @@ where
487494
LlmpConnection::IsClient { client } => {
488495
#[cfg(not(feature = "adaptive_serialization"))]
489496
let mgr: LlmpEventManager<EMH, S, SP> = LlmpEventManager::builder()
497+
.always_interesting(self.always_interesting)
490498
.hooks(self.hooks)
491499
.build_from_client(client, self.configuration)?;
492500
#[cfg(feature = "adaptive_serialization")]
493501
let mgr: LlmpEventManager<EMH, S, SP> = LlmpEventManager::builder()
502+
.always_interesting(self.always_interesting)
494503
.hooks(self.hooks)
495504
.build_from_client(
496505
client,
@@ -515,6 +524,7 @@ where
515524
// We are a client
516525
#[cfg(not(feature = "adaptive_serialization"))]
517526
let mgr = LlmpEventManager::builder()
527+
.always_interesting(self.always_interesting)
518528
.hooks(self.hooks)
519529
.build_on_port(
520530
self.shmem_provider.clone(),
@@ -523,6 +533,7 @@ where
523533
)?;
524534
#[cfg(feature = "adaptive_serialization")]
525535
let mgr = LlmpEventManager::builder()
536+
.always_interesting(self.always_interesting)
526537
.hooks(self.hooks)
527538
.build_on_port(
528539
self.shmem_provider.clone(),

0 commit comments

Comments
 (0)