From 5c8c3be9e506c7d31e0288dc0561b8db85046860 Mon Sep 17 00:00:00 2001 From: Andrea Fioraldi Date: Tue, 8 Jun 2021 15:45:35 +0200 Subject: [PATCH 1/2] print sender id --- libafl/src/events/llmp.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libafl/src/events/llmp.rs b/libafl/src/events/llmp.rs index 9f6cf73164..9a4eee9bf6 100644 --- a/libafl/src/events/llmp.rs +++ b/libafl/src/events/llmp.rs @@ -446,10 +446,15 @@ where fn process(&mut self, fuzzer: &mut Z, state: &mut S, executor: &mut E) -> Result { // TODO: Get around local event copy by moving handle_in_client let mut events = vec![]; + let self_id = self.llmp.sender.id; while let Some((sender_id, tag, _flags, msg)) = self.llmp.recv_buf_with_flags()? { if tag == _LLMP_TAG_EVENT_TO_BROKER { panic!("EVENT_TO_BROKER parcel should not have arrived in the client!"); } + println!("[{}] Message from {}", self_id, sender_id); + if sender_id == self_id { + continue; + } #[cfg(not(feature = "llmp_compression"))] let event_bytes = msg; #[cfg(feature = "llmp_compression")] From 6d2074bd7e2c7cdaba57a1a5b1c93886e9675663 Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Tue, 8 Jun 2021 16:24:19 +0200 Subject: [PATCH 2/2] storing sender id to env --- libafl/src/bolts/llmp.rs | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/libafl/src/bolts/llmp.rs b/libafl/src/bolts/llmp.rs index 20584e7290..ff92c47379 100644 --- a/libafl/src/bolts/llmp.rs +++ b/libafl/src/bolts/llmp.rs @@ -475,7 +475,7 @@ unsafe fn _llmp_next_msg_ptr(last_msg: *const LlmpMsg) -> *mut LlmpMsg { /// May be used to restore the map by id. #[derive(Copy, Clone, Debug, Serialize, Deserialize)] pub struct LlmpDescription { - /// Info about the SharedMap in use + /// Info about the ShredMap in use shmem: ShMemDescription, /// The last message sent or received, depnding on page type last_message_offset: Option, @@ -751,15 +751,36 @@ where self.last_msg_sent = ptr::null_mut(); } + /// Reads the stored sender / client id for the given `env_name` (by appending `_CLIENT_ID`). + /// If the content of the env is `_NULL`, returns [`Option::None`]. + #[cfg(feature = "std")] + #[inline] + fn client_id_from_env(env_name: &str) -> Result, Error> { + let client_id_str = env::var(&format!("{}_CLIENT_ID", env_name))?; + Ok(if client_id_str == _NULL_ENV_STR { + None + } else { + Some(client_id_str.parse()?) + }) + } + + /// Writes the `id` to an env var + #[cfg(feature = "std")] + fn client_id_to_env(env_name: &str, id: ClientId) { + env::set_var(&format!("{}_CLIENT_ID", env_name), &format!("{}", id)); + } + /// Reattach to a vacant `out_map`, to with a previous sender stored the information in an env before. #[cfg(feature = "std")] pub fn on_existing_from_env(mut shmem_provider: SP, env_name: &str) -> Result { let msg_sent_offset = msg_offset_from_env(env_name)?; - Self::on_existing_map( + let mut ret = Self::on_existing_map( shmem_provider.clone(), shmem_provider.existing_from_env(env_name)?, msg_sent_offset, - ) + )?; + ret.id = Self::client_id_from_env(env_name)?.unwrap_or_default(); + Ok(ret) } /// Store the info to this sender to env. @@ -768,6 +789,7 @@ where pub fn to_env(&self, env_name: &str) -> Result<(), Error> { let current_out_map = self.out_maps.last().unwrap(); current_out_map.shmem.write_to_env(env_name)?; + Self::client_id_to_env(env_name, self.id); unsafe { current_out_map.msg_to_env(self.last_msg_sent, env_name) } }