Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
3ccc726
compile-time edge module compilation trick
rmalmain Oct 8, 2024
ef8d01a
clippy
rmalmain Oct 8, 2024
6bb94fa
possible since rust 1.79
rmalmain Oct 9, 2024
aa50cb2
split edge module in submodules
rmalmain Oct 9, 2024
5b39956
Update frida to 0.14.0 (#2596)
rmalmain Oct 9, 2024
4350245
tracers and generators private modules
rmalmain Oct 9, 2024
decaa67
do not use star export.
rmalmain Oct 9, 2024
d04be02
same for drcov
rmalmain Oct 9, 2024
964da23
forgot a file...
rmalmain Oct 9, 2024
d66d787
first draft of generic-based edge module for ConstantLengthMapObserver.
rmalmain Oct 9, 2024
505c88d
integration of OwnedSizedSlice.
rmalmain Oct 10, 2024
6bf7530
Merge branch 'main' into improve_edge_module_builder
rmalmain Oct 25, 2024
6e838aa
fix serde stuff
rmalmain Oct 25, 2024
0611e32
no std
rmalmain Oct 25, 2024
d9dc77c
import
rmalmain Oct 25, 2024
35297dc
fixed qemu_cmin with new constant map abstraction.
rmalmain Oct 25, 2024
65c3ff7
fix const map
rmalmain Oct 25, 2024
2b59798
fix clippy from another pr...
rmalmain Oct 25, 2024
b22cf6c
fix non-null usage
rmalmain Oct 25, 2024
f8ac5b0
fix ci?
rmalmain Oct 25, 2024
bfe4b14
Merge branch 'main' into improve_edge_module_builder
rmalmain Oct 25, 2024
925dab2
new feature stuff
rmalmain Oct 25, 2024
c7c8cd8
Merge branch 'main' into improve_edge_module_builder
rmalmain Oct 28, 2024
6b8035a
Merge branch 'main' into improve_edge_module_builder
rmalmain Oct 30, 2024
bb70553
Merge branch 'main' into improve_edge_module_builder
rmalmain Oct 31, 2024
ad413e7
Merge branch 'main' into improve_edge_module_builder
rmalmain Nov 3, 2024
606f5e0
fixes
rmalmain Nov 3, 2024
c870076
minor fixes
rmalmain Nov 3, 2024
f715038
fmt
rmalmain Nov 3, 2024
236b2b3
non null
rmalmain Nov 3, 2024
481cee8
im stupid
rmalmain Nov 3, 2024
3d51d58
fmt
rmalmain Nov 3, 2024
1a69530
fix fuzzer
rmalmain Nov 3, 2024
7982f7f
fix fuzzers
rmalmain Nov 3, 2024
93b5bbf
sized slice
rmalmain Nov 3, 2024
cb21994
fuzzer fixes
rmalmain Nov 4, 2024
f520a9a
ptr::NonNull -> NonNull
rmalmain Nov 4, 2024
fa035af
shorter trait length
rmalmain Nov 4, 2024
7263d91
fmt
rmalmain Nov 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fuzzers/binary_only/frida_executable_libpng/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ libafl = { path = "../../../libafl", features = [
"frida_cli",
] } #, "llmp_small_maps", "llmp_debug"]}
libafl_bolts = { path = "../../../libafl_bolts" }
frida-gum = { version = "0.13.7", features = [
frida-gum = { version = "0.14.0", features = [
"auto-download",
"event-sink",
"invocation-listener",
Expand Down
2 changes: 1 addition & 1 deletion fuzzers/binary_only/frida_gdiplus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ libafl = { path = "../../../libafl", features = [
"errors_backtrace",
] } #, "llmp_small_maps", "llmp_debug"]}
libafl_bolts = { path = "../../../libafl_bolts" }
frida-gum = { version = "0.13.7", features = [
frida-gum = { version = "0.14.0", features = [
"auto-download",
"event-sink",
"invocation-listener",
Expand Down
2 changes: 1 addition & 1 deletion fuzzers/binary_only/frida_libpng/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ libafl = { path = "../../../libafl", features = [
"errors_backtrace",
] } #, "llmp_small_maps", "llmp_debug"]}
libafl_bolts = { path = "../../../libafl_bolts" }
frida-gum = { version = "0.13.7", features = [
frida-gum = { version = "0.14.0", features = [
"auto-download",
"event-sink",
"invocation-listener",
Expand Down
2 changes: 1 addition & 1 deletion libafl/src/executors/forkserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1524,7 +1524,7 @@ mod tests {

let mut shmem = shmem_provider.new_shmem(MAP_SIZE).unwrap();
shmem.write_to_env("__AFL_SHM_ID").unwrap();
let shmem_buf = shmem.as_slice_mut();
let shmem_buf: &mut [u8; MAP_SIZE] = shmem.as_slice_mut().try_into().unwrap();

let edges_observer = HitcountsMapObserver::new(ConstMapObserver::<_, MAP_SIZE>::new(
"shared_mem",
Expand Down
56 changes: 11 additions & 45 deletions libafl/src/observers/map/const_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,25 @@ use core::{
hash::{Hash, Hasher},
ops::{Deref, DerefMut},
};
use std::ptr::NonNull;

use ahash::RandomState;
use libafl_bolts::{ownedref::OwnedMutSlice, AsSlice, AsSliceMut, HasLen, Named};
use libafl_bolts::{ownedref::OwnedMutSizedSlice, AsSlice, AsSliceMut, HasLen, Named};
use serde::{de::DeserializeOwned, Deserialize, Serialize};

use crate::{
observers::{map::MapObserver, Observer, VariableLengthMapObserver},
observers::{map::MapObserver, ConstantLengthMapObserver, Observer},
Error,
};

// TODO: remove the size field and implement ConstantLengthMapObserver

/// Use a const size to speedup `Feedback::is_interesting` when the user can
/// know the size of the map at compile time.
#[derive(Serialize, Deserialize, Debug)]
#[allow(clippy::unsafe_derive_deserialize)]
pub struct ConstMapObserver<'a, T, const N: usize> {
map: OwnedMutSlice<'a, T>,
map: OwnedMutSizedSlice<'a, T, N>,
initial: T,
name: Cow<'static, str>,
size: usize,
}

impl<I, S, T, const N: usize> Observer<I, S> for ConstMapObserver<'_, T, N>
Expand Down Expand Up @@ -150,25 +148,17 @@ where
}
}

impl<T, const N: usize> VariableLengthMapObserver for ConstMapObserver<'_, T, N>
impl<T, const N: usize> ConstantLengthMapObserver<N> for ConstMapObserver<'_, T, N>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about renaming them to ConstLenMapObserver and VarLenMapObserver btw? Seems shorter and just as to clear.
Random idea of course, feel free to ignore.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok for me, both work out imho

where
T: PartialEq + Copy + Hash + Serialize + DeserializeOwned + Debug + 'static,
{
fn map_slice(&mut self) -> &[Self::Entry] {
fn map_slice(&self) -> &[Self::Entry; N] {
self.map.as_slice()
}

fn map_slice_mut(&mut self) -> &mut [Self::Entry] {
fn map_slice_mut(&mut self) -> &mut [Self::Entry; N] {
self.map.as_slice_mut()
}

fn size(&mut self) -> &usize {
&N
}

fn size_mut(&mut self) -> &mut usize {
&mut self.size
}
}

impl<T, const N: usize> Deref for ConstMapObserver<'_, T, N> {
Expand All @@ -194,48 +184,24 @@ where
/// Will get a pointer to the map and dereference it at any point in time.
/// The map must not move in memory!
#[must_use]
pub fn new(name: &'static str, map: &'a mut [T]) -> Self {
pub fn new(name: &'static str, map: &'a mut [T; N]) -> Self {
assert!(map.len() >= N);
Self {
map: OwnedMutSlice::from(map),
map: OwnedMutSizedSlice::from(map),
name: Cow::from(name),
initial: T::default(),
size: N,
}
}

/// Creates a new [`MapObserver`] from a raw pointer
///
/// # Safety
/// Will dereference the `map_ptr` with up to len elements.
pub unsafe fn from_mut_ptr(name: &'static str, map_ptr: *mut T) -> Self {
pub unsafe fn from_mut_ptr(name: &'static str, map_ptr: NonNull<T>) -> Self {
ConstMapObserver {
map: OwnedMutSlice::from_raw_parts_mut(map_ptr, N),
map: OwnedMutSizedSlice::from_raw_parts_mut(map_ptr),
name: Cow::from(name),
initial: T::default(),
size: N,
}
}
}

impl<T, const N: usize> ConstMapObserver<'_, T, N>
where
T: Default + Clone,
{
/// Creates a new [`MapObserver`] with an owned map
#[must_use]
pub fn owned(name: &'static str, map: Vec<T>) -> Self {
assert!(map.len() >= N);
let initial = if map.is_empty() {
T::default()
} else {
map[0].clone()
};
Self {
map: OwnedMutSlice::from(map),
name: Cow::from(name),
initial,
size: N,
}
}
}
4 changes: 2 additions & 2 deletions libafl/src/observers/map/hitcount_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,15 @@ impl<M> VariableLengthMapObserver for HitcountsMapObserver<M>
where
M: VariableLengthMapObserver + MapObserver<Entry = u8>,
{
fn map_slice(&mut self) -> &[Self::Entry] {
fn map_slice(&self) -> &[Self::Entry] {
self.base.map_slice()
}

fn map_slice_mut(&mut self) -> &mut [Self::Entry] {
self.base.map_slice_mut()
}

fn size(&mut self) -> &usize {
fn size(&self) -> &usize {
self.base.size()
}

Expand Down
7 changes: 5 additions & 2 deletions libafl/src/observers/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,14 +390,14 @@ pub trait MapObserver:
pub trait VariableLengthMapObserver: MapObserver {
/// A mutable slice reference to the map.
/// The length of the map gives the maximum allocatable size.
fn map_slice(&mut self) -> &[Self::Entry];
fn map_slice(&self) -> &[Self::Entry];

/// A slice reference to the map.
/// The length of the map gives the maximum allocatable size.
fn map_slice_mut(&mut self) -> &mut [Self::Entry];

/// A reference to the size of the map.
fn size(&mut self) -> &usize;
fn size(&self) -> &usize;

/// A mutable reference to the size of the map.
fn size_mut(&mut self) -> &mut usize;
Expand All @@ -408,6 +408,9 @@ pub trait ConstantLengthMapObserver<const N: usize>: MapObserver {
/// The size of the map
const LENGTH: usize = N;

/// A mutable slice reference to the map
fn map_slice(&self) -> &[Self::Entry; N];

/// A mutable slice reference to the map
fn map_slice_mut(&mut self) -> &mut [Self::Entry; N];
}
Expand Down
4 changes: 2 additions & 2 deletions libafl/src/observers/map/variable_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,15 @@ impl<T> VariableLengthMapObserver for VariableMapObserver<'_, T>
where
T: PartialEq + Copy + Hash + Serialize + DeserializeOwned + Debug,
{
fn map_slice(&mut self) -> &[Self::Entry] {
fn map_slice(&self) -> &[Self::Entry] {
self.map.as_ref()
}

fn map_slice_mut(&mut self) -> &mut [Self::Entry] {
self.map.as_mut()
}

fn size(&mut self) -> &usize {
fn size(&self) -> &usize {
self.size.as_ref()
}

Expand Down
49 changes: 47 additions & 2 deletions libafl_bolts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,18 @@ pub trait AsSlice<'a> {
fn as_slice(&'a self) -> Self::SliceRef;
}

impl<'a, T, R> AsSlice<'a> for R
/// Can be converted to a slice
pub trait AsSizedSlice<'a, const N: usize> {
/// Type of the entries of this slice
type Entry: 'a;
/// Type of the reference to this slice
type SliceRef: Deref<Target = [Self::Entry; N]>;

/// Convert to a slice
fn as_sized_slice(&'a self) -> Self::SliceRef;
}

impl<'a, T, R: ?Sized> AsSlice<'a> for R
where
T: 'a,
R: Deref<Target = [T]>,
Expand All @@ -711,6 +722,19 @@ where
}
}

impl<'a, T, const N: usize, R: ?Sized> AsSizedSlice<'a, N> for R
where
T: 'a,
R: Deref<Target = [T; N]>,
{
type Entry = T;
type SliceRef = &'a [T; N];

fn as_sized_slice(&'a self) -> Self::SliceRef {
&*self
}
}

/// Can be converted to a mutable slice
pub trait AsSliceMut<'a>: AsSlice<'a> {
/// Type of the mutable reference to this slice
Expand All @@ -720,7 +744,16 @@ pub trait AsSliceMut<'a>: AsSlice<'a> {
fn as_slice_mut(&'a mut self) -> Self::SliceRefMut;
}

impl<'a, T, R> AsSliceMut<'a> for R
/// Can be converted to a mutable slice
pub trait AsSizedSliceMut<'a, const N: usize>: AsSizedSlice<'a, N> {
/// Type of the mutable reference to this slice
type SliceRefMut: DerefMut<Target = [Self::Entry; N]>;

/// Convert to a slice
fn as_sized_slice_mut(&'a mut self) -> Self::SliceRefMut;
}

impl<'a, T, R: ?Sized> AsSliceMut<'a> for R
where
T: 'a,
R: DerefMut<Target = [T]>,
Expand All @@ -732,6 +765,18 @@ where
}
}

impl<'a, T, const N: usize, R: ?Sized> AsSizedSliceMut<'a, N> for R
where
T: 'a,
R: DerefMut<Target = [T; N]>,
{
type SliceRefMut = &'a mut [T; N];

fn as_sized_slice_mut(&'a mut self) -> Self::SliceRefMut {
&mut *self
}
}

/// Create an `Iterator` from a reference
pub trait AsIter<'it> {
/// The item type
Expand Down
Loading