Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discard non-new testcase events for multi-machine messages #2583

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion libafl/src/events/broker_hooks/centralized_multi_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ where
) -> Result<LlmpMsgHookResult, Error> {
let shared_state = self.shared_state.clone();

// Here, we suppose msg will never be written again and will always be available.
// # Safety
// Here, we suppose msg will *never* be written again and will always be available.
// Thus, it is safe to handle this in a separate thread.
let msg_lock = unsafe { NullLock::new((msg.as_ptr(), msg.len())) };
// let flags = msg_flags.clone();
Expand Down
13 changes: 10 additions & 3 deletions libafl/src/events/llmp/mgr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use libafl_bolts::{
};
use libafl_bolts::{
current_time,
llmp::{LlmpClient, LlmpClientDescription},
llmp::{LlmpClient, LlmpClientDescription, LLMP_FLAG_FROM_MM},
shmem::{NopShMemProvider, ShMemProvider},
tuples::Handle,
ClientId,
Expand Down Expand Up @@ -605,7 +605,7 @@ where
// TODO: Get around local event copy by moving handle_in_client
let self_id = self.llmp.sender().id();
let mut count = 0;
while let Some((client_id, tag, _flags, msg)) = self.llmp.recv_buf_with_flags()? {
while let Some((client_id, tag, flags, msg)) = self.llmp.recv_buf_with_flags()? {
assert!(
tag != _LLMP_TAG_EVENT_TO_BROKER,
"EVENT_TO_BROKER parcel should not have arrived in the client!"
Expand All @@ -619,14 +619,21 @@ where
#[cfg(feature = "llmp_compression")]
let compressed;
#[cfg(feature = "llmp_compression")]
let event_bytes = if _flags & LLMP_FLAG_COMPRESSED == LLMP_FLAG_COMPRESSED {
let event_bytes = if flags & LLMP_FLAG_COMPRESSED == LLMP_FLAG_COMPRESSED {
compressed = self.compressor.decompress(msg)?;
&compressed
} else {
msg
};
let event: Event<S::Input> = postcard::from_bytes(event_bytes)?;
log::debug!("Received event in normal llmp {}", event.name_detailed());

// If the message comes from another machine, do not
// consider other events than new testcase.
if !event.is_new_testcase() && (flags & LLMP_FLAG_FROM_MM == LLMP_FLAG_FROM_MM) {
Copy link
Member

Choose a reason for hiding this comment

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

Why? We can totally share metadata etc in the future

Copy link
Member

Choose a reason for hiding this comment

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

Pretty sure this check belongs into handle_in_client, if it should exist et all(?)

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, we were trying to bugfix something quickly for an experiment, i was planning to clean-up this today.
I'll reopen a pr soon

Copy link
Member

Choose a reason for hiding this comment

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

Why merge tests to main?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes it was not a good idea in the first place, i'll just revert this one in the next patch

continue;
}

self.handle_in_client(fuzzer, executor, state, client_id, event)?;
count += 1;
}
Expand Down
5 changes: 5 additions & 0 deletions libafl/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@ where
} => "todo",*/
}
}

/// Returns true if self is a new testcase, false otherwise.
pub fn is_new_testcase(&self) -> bool {
matches!(self, Event::NewTestcase { .. })
}
}

/// [`EventFirer`] fires an event.
Expand Down
2 changes: 2 additions & 0 deletions libafl_bolts/src/llmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ pub const LLMP_FLAG_INITIALIZED: Flags = Flags(0x0);
pub const LLMP_FLAG_COMPRESSED: Flags = Flags(0x1);
/// From another broker.
pub const LLMP_FLAG_FROM_B2B: Flags = Flags(0x2);
/// From another machine (with the `multi_machine` mode)
pub const LLMP_FLAG_FROM_MM: Flags = Flags(0x4);

/// Timt the broker 2 broker connection waits for incoming data,
/// before checking for own data to forward again.
Expand Down