From 7f1021b4ce8474e9c8b0376bda3031e40e5b6c68 Mon Sep 17 00:00:00 2001 From: Brian Caswell Date: Thu, 17 Jun 2021 20:18:50 -0400 Subject: [PATCH 1/2] if libFuzzer is exiting rapidly, give some breathing room to allow the handles to be reaped --- .../onefuzz-agent/src/tasks/fuzz/libfuzzer_fuzz.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/agent/onefuzz-agent/src/tasks/fuzz/libfuzzer_fuzz.rs b/src/agent/onefuzz-agent/src/tasks/fuzz/libfuzzer_fuzz.rs index b3bb864885..cecaa40b76 100644 --- a/src/agent/onefuzz-agent/src/tasks/fuzz/libfuzzer_fuzz.rs +++ b/src/agent/onefuzz-agent/src/tasks/fuzz/libfuzzer_fuzz.rs @@ -24,7 +24,7 @@ use tokio::{ select, sync::{mpsc, Notify}, task, - time::{sleep, Duration}, + time::{sleep, Duration, Instant}, }; use uuid::Uuid; @@ -37,6 +37,8 @@ const PROC_INFO_PERIOD: Duration = Duration::from_secs(30); // Period of reporting fuzzer-generated runtime stats. const RUNTIME_STATS_PERIOD: Duration = Duration::from_secs(60); +const COOLOFF_PERIOD: Duration = Duration::from_secs(5); + /// Maximum number of log message to safe in case of libFuzzer failing, /// arbitrarily chosen const LOGS_BUFFER_SIZE: usize = 1024; @@ -160,6 +162,7 @@ impl LibFuzzerFuzzTask { ) -> Result<()> { let local_input_dir = self.create_local_temp_dir().await?; loop { + let instant = Instant::now(); self.run_fuzzer(&local_input_dir.path(), worker_id, stats_sender) .await?; @@ -181,6 +184,12 @@ impl LibFuzzerFuzzTask { ) })?; } + + // if libFuzzer is exiting rapidly, give some breathing room to allow the + // handles to be reaped. + if instant.elapsed() < COOLOFF_PERIOD { + sleep(COOLOFF_PERIOD).await; + } } } @@ -335,7 +344,7 @@ async fn report_fuzzer_sys_info( ) -> Result<()> { // Allow for sampling CPU usage. let mut period = tokio::time::interval_at( - tokio::time::Instant::now() + PROC_INFO_COLLECTION_DELAY, + Instant::now() + PROC_INFO_COLLECTION_DELAY, PROC_INFO_PERIOD, ); loop { From 6872c654cdaa5a434f04b5065c60bc4722798540 Mon Sep 17 00:00:00 2001 From: Brian Caswell Date: Fri, 18 Jun 2021 09:47:53 -0400 Subject: [PATCH 2/2] address feedback --- src/agent/onefuzz-agent/src/tasks/fuzz/libfuzzer_fuzz.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/agent/onefuzz-agent/src/tasks/fuzz/libfuzzer_fuzz.rs b/src/agent/onefuzz-agent/src/tasks/fuzz/libfuzzer_fuzz.rs index cecaa40b76..cefc347277 100644 --- a/src/agent/onefuzz-agent/src/tasks/fuzz/libfuzzer_fuzz.rs +++ b/src/agent/onefuzz-agent/src/tasks/fuzz/libfuzzer_fuzz.rs @@ -37,7 +37,8 @@ const PROC_INFO_PERIOD: Duration = Duration::from_secs(30); // Period of reporting fuzzer-generated runtime stats. const RUNTIME_STATS_PERIOD: Duration = Duration::from_secs(60); -const COOLOFF_PERIOD: Duration = Duration::from_secs(5); +// 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, /// arbitrarily chosen @@ -187,8 +188,9 @@ impl LibFuzzerFuzzTask { // if libFuzzer is exiting rapidly, give some breathing room to allow the // handles to be reaped. - if instant.elapsed() < COOLOFF_PERIOD { - sleep(COOLOFF_PERIOD).await; + let runtime = instant.elapsed(); + if runtime < COOLOFF_PERIOD { + sleep(COOLOFF_PERIOD - runtime).await; } } }