Skip to content

Commit

Permalink
Clean up warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
corydu committed Dec 19, 2023
1 parent 2dc71a4 commit 1a489fc
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 70 deletions.
8 changes: 2 additions & 6 deletions src/cmdline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
use anyhow::{anyhow, ensure, Context, Result};
use clap::Parser;
use log::debug;
use rustc_hash::{FxHashMap, FxHashSet};
use smallvec::SmallVec;
use thiserror::Error;

use std::collections::{BTreeMap, BTreeSet, HashMap};
use std::fs::File;
use std::num::NonZeroUsize;
use std::collections::{BTreeMap, HashMap};
use std::ops::Range;
use std::path::{Path, PathBuf};
use std::time::Duration;
Expand All @@ -20,7 +17,6 @@ use crate::config::Config;
use crate::feedback::FeedbackTracker;
use crate::fuzzer::ResetBreakpointType;
use crate::stack_unwinder::StackUnwinders;
use crate::stats;
use crate::symbols::{Symbol, LINUX_KERNEL_SYMBOLS, LINUX_USERLAND_SYMBOLS};
use crate::vbcpu::{VbCpu, VmSelector, X86FxState, X86XSaveArea, X86XSaveHeader, X86XsaveYmmHi};
use crate::SymbolList;
Expand Down Expand Up @@ -774,7 +770,7 @@ pub fn get_project_state(dir: &Path, cmd: Option<&SubCommand>) -> Result<Project
let mut redqueen_breakpoints = None;

#[cfg(feature = "redqueen")]
let mut redqueen_bp_addrs: FxHashSet<VirtAddr> = FxHashSet::default();
let mut redqueen_bp_addrs: rustc_hash::FxHashSet<VirtAddr> = rustc_hash::FxHashSet::default();

