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

add crash_exitcode to Forkserver to accomodate AFL_CRASH_EXITCODE #2107

Merged
merged 2 commits into from
Apr 26, 2024
Merged
Changes from 1 commit
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
20 changes: 19 additions & 1 deletion libafl/src/executors/forkserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ where
phantom: PhantomData<S>,
map_size: Option<usize>,
timeout: TimeSpec,
crash_exitcode: Option<i32>,
}

impl<OT, S, SP> Debug for ForkserverExecutor<OT, S, SP>
Expand Down Expand Up @@ -583,6 +584,7 @@ pub struct ForkserverExecutorBuilder<'a, SP> {
real_map_size: i32,
kill_signal: Option<Signal>,
timeout: Option<Duration>,
crash_exitcode: Option<i32>,
}

impl<'a, SP> ForkserverExecutorBuilder<'a, SP> {
Expand Down Expand Up @@ -631,6 +633,7 @@ impl<'a, SP> ForkserverExecutorBuilder<'a, SP> {
phantom: PhantomData,
map_size: self.map_size,
timeout,
crash_exitcode: self.crash_exitcode,
})
}

Expand Down Expand Up @@ -688,6 +691,7 @@ impl<'a, SP> ForkserverExecutorBuilder<'a, SP> {
phantom: PhantomData,
map_size: self.map_size,
timeout,
crash_exitcode: self.crash_exitcode,
})
}

Expand Down Expand Up @@ -999,6 +1003,13 @@ impl<'a, SP> ForkserverExecutorBuilder<'a, SP> {
self
}

/// Treats an execution as a crash if the provided exitcode is returned
#[must_use]
pub fn crash_exitcode(mut self, exitcode: i32) -> Self {
self.crash_exitcode = Some(exitcode);
self
}

/// Call this if the harness uses deferred forkserver mode; default is false
#[must_use]
pub fn is_deferred_frksrv(mut self, is_deferred_frksrv: bool) -> Self {
Expand Down Expand Up @@ -1047,6 +1058,7 @@ impl<'a> ForkserverExecutorBuilder<'a, UnixShMemProvider> {
max_input_size: MAX_INPUT_SIZE_DEFAULT,
kill_signal: None,
timeout: None,
crash_exitcode: None,
}
}

Expand All @@ -1072,6 +1084,7 @@ impl<'a> ForkserverExecutorBuilder<'a, UnixShMemProvider> {
max_input_size: MAX_INPUT_SIZE_DEFAULT,
kill_signal: None,
timeout: None,
crash_exitcode: None,
}
}
}
Expand Down Expand Up @@ -1157,7 +1170,12 @@ where

if let Some(status) = self.forkserver.read_st_timed(&self.timeout)? {
self.forkserver.set_status(status);
if libc::WIFSIGNALED(self.forkserver().status()) {
let exitcode_is_crash = if let Some(crash_exitcode) = self.crash_exitcode {
libc::WSTOPSIG(self.forkserver().status()) == crash_exitcode
Copy link
Member

Choose a reason for hiding this comment

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

wfisignaled doesn't work here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

WIFSIGNALED returns a bool so we can't compare it to a given exit code

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 WTERMSIG

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Should we keep this closer to AFL++? @vanhauser-thc for visibility

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@domenukk yeah you're right. its i8.

Copy link
Member

Choose a reason for hiding this comment

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

i think it should be close to AFLpp

} else {
false
};
if libc::WIFSIGNALED(self.forkserver().status()) || exitcode_is_crash {
exit_kind = ExitKind::Crash;
#[cfg(feature = "regex")]
if let Some(asan_observer) = self
Expand Down
Loading