mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-17 12:28:07 +00:00
Factor out generic libfuzzer task (#2214)
This commit is contained in:
@ -16,8 +16,8 @@ use crate::{
|
|||||||
},
|
},
|
||||||
tasks::{
|
tasks::{
|
||||||
analysis::generic::run as run_analysis, config::CommonConfig,
|
analysis::generic::run as run_analysis, config::CommonConfig,
|
||||||
fuzz::libfuzzer_fuzz::LibFuzzerFuzzTask, regression::libfuzzer::LibFuzzerRegressionTask,
|
fuzz::libfuzzer::generic::LibFuzzerFuzzTask,
|
||||||
report::libfuzzer_report::ReportTask,
|
regression::libfuzzer::LibFuzzerRegressionTask, report::libfuzzer_report::ReportTask,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
||||||
|
@ -9,7 +9,7 @@ use crate::{
|
|||||||
},
|
},
|
||||||
tasks::{
|
tasks::{
|
||||||
config::CommonConfig,
|
config::CommonConfig,
|
||||||
fuzz::libfuzzer_fuzz::{Config, LibFuzzerFuzzTask},
|
fuzz::libfuzzer::generic::{Config, LibFuzzerFuzzTask},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
@ -51,6 +51,7 @@ pub fn build_fuzz_config(
|
|||||||
check_fuzzer_help,
|
check_fuzzer_help,
|
||||||
expect_crash_on_failure,
|
expect_crash_on_failure,
|
||||||
common,
|
common,
|
||||||
|
extra: (),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(config)
|
Ok(config)
|
||||||
|
@ -88,7 +88,7 @@ pub enum Config {
|
|||||||
DotnetCoverage(coverage::dotnet::Config),
|
DotnetCoverage(coverage::dotnet::Config),
|
||||||
|
|
||||||
#[serde(alias = "libfuzzer_fuzz")]
|
#[serde(alias = "libfuzzer_fuzz")]
|
||||||
LibFuzzerFuzz(fuzz::libfuzzer_fuzz::Config),
|
LibFuzzerFuzz(fuzz::libfuzzer::generic::Config),
|
||||||
|
|
||||||
#[serde(alias = "libfuzzer_crash_report")]
|
#[serde(alias = "libfuzzer_crash_report")]
|
||||||
LibFuzzerReport(report::libfuzzer_report::Config),
|
LibFuzzerReport(report::libfuzzer_report::Config),
|
||||||
@ -225,7 +225,7 @@ impl Config {
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
Config::LibFuzzerFuzz(config) => {
|
Config::LibFuzzerFuzz(config) => {
|
||||||
fuzz::libfuzzer_fuzz::LibFuzzerFuzzTask::new(config)?
|
fuzz::libfuzzer::generic::LibFuzzerFuzzTask::new(config)?
|
||||||
.run()
|
.run()
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
5
src/agent/onefuzz-task/src/tasks/fuzz/libfuzzer.rs
Normal file
5
src/agent/onefuzz-task/src/tasks/fuzz/libfuzzer.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
pub mod common;
|
||||||
|
pub mod generic;
|
@ -40,8 +40,20 @@ pub fn default_workers() -> usize {
|
|||||||
usize::max(1, cpus - 1)
|
usize::max(1, cpus - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// LibFuzzer subtypes that share custom configuration or process initialization.
|
||||||
|
pub trait LibFuzzerType {
|
||||||
|
/// Extra configuration values expected by the `Config` for this type.
|
||||||
|
type Config;
|
||||||
|
|
||||||
|
/// Method that constructs a `LibFuzzer` configured as appropriate for the subtype.
|
||||||
|
///
|
||||||
|
/// This may include things like setting special environment variables, or overriding
|
||||||
|
/// the defaults or values of some command arguments.
|
||||||
|
fn from_config(config: &Config<Self>) -> LibFuzzer;
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Clone)]
|
#[derive(Debug, Deserialize, Clone)]
|
||||||
pub struct Config {
|
pub struct Config<L: LibFuzzerType + ?Sized> {
|
||||||
pub inputs: SyncedDir,
|
pub inputs: SyncedDir,
|
||||||
pub readonly_inputs: Option<Vec<SyncedDir>>,
|
pub readonly_inputs: Option<Vec<SyncedDir>>,
|
||||||
pub crashes: SyncedDir,
|
pub crashes: SyncedDir,
|
||||||
@ -61,14 +73,23 @@ pub struct Config {
|
|||||||
|
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub common: CommonConfig,
|
pub common: CommonConfig,
|
||||||
|
|
||||||
|
#[serde(flatten)]
|
||||||
|
pub extra: L::Config,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct LibFuzzerFuzzTask {
|
pub struct LibFuzzerFuzzTask<L>
|
||||||
config: Config,
|
where
|
||||||
|
L: LibFuzzerType,
|
||||||
|
{
|
||||||
|
config: Config<L>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LibFuzzerFuzzTask {
|
impl<L> LibFuzzerFuzzTask<L>
|
||||||
pub fn new(config: Config) -> Result<Self> {
|
where
|
||||||
|
L: LibFuzzerType,
|
||||||
|
{
|
||||||
|
pub fn new(config: Config<L>) -> Result<Self> {
|
||||||
Ok(Self { config })
|
Ok(Self { config })
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,12 +129,8 @@ impl LibFuzzerFuzzTask {
|
|||||||
directories.append(&mut dirs);
|
directories.append(&mut dirs);
|
||||||
}
|
}
|
||||||
|
|
||||||
let fuzzer = LibFuzzer::new(
|
let fuzzer = L::from_config(&self.config);
|
||||||
&self.config.target_exe,
|
|
||||||
&self.config.target_options,
|
|
||||||
&self.config.target_env,
|
|
||||||
&self.config.common.setup_dir,
|
|
||||||
);
|
|
||||||
fuzzer
|
fuzzer
|
||||||
.verify(self.config.check_fuzzer_help, Some(directories))
|
.verify(self.config.check_fuzzer_help, Some(directories))
|
||||||
.await
|
.await
|
29
src/agent/onefuzz-task/src/tasks/fuzz/libfuzzer/generic.rs
Normal file
29
src/agent/onefuzz-task/src/tasks/fuzz/libfuzzer/generic.rs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
use onefuzz::libfuzzer::LibFuzzer;
|
||||||
|
|
||||||
|
use crate::tasks::fuzz::libfuzzer::common;
|
||||||
|
|
||||||
|
/// Generic LibFuzzer with no special extra configuration.
|
||||||
|
///
|
||||||
|
/// Its configuration is fully controlled by the user, up to the constraints of the
|
||||||
|
/// `LibFuzzer` wrapper itself.
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct GenericLibFuzzer;
|
||||||
|
|
||||||
|
impl common::LibFuzzerType for GenericLibFuzzer {
|
||||||
|
type Config = ();
|
||||||
|
|
||||||
|
fn from_config(config: &common::Config<Self>) -> LibFuzzer {
|
||||||
|
LibFuzzer::new(
|
||||||
|
&config.target_exe,
|
||||||
|
&config.target_options,
|
||||||
|
&config.target_env,
|
||||||
|
&config.common.setup_dir,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type Config = common::Config<GenericLibFuzzer>;
|
||||||
|
pub type LibFuzzerFuzzTask = common::LibFuzzerFuzzTask<GenericLibFuzzer>;
|
@ -2,5 +2,5 @@
|
|||||||
// Licensed under the MIT License.
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
pub mod generator;
|
pub mod generator;
|
||||||
pub mod libfuzzer_fuzz;
|
pub mod libfuzzer;
|
||||||
pub mod supervisor;
|
pub mod supervisor;
|
||||||
|
Reference in New Issue
Block a user