Skip to content

Commit

Permalink
Add avoid_crash option to scheduler (#2530)
Browse files Browse the repository at this point in the history
* chg

* add avoid_crash

* a

* clp

* just use .00 at this point

* libafl-fuzz chg
  • Loading branch information
tokatoka authored Sep 18, 2024
1 parent 902571c commit 5b7d307
Show file tree
Hide file tree
Showing 21 changed files with 189 additions and 59 deletions.
6 changes: 5 additions & 1 deletion fuzzers/fuzzbench/fuzzbench/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,11 @@ fn fuzz(
// A minimization+queue policy to get testcasess from the corpus
let scheduler = IndexesLenTimeMinimizerScheduler::new(
&edges_observer,
StdWeightedScheduler::with_schedule(&mut state, &edges_observer, Some(PowerSchedule::FAST)),
StdWeightedScheduler::with_schedule(
&mut state,
&edges_observer,
Some(PowerSchedule::fast()),
),
);

// A fuzzer with feedbacks and a corpus scheduler
Expand Down
6 changes: 5 additions & 1 deletion fuzzers/fuzzbench/fuzzbench_ctx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,11 @@ fn fuzz(
// A minimization+queue policy to get testcasess from the corpus
let scheduler = IndexesLenTimeMinimizerScheduler::new(
&edges_observer,
StdWeightedScheduler::with_schedule(&mut state, &edges_observer, Some(PowerSchedule::FAST)),
StdWeightedScheduler::with_schedule(
&mut state,
&edges_observer,
Some(PowerSchedule::fast()),
),
);

// A fuzzer with feedbacks and a corpus scheduler
Expand Down
2 changes: 1 addition & 1 deletion fuzzers/fuzzbench/fuzzbench_fork_qemu/src/fuzzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ fn fuzz(
// A minimization+queue policy to get testcasess from the corpus
let scheduler = IndexesLenTimeMinimizerScheduler::new(
&edges_observer,
PowerQueueScheduler::new(&mut state, &edges_observer, PowerSchedule::FAST),
PowerQueueScheduler::new(&mut state, &edges_observer, PowerSchedule::fast()),
);

// A fuzzer with feedbacks and a corpus scheduler
Expand Down
2 changes: 1 addition & 1 deletion fuzzers/fuzzbench/fuzzbench_forkserver/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ fn fuzz(
StdWeightedScheduler::with_schedule(
&mut state,
&edges_observer,
Some(PowerSchedule::EXPLORE),
Some(PowerSchedule::explore()),
),
);

Expand Down
2 changes: 1 addition & 1 deletion fuzzers/fuzzbench/fuzzbench_forkserver_cmplog/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ fn fuzz(
StdWeightedScheduler::with_schedule(
&mut state,
&edges_observer,
Some(PowerSchedule::EXPLORE),
Some(PowerSchedule::explore()),
),
);

Expand Down
2 changes: 1 addition & 1 deletion fuzzers/fuzzbench/fuzzbench_qemu/src/fuzzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ fn fuzz(
// A minimization+queue policy to get testcasess from the corpus
let scheduler = IndexesLenTimeMinimizerScheduler::new(
&edges_observer,
PowerQueueScheduler::new(&mut state, &edges_observer, PowerSchedule::FAST),
PowerQueueScheduler::new(&mut state, &edges_observer, PowerSchedule::fast()),
);

// A fuzzer with feedbacks and a corpus scheduler
Expand Down
4 changes: 2 additions & 2 deletions fuzzers/fuzzbench/fuzzbench_text/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ fn fuzz_binary(
StdWeightedScheduler::with_schedule(
&mut state,
&edges_observer,
Some(PowerSchedule::EXPLORE),
Some(PowerSchedule::explore()),
),
);

Expand Down Expand Up @@ -605,7 +605,7 @@ fn fuzz_text(
StdWeightedScheduler::with_schedule(
&mut state,
&edges_observer,
Some(PowerSchedule::EXPLORE),
Some(PowerSchedule::explore()),
),
);

Expand Down
6 changes: 5 additions & 1 deletion fuzzers/libpng/libfuzzer_libpng/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ fn fuzz(corpus_dirs: &[PathBuf], objective_dir: PathBuf, broker_port: u16) -> Re
// A minimization+queue policy to get testcasess from the corpus
let scheduler = IndexesLenTimeMinimizerScheduler::new(
&edges_observer,
StdWeightedScheduler::with_schedule(&mut state, &edges_observer, Some(PowerSchedule::FAST)),
StdWeightedScheduler::with_schedule(
&mut state,
&edges_observer,
Some(PowerSchedule::fast()),
),
);

// A fuzzer with feedbacks and a corpus scheduler
Expand Down
6 changes: 5 additions & 1 deletion fuzzers/libpng/libfuzzer_libpng_cmin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ fn fuzz(corpus_dirs: &[PathBuf], objective_dir: PathBuf, broker_port: u16) -> Re
// A minimization+queue policy to get testcasess from the corpus
let scheduler = IndexesLenTimeMinimizerScheduler::new(
&edges_observer,
StdWeightedScheduler::with_schedule(&mut state, &edges_observer, Some(PowerSchedule::FAST)),
StdWeightedScheduler::with_schedule(
&mut state,
&edges_observer,
Some(PowerSchedule::fast()),
),
);

// A fuzzer with feedbacks and a corpus scheduler
Expand Down
6 changes: 5 additions & 1 deletion fuzzers/libpng/libfuzzer_libpng_tcp_manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ fn fuzz(corpus_dirs: &[PathBuf], objective_dir: PathBuf, broker_port: u16) -> Re
// A minimization+queue policy to get testcasess from the corpus
let scheduler = IndexesLenTimeMinimizerScheduler::new(
&edges_observer,
StdWeightedScheduler::with_schedule(&mut state, &edges_observer, Some(PowerSchedule::FAST)),
StdWeightedScheduler::with_schedule(
&mut state,
&edges_observer,
Some(PowerSchedule::fast()),
),
);

// A fuzzer with feedbacks and a corpus scheduler
Expand Down
6 changes: 5 additions & 1 deletion fuzzers/others/dynamic_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,11 @@ fn fuzz(
// A minimization+queue policy to get testcasess from the corpus
let scheduler = IndexesLenTimeMinimizerScheduler::new(
&edges_observer,
StdWeightedScheduler::with_schedule(&mut state, &edges_observer, Some(PowerSchedule::FAST)),
StdWeightedScheduler::with_schedule(
&mut state,
&edges_observer,
Some(PowerSchedule::fast()),
),
);

// A fuzzer with feedbacks and a corpus scheduler
Expand Down
9 changes: 5 additions & 4 deletions fuzzers/others/libafl-fuzz/src/fuzzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use libafl::{
},
observers::{CanTrack, HitcountsMapObserver, StdMapObserver, TimeObserver},
schedulers::{
powersched::PowerSchedule, IndexesLenTimeMinimizerScheduler, QueueScheduler,
StdWeightedScheduler,
powersched::{BaseSchedule, PowerSchedule},
IndexesLenTimeMinimizerScheduler, QueueScheduler, StdWeightedScheduler,
},
stages::{
mutational::MultiMutationalStage, CalibrationStage, ColorizationStage, IfStage,
Expand Down Expand Up @@ -185,7 +185,7 @@ where
)
};
let mutational_stage = TimeTrackingStageWrapper::<FuzzTime, _, _>::new(inner_mutational_stage);
let strategy = opt.power_schedule.unwrap_or(PowerSchedule::EXPLORE);
let strategy = opt.power_schedule.unwrap_or(BaseSchedule::EXPLORE);

// Create our ColorizationStage
let colorization = ColorizationStage::new(&edges_observer);
Expand All @@ -197,8 +197,9 @@ where
if opt.sequential_queue {
scheduler = SupportedSchedulers::Queue(QueueScheduler::new(), PhantomData);
} else {
let ps = PowerSchedule::new(strategy);
let mut weighted_scheduler =
StdWeightedScheduler::with_schedule(&mut state, &edges_observer, Some(strategy));
StdWeightedScheduler::with_schedule(&mut state, &edges_observer, Some(ps));
if opt.cycle_schedules {
weighted_scheduler = weighted_scheduler.cycling_scheduler();
}
Expand Down
6 changes: 0 additions & 6 deletions fuzzers/others/libafl-fuzz/src/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ pub struct LibAflFuzzEventHook {
exit_on_solution: bool,
}

impl LibAflFuzzEventHook {
pub fn new(exit_on_solution: bool) -> Self {
Self { exit_on_solution }
}
}

impl<S> EventManagerHook<S> for LibAflFuzzEventHook
where
S: State + Stoppable,
Expand Down
4 changes: 2 additions & 2 deletions fuzzers/others/libafl-fuzz/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use fuzzer::run_client;
use libafl::{
events::{CentralizedLauncher, EventConfig},
monitors::MultiMonitor,
schedulers::powersched::PowerSchedule,
schedulers::powersched::BaseSchedule,
Error,
};
use libafl_bolts::{
Expand Down Expand Up @@ -126,7 +126,7 @@ struct Opt {
rng_seed: Option<u64>,
/// power schedules compute a seed's performance score: explore(default), fast, exploit, seek, rare, mmopt, coe, lin
#[arg(short = 'p')]
power_schedule: Option<PowerSchedule>,
power_schedule: Option<BaseSchedule>,
/// enable `CmpLog` by specifying a binary compiled for it.
#[arg(short = 'c')]
cmplog: Option<String>,
Expand Down
6 changes: 5 additions & 1 deletion fuzzers/others/libfuzzer_windows_asan/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ fn fuzz(corpus_dirs: &[PathBuf], objective_dir: PathBuf, broker_port: u16) -> Re
// A minimization+queue policy to get testcasess from the corpus
let scheduler = IndexesLenTimeMinimizerScheduler::new(
&edges_observer,
StdWeightedScheduler::with_schedule(&mut state, &edges_observer, Some(PowerSchedule::FAST)),
StdWeightedScheduler::with_schedule(
&mut state,
&edges_observer,
Some(PowerSchedule::fast()),
),
);

// A fuzzer with feedbacks and a corpus scheduler
Expand Down
2 changes: 1 addition & 1 deletion fuzzers/others/tutorial/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ fn fuzz(corpus_dirs: &[PathBuf], objective_dir: PathBuf, broker_port: u16) -> Re
// A minimization+queue policy to get testcasess from the corpus
let scheduler = PacketLenMinimizerScheduler::new(
&edges_observer,
PowerQueueScheduler::new(&mut state, &edges_observer, PowerSchedule::FAST),
PowerQueueScheduler::new(&mut state, &edges_observer, PowerSchedule::fast()),
);

// A fuzzer with feedbacks and a corpus scheduler
Expand Down
2 changes: 1 addition & 1 deletion fuzzers/qemu/qemu_launcher/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl<'a, M: Monitor> Instance<'a, M> {
// A minimization+queue policy to get testcasess from the corpus
let scheduler = IndexesLenTimeMinimizerScheduler::new(
&edges_observer,
PowerQueueScheduler::new(&mut state, &edges_observer, PowerSchedule::FAST),
PowerQueueScheduler::new(&mut state, &edges_observer, PowerSchedule::fast()),
);

let observers = tuple_list!(edges_observer, time_observer);
Expand Down
96 changes: 95 additions & 1 deletion libafl/src/schedulers/powersched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,104 @@ impl SchedulerMetadata {
}
}

/// The struct for the powerschedule algorithm
#[derive(Debug, Clone, Serialize, Deserialize, Copy)]
pub struct PowerSchedule {
base: BaseSchedule,
avoid_crash: bool,
}

impl PowerSchedule {
#[must_use]
/// Constructor
pub fn new(base: BaseSchedule) -> Self {
Self {
base,
avoid_crash: false,
}
}

/// Use `explore` power schedule
#[must_use]
pub fn explore() -> Self {
Self {
base: BaseSchedule::EXPLORE,
avoid_crash: false,
}
}

/// Use `exploit` power schedule
#[must_use]
pub fn exploit() -> Self {
Self {
base: BaseSchedule::EXPLOIT,
avoid_crash: false,
}
}

/// Use `fast` power schedule
#[must_use]
pub fn fast() -> Self {
Self {
base: BaseSchedule::FAST,
avoid_crash: false,
}
}

/// Use `coe` power schedule
#[must_use]
pub fn coe() -> Self {
Self {
base: BaseSchedule::COE,
avoid_crash: false,
}
}

/// Use `lin` power schedule
#[must_use]
pub fn lin() -> Self {
Self {
base: BaseSchedule::LIN,
avoid_crash: false,
}
}

/// Use `quad` power schedule
#[must_use]
pub fn quad() -> Self {
Self {
base: BaseSchedule::QUAD,
avoid_crash: false,
}
}

/// Getter to `avoid_crash`
#[must_use]
pub fn avoid_crash(&self) -> bool {
self.avoid_crash
}

/// Avoid scheduling testcases that caused crashes
pub fn set_avoid_crash(&mut self) {
self.avoid_crash = true;
}

/// Getter to the base scheduler
#[must_use]
pub fn base(&self) -> &BaseSchedule {
&self.base
}

/// Setter to the base scheduler
pub fn set_base(&mut self, base: BaseSchedule) {
self.base = base;
}
}

/// The power schedule to use
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
pub enum PowerSchedule {
pub enum BaseSchedule {
/// The `explore` power schedule
EXPLORE,
/// The `exploit` power schedule
Expand Down
Loading

0 comments on commit 5b7d307

Please sign in to comment.