-
Notifications
You must be signed in to change notification settings - Fork 162
Add Unsafe array access sanitizer
#932
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 Unsafe array access sanitizer
#932
Conversation
sanitizers/src/main/java/com/code_intelligence/jazzer/sanitizers/BUILD.bazel
Outdated
Show resolved
Hide resolved
sanitizers/src/main/java/com/code_intelligence/jazzer/sanitizers/UnsafeArrayOutOfBounds.java
Outdated
Show resolved
Hide resolved
sanitizers/src/test/java/com/example/UnsafeArrayOutOfBounds.java
Outdated
Show resolved
Hide resolved
|
I think this PR is now ready for an initial review; any feedback is appreciated! Please also let me know what you think about the points I mentioned above in my review comments. Also, is there a way to let Bazel install the Maven artifacts (especially the Jazzer JUnit artifact and its dependencies) as SNAPSHOT to the local Maven repository (similar to what |
|
|
|
Thanks! That only works for Linux though because I will see if I can maybe get it working with WSL 2 or a Docker container. But if that then only produces the Linux and not the Windows native libraries for Jazzer (not completely sure how the native build for Jazzer works) it will also be a bit cumbersome to then use these artifacts. (Side note: I had to update locally some of the Edit: Was able to build it now in a Docker container, but had to copy the native libraries which I had previously built on Windows into the JAR. The sanitizer seems to work. |
|
If you follow the steps at https://bazel.build/install/windows#install-compilers to install MSYS2 and Visual Studio, The publishing script for |
sanitizers/src/main/java/com/code_intelligence/jazzer/sanitizers/UnsafeArrayOutOfBounds.java
Show resolved
Hide resolved
|
Thanks for the hints!
I worked around it now by building within a Docker container, but maybe other users would benefit from that as well, so thanks for your work on this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this awesome contribution!
I am not familiar with the unsafe, but this PR looks good already!
sanitizers/src/main/java/com/code_intelligence/jazzer/sanitizers/UnsafeArrayOutOfBounds.java
Show resolved
Hide resolved
sanitizers/src/main/java/com/code_intelligence/jazzer/sanitizers/BUILD.bazel
Outdated
Show resolved
Hide resolved
sanitizers/src/main/java/com/code_intelligence/jazzer/sanitizers/UnsafeArrayOutOfBounds.java
Show resolved
Hide resolved
sanitizers/src/main/java/com/code_intelligence/jazzer/sanitizers/UnsafeArrayOutOfBounds.java
Show resolved
Hide resolved
sanitizers/src/test/java/com/example/UnsafeArrayOutOfBounds.java
Outdated
Show resolved
Hide resolved
sanitizers/src/main/java/com/code_intelligence/jazzer/sanitizers/UnsafeArrayOutOfBounds.java
Outdated
Show resolved
Hide resolved
|
Side note: The current test failure for the GitHub workflow seems to be unrelated to my changes: |
It turns out, using What's interesting though, is this:
I am still investigating what adds the >3 minutes overhead on Windows. Can you already add 45405d2 to your PR? It's already good improvement to use 6 seconds instead of 2 minutes! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, thanks! Only the timeout test needs to be fixed like shown in 45405d2
I don't know why some comments appear twice in different places 🙈
sanitizers/src/main/java/com/code_intelligence/jazzer/sanitizers/UnsafeArrayOutOfBounds.java
Outdated
Show resolved
Hide resolved
sanitizers/src/main/java/com/code_intelligence/jazzer/sanitizers/UnsafeArrayOutOfBounds.java
Show resolved
Hide resolved
sanitizers/src/main/java/com/code_intelligence/jazzer/sanitizers/UnsafeArrayOutOfBounds.java
Show resolved
Hide resolved
sanitizers/src/main/java/com/code_intelligence/jazzer/sanitizers/UnsafeArrayOutOfBounds.java
Outdated
Show resolved
Hide resolved
|
Thanks! I have included 45405d2 now. Should I also squash the commits or will you do that on merge? Also, maybe the
Do you mean the review comments here on the GitHub UI? I think that happens when you submit review comments on an existing comment thread. Then GitHub shows the comments on that thread but additionally (without any context...) for the review event. Hopefully GitHub improves this some day. |
I am planning to rebase and merge. Can you group meaningful commits together?
It is totally unsafe! I usually run only specific tests locally, and the rest on Github. |
Is it ok if I just squash all my commits into a single one and keep your commit (with slightly different message)? I don't think for my commits it is worth keeping any of the intermediate state as separate commit. |
Yes, thank you! |
45405d2 to
28c431d
Compare
|
Have squashed the commits now. Regarding your comment above:
Jazzer uses |
Previous usage of `FuzzedDataProvider#consumeRemainingAsAsciiString` caused a timeout.
28c431d to
6b8d574
Compare
Adds a sanitizer which looks for invalid array access performed by
sun.misc.Unsafe. Unlike native memory access performed byUnsafe, array access can be sanitized in a stateless way just based on the arguments passed to theUnsafemethod. And multiple Java libraries have usedUnsafefor arrays in the past to improve performance, see related security advisories GHSA-8wh2-6qhj-h7j9 and GHSA-973x-65j7-xcf4.Note that fuzzing likely cannot find all such invalid accesses because some of it occurs for numeric overflow respectively multiple MB of processed data, which the fuzzer might be unable to generate.
See related #891
I used #915 as reference for how to implement a sanitizer. However, I am not very familiar with Bazel and this project setup here, and also have / had issues with building it locally on Windows. Therefore I have marked this PR as Draft for now.
Any feedback is appreciated!