-
Notifications
You must be signed in to change notification settings - Fork 20
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
Reimplement fuzzing instrumentation using Bazel transitions. #86
Merged
Merged
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
de016e2
Reimplement fuzzing instrumentation using Bazel transitions.
stefanbucur 95b979a
Updated the documentation, too.
stefanbucur f4714a2
Fix tagging issues with the new rule separation.
stefanbucur 67967b6
Updated again the documentation.
stefanbucur 6e4e34b
Fixed CI tests.
stefanbucur 903a6c8
Revamped the presubmit tests to include richer smoke testing behavior.
stefanbucur dbba6b7
Installing Honggfuzz deps in the smoke test workflow.
stefanbucur 837aab3
Exclude some MSAN smoke tests.
stefanbucur ed6738b
Added code documentation for the cc_engine_sanitizer values.
stefanbucur 57b9113
Address reviewer comments.
stefanbucur 968876b
Make buildifier happy.
stefanbucur f547a36
Rename msan-repro sanitizer option to msan-origin-tracking.
stefanbucur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# Copyright 2020 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Fuzz test instrumentation options. | ||
|
||
Each fuzzing engine or sanitizer instrumentation recognized by the | ||
//fuzzing:cc_engine_instrumentation and //fuzzing:cc_engine_sanitizer | ||
configuration flag should be defined here. | ||
""" | ||
|
||
def _check_is_string_list(name, value): | ||
markus-kusano marked this conversation as resolved.
Show resolved
Hide resolved
|
||
string_type = type("string") | ||
markus-kusano marked this conversation as resolved.
Show resolved
Hide resolved
|
||
list_type = type(["list"]) | ||
|
||
if type(value) != list_type: | ||
fail("%s should be a list, but was %s" % (name, type(value))) | ||
if any([type(element) != string_type for element in value]): | ||
fail("%s should be a list of strings" % name) | ||
|
||
def instrumentation_opts(copts = [], linkopts = []): | ||
"""Creates a set of instrumentation options. | ||
markus-kusano marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Args: | ||
copts: A list of compilation options to pass as `--copt` | ||
configuration flags. | ||
linkopts: A list of linker options to pass as `--linkopt` | ||
configuration flags. | ||
""" | ||
_check_is_string_list("copts", copts) | ||
markus-kusano marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_check_is_string_list("linkopts", linkopts) | ||
return struct( | ||
copts = copts, | ||
linkopts = linkopts, | ||
) | ||
|
||
# Base instrumentation applied to all fuzz test executables. | ||
base_opts = instrumentation_opts( | ||
copts = ["-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION"], | ||
linkopts = [], | ||
) | ||
|
||
# Engine-specific instrumentation. | ||
fuzzing_engine_opts = { | ||
"none": instrumentation_opts(), | ||
"libfuzzer": instrumentation_opts( | ||
copts = ["-fsanitize=fuzzer"], | ||
linkopts = ["-fsanitize=fuzzer"], | ||
), | ||
# Reflects the set of options at | ||
# https://github.com/google/honggfuzz/blob/master/hfuzz_cc/hfuzz-cc.c | ||
"honggfuzz": instrumentation_opts( | ||
copts = [ | ||
"-mllvm", | ||
"-inline-threshold=2000", | ||
"-fno-builtin", | ||
"-fno-omit-frame-pointer", | ||
"-D__NO_STRING_INLINES", | ||
"-fsanitize-coverage=trace-pc-guard,trace-cmp,trace-div,indirect-calls", | ||
"-fno-sanitize=fuzzer", | ||
], | ||
linkopts = [ | ||
"-fno-sanitize=fuzzer", | ||
], | ||
), | ||
} | ||
|
||
# Sanitizer-specific instrumentation. | ||
sanitizer_opts = { | ||
"none": instrumentation_opts(), | ||
"asan": instrumentation_opts( | ||
copts = ["-fsanitize=address"], | ||
linkopts = ["-fsanitize=address"], | ||
), | ||
"msan": instrumentation_opts( | ||
copts = ["-fsanitize=memory"], | ||
linkopts = ["-fsanitize=memory"], | ||
), | ||
"msan-repro": instrumentation_opts( | ||
copts = [ | ||
"-fsanitize=memory", | ||
"-fsanitize-memory-track-origins=2", | ||
], | ||
linkopts = ["-fsanitize=memory"], | ||
), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,5 @@ exports_files([ | |
"common.bzl", | ||
"engine.bzl", | ||
"fuzz_test.bzl", | ||
"instrument.bzl", | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Just a suggestion (I might be missing context): would it make sense to have a smoke test also for honggfuzz? Also perhaps the reproduction mode for libFuzzer? Maybe MSAN as well?
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 is a great point. I've replaced this set of steps with a separate "Smoke testing" job and enabled a matrix of configuration to test multiple combinations of config x fuzz target.
On this occasion, I discovered that the RE2 example actually triggers an MSAN error :) I will report this on the RE2 project itself and we can decide if we want to include this simple fuzz target as a RE2 fuzzer for OSS-Fuzz too. CC @inferno-chromium @oliverchang
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.
LGTM, feel free to resolve, leaving open for other's to take a look.