Skip to content

test/fuzz: Destroy the HTTP filter fuzzer's filters on every path, and keep its headers alive - #49398

Merged
phlax merged 1 commit into
envoyproxy:mainfrom
phlax:test-http-filter-fuzz-teardown
Nov 20, 2026
Merged

phlax merged 1 commit into
envoyproxy:mainfrom
phlax:test-http-filter-fuzz-teardown

Conversation

@phlax

@phlax phlax commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

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 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

…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]>
@repokitteh-read-only

Copy link
Copy Markdown

As a reminder, PRs marked as draft will not be automatically assigned reviewers,
or be handled by maintainer-oncall triage.

Please mark your PR as ready when you want it to be reviewed!

🐱

Caused by: #49398 was opened by phlax.

see: more, trace.

Copilot AI left a comment

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.

🔵 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 phlax changed the title [WIP] test/fuzz: Destroy the HTTP filter fuzzer's filters on every path, and keep its headers alive test/fuzz: Destroy the HTTP filter fuzzer's filters on every path, and keep its headers alive Nov 18, 2026
@phlax
phlax marked this pull request as ready for review November 18, 2026 16:16
@agrawroh agrawroh self-assigned this Nov 20, 2026
@phlax
phlax merged commit 205e84d into envoyproxy:main Nov 20, 2026
26 checks passed
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants