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

Share objectives between nodes #2754

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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: 3 additions & 0 deletions libafl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ unicode = ["libafl_bolts/alloc", "ahash/std", "serde/rc", "bitvec"]
## Enable multi-part input formats and mutators
multipart_inputs = ["arrayvec", "rand_trait"]

## Share objectives across nodes
share_objectives = []

#! ## LibAFL-Bolts Features

## Provide the `#[derive(SerdeAny)]` macro.
Expand Down
24 changes: 20 additions & 4 deletions libafl/src/events/centralized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,22 +287,29 @@ where
) -> Result<(), Error> {
if !self.is_main {
// secondary node
let mut is_tc = false;
// Forward to main only if new tc or heartbeat
let mut is_tc_or_obj = false;
// Forward to main only if new tc, heartbeat, or optionally, a new objective
let should_be_forwarded = match &mut event {
Event::NewTestcase { forward_id, .. } => {
*forward_id = Some(ClientId(self.inner.mgr_id().0 as u32));
is_tc = true;
is_tc_or_obj = true;
true
}
Event::UpdateExecStats { .. } => true, // send it but this guy won't be handled. the only purpose is to keep this client alive else the broker thinks it is dead and will dc it

#[cfg(feature = "share_objectives")]
Event::Objective { .. } => {
is_tc_or_obj = true;
true
}

Event::Stop => true,
_ => false,
};

if should_be_forwarded {
self.forward_to_main(&event)?;
if is_tc {
if is_tc_or_obj {
// early return here because we only send it to centralized not main broker.
return Ok(());
}
Expand Down Expand Up @@ -675,6 +682,15 @@ where
log::debug!("[{}] {} was discarded...)", process::id(), event_name);
}
}

#[cfg(feature = "share_objectives")]
BAGUVIX456 marked this conversation as resolved.
Show resolved Hide resolved
Event::Objective { .. } => {
log::debug!("Received new Objective");

self.hooks.on_fire_all(state, client_id, &event)?;
BAGUVIX456 marked this conversation as resolved.
Show resolved Hide resolved
self.inner.fire(state, event)?;
}

Event::Stop => {
state.request_stop();
}
Expand Down
6 changes: 6 additions & 0 deletions libafl/src/events/llmp/mgr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,12 @@ where
}
}
}

#[cfg(feature = "share_objectives")]
Copy link
Member

Choose a reason for hiding this comment

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

here put the same code as you did in llmp/mod.rs

Event::Objective { .. } => {
log::debug!("Received new Objective");
}

Event::CustomBuf { tag, buf } => {
for handler in &mut self.custom_buf_handlers {
if handler(state, &tag, &buf)? == CustomBufEventResult::Handled {
Expand Down
7 changes: 7 additions & 0 deletions libafl/src/events/llmp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,13 @@ where
}
Ok(())
}

#[cfg(feature = "share_objectives")]
BAGUVIX456 marked this conversation as resolved.
Show resolved Hide resolved
Event::Objective { .. } => {
log::info!("Received new Objective");
Ok(())
}

Event::CustomBuf { tag, buf } => {
for handler in &mut self.custom_buf_handlers {
if handler(state, &tag, &buf)? == CustomBufEventResult::Handled {
Expand Down
6 changes: 6 additions & 0 deletions libafl/src/events/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,12 @@ where
log::info!("Added received Testcase as item #{item}");
}
}

#[cfg(feature = "share_objectives")]
BAGUVIX456 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

Can we add a runtime flag instead of compile time? Overhead should be minimal and it's easier to use IMHO

Event::Objective { .. } => {
log::info!("Received new Objective");
}

Event::CustomBuf { tag, buf } => {
for handler in &mut self.custom_buf_handlers {
if handler(state, &tag, &buf)? == CustomBufEventResult::Handled {
Expand Down
Loading