#[cfg(feature = "redqueen")]
if !cmps_paths.is_empty() {
Expand Down
15 changes: 12 additions & 3 deletions src/commands/corpus_min.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::fuzzvm::{FuzzVm, FuzzVmExit};
use crate::memory::Memory;
use crate::{cmdline, fuzzvm, unblock_sigalrm, SymbolList, THREAD_IDS};
use crate::{handle_vmexit, init_environment, KvmEnvironment, ProjectState};
use crate::{Cr3, Execution, ResetBreakpointType, Symbol, VbCpu, VirtAddr};
use crate::{Cr3, Execution, ResetBreakpointType, VbCpu, VirtAddr};

/// Get all of the files found in the given path recursively
fn get_files(path: &Path) -> Result<Vec<PathBuf>, std::io::Error> {
Expand Down Expand Up @@ -79,7 +79,13 @@ pub(crate) fn run<FUZZER: Fuzzer>(
// Gather the total coverage for this project
{
let curr_clean_snapshot = clean_snapshot.read().unwrap();
for addr in project_state.coverage_breakpoints.as_ref().unwrap().keys().copied() {
for addr in project_state
.coverage_breakpoints
.as_ref()
.unwrap()
.keys()
.copied()
{
if let Ok(orig_byte) = curr_clean_snapshot.read_byte(addr, cr3) {
covbp_bytes.insert(addr, orig_byte);
total_coverage.push(addr.0);
Expand Down Expand Up @@ -270,7 +276,10 @@ pub(crate) fn run<FUZZER: Fuzzer>(
let coverage_lcov = project_state.path.clone().join("coverage_min.lcov.info");
if let Ok(debug_info) = crate::stats::DebugInfo::new(&project_state) {
let mut lcov = debug_info.empty_lcov_info();
debug_info.update_lcov_addresses(&mut lcov, minimizer.addr_to_inputs.keys().cloned().map(|x| (x, 1_u32)));
debug_info.update_lcov_addresses(
&mut lcov,
minimizer.addr_to_inputs.keys().cloned().map(|x| (x, 1_u32)),
);
lcov.write_to_file(coverage_lcov)?;
} else {
log::info!("failed to load debug info");
Expand Down
17 changes: 5 additions & 12 deletions src/commands/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
use anyhow::{anyhow, ensure, Context, Result};

use std::collections::{BTreeMap, BTreeSet, VecDeque};
use std::convert::Into;
use std::fs::File;
use std::collections::BTreeMap;
use std::os::unix::io::AsRawFd;
use std::path::{Path, PathBuf};
use std::path::PathBuf;
use std::sync::{Arc, RwLock};
use std::time::Duration;

Expand All @@ -16,11 +14,11 @@ use kvm_ioctls::VmFd;

use crate::fuzz_input::InputWithMetadata;
use crate::fuzzer::Fuzzer;
use crate::fuzzvm::{FuzzVm, FuzzVmExit};
use crate::fuzzvm::FuzzVm;
use crate::memory::Memory;
use crate::{cmdline, fuzzvm, unblock_sigalrm, SymbolList, THREAD_IDS};
use crate::{handle_vmexit, init_environment, KvmEnvironment, ProjectState};
use crate::{Cr3, Execution, ResetBreakpointType, Symbol, VirtAddr};
use crate::{init_environment, KvmEnvironment, ProjectState};
use crate::{Cr3, ResetBreakpointType, VirtAddr};

/// Execute the Coverage subcommand to gather coverage for a particular input
pub(crate) fn run<FUZZER: Fuzzer>(
Expand Down Expand Up @@ -110,8 +108,6 @@ pub(crate) fn start_core<FUZZER: Fuzzer>(
path: project_dir,
..
} = project_state;
let debug_info = crate::stats::DebugInfo::new(project_state);

// Use the current fuzzer
let mut fuzzer = FUZZER::default();

Expand Down Expand Up @@ -212,18 +208,15 @@ pub(crate) fn start_core<FUZZER: Fuzzer>(
symbols_file.display()
);
crate::stats::write_human_readable_text_coverage(
project_state,
&debug_info,
symbols.as_ref(),
&feedback,
symbols_file,
)?;

} else {
log::warn!("failed to load debug info");
}


if display_context {
fuzzvm.print_context()?;
}
Expand Down
6 changes: 3 additions & 3 deletions src/commands/find_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use anyhow::{anyhow, ensure, Context, Result};

use std::collections::{BTreeMap, HashSet, VecDeque};
use std::collections::{BTreeMap, HashSet};
use std::os::unix::io::AsRawFd;
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
Expand All @@ -19,9 +19,9 @@ use crate::fuzzer::Fuzzer;
use crate::fuzzvm::{FuzzVm, FuzzVmExit};
use crate::memory::Memory;
use crate::stack_unwinder::StackUnwinders;
use crate::{cmdline, fuzzvm, unblock_sigalrm, THREAD_IDS, SymbolList};
use crate::{cmdline, fuzzvm, unblock_sigalrm, SymbolList, THREAD_IDS};
use crate::{handle_vmexit, init_environment, KvmEnvironment, ProjectState};
use crate::{Cr3, Execution, ResetBreakpointType, Symbol, VbCpu, VirtAddr};
use crate::{Cr3, Execution, ResetBreakpointType, VbCpu, VirtAddr};

/// Thread worker to execute a single input and write the single step trace for that
/// input
Expand Down
10 changes: 3 additions & 7 deletions src/commands/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
use anyhow::{ensure, Context, Result};

use std::collections::{HashMap, VecDeque};

use std::collections::{BTreeMap, BTreeSet};
use std::os::unix::io::AsRawFd;
use std::path::PathBuf;
Expand All @@ -14,7 +12,6 @@ use std::time::{Duration, Instant};
use core_affinity::CoreId;
use kvm_bindings::CpuId;
use kvm_ioctls::VmFd;
use rand::Rng as _;

use crate::cmdline::ProjectCoverage;
use crate::{cmdline, SymbolList};
Expand All @@ -34,12 +31,14 @@ use crate::{block_sigalrm, kick_cores, Stats, FINISHED};
use crate::memory::Memory;
use crate::{fuzzvm, unblock_sigalrm, write_crash_input, THREAD_IDS};
use crate::{handle_vmexit, init_environment, KvmEnvironment, ProjectState};
use crate::{Cr3, Execution, ResetBreakpointType, Symbol, VbCpu, VirtAddr};
use crate::{Cr3, Execution, ResetBreakpointType, VbCpu, VirtAddr};

use crate::feedback::FeedbackTracker;

#[cfg(feature = "redqueen")]
use crate::cmp_analysis::RedqueenArguments;
#[cfg(feature = "redqueen")]
use std::collections::HashMap;

use crate::stack_unwinder::StackUnwinders;

Expand Down Expand Up @@ -774,7 +773,6 @@ fn start_core<FUZZER: Fuzzer>(
// Get the crash dir for this project
let crash_dir = project_dir.join("crashes");

let fuzz_start_time = std::time::Instant::now();
core_stats.lock().unwrap().perf_stats.start_time = crate::utils::rdtsc();

// Cache the shared redqueen seen state to avoid having to shared lock as much as possible
Expand Down Expand Up @@ -1192,8 +1190,6 @@ fn start_core<FUZZER: Fuzzer>(

// Check if the input hit any kasan_report blocks
if let Some(path) = fuzzvm.get_kasan_crash_path() {
let input_bytes = input.input_as_bytes()?;

// Found a valid KASAN output, write out the crashing input
if let Some(crash_file) =
write_crash_input(&crash_dir, &path, &input, &fuzzvm.console_output)?
Expand Down
14 changes: 10 additions & 4 deletions src/commands/minimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use anyhow::{anyhow, ensure, Context, Result};
use rustc_hash::FxHashSet;

use std::collections::{BTreeMap, VecDeque};
use std::collections::BTreeMap;
use std::os::unix::io::AsRawFd;
use std::path::PathBuf;
use std::sync::{Arc, RwLock};
Expand All @@ -19,9 +19,9 @@ use crate::fuzzer::{BreakpointType, Fuzzer};
use crate::fuzzvm::FuzzVm;
use crate::memory::Memory;
use crate::stack_unwinder::StackUnwinders;
use crate::{fuzzvm, unblock_sigalrm, THREAD_IDS, SymbolList};
use crate::{fuzzvm, unblock_sigalrm, SymbolList, THREAD_IDS};
use crate::{init_environment, KvmEnvironment, ProjectState};
use crate::{Cr3, Execution, ResetBreakpointType, Symbol, VbCpu, VirtAddr};
use crate::{Cr3, Execution, ResetBreakpointType, VbCpu, VirtAddr};

/// Stages to measure performance during minimization
#[derive(Debug, Copy, Clone)]
Expand Down Expand Up @@ -286,7 +286,13 @@ fn start_core<FUZZER: Fuzzer>(

let (execution, mut feedback) = time!(
RunInput,
fuzzvm.gather_feedback(&mut fuzzer, &curr_input, vm_timeout, covbps_addrs.iter().cloned(), bp_type)?
fuzzvm.gather_feedback(
&mut fuzzer,
&curr_input,
vm_timeout,
covbps_addrs.iter().cloned(),
bp_type
)?
);

// Check if the VM resulted in the same crashing state. If so, keep the minimized input as the
Expand Down
14 changes: 3 additions & 11 deletions src/commands/redqueen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@ use kvm_bindings::CpuId;
use kvm_ioctls::VmFd;

#[cfg(feature = "redqueen")]
use std::{
collections::{BTreeMap, VecDeque},
fs::File,
os::unix::io::AsRawFd,
path::PathBuf,
time::Duration,
};
use std::{collections::BTreeMap, fs::File, os::unix::io::AsRawFd, path::PathBuf, time::Duration};

#[cfg(feature = "redqueen")]
use crate::{
Expand All @@ -34,8 +28,8 @@ use crate::{
fuzzvm::FuzzVm,
init_environment,
stack_unwinder::StackUnwinders,
unblock_sigalrm, Cr3, KvmEnvironment, Memory, ProjectState, ResetBreakpointType, Symbol,
SymbolList, VbCpu, VirtAddr, THREAD_IDS,
unblock_sigalrm, Cr3, KvmEnvironment, Memory, ProjectState, ResetBreakpointType, SymbolList,
VbCpu, VirtAddr, THREAD_IDS,
};

/// Execute the c subcommand to gather coverage for a particular input
Expand Down Expand Up @@ -105,8 +99,6 @@ pub(crate) fn start_core<FUZZER: Fuzzer>(
project_state: &ProjectState,
) -> Result<()> {
// Store the thread ID of this thread used for passing the SIGALRM to this thread

use crate::SymbolList;
let thread_id = unsafe { libc::pthread_self() };
*THREAD_IDS[core_id.id].lock().unwrap() = Some(thread_id);

Expand Down
3 changes: 1 addition & 2 deletions src/commands/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
use anyhow::{anyhow, ensure, Context, Result};
use rustc_hash::FxHashSet;

use std::cell::RefCell;
use std::collections::{BTreeMap, BTreeSet};
use std::collections::BTreeMap;
use std::fs::File;
use std::os::unix::io::AsRawFd;
use std::path::PathBuf;
Expand Down
1 change: 0 additions & 1 deletion src/coverage_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,6 @@ impl CoverageAnalysis {
}

// Found a new result, add it!
let node = &self.nodes[*node_index];
self.cached_total_results
.push((*score, *addr, hit_parents.to_vec()));
}
Expand Down
2 changes: 0 additions & 2 deletions src/fuzz_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,6 @@ impl FuzzInput for Vec<u8> {
// Mutations applied to this input
let mut mutations: Vec<String> = Vec::new();

let orig_len = input.len();

// Perform some number of mutations on the input
for _ in 0..num_change {
// Special case the redqueen mutation if there are available rules
Expand Down
14 changes: 6 additions & 8 deletions src/fuzzvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,17 @@ use crate::{
fuzz_input::FuzzInput,
};

use std::collections::{BTreeMap, HashMap, VecDeque};
use std::collections::BTreeMap;
use std::convert::TryInto;
use std::path::Path;
use std::sync::atomic::Ordering;
use std::sync::{Arc, Mutex, RwLock};
use std::time::{Duration, Instant};

#[cfg(feature = "redqueen")]
use std::collections::BTreeSet;
use std::{
collections::{BTreeSet, HashMap},
path::Path,
sync::atomic::Ordering,
};

/// APIC base we are expecting the guest to adhere to. Primarily comes into play when
/// mapping guest memory regions in KVM as we need to leave to leave a gap in the guest
Expand Down Expand Up @@ -2748,10 +2750,6 @@ impl<'a, FUZZER: Fuzzer> FuzzVm<'a, FUZZER> {

// Create the dirty bitmap for this core for this slot
self.dirty_bitmaps[slot] = vec![0; bitmap_size];

// Store the pointer for this bitmap in the densely packed bitmap storage
let core_id = try_usize!(self.core_id);

self.number_of_pages[slot] = try_u32!(memory_size / page_size);
}

Expand Down
7 changes: 3 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@
#![feature(stdsimd)]
#![feature(avx512_target_feature)]
#![feature(core_intrinsics)]
#![feature(const_discriminant)]
#![feature(associated_type_defaults)]
#![feature(variant_count)]
#![feature(path_file_prefix)]
Expand All @@ -125,12 +124,12 @@ use vmm_sys_util::fam::FamStructWrapper;

extern crate bitflags;

use std::collections::{BTreeMap, VecDeque};
use std::collections::BTreeMap;
use std::convert::TryInto;
use std::fs::{File, OpenOptions};
use std::os::unix::io::AsRawFd;
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, AtomicPtr, AtomicUsize, Ordering};
use std::path::Path;
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use std::sync::{Arc, Mutex, RwLock};

pub use rand;
Expand Down
8 changes: 3 additions & 5 deletions src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ use crossterm::event::KeyCode;
use ahash::{AHashMap, AHashSet};
use rand::seq::IteratorRandom;
use rand::Rng as _;
use rustc_hash::{FxHashMap, FxHashSet};
use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize};
use tui::text::Span;
use tui::widgets::ListItem;
use tui_logger::{TuiWidgetEvent, TuiWidgetState};

use std::collections::{BTreeMap, BTreeSet};
use std::convert::{From, Into};
use std::collections::BTreeSet;
use std::convert::Into;
use std::fs::File;
use std::io::Write;
use std::mem::variant_count;
Expand All @@ -39,7 +39,6 @@ use crate::fuzzer::Fuzzer;
use crate::fuzzvm::FuzzVmExit;
use crate::rng::Rng;
use crate::stats_tui::StatsApp;
use crate::symbols::Symbol;
use crate::utils::save_input_in_project;
use crate::{FxIndexMap, FxIndexSet, SymbolList};

Expand Down Expand Up @@ -2151,7 +2150,6 @@ pub fn write_text_coverage<P: std::convert::AsRef<std::path::Path>>(

/// Write human readable coverage to a text file.
pub fn write_human_readable_text_coverage<P: std::convert::AsRef<std::path::Path>>(
project_state: &crate::ProjectState,
debug_info: &DebugInfo,
symbols: Option<&SymbolList>,
feedback: &FeedbackTracker,
Expand Down
1 change: 0 additions & 1 deletion src/symbols.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Utilites for obtaining symbols for a given address for a variety of operating systems
use serde::{Deserialize, Serialize};
use std::collections::VecDeque;

use crate::fuzzer::ResetBreakpointType;

Expand Down
Loading

0 comments on commit 1a489fc

Please sign in to comment.