-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Fuzzing: Cannot compile code using compiler plugin with -C panic=abort
#5423
Comments
Thanks for the report! Those are pretty old issues at this point and they're not entirely in cache for me, though. Do you have a sample project I could check out and explore what's going on here? |
I set up a concrete example for you. In this project there is an now, from the
|
Ah ok, thanks @PaulGrandperrin! As I suspected though this isn't really related to Cargo at all, rather it's a rustc/proc-macro2 issue:
The problem is that the There's two fixes here:
|
This bug is probably technically equivalent to those two closed issues #2738 and #3166 but I want to present the issue from another perspective.
At rust-fuzz, we use this feature to transform panics into something that the fuzzer can interpret as an abnormal process termination.
Indeed by default, fuzzers do not interpret
writing on stderr
+returning a non-zero exit code
as an abnormal process termination.So it means that we really rely on this behavior for our fuzzers to work nominally.
If this behavior is ignored when linking to compiler crates (as suggested in #3166 (comment)) then, our fuzzers will silently miss all bugs triggering panics.
That being said, for instance, right now it's impossible to build with
panic=abort
a project linking toproc_macro2
:We do have stop-gap solutions but they are not perfect:
The first one is to use panic::catch_unwind() on our target closure and calling
abort
on unwinding.This method has a major drawback: to distinguish between already reported bugs and new ones, fuzzers inspects the state of the stack frames of the process being signaled (here SIGABRT). However, with this method we call
abort()
after all of the closure stack frames have been unrolled and so the information of where the panic was thrown is lost from the point of view of the fuzzer. The fuzzer then sees all bugs coming from the same place and so will only report the first one to the user and ignore all the others as duplicates.the second one is to use panic::set_hook() to register a panic handler that directly calls
abort()
. Functionally, it works fine as the process aborts before unwinding and the fuzzer can then read the stack frames and tell apart different bugs.This is however not perfect because it means we need to setup this hook at runtime before starting fuzzing but this is not always obvious in a fuzzing context.
Also, @nagisa feels strongly about this being a hack that should only exist temporarily until the real fix is implemented.
references:
https://github.com/rust-fuzz/libfuzzer-sys/issues/31
https://github.com/rust-fuzz/libfuzzer-sys/pull/32
rust-fuzz/afl.rs@201d80b
rust-fuzz/afl.rs#134
rust-fuzz/cargo-fuzz#152
rust-fuzz/cargo-fuzz#153
rust-fuzz/honggfuzz-rs@abe2b4c
rust-fuzz/honggfuzz-rs@1d7df87
The text was updated successfully, but these errors were encountered: