This is an archive of the discontinued LLVM Phabricator instance.

[LibFuzzer] Add support for an optional user defined callback (`LLVMFuzzerOnExitHandler()`)
Needs ReviewPublic

Authored by delcypher on Apr 18 2018, 5:30 AM.

Details

Summary

[LibFuzzer] Add support for an optional user defined callback (LLVMFuzzerOnExitHandler())
which is called when LibFuzzer exits.

This callback will be called by LibFuzzer when it exits in most
scenarios. It currently doesn't call the callback if:

  • LibFuzzer is launched incorrectly.
  • LibFuzzer observes that the client corrupts the fuzzing input.

This upstreams a change from the JFS solver's fork of LibFuzzer. JFS's use
case is to ensure that an event log gets flushed to disk whenever
LibFuzzer decides that it wants to exit. There are probably other use
cases too.

Diff Detail

Event Timeline

delcypher created this revision.Apr 18 2018, 5:30 AM
Herald added a subscriber: Restricted Project. · View Herald TranscriptApr 18 2018, 5:30 AM
kcc added a comment.Apr 18 2018, 12:09 PM

Why is it not enough to cal atexit() in LLVMFuzzerInitialize?

In D45762#1071308, @kcc wrote:

Why is it not enough to cal atexit() in LLVMFuzzerInitialize?

LibFuzzer currently uses _Exit() in several cases which means that it is not guaranteed that registered atexit() callbacks will be called by LibFuzer. In particular in JFS we currently use abort() in the program under test to detect we've reached the target and we implement a timeout externally (there are technical reasons for doing this) and send SIGINT to LibFuzzer when the timeout occurs. In both of these cases atexit handlers would not be called. Therefore we needed to implement a callback for the fuzzer exiting. This patch seemed like the most general way of doing this.

george.karpenkov resigned from this revision.May 30 2018, 4:28 PM
george.karpenkov added a subscriber: george.karpenkov.