From bb443027f7effdb2fd35dbd8317b0e37f3d155b1 Mon Sep 17 00:00:00 2001 From: "Dongjia \"toka\" Zhang" Date: Wed, 24 Jan 2024 03:30:22 +0100 Subject: [PATCH] Observer fix (#1807) * fix * Increase default edgemap size for libafl_cc and libafl_targets (#1798) * fmt --------- Co-authored-by: Dominik Maier --- libafl/src/observers/map.rs | 117 ++++++++++++++++++++++-------------- libafl_cc/build.rs | 2 +- libafl_cc/src/cfg.rs | 2 +- libafl_targets/build.rs | 2 +- 4 files changed, 76 insertions(+), 47 deletions(-) diff --git a/libafl/src/observers/map.rs b/libafl/src/observers/map.rs index ed68926378..652c2b5aac 100644 --- a/libafl/src/observers/map.rs +++ b/libafl/src/observers/map.rs @@ -983,7 +983,7 @@ where #[allow(clippy::unsafe_derive_deserialize)] pub struct VariableMapObserver<'a, T> where - T: Default + Copy + 'static + Serialize, + T: Default + Copy + 'static + Serialize + PartialEq + Bounded, { map: OwnedMutSlice<'a, T>, size: OwnedMutPtr, @@ -994,7 +994,14 @@ where impl<'a, S, T> Observer for VariableMapObserver<'a, T> where S: UsesInput, - T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug, + T: Default + + Copy + + 'static + + Serialize + + serde::de::DeserializeOwned + + Debug + + Bounded + + PartialEq, Self: MapObserver, { #[inline] @@ -1005,7 +1012,7 @@ where impl<'a, T> Named for VariableMapObserver<'a, T> where - T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned, + T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Bounded + PartialEq, { #[inline] fn name(&self) -> &str { @@ -1015,7 +1022,7 @@ where impl<'a, T> HasLen for VariableMapObserver<'a, T> where - T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned, + T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + PartialEq + Bounded, { #[inline] fn len(&self) -> usize { @@ -1032,7 +1039,9 @@ where + 'static + Serialize + serde::de::DeserializeOwned - + Debug, + + Debug + + PartialEq + + Bounded, { type Item = T; type IntoIter = Iter<'it, T>; @@ -1052,7 +1061,9 @@ where + 'static + Serialize + serde::de::DeserializeOwned - + Debug, + + Debug + + PartialEq + + Bounded, { type Item = T; type IntoIter = IterMut<'it, T>; @@ -1072,7 +1083,9 @@ where + 'static + Serialize + serde::de::DeserializeOwned - + Debug, + + Debug + + PartialEq + + Bounded, { type Item = as Iterator>::Item; type IntoIter = Iter<'it, T>; @@ -1092,7 +1105,9 @@ where + 'static + Serialize + serde::de::DeserializeOwned - + Debug, + + Debug + + PartialEq + + Bounded, { type Item = as Iterator>::Item; type IntoIter = IterMut<'it, T>; @@ -1112,7 +1127,9 @@ where + 'static + Serialize + serde::de::DeserializeOwned - + Debug, + + Debug + + PartialEq + + Bounded, { /// Returns an iterator over the map. pub fn iter(&self) -> Iter<'_, T> { @@ -1134,7 +1151,9 @@ where + 'static + Serialize + serde::de::DeserializeOwned - + Debug, + + Debug + + PartialEq + + Bounded, { type Entry = T; @@ -1213,7 +1232,9 @@ where + 'static + Serialize + serde::de::DeserializeOwned - + Debug, + + Debug + + PartialEq + + Bounded, { type Entry = T; #[inline] @@ -1224,18 +1245,26 @@ where } impl<'a, T> AsMutSlice for VariableMapObserver<'a, T> where - T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug, + T: 'static + + Default + + Copy + + Serialize + + serde::de::DeserializeOwned + + Debug + + PartialEq + + Bounded, { type Entry = T; #[inline] fn as_mut_slice(&mut self) -> &mut [T] { - self.map.as_mut_slice() + let cnt = self.usable_count(); + &mut self.map.as_mut_slice()[..cnt] } } impl<'a, T> VariableMapObserver<'a, T> where - T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned, + T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + PartialEq + Bounded, { /// Creates a new [`MapObserver`] from an [`OwnedMutSlice`] /// @@ -1810,7 +1839,7 @@ where #[allow(clippy::unsafe_derive_deserialize)] pub struct MultiMapObserver<'a, T, const DIFFERENTIAL: bool> where - T: Default + Copy + 'static + Serialize + Debug, + T: 'static + Default + Copy + Serialize + Debug, { maps: Vec>, intervals: IntervalTree, @@ -1823,7 +1852,7 @@ where impl<'a, S, T> Observer for MultiMapObserver<'a, T, false> where S: UsesInput, - T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug, + T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug, Self: MapObserver, { #[inline] @@ -1835,7 +1864,7 @@ where impl<'a, S, T> Observer for MultiMapObserver<'a, T, true> where S: UsesInput, - T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug, + T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug, Self: MapObserver, { // in differential mode, we are *not* responsible for resetting the map! @@ -1843,7 +1872,7 @@ where impl<'a, T, const DIFFERENTIAL: bool> Named for MultiMapObserver<'a, T, DIFFERENTIAL> where - T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug, + T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug, { #[inline] fn name(&self) -> &str { @@ -1853,7 +1882,7 @@ where impl<'a, T, const DIFFERENTIAL: bool> HasLen for MultiMapObserver<'a, T, DIFFERENTIAL> where - T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug, + T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug, { #[inline] fn len(&self) -> usize { @@ -1863,11 +1892,11 @@ where impl<'a, T, const DIFFERENTIAL: bool> MapObserver for MultiMapObserver<'a, T, DIFFERENTIAL> where - T: Bounded + T: 'static + + Bounded + PartialEq + Default + Copy - + 'static + Serialize + serde::de::DeserializeOwned + Debug, @@ -1960,7 +1989,7 @@ where impl<'a, T, const DIFFERENTIAL: bool> MultiMapObserver<'a, T, DIFFERENTIAL> where - T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug, + T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug, { /// Creates a new [`MultiMapObserver`], maybe in differential mode #[must_use] @@ -1985,7 +2014,7 @@ where impl<'a, T> MultiMapObserver<'a, T, true> where - T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug, + T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug, { /// Creates a new [`MultiMapObserver`] in differential mode #[must_use] @@ -1996,7 +2025,7 @@ where impl<'a, T> MultiMapObserver<'a, T, false> where - T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug, + T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug, { /// Creates a new [`MultiMapObserver`] #[must_use] @@ -2033,7 +2062,7 @@ where impl<'a, 'it, T, const DIFFERENTIAL: bool> AsIter<'it> for MultiMapObserver<'a, T, DIFFERENTIAL> where - T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug, + T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug, 'a: 'it, { type Item = T; @@ -2046,7 +2075,7 @@ where impl<'a, 'it, T, const DIFFERENTIAL: bool> AsIterMut<'it> for MultiMapObserver<'a, T, DIFFERENTIAL> where - T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug, + T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug, 'a: 'it, { type Item = T; @@ -2060,7 +2089,7 @@ where impl<'a, 'it, T, const DIFFERENTIAL: bool> IntoIterator for &'it MultiMapObserver<'a, T, DIFFERENTIAL> where - T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug, + T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug, { type Item = as Iterator>::Item; type IntoIter = Flatten>>; @@ -2073,7 +2102,7 @@ where impl<'a, 'it, T, const DIFFERENTIAL: bool> IntoIterator for &'it mut MultiMapObserver<'a, T, DIFFERENTIAL> where - T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug, + T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug, { type Item = as Iterator>::Item; type IntoIter = Flatten>>; @@ -2085,7 +2114,7 @@ where impl<'a, T, const DIFFERENTIAL: bool> MultiMapObserver<'a, T, DIFFERENTIAL> where - T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug, + T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug, { /// Returns an iterator over the map. pub fn iter(&self) -> <&Self as IntoIterator>::IntoIter { @@ -2100,7 +2129,7 @@ where impl<'a, T, OTA, OTB, S> DifferentialObserver for MultiMapObserver<'a, T, true> where - T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug, + T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug, Self: MapObserver, OTA: ObserversTuple, OTB: ObserversTuple, @@ -2115,7 +2144,7 @@ where #[allow(clippy::unsafe_derive_deserialize)] pub struct OwnedMapObserver where - T: Default + Copy + 'static + Serialize, + T: 'static + Default + Copy + Serialize, { map: Vec, initial: T, @@ -2125,7 +2154,7 @@ where impl Observer for OwnedMapObserver where S: UsesInput, - T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug, + T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug, Self: MapObserver, { #[inline] @@ -2136,7 +2165,7 @@ where impl Named for OwnedMapObserver where - T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned, + T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned, { #[inline] fn name(&self) -> &str { @@ -2146,7 +2175,7 @@ where impl HasLen for OwnedMapObserver where - T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned, + T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned, { #[inline] fn len(&self) -> usize { @@ -2156,7 +2185,7 @@ where impl<'it, T> AsIter<'it> for OwnedMapObserver where - T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug, + T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug, { type Item = T; type IntoIter = Iter<'it, T>; @@ -2168,7 +2197,7 @@ where impl<'it, T> AsIterMut<'it> for OwnedMapObserver where - T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug, + T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug, { type Item = T; type IntoIter = IterMut<'it, T>; @@ -2180,7 +2209,7 @@ where impl<'it, T> IntoIterator for &'it OwnedMapObserver where - T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug, + T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug, { type Item = as Iterator>::Item; type IntoIter = Iter<'it, T>; @@ -2192,7 +2221,7 @@ where impl<'it, T> IntoIterator for &'it mut OwnedMapObserver where - T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug, + T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug, { type Item = as Iterator>::Item; type IntoIter = IterMut<'it, T>; @@ -2204,7 +2233,7 @@ where impl OwnedMapObserver where - T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug, + T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug, { /// Returns an iterator over the map. pub fn iter(&self) -> Iter<'_, T> { @@ -2219,11 +2248,11 @@ where impl MapObserver for OwnedMapObserver where - T: Bounded + T: 'static + + Bounded + PartialEq + Default + Copy - + 'static + Serialize + serde::de::DeserializeOwned + Debug, @@ -2300,7 +2329,7 @@ where impl AsSlice for OwnedMapObserver where - T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug, + T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug, { type Entry = T; #[must_use] @@ -2312,7 +2341,7 @@ where impl AsMutSlice for OwnedMapObserver where - T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug, + T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug, { type Entry = T; #[must_use] @@ -2324,7 +2353,7 @@ where impl OwnedMapObserver where - T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned, + T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned, { /// Creates a new [`MapObserver`] with an owned map #[must_use] diff --git a/libafl_cc/build.rs b/libafl_cc/build.rs index 84a9f7e397..0816b2cbb3 100644 --- a/libafl_cc/build.rs +++ b/libafl_cc/build.rs @@ -311,7 +311,7 @@ pub const LIBAFL_CC_LLVM_VERSION: Option = None; let mut cxxflags: Vec = cxxflags.split_whitespace().map(String::from).collect(); let edges_map_size: usize = option_env!("LIBAFL_EDGES_MAP_SIZE") - .map_or(Ok(65536), str::parse) + .map_or(Ok(2621440), str::parse) .expect("Could not parse LIBAFL_EDGES_MAP_SIZE"); cxxflags.push(format!("-DLIBAFL_EDGES_MAP_SIZE={edges_map_size}")); diff --git a/libafl_cc/src/cfg.rs b/libafl_cc/src/cfg.rs index 2c5aed01f1..a7519d37fe 100644 --- a/libafl_cc/src/cfg.rs +++ b/libafl_cc/src/cfg.rs @@ -96,7 +96,7 @@ where #[must_use] pub fn new() -> Self { let map_size = option_env!("LIBAFL_EDGES_MAP_SIZE") - .map_or(Ok(65536), str::parse) + .map_or(Ok(2621440), str::parse) .expect("Could not parse LIBAFL_EDGES_MAP_SIZE"); Self { edges: (0..map_size).map(|_| None).collect(), diff --git a/libafl_targets/build.rs b/libafl_targets/build.rs index 09f2f2059b..81ee333262 100644 --- a/libafl_targets/build.rs +++ b/libafl_targets/build.rs @@ -13,7 +13,7 @@ fn main() { let mut constants_file = File::create(dest_path).expect("Could not create file"); let edges_map_size: usize = option_env!("LIBAFL_EDGES_MAP_SIZE") - .map_or(Ok(65536), str::parse) + .map_or(Ok(2621440), str::parse) .expect("Could not parse LIBAFL_EDGES_MAP_SIZE"); let cmp_map_size: usize = option_env!("LIBAFL_CMP_MAP_SIZE") .map_or(Ok(65536), str::parse)