Skip to content

Commit bc48a2a

Browse files
committed
fix intel_pt_command_executor example fuzzer
1 parent fb22469 commit bc48a2a

File tree

3 files changed

+42
-12
lines changed

3 files changed

+42
-12
lines changed

fuzzers/binary_only/intel_pt_command_executor/Cargo.lock

Lines changed: 23 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fuzzers/binary_only/intel_pt_command_executor/Justfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import "../../../just/libafl.just"
22

33
FUZZER_NAME := "intel_pt_command_executor"
44

5+
[unix]
6+
default: run
7+
58
[unix]
69
target_dir:
710
mkdir -p {{ TARGET_DIR }}

fuzzers/binary_only/intel_pt_command_executor/src/main.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::{
2-
env, ffi::CString, num::NonZero, os::unix::ffi::OsStrExt, path::PathBuf, slice, time::Duration,
2+
env, ffi::CString, num::NonZero, os::unix::ffi::OsStrExt, path::PathBuf, time::Duration,
33
};
44

55
use libafl::{
@@ -20,7 +20,7 @@ use libafl::{
2020
state::StdState,
2121
};
2222
use libafl_bolts::{core_affinity, rands::StdRand, tuples::tuple_list};
23-
use libafl_intelpt::{IntelPT, PAGE_SIZE};
23+
use libafl_intelpt::{AddrFilter, AddrFilterType, AddrFilters, IntelPT, PAGE_SIZE};
2424

2525
// Coverage map
2626
const MAP_SIZE: usize = 4096;
@@ -90,25 +90,31 @@ pub fn main() {
9090

9191
// The target is a ET_DYN elf, it will be relocated by the loader with this offset.
9292
// see https://github.com/torvalds/linux/blob/c1e939a21eb111a6d6067b38e8e04b8809b64c4e/arch/x86/include/asm/elf.h#L234C1-L239C38
93-
const DEFAULT_MAP_WINDOW: usize = (1 << 47) - PAGE_SIZE;
94-
const ELF_ET_DYN_BASE: usize = (DEFAULT_MAP_WINDOW / 3 * 2) & !(PAGE_SIZE - 1);
93+
const DEFAULT_MAP_WINDOW: u64 = (1 << 47) - PAGE_SIZE as u64;
94+
const ELF_ET_DYN_BASE: u64 = (DEFAULT_MAP_WINDOW / 3 * 2) & !(PAGE_SIZE as u64 - 1);
9595

9696
// Set the instruction pointer (IP) filter and memory image of our target.
9797
// These information can be retrieved from `readelf -l` (for example)
98-
let code_memory_addresses = ELF_ET_DYN_BASE + 0x15000..=ELF_ET_DYN_BASE + 0x14000 + 0x41000;
99-
98+
let (code_memory_start, code_memory_end) =
99+
(ELF_ET_DYN_BASE + 0x6000, ELF_ET_DYN_BASE + 0x6000 + 0x3dfd9);
100+
let filters = AddrFilters::new(&[AddrFilter::new(
101+
code_memory_start,
102+
code_memory_end,
103+
AddrFilterType::FILTER,
104+
)])
105+
.unwrap();
100106
let intel_pt = IntelPT::builder()
101107
.cpu(cpu.0)
102108
.inherit(true)
103-
.ip_filters(slice::from_ref(&code_memory_addresses))
109+
.ip_filters(&filters)
104110
.build()
105111
.unwrap();
106112

107113
let sections = [SectionInfo {
108114
filename: target_path.to_string_lossy().to_string(),
109-
offset: 0x14000,
110-
size: (*code_memory_addresses.end() - *code_memory_addresses.start() + 1) as u64,
111-
virtual_address: *code_memory_addresses.start() as u64,
115+
offset: 0x6000,
116+
size: code_memory_end - code_memory_start,
117+
virtual_address: code_memory_start,
112118
}];
113119

114120
let hook = unsafe { IntelPTHook::builder().map_ptr(MAP_PTR).map_len(MAP_SIZE) }

0 commit comments

Comments
 (0)