add cooloff period for rapidly exiting libFuzzer targets (#1002)

This commit is contained in:
bmc-msft
2021-06-18 11:40:36 -04:00
committed by GitHub
parent 888c0459ad
commit c8862c7f18

View File

@ -24,7 +24,7 @@ use tokio::{
select, select,
sync::{mpsc, Notify}, sync::{mpsc, Notify},
task, task,
time::{sleep, Duration}, time::{sleep, Duration, Instant},
}; };
use uuid::Uuid; use uuid::Uuid;
@ -37,6 +37,9 @@ const PROC_INFO_PERIOD: Duration = Duration::from_secs(30);
// Period of reporting fuzzer-generated runtime stats. // Period of reporting fuzzer-generated runtime stats.
const RUNTIME_STATS_PERIOD: Duration = Duration::from_secs(60); const RUNTIME_STATS_PERIOD: Duration = Duration::from_secs(60);
// Period for minimum duration between launches of libFuzzer
const COOLOFF_PERIOD: Duration = Duration::from_secs(10);
/// Maximum number of log message to safe in case of libFuzzer failing, /// Maximum number of log message to safe in case of libFuzzer failing,
/// arbitrarily chosen /// arbitrarily chosen
const LOGS_BUFFER_SIZE: usize = 1024; const LOGS_BUFFER_SIZE: usize = 1024;
@ -160,6 +163,7 @@ impl LibFuzzerFuzzTask {
) -> Result<()> { ) -> Result<()> {
let local_input_dir = self.create_local_temp_dir().await?; let local_input_dir = self.create_local_temp_dir().await?;
loop { loop {
let instant = Instant::now();
self.run_fuzzer(&local_input_dir.path(), worker_id, stats_sender) self.run_fuzzer(&local_input_dir.path(), worker_id, stats_sender)
.await?; .await?;
@ -181,6 +185,13 @@ impl LibFuzzerFuzzTask {
) )
})?; })?;
} }
// if libFuzzer is exiting rapidly, give some breathing room to allow the
// handles to be reaped.
let runtime = instant.elapsed();
if runtime < COOLOFF_PERIOD {
sleep(COOLOFF_PERIOD - runtime).await;
}
} }
} }
@ -335,7 +346,7 @@ async fn report_fuzzer_sys_info(
) -> Result<()> { ) -> Result<()> {
// Allow for sampling CPU usage. // Allow for sampling CPU usage.
let mut period = tokio::time::interval_at( let mut period = tokio::time::interval_at(
tokio::time::Instant::now() + PROC_INFO_COLLECTION_DELAY, Instant::now() + PROC_INFO_COLLECTION_DELAY,
PROC_INFO_PERIOD, PROC_INFO_PERIOD,
); );
loop { loop {