-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Better support for fuzzing Rust, remaining - code coverage; MSan; LSan in ASan #3469
Comments
Fixing this inconsistency/getting the normal thing working on jenkins: #3298 |
IIUC rust-lang/rust#34701 could be a precursor to adding support for something like clang source-based coverage for Rust targets (related issue: #3468). |
Support MSAN when mixing C and Rust cf |
Didnt realise sanitizers were disabled for Rust projects, this definitely seems bad. oss-fuzz/projects/mp4parse-rust/build.sh Line 24 in 44f4b89
|
@catenacyber - MSan should work after #3830, maybe you want to try with some projects ? If you can also find what things are missing, that would be much appreciated. |
Interesting, now I get a build failure ( bug found by MSAN ?) :
Adding
|
Ah the problem with that @catenacyber is that the usage of |
Thanks @alexcrichton More info, when trying to build with ASAN, I get |
Yes you can add |
Thanks @alexcrichton Then @inferno-chromium it seems I am back to the previous problem of the fuzz target mixing C and Rust :
with the line being |
@catenacyber - i have fixed this now in #3859 , base build images should be rebuilt in one hour, then you need to infra/helper.py pull_images and retry. |
Ok for MSan, check_build fails (which actually runs the binaries). @alexcrichton , can you please check below. Many projects use cargo fuzz build, is there a difference.
|
Ah sorry I don't think I'm knowledgeable enough about fuzzers/msan/etc to understand what's going on there. Given "Might be a bug in MemorySanitizer origin tracking." it looks like something possibly wasn't compiled correctly? I don't have much experience myself in using other fuzzers in Rust. It might be worthwhile to raise this on the cargo-fuzz repo and see if others can help out? |
@catenacyber @victorjulien, just fyi suricata project build seems broken due to recent default all Rust flags [https://github.com//pull/3859]. You would need to remove stable cargo from Dockerfile, use rust nightly directly(no need to install) and add this target CARGO_BUILD_TARGET="x86_64-unknown-linux-gnu" to make it work with sanitizer. I could not go far beyond that, there is some weird error - "make[2]: *** No rule to make target '../rust/target/release/libsuricata.a', needed by 'suricata'. Stop." |
@inferno-chromium I will take a good look at it next week Quick and dirty patch I have been using is :
I will try to adding |
Quick and dirty patch seems good in fact |
Fyi, msan can't be enabled due to #3988 (comment) |
Is there a current work to have MSAN with recompiled std library ? |
I dont know what is required here or changes needed in cargo fuzz. |
For simple cargo projects the minimal set of flags required for MemorySanitizer would be: $ export CC=clang CFLAGS=-fsanitize=memory RUSTFLAGS=-Zsanitizer=memory RUSTDOCFLAGS=-Zsanitizer=memory
$ cargo test --workspace -Z build-std --target x86_64-unknown-linux-gnu
For projects using cargo-fuzz it would be additionally: $ export CUSTOM_LIBFUZZER_PATH=...
$ cargo fuzz run fuzz_target -s memory -Z build-std --target x86_64-unknown-linux-gnu
|
Thanks @tmiasko it looks like it works cf OISF/suricata#5395 |
rust-lang/rust#34701 is merged now which should help with getting coverage information. |
Support for LLVM-based code coverage for Rust was implemented awhile back (and has a [nice blog post][post] with [documentation]), and we ran across this internally today. I'm curious if this change is all that's needed to enable source coverage for Rust builds! I'm not 100% sure how coverage is all set up in oss-fuzz but I figured this might be a good place to get the ball rolling. cc google#3469 [post]: https://blog.rust-lang.org/inside-rust/2020/11/12/source-based-code-coverage.html [documentation]: https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/source-based-code-coverage.html
FWIW, |
Thanks for this news @fitzgen |
It does not. Is this something every user will need, or just oss-fuzz style users that move the binaries to new locations/machines? It hasn't been necessary for any of the local coverage experiments I've performed yet.
Optimizations can be controlled via passing the Agreed that the upstream rustc bug should get fixed, but I'm not convinced it warrants entangling optimized vs not builds together with coverage vs not builds.
Do you want the ability to build coverage binaries without automatically running them over the corpus to produce coverage data? We can definitely make it so that you can build a coverage-instrumented binary with |
It is not about a new machine (this is handled by llvm-cov flags)
You can try wasmtime from oss-fuzz
It may be better to wait for the rustc bug fix...
Yes :-)
For oss-fuzz projects, it could be easier with |
In oss-fuzz, to build with MemorySanitizer, Rust part needs to use ``` CARGO_BUILD_TARGET="x86_64-unknown-linux-gnu" ``` to resolve libc `MemorySanitizer: use-of-uninitialized-value` error according to google#3469.
* CRAS: Use CARGO_BUILD_TARGET="x86_64-unknown-linux-gnu" In oss-fuzz, to build with MemorySanitizer, Rust part needs to use ``` CARGO_BUILD_TARGET="x86_64-unknown-linux-gnu" ``` to resolve libc `MemorySanitizer: use-of-uninitialized-value` error according to #3469. * CRAS: Add new member to auto_ccs Co-authored-by: paulhsia <[email protected]>
* CRAS: Use CARGO_BUILD_TARGET="x86_64-unknown-linux-gnu" In oss-fuzz, to build with MemorySanitizer, Rust part needs to use ``` CARGO_BUILD_TARGET="x86_64-unknown-linux-gnu" ``` to resolve libc `MemorySanitizer: use-of-uninitialized-value` error according to google#3469. * CRAS: Add new member to auto_ccs Co-authored-by: paulhsia <[email protected]>
* CRAS: Use CARGO_BUILD_TARGET="x86_64-unknown-linux-gnu" In oss-fuzz, to build with MemorySanitizer, Rust part needs to use ``` CARGO_BUILD_TARGET="x86_64-unknown-linux-gnu" ``` to resolve libc `MemorySanitizer: use-of-uninitialized-value` error according to google#3469. * CRAS: Add new member to auto_ccs Co-authored-by: paulhsia <[email protected]>
Tracking bug for ideas / suggestions
The text was updated successfully, but these errors were encountered: