Repository navigation
test/fuzz: Destroy the HTTP filter fuzzer's filters on every path, and keep its headers alive - #49398
Merged
Merged
Conversation
…d keep its headers alive The fuzzer (`UberFilterFuzzer`) is one static object, reused for every input, and left state behind for the next one: - `reset()`, which calls `onDestroy()` and drops the filters, only ran when `fuzz()` got to its end. If it left early (the factory threw after adding a filter, or the filter did not finish) the filters stayed, and were destroyed without `onDestroy()` when the next input added its own. - The request headers that the decoder callbacks return were a local of the block that runs the decoder, so were gone while the filter was still encoding, access logging, or completing work in the loop that waits for it. - What a filter had posted to the dispatcher was left to run during the next input, after the filter was gone. The filters are now destroyed however `fuzz()` returns, the headers live as long as the fuzzer, and the dispatcher is run once before the filters are dropped. Signed-off-by: Ryan Northey <[email protected]>
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
A human should review the pending ASAN replay to determine whether the lifecycle fix resolves the intermittent cross-input use-after-free involving real worker-thread callbacks.
No open issues 🎉
What changed in this PR
This test-only change addresses intermittent HTTP filter fuzzing crashes by improving cleanup and request-header lifetime in the reused UberFilterFuzzer.
Changes:
- Ensure filters are cleaned up on normal completion, early returns, and exceptions.
- Keep callback request headers alive until filter cleanup.
- Run pending dispatcher work before releasing filters.
| File | Description |
|---|---|
test/extensions/filters/http/common/fuzz/uber_filter.h |
Store callback request headers as a fuzzer member. |
test/extensions/filters/http/common/fuzz/uber_filter.cc |
Add scope-based cleanup, drain dispatcher work, and clear retained headers during reset. |
test/extensions/filters/http/common/fuzz/BUILD |
Add the cleanup utility dependency. |
Review effort: Balanced
phlax
marked this pull request as ready for review
November 18, 2026 16:16
agrawroh
approved these changes
Nov 20, 2026
phlax
added a commit
to phlax/envoy
that referenced
this pull request
Nov 20, 2026
…d keep its headers alive (envoyproxy#49398) Fixes a flake of the fuzz coverage job: `//test/extensions/filters/http/common/fuzz:filter_fuzz_test` occasionally dies with a SEGV while replaying the corpus, as in [this run](https://github.com/envoyproxy/envoy/actions/runs/44306995860/job/134811152021) of envoyproxy#49388, which passed on a retest. ### Cause The fuzzer (`UberFilterFuzzer`) is one static object, reused for every input, and it left state behind for the next one: - `reset()`, which calls `onDestroy()` and drops the filters, only ran when `fuzz()` got to its end. If it left early (the factory threw after adding a filter, or the filter did not finish) the filters stayed, and were destroyed without `onDestroy()` when a later input added its own. - The request headers that the decoder callbacks return were a local of the block that runs the decoder, so they were gone while the filter was still encoding, access logging, or completing work in the loop that waits for it. - What a filter had posted to the dispatcher was left to run during the next input, after the filter was gone. With ASAN this is a heap-use-after-free in `FileSystemBufferFilter::onStateChange()`, run from a callback that the filter posted, in an input after the one whose `reset()` freed the filter. The filter guards those callbacks with a flag set in `onDestroy()`, so this is a filter that was freed without `onDestroy()`: a test harness bug, not one in the filter. ### Fix Test only: the filters are destroyed however `fuzz()` returns, the headers live as long as the fuzzer, and the dispatcher is run once before the filters are dropped. ### Testing Runs of `filter_fuzz_test` with the fuzz coverage job's flow (fuzz for 60s, then replay the corpus, which only fails on a crash), in envoy-ci-staging: | Config | Code | Failures | | --- | --- | --- | | fuzz coverage | `main` (and the envoyproxy#49388 stack) | 4 of 600 (SEGV in the replay) | | fuzz coverage | this change | 0 of 400 | | ASAN, asserts off | `main` | 7 of 400, all the use-after-free above | | ASAN, asserts off | this change | 0 of 400 | The fuzz coverage result alone is not conclusive at that failure rate. The ASAN one is: at the 1.75% that `main` fails there, 400 clean runs would happen by chance less than once in a thousand. The same ASAN build with asserts on aborts in the fuzzing phase in about 40% of runs on `main`, on asserts that this does not address: a `host_rewrite` that is not a valid header value (`aws_request_signing`), and an assert in `HttpPerRequestTapperImpl::onBody` (`tap`). The fuzz coverage job ignores failures of that phase. Risk Level: Low (test only) Testing: as above Docs Changes: N/A Release Notes: N/A Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 205e84d) Signed-off-by: Ryan Northey <[email protected]>
phlax
added a commit
that referenced
this pull request
Nov 20, 2026
…d keep its headers alive (#49398) Fixes a flake of the fuzz coverage job: `//test/extensions/filters/http/common/fuzz:filter_fuzz_test` occasionally dies with a SEGV while replaying the corpus, as in [this run](https://github.com/envoyproxy/envoy/actions/runs/44306995860/job/134811152021) of #49388, which passed on a retest. ### Cause The fuzzer (`UberFilterFuzzer`) is one static object, reused for every input, and it left state behind for the next one: - `reset()`, which calls `onDestroy()` and drops the filters, only ran when `fuzz()` got to its end. If it left early (the factory threw after adding a filter, or the filter did not finish) the filters stayed, and were destroyed without `onDestroy()` when a later input added its own. - The request headers that the decoder callbacks return were a local of the block that runs the decoder, so they were gone while the filter was still encoding, access logging, or completing work in the loop that waits for it. - What a filter had posted to the dispatcher was left to run during the next input, after the filter was gone. With ASAN this is a heap-use-after-free in `FileSystemBufferFilter::onStateChange()`, run from a callback that the filter posted, in an input after the one whose `reset()` freed the filter. The filter guards those callbacks with a flag set in `onDestroy()`, so this is a filter that was freed without `onDestroy()`: a test harness bug, not one in the filter. ### Fix Test only: the filters are destroyed however `fuzz()` returns, the headers live as long as the fuzzer, and the dispatcher is run once before the filters are dropped. ### Testing Runs of `filter_fuzz_test` with the fuzz coverage job's flow (fuzz for 60s, then replay the corpus, which only fails on a crash), in envoy-ci-staging: | Config | Code | Failures | | --- | --- | --- | | fuzz coverage | `main` (and the #49388 stack) | 4 of 600 (SEGV in the replay) | | fuzz coverage | this change | 0 of 400 | | ASAN, asserts off | `main` | 7 of 400, all the use-after-free above | | ASAN, asserts off | this change | 0 of 400 | The fuzz coverage result alone is not conclusive at that failure rate. The ASAN one is: at the 1.75% that `main` fails there, 400 clean runs would happen by chance less than once in a thousand. The same ASAN build with asserts on aborts in the fuzzing phase in about 40% of runs on `main`, on asserts that this does not address: a `host_rewrite` that is not a valid header value (`aws_request_signing`), and an assert in `HttpPerRequestTapperImpl::onBody` (`tap`). The fuzz coverage job ignores failures of that phase. Risk Level: Low (test only) Testing: as above Docs Changes: N/A Release Notes: N/A Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 205e84d) Signed-off-by: Ryan Northey <[email protected]>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes a flake of the fuzz coverage job:
//test/extensions/filters/http/common/fuzz:filter_fuzz_testoccasionally dies with a SEGV while replaying the corpus, as in this run of #49388, which passed on a retest.Cause
The fuzzer (
UberFilterFuzzer) is one static object, reused for every input, and it left state behind for the next one:reset(), which callsonDestroy()and drops the filters, only ran whenfuzz()got to its end. If it left early (the factory threw after adding a filter, or the filter did not finish) the filters stayed, and were destroyed withoutonDestroy()when a later input added its own.With ASAN this is a heap-use-after-free in
FileSystemBufferFilter::onStateChange(), run from a callback that the filter posted, in an input after the one whosereset()freed the filter. The filter guards those callbacks with a flag set inonDestroy(), so this is a filter that was freed withoutonDestroy(): a test harness bug, not one in the filter.Fix
Test only: the filters are destroyed however
fuzz()returns, the headers live as long as the fuzzer, and the dispatcher is run once before the filters are dropped.Testing
Runs of
filter_fuzz_testwith the fuzz coverage job's flow (fuzz for 60s, then replay the corpus, which only fails on a crash), in envoy-ci-staging:main(and the #49388 stack)mainThe fuzz coverage result alone is not conclusive at that failure rate. The ASAN one is: at the 1.75% that
mainfails there, 400 clean runs would happen by chance less than once in a thousand.The same ASAN build with asserts on aborts in the fuzzing phase in about 40% of runs on
main, on asserts that this does not address: ahost_rewritethat is not a valid header value (aws_request_signing), and an assert inHttpPerRequestTapperImpl::onBody(tap). The fuzz coverage job ignores failures of that phase.Risk Level: Low (test only)
Testing: as above
Docs Changes: N/A
Release Notes: N/A