Skip to content

Commit 4e2c64b

Browse files
authored
IntelPT babyfuzzer remove TUI (#3725)
* libafl_intelpt README.md: Add also my name * intelPT babyfuzzer lints - Remove the TUI monitor as it is useless in babyfuzzers where the process ends on the first objective in less than a second - Try to clarify a bit some comments
1 parent 4889a23 commit 4e2c64b

3 files changed

Lines changed: 14 additions & 22 deletions

File tree

crates/libafl_intelpt/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Intel Processor Trace (PT) low level code
1+
# Intel Processor Trace (PT) low level code for `LibAFL`
22

33
This module is a wrapper around the `IntelPT` kernel driver, exposing functionalities specifically crafted for `LibAFL`.
44

@@ -7,6 +7,8 @@ At the moment only `Linux` hosts are supported.
77
You can run `sudo -E cargo test intel_pt_check_availability -- --show-output` to check if your host has all the features
88
used by this crate.
99

10+
This crate is part of [LibAFL](https://github.com/AFLplusplus/LibAFL) and is maintained by Marco Cavenati.
11+
1012
## The `LibAFL` Project
1113

1214
The `LibAFL` project is part of [`AFLplusplus`](https://github.com/AFLplusplus) and maintained by

fuzzers/binary_only/intel_pt_baby_fuzzer/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ The tested program is a simple Rust function without any instrumentation.
99
After building this example with `cargo build`, you need to give to the executable the necessary capabilities with
1010
`sudo setcap cap_ipc_lock,cap_sys_ptrace,cap_sys_admin,cap_syslog=ep ./target/debug/intel_pt_baby_fuzzer`.
1111

12-
You can run this example using `cargo run`, and you can enable the TUI feature by building and running with
13-
`--features tui`.
12+
You can run this example using `cargo run`.
1413

1514
As an alternative, simply run `just` to build and run the fuzzer (requires `just`).
1615

fuzzers/binary_only/intel_pt_baby_fuzzer/src/main.rs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ use std::{
22
hint::black_box, num::NonZero, path::PathBuf, process, ptr::copy_nonoverlapping, time::Duration,
33
};
44

5-
#[cfg(feature = "tui")]
6-
use libafl::monitors::tui::TuiMonitor;
7-
#[cfg(not(feature = "tui"))]
8-
use libafl::monitors::SimpleMonitor;
95
use libafl::{
106
corpus::{InMemoryCorpus, OnDiskCorpus},
117
events::SimpleEventManager,
@@ -18,26 +14,27 @@ use libafl::{
1814
fuzzer::{Fuzzer, StdFuzzer},
1915
generators::RandPrintablesGenerator,
2016
inputs::{BytesInput, HasTargetBytes},
17+
monitors::SimpleMonitor,
2118
mutators::{havoc_mutations::havoc_mutations, scheduled::HavocScheduledMutator},
2219
observers::ConstMapObserver,
2320
schedulers::QueueScheduler,
2421
stages::mutational::StdMutationalStage,
2522
state::StdState,
2623
};
27-
use libafl_bolts::{current_nanos, nonnull_raw_mut, rands::StdRand, tuples::tuple_list, AsSlice};
24+
use libafl_bolts::{current_nanos, nonnull_raw_mut, rands::StdRand, tuples::tuple_list};
2825
use proc_maps::get_process_maps;
2926

30-
// Coverage map
27+
// Edge coverage map.
3128
const MAP_SIZE: usize = 4096;
3229
static mut MAP: [u8; MAP_SIZE] = [0; MAP_SIZE];
3330
static mut MAP_PTR: *mut u8 = &raw mut MAP as _;
3431

3532
pub fn main() {
36-
// The closure that we want to fuzz
33+
// The function that we want to fuzz
3734
let mut harness = |input: &BytesInput| {
38-
let target = input.target_bytes();
39-
let buf = target.as_slice();
35+
let buf = input.target_bytes();
4036
if !buf.is_empty() && buf[0] == b'a' {
37+
// Avoid compiler optimizations
4138
let _do_something = black_box(0);
4239
if buf.len() > 1 && buf[1] == b'b' {
4340
let _do_something = black_box(0);
@@ -50,17 +47,16 @@ pub fn main() {
5047
};
5148

5249
// Create an observation channel using the map
53-
let observer = unsafe { ConstMapObserver::from_mut_ptr("signals", nonnull_raw_mut!(MAP)) };
50+
let observer = unsafe { ConstMapObserver::from_mut_ptr("edges", nonnull_raw_mut!(MAP)) };
5451

5552
// Feedback to rate the interestingness of an input
5653
let mut feedback = MaxMapFeedback::new(&observer);
5754

5855
// A feedback to choose if an input is a solution or not
5956
let mut objective = CrashFeedback::new();
6057

61-
// create a State from scratch
6258
let mut state = StdState::new(
63-
// RNG
59+
// Random Number Generator
6460
StdRand::with_seed(current_nanos()),
6561
// Corpus that will be evolved, we keep it in memory for performance
6662
InMemoryCorpus::new(),
@@ -75,14 +71,8 @@ pub fn main() {
7571
)
7672
.unwrap();
7773

78-
// The Monitor trait define how the fuzzer stats are displayed to the user
79-
#[cfg(not(feature = "tui"))]
74+
// The Monitor define how the fuzzer stats are displayed to the user, here we simply print
8075
let mon = SimpleMonitor::new(|s| println!("{s}"));
81-
#[cfg(feature = "tui")]
82-
let mon = TuiMonitor::builder()
83-
.title("Baby Fuzzer Intel PT")
84-
.enhanced_graphics(false)
85-
.build();
8676

8777
// The event manager handle the various events generated during the fuzzing loop
8878
// such as the notification of the addition of a new item to the corpus
@@ -113,6 +103,7 @@ pub fn main() {
113103
})
114104
.collect::<Vec<_>>();
115105

106+
// Pass the executable memory to the code responsible for Intel PT trace decoding
116107
let pt = IntelPT::builder().images(images).build().unwrap();
117108
// Intel PT hook that will handle the setup of Intel PT for each execution and fill the map
118109
let pt_hook = unsafe {

0 commit comments

Comments
 (0)