Skip to content

The first working draft of the rules_fuzzing integration in Envoy.#14675

Closed
stefanbucur wants to merge 14 commits intoenvoyproxy:mainfrom
stefanbucur:add-bazel-rules-fuzzing
Closed

The first working draft of the rules_fuzzing integration in Envoy.#14675
stefanbucur wants to merge 14 commits intoenvoyproxy:mainfrom
stefanbucur:add-bazel-rules-fuzzing

Conversation

@stefanbucur
Copy link
Copy Markdown
Contributor

Commit Message: Use the new rules_fuzzing Bazel repository for fuzzing support.

Additional Description: The new fuzzing rules provide an improved fuzzing development experience and simplifies a number of tasks, such as OSS-Fuzz integration.

Risk Level: High

Testing: Used RBE to test the changes on all fuzz tests: bazel test --config=remote --config=asan-fuzzer -c opt $(bazel query 'let all_fuzz_tests = attr(tags, "fuzz_target", "...") in $all_fuzz_tests - attr(tags, "no_fuzz", $all_fuzz_tests)')

Docs Changes: None yet.

Release Notes: N/A

Platform Specific Features: Fuzz tests run on Linux platforms only.

@repokitteh-read-only
Copy link
Copy Markdown

Hi @stefanbucur, welcome and thank you for your contribution.

We will try to review your Pull Request as quickly as possible.

In the meantime, please take a look at the contribution guidelines if you have not done so already.

🐱

Caused by: #14675 was opened by stefanbucur.

see: more, trace.

@repokitteh-read-only repokitteh-read-only bot added the deps Approval required for changes to Envoy's external dependencies label Jan 12, 2021
@repokitteh-read-only
Copy link
Copy Markdown

CC @envoyproxy/dependency-shepherds: Your approval is needed for changes made to (bazel/.*repos.*\.bzl)|(bazel/dependency_imports\.bzl)|(api/bazel/.*\.bzl)|(.*/requirements\.txt)|(.*\.patch).

🐱

Caused by: #14675 was opened by stefanbucur.

see: more, trace.

@stefanbucur
Copy link
Copy Markdown
Contributor Author

@asraa This is the PR with all my changes so far, PTAL when you get the chance.

@stefanbucur stefanbucur force-pushed the add-bazel-rules-fuzzing branch from ab8726c to e5ec2ef Compare January 12, 2021 20:25
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does the raw binary name get compiled as a cc_test?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good question - so I left the original binary as a cc_test since I didn't get the chance to look at coverage support, so I left in place the original cc_test + its data dependency on the corpus so we can still use the old way of collecting code coverage. Maybe we can migrate this part to bazel_rules in a subsequent step, or you think we should do it now?

Copy link
Copy Markdown
Contributor

@asraa asraa Jan 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm fuzz coverage actually uses the libfuzzer linked target (and normal test coverage ignores fuzzers).

Let me clone locally and see what happens when running fuzz_coverage. It might work since the fuzz coverage script expects a libfuzzer linked binary but the tag might need to change to filter for fuzz_target_binary targets.

@asraa
Copy link
Copy Markdown
Contributor

asraa commented Jan 13, 2021

Looks good to me otherwise! Thank you so much --

to fix the format CI, you can run ./tools/code_format/check_format.py fix locally

@stefanbucur
Copy link
Copy Markdown
Contributor Author

Looks good to me otherwise! Thank you so much --

to fix the format CI, you can run ./tools/code_format/check_format.py fix locally

Ah, great, thanks for the pointer!

BTW, I realized there are two failures here. The other one is:

Dependency validation failed, please check metadata in bazel/repository_locations.bzl
Missing deps in test_only "use_category": ['rules_fuzzing_oss_fuzz', 'honggfuzz', 'fuzzing_py_deps_pypi__absl_py_0_11_0']

Are there other places in the Bazel dependency configuration where we need to add these?

@stefanbucur stefanbucur force-pushed the add-bazel-rules-fuzzing branch from d33e36b to 92ba190 Compare January 15, 2021 22:54
Base automatically changed from master to main January 15, 2021 23:02
@asraa
Copy link
Copy Markdown
Contributor

asraa commented Jan 19, 2021

Checking out coverage, there is a fuzz coverage script here: https://github.com/envoyproxy/envoy/blob/main/bazel/coverage/fuzz_coverage_wrapper.sh

that now needs to run ${TEST_BINARY}_instrum, and also grab the corpus via:
cp -r "${TEST_BINARY}"_corpus fuzz_corpus/seed_corpus.

This is currently how bazel coverage is co-opted to run the fuzzing binary

@stefanbucur stefanbucur force-pushed the add-bazel-rules-fuzzing branch from e7ac795 to c2008eb Compare January 19, 2021 22:29
@asraa
Copy link
Copy Markdown
Contributor

asraa commented Jan 25, 2021

@stefanbucur it looks like it passes CI now (including the fuzz coverage script, which runs fuzzing as normal and produces the output!)

Should this be moved out of DRAFT now?

@stefanbucur
Copy link
Copy Markdown
Contributor Author

@stefanbucur it looks like it passes CI now (including the fuzz coverage script, which runs fuzzing as normal and produces the output!)

Should this be moved out of DRAFT now?

Yes, I think it's time to move this out of draft! This now works, but unfortunately I had to reduce some functionality due to the impact on build output size, as well as the build effort. More specifically:

  • The configuration transition that instruments the binary is now disabled, so we're still relying on the .bazelrc file to specify the instrumentation flags. This keeps the build output size and build effort low, while we can re-enable the transitions once Build failure caused by no-op starlark transition (friction between Starlark None and java null) bazelbuild/bazel#12888 is resolved.
  • The regression test that ships with rules_fuzzing is also disabled, thus still relying on the old way of using the cc_test with the args attribute configured. This is due to an unexpected interaction with RBE, which pulls in local build artifacts when running in sanitizer mode. This needs more investigation and we can easily enable this back once we have a fix.
  • Honggfuzz support is not yet enabled, since it pulls an extra Honggfuzz dependency that would need to be explicitly declared here. There is no issue with that, it's just that it felt like this should be an add-on PR sent out separately, if needed.

I would suggest though to do this PR in smaller, incremental sub-PRs, to minimize the risk of any disruption:

  1. I will first send a PR that adds in the new rules_fuzzing dependencies and enables the new targets. All the old targets will still be there, including the OSS-Fuzz one, such that the OSS-Fuzz builds are not affected.
  2. I will then send out an OSS-Fuzz PR that switches over the build.sh script from the old rules to the new rules. This should substantially simplify the build script.
  3. Once OSS-Fuzz is switched over, I will send out a clean-up PR to remove any unused rules from the macro.

@asraa How does the plan sound?

@asraa
Copy link
Copy Markdown
Contributor

asraa commented Jan 26, 2021

Transition plan sounds great re OSS-Fuzz. My read is that between 1 and 2 there will never be a time where OSS-Fuzz can't build. That's ideal.

Tag me on PRs!

Signed-off-by: Stefan Bucur <sbucur@google.com>
…uration flag.

Use instead a select() statement that builds upon the existing FUZZING_ENGINE variable.

Signed-off-by: Stefan Bucur <sbucur@google.com>
Signed-off-by: Stefan Bucur <sbucur@google.com>
Remove Honggfuzz support for this initial integration. Also use consistent naming of fuzzing Python dependencies.

Signed-off-by: Stefan Bucur <sbucur@google.com>
Signed-off-by: Stefan Bucur <sbucur@google.com>
…dency.

Signed-off-by: Stefan Bucur <sbucur@google.com>
Signed-off-by: Stefan Bucur <sbucur@google.com>
Signed-off-by: Stefan Bucur <sbucur@google.com>
Signed-off-by: Stefan Bucur <sbucur@google.com>
… by ~8GiB.

Signed-off-by: Stefan Bucur <sbucur@google.com>
Signed-off-by: Stefan Bucur <sbucur@google.com>
Signed-off-by: Stefan Bucur <sbucur@google.com>
Signed-off-by: Stefan Bucur <sbucur@google.com>
Signed-off-by: Stefan Bucur <sbucur@google.com>
@stefanbucur stefanbucur force-pushed the add-bazel-rules-fuzzing branch from ff88099 to 62d81d7 Compare January 26, 2021 22:57
htuch pushed a commit that referenced this pull request Feb 2, 2021
Introduce the new https://github.com/bazelbuild/rules_fuzzing library for fuzz testing support.

The new library provides new functionality (support for testing the fuzz test locally) and simplifies existing fuzzing tasks. This is the first PR in the series. See #14675 for the detailed rollout plan.

Risk Level: Low (new dependencies and major change to the existing envoy_cc_fuzz_test macro, but does not affect Envoy binary)
Testing: The changes consist of either (a) code that should be a drop-in replacement to the existing functionality, or (b) new targets marked as "manual". For (a), the Envoy regression tests should catch deviations from the original behavior. The new functionality in (b) is either tested manually, or through the OSS-Fuzz integration (changes coming in future PR).
Docs Changes: None (this is test-only functionality).
Release Notes: N/A
Platform Specific Features: The fuzz tests run on Linux platforms only.

Signed-off-by: Stefan Bucur <sbucur@google.com>
@stefanbucur
Copy link
Copy Markdown
Contributor Author

Submitted as #14834, closing here.

@stefanbucur stefanbucur closed this Feb 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deps Approval required for changes to Envoy's external dependencies

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants