Skip to content

Commit c917a02

Browse files
tokatokatoka
andauthored
Pass Handle to construct CalibrationStage (#3356)
* just pass the handle * fix? * ? * i'm dumb * fix * rename * fix * fix fix * further fix * alloc * fix * fix --------- Co-authored-by: toka <toka@tokas-MacBook-Air.local>
1 parent 544e2e7 commit c917a02

File tree

27 files changed

+207
-131
lines changed

27 files changed

+207
-131
lines changed

crates/libafl/src/stages/calibrate.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::{
1717
corpus::{Corpus, HasCurrentCorpusId, SchedulerTestcaseMetadata},
1818
events::{Event, EventFirer, EventWithStats, LogSeverity},
1919
executors::{Executor, ExitKind, HasObservers},
20-
feedbacks::{HasObserverHandle, map::MapFeedbackMetadata},
20+
feedbacks::map::MapFeedbackMetadata,
2121
fuzzer::Evaluator,
2222
inputs::Input,
2323
monitors::stats::{AggregatorOps, UserStats, UserStatsValue},
@@ -400,30 +400,32 @@ where
400400
{
401401
/// Create a new [`CalibrationStage`].
402402
#[must_use]
403-
pub fn new<F>(map_feedback: &F) -> Self
403+
pub fn new(observer_handle: &Handle<C>, map_feedback_name: Cow<'static, str>) -> Self
404404
where
405-
F: HasObserverHandle<Observer = C> + Named,
405+
C: Named,
406406
{
407-
let map_name = map_feedback.name().clone();
408407
Self {
409-
map_observer_handle: map_feedback.observer_handle().clone(),
410-
map_name: map_name.clone(),
408+
map_observer_handle: observer_handle.clone(),
409+
map_name: map_feedback_name.clone(),
411410
stage_max: CAL_STAGE_START,
412411
track_stability: true,
413412
phantom: PhantomData,
414413
name: Cow::Owned(
415-
CALIBRATION_STAGE_NAME.to_owned() + ":" + map_name.into_owned().as_str(),
414+
CALIBRATION_STAGE_NAME.to_owned() + ":" + map_feedback_name.into_owned().as_str(),
416415
),
417416
}
418417
}
419418

420419
/// Create a new [`CalibrationStage`], but without checking stability.
421420
#[must_use]
422-
pub fn ignore_stability<F>(map_feedback: &F) -> Self
421+
pub fn ignore_stability<F>(
422+
observer_handle: &Handle<C>,
423+
map_feedback_name: Cow<'static, str>,
424+
) -> Self
423425
where
424-
F: HasObserverHandle<Observer = C> + Named,
426+
C: Named,
425427
{
426-
let mut ret = Self::new(map_feedback);
428+
let mut ret = Self::new(observer_handle, map_feedback_name);
427429
ret.track_stability = false;
428430
ret
429431
}

crates/libafl_libfuzzer/runtime/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ macro_rules! fuzz_with {
187187
misc::should_use_grimoire,
188188
observers::{MappedEdgeMapObserver, SizeValueObserver},
189189
};
190+
use libafl_bolts::{tuples::Handled, Named};
190191

191192
let edge_maker = &$edge_maker;
192193

@@ -196,6 +197,7 @@ macro_rules! fuzz_with {
196197
let grimoire = grimoire_metadata.should();
197198

198199
let edges_observer = edge_maker().track_indices().track_novelties();
200+
let edges_observer_name = edges_observer.name().clone();
199201
let size_edges_observer = MappedEdgeMapObserver::new(edge_maker(), SizeValueObserver::default());
200202

201203
let keep_observer = LibfuzzerKeepFeedback::new();
@@ -230,7 +232,7 @@ macro_rules! fuzz_with {
230232
let generalization = GeneralizationStage::new(&edges_observer);
231233
let generalization = IfStage::new(|_, _, _, _| Ok(grimoire.into()), tuple_list!(generalization));
232234

233-
let calibration = CalibrationStage::new(&map_feedback);
235+
let calibration = CalibrationStage::new(&edges_observer.handle(), edges_observer_name);
234236

235237
let add_extra_feedback = $extra_feedback;
236238
let coverage_feedback = add_extra_feedback(

crates/libafl_sugar/src/forkserver.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! An `afl`-style forkserver fuzzer.
22
//! Use this if your target has complex state that needs to be reset.
3+
use alloc::borrow::Cow;
34
use core::{net::SocketAddr, time::Duration};
45
use std::{fs, path::PathBuf};
56

@@ -37,7 +38,7 @@ use libafl_bolts::{
3738
ownedref::OwnedRefMut,
3839
rands::StdRand,
3940
shmem::{ShMem, ShMemProvider, UnixShMemProvider},
40-
tuples::{Merge, tuple_list},
41+
tuples::{Handled, Merge, tuple_list},
4142
};
4243
use libafl_targets::AflppCmpLogMap;
4344
use typed_builder::TypedBuilder;
@@ -151,7 +152,8 @@ impl ForkserverBytesCoverageSugar<'_> {
151152
// Extra MapFeedback to deduplicate finds according to the cov map
152153
let map_objective = MaxMapFeedback::with_name("map_objective", &edges_observer);
153154

154-
let calibration = CalibrationStage::new(&map_feedback);
155+
let calibration =
156+
CalibrationStage::new(&edges_observer.handle(), Cow::Borrowed("map_feedback"));
155157

156158
// Feedback to rate the interestingness of an input
157159
// This one is composed by two Feedbacks in OR

crates/libafl_sugar/src/inprocess.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! In-Process fuzzing made easy.
22
//! Use this sugar for scaling `libfuzzer`-style fuzzers.
33
4+
use alloc::borrow::Cow;
45
use core::{
56
fmt::{self, Debug, Formatter},
67
net::SocketAddr,
@@ -36,7 +37,7 @@ use libafl_bolts::{
3637
ownedref::OwnedMutSlice,
3738
rands::StdRand,
3839
shmem::{ShMemProvider, StdShMemProvider},
39-
tuples::{Merge, tuple_list},
40+
tuples::{Handled, Merge, tuple_list},
4041
};
4142
use libafl_targets::{CmpLogObserver, EDGES_MAP_ALLOCATED_SIZE, edges_map_mut_ptr};
4243
use typed_builder::TypedBuilder;
@@ -170,7 +171,8 @@ where
170171
// Extra MapFeedback to deduplicate finds according to the cov map
171172
let map_objective = MaxMapFeedback::with_name("map_objective", &edges_observer);
172173

173-
let calibration = CalibrationStage::new(&map_feedback);
174+
let calibration =
175+
CalibrationStage::new(&edges_observer.handle(), Cow::Borrowed("map_feedback"));
174176

175177
// Feedback to rate the interestingness of an input
176178
// This one is composed by two Feedbacks in OR

crates/libafl_sugar/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ pub const CORPUS_CACHE_SIZE: usize = 4096;
6363
#[cfg(feature = "python")]
6464
use pyo3::prelude::*;
6565

66+
extern crate alloc;
67+
6668
/// The sugar python module
6769
#[cfg(feature = "python")]
6870
#[pymodule]

crates/libafl_sugar/src/qemu.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//! In-Process fuzzer with `QEMU`-based binary-only instrumentation
2+
use alloc::borrow::Cow;
23
use core::{
34
fmt::{self, Debug, Formatter},
45
net::SocketAddr,
@@ -35,7 +36,7 @@ use libafl_bolts::{
3536
ownedref::OwnedMutSlice,
3637
rands::StdRand,
3738
shmem::{ShMemProvider, StdShMemProvider},
38-
tuples::{Merge, tuple_list},
39+
tuples::{Handled, Merge, tuple_list},
3940
};
4041
#[cfg(not(any(feature = "mips", feature = "hexagon")))]
4142
use libafl_qemu::modules::CmpLogModule;
@@ -187,8 +188,10 @@ where
187188
// Extra MapFeedback to deduplicate finds according to the cov map
188189
let map_objective = MaxMapFeedback::with_name("map_objective", &edges_observer);
189190

190-
let calibration = CalibrationStage::new(&map_feedback);
191-
let calibration_cmplog = CalibrationStage::new(&map_feedback);
191+
let calibration =
192+
CalibrationStage::new(&edges_observer.handle(), Cow::Borrowed("map_feedback"));
193+
let calibration_cmplog =
194+
CalibrationStage::new(&edges_observer.handle(), Cow::Borrowed("map_feedback"));
192195

193196
// Feedback to rate the interestingness of an input
194197
// This one is composed by two Feedbacks in OR

fuzzers/baby/baby_fuzzer_custom_executor/src/main.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#[cfg(windows)]
22
use std::ptr::write_volatile;
3-
use std::{marker::PhantomData, path::PathBuf, ptr::write};
3+
use std::{borrow::Cow, marker::PhantomData, path::PathBuf, ptr::write};
44

55
#[cfg(feature = "tui")]
66
use libafl::monitors::tui::TuiMonitor;
@@ -22,7 +22,12 @@ use libafl::{
2222
state::{HasCorpus, HasExecutions, StdState},
2323
BloomInputFilter,
2424
};
25-
use libafl_bolts::{current_nanos, nonzero, rands::StdRand, tuples::tuple_list, AsSlice};
25+
use libafl_bolts::{
26+
current_nanos, nonzero,
27+
rands::StdRand,
28+
tuples::{tuple_list, Handled},
29+
AsSlice,
30+
};
2631
/// Coverage map with explicit assignments due to the lack of instrumentation
2732
static mut SIGNALS: [u8; 16] = [0; 16];
2833
static mut SIGNALS_PTR: *mut u8 = &raw mut SIGNALS as _;
@@ -85,7 +90,7 @@ pub fn main() {
8590
// Feedback to rate the interestingness of an input
8691
let mut feedback = MaxMapFeedback::new(&observer);
8792

88-
let calibration_stage = CalibrationStage::new(&feedback);
93+
let calibration_stage = CalibrationStage::new(&observer.handle(), Cow::Borrowed("signals"));
8994
let stats_stage = AflStatsStage::builder()
9095
.map_observer(&observer)
9196
.build()

fuzzers/baby/tutorial/src/lib.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//#![feature(min_const_generics)]
55

66
use core::time::Duration;
7-
use std::{env, path::PathBuf};
7+
use std::{borrow::Cow, env, path::PathBuf};
88

99
use libafl::{
1010
corpus::{Corpus, InMemoryCorpus, OnDiskCorpus},
@@ -21,7 +21,11 @@ use libafl::{
2121
state::{HasCorpus, StdState},
2222
Error, Fuzzer,
2323
};
24-
use libafl_bolts::{rands::StdRand, tuples::tuple_list, AsSlice};
24+
use libafl_bolts::{
25+
rands::StdRand,
26+
tuples::{tuple_list, Handled},
27+
AsSlice,
28+
};
2529
use libafl_targets::{libfuzzer_initialize, libfuzzer_test_one_input, std_edges_map_observer};
2630

2731
mod input;
@@ -93,7 +97,7 @@ fn fuzz(corpus_dirs: &[PathBuf], objective_dir: PathBuf, broker_port: u16) -> Re
9397

9498
let map_feedback = MaxMapFeedback::new(&edges_observer);
9599

96-
let calibration = CalibrationStage::new(&map_feedback);
100+
let calibration = CalibrationStage::new(&edges_observer.handle(), Cow::Borrowed("edges"));
97101

98102
// Feedback to rate the interestingness of an input
99103
// This one is composed by two Feedbacks in OR

fuzzers/binary_only/fuzzbench

Whitespace-only changes.

fuzzers/binary_only/fuzzbench_fork_qemu/src/fuzzer.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use core::cell::RefCell;
44
#[cfg(unix)]
55
use std::os::unix::io::FromRawFd;
66
use std::{
7+
borrow::Cow,
78
env,
89
fs::{self, File, OpenOptions},
910
io::Write,
@@ -44,7 +45,7 @@ use libafl_bolts::{
4445
current_time,
4546
rands::StdRand,
4647
shmem::{ShMemProvider, StdShMemProvider},
47-
tuples::{tuple_list, Merge},
48+
tuples::{tuple_list, Handled, Merge},
4849
AsSlice, AsSliceMut,
4950
};
5051
use libafl_qemu::{
@@ -276,7 +277,7 @@ fn fuzz(
276277

277278
let map_feedback = MaxMapFeedback::new(&edges_observer);
278279

279-
let calibration = CalibrationStage::new(&map_feedback);
280+
let calibration = CalibrationStage::new(&edges_observer.handle(), Cow::Borrowed("edges"));
280281

281282
// Feedback to rate the interestingness of an input
282283
// This one is composed by two Feedbacks in OR

0 commit comments

Comments
 (0)