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

Adding ExitCodeObserver and ExitSignalObserver #2138

Merged
merged 2 commits into from
May 8, 2024

Conversation

riesentoaster
Copy link
Contributor

These observers allow observing the exit code and exit signal of a process, specifically in CommandExecutor. This is helpful if the standard CrashFeedback is not specific enough.

@tokatoka
Copy link
Member

tokatoka commented May 3, 2024

nice


match res.map(|status| status.signal()) {
// for reference: https://www.man7.org/linux/man-pages/man7/signal.7.html
Some(Some(9)) => Ok(ExitKind::Oom),
Copy link
Member

@tokatoka tokatoka May 3, 2024

Choose a reason for hiding this comment

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

This is not your fault,
but can you change this exitkind::oom (and all occurences of exitkind::oom) to something else?
for example exitkind::sigkill

exit code 9 is not oom. there's no way to tell if the process exited out of oom (unless we type dmesg

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was wondering what was up with that but didn't want to touch it without understanding what was actually happening.

If this gets touched already: Does it make sense to have an exit kind for SIGKILL only? Or do we want further types for certain signals? Or just remove it altogether and use an ExitSignalObserver whenever we need the functionality? What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

imo just changing this to ExitKind::SIGKILL is fine. it represents an error sent by the kernel (but not necessarily OOM)
ideally we could separate it into SIGSEGV, SIGABRT, SIGTERM... (if you want to do it)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've looked into it a bit more deeply and I think the best way would just be to remove ExitKind::Oom without replacement. If a user wants more advanced handling of exits, they have to write a custom Feedback implementation regardless, and they can just use a ExitSignalObserver to get the specific signal.

The issue is that a SIGSEGV etc. is also a crash, so a user may be confused if it isn't reported as such.

I'm more so thinking about what signals may not indicate a crash and maybe handle them differently (or just report them as ExitKind::Ok. I don't know Unix well enough to make this a final list, but maybe something like this:

  • SIGTERM
  • SIGINT
  • SIGUSR1
  • SIGUSR2
  • SIGCONT
  • SIGALRM

Any other signal? How do we handle them?

Copy link
Member

Choose a reason for hiding this comment

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

I would call them maybe ExitKind::Interrupted.

Copy link
Contributor Author

@riesentoaster riesentoaster May 8, 2024

Choose a reason for hiding this comment

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

I had to re-add ExitKind::Oom, because libafl_libfuzzer uses it — I added a disclaimer to the definition.

In the future, I'd prefer if all features are implemented for all possible combinations, or at least have compile-time errors it not — it's a recipe for weird behaviour for people new to libafl. Not sure how this would be done here and I feel like it doesn't have much to do with this PR, so I'm not going to make those changes now. This is something I've stumbled across at multiple places within the code base, so it may be good to fundamentally think about this at some point.

@tokatoka
Copy link
Member

tokatoka commented May 6, 2024

can you fix the clippy errors too?

@riesentoaster riesentoaster force-pushed the exit_observers branch 2 times, most recently from ff623be to 7c6c5c0 Compare May 8, 2024 11:53
@riesentoaster
Copy link
Contributor Author

(I'm so sorry, I messed up my git history. Should hopefully be better now.)

@tokatoka tokatoka merged commit ee7dafa into AFLplusplus:main May 8, 2024
99 checks passed
@tokatoka
Copy link
Member

tokatoka commented May 8, 2024

thank you 👍

@tokatoka
Copy link
Member

tokatoka commented May 8, 2024

Sorry. I have another idea about this.
IMO i don't think we should add these two methods into ObserverTuples

    /// Runs `observe_exit_code` for all exit code observers in the list
    fn observe_exit_code(&mut self, exit_code: i32);
    /// Runs `observe_exit_signal` for all exit signal observers in the list
    fn observe_exit_signal(&mut self, exit_signal: i32);

(Okay there is fn observe_stdout(&mut self, stdout: &[u8]); and fn observe_stderr(&mut self, stderr: &[u8]);
but IMO there should be removed too)

What I would do is
instead of doing

        if self.observers.observes_exit_signal() {

can you

  1. When instantiate this command executor, give the Handle or name of the exit code observer
  2. When you want to check the exit signal, search it by executor.observers.match_name
    ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants