Skip to content

listener: fix use-after-free in filter_chain_benchmark_test at exit - #48757

Merged
jwendell merged 2 commits into
envoyproxy:mainfrom
wdauchy:fix-filter-chain-benchmark-gcc
Oct 27, 2026
Merged

jwendell merged 2 commits into
envoyproxy:mainfrom
wdauchy:fix-filter-chain-benchmark-gcc

Conversation

@wdauchy

@wdauchy wdauchy commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Commit Message: listener: fix use-after-free in filter_chain_benchmark_test at exit

Each FilterChainBenchmarkFixture held a Logger::Context, which reactivates the previous context on destruction. The benchmark library builds the fixtures at static initialization and destroys them at exit; with libstdc++ this happens in registration order, so the second fixture reactivates the first one's freed context. Under GCC this corrupts the heap and tcmalloc aborts with CHECK in BitmapPushBatch (libc++ destroys them in reverse order, so clang builds are unaffected).

The fixture context is redundant since test/benchmark/main.cc already installs one for the whole run. Remove it.

Additional Description:
The GCC job of Envoy/Checks fails after all benchmarks have run on PRs that invalidate this test's cache entry, e.g. #48470 (job) and #48449 (job). main looks green because its GCC runs take this result from the remote cache. The bug is old; whether it aborts depends on heap layout.

33302 external/tcmalloc+/tcmalloc/span.h:465] CHECK in BitmapPushBatch: small_span_state_.bitmap.GetBit(idx) == 0 (true == 0)
... Aborted (core dumped) ... --skip_expensive_benchmarks -- --benchmark_min_time=0s

Logger::Context lifetimes traced with gdb on the GCC build:

CTOR     ...7740  FilterChainBenchmarkFixture_FilterChainManagerBuildTest_Benchmark   (static init)
CTOR     ...7bc0  FilterChainBenchmarkFixture_FilterChainFindTest_Benchmark           (static init)
CTOR     ...fb80  main
DTOR     ...fb80  main                         -> ACTIVATE ...7bc0
DTOR     ...7740  ~..._FilterChainManagerBuildTest_Benchmark (unique_ptr, freed)
DTOR     ...7bc0  ~..._FilterChainFindTest_Benchmark          -> ACTIVATE ...7740 (freed)

Risk Level: Low. Test only.
Testing: bazel test --config=gcc --nocache_test_results //test/common/listener_manager:filter_chain_benchmark_test_benchmark_test in the envoy-build image (gcc 13.3.0): fails on main (5af8d91), passes 5/5 with this change.
Docs Changes: N/A
Release Notes: N/A
Platform Specific Features: N/A

AI assistance: prepared with AI assistance (Cursor agent). We reviewed and understand all of it.

The benchmark library creates the FilterChainBenchmarkFixture instances
during static initialization and destroys them at exit. Each fixture
held a Logger::Context, which saves a raw pointer to the context that
was current when it was built and reactivates it on destruction.

With libstdc++ the registered benchmarks are destroyed in registration
order, so the second fixture reactivates the context of the first one
after it was freed. Under the GCC build this corrupts the heap and
tcmalloc aborts at exit with "CHECK in BitmapPushBatch". libc++
destroys them in reverse order, which is why clang builds, including
the sanitizer ones, do not see it.

The fixture context is redundant: test/benchmark/main.cc installs a
logging context for the whole run. Remove it.

Signed-off-by: William Dauchy <[email protected]>
@jwendell
jwendell enabled auto-merge (squash) October 27, 2026 11:38
@jwendell
jwendell merged commit aedd2c4 into envoyproxy:main Oct 27, 2026
27 checks passed
jwendell pushed a commit that referenced this pull request Nov 12, 2026
…48757)

Commit Message: listener: fix use-after-free in
filter_chain_benchmark_test at exit

Each `FilterChainBenchmarkFixture` held a `Logger::Context`, which
reactivates the previous context on destruction. The benchmark library
builds the fixtures at static initialization and destroys them at exit;
with libstdc++ this happens in registration order, so the second fixture
reactivates the first one's freed context. Under GCC this corrupts the
heap and tcmalloc aborts with `CHECK in BitmapPushBatch` (libc++
destroys them in reverse order, so clang builds are unaffected).

The fixture context is redundant since `test/benchmark/main.cc` already
installs one for the whole run. Remove it.

Additional Description:
The GCC job of `Envoy/Checks` fails after all benchmarks have run on PRs
that invalidate this test's cache entry, e.g. #48470
([job](https://github.com/envoyproxy/envoy/actions/runs/40478692516/job/122125067805))
and #48449
([job](https://github.com/envoyproxy/envoy/actions/runs/40354667795/job/121684997303)).
main looks green because its GCC runs take this result from the remote
cache. The bug is old; whether it aborts depends on heap layout.

```
33302 external/tcmalloc+/tcmalloc/span.h:465] CHECK in BitmapPushBatch: small_span_state_.bitmap.GetBit(idx) == 0 (true == 0)
... Aborted (core dumped) ... --skip_expensive_benchmarks -- --benchmark_min_time=0s
```

`Logger::Context` lifetimes traced with gdb on the GCC build:

```
CTOR     ...7740  FilterChainBenchmarkFixture_FilterChainManagerBuildTest_Benchmark   (static init)
CTOR     ...7bc0  FilterChainBenchmarkFixture_FilterChainFindTest_Benchmark           (static init)
CTOR     ...fb80  main
DTOR     ...fb80  main                         -> ACTIVATE ...7bc0
DTOR     ...7740  ~..._FilterChainManagerBuildTest_Benchmark (unique_ptr, freed)
DTOR     ...7bc0  ~..._FilterChainFindTest_Benchmark          -> ACTIVATE ...7740 (freed)
```

Risk Level: Low. Test only.
Testing: `bazel test --config=gcc --nocache_test_results
//test/common/listener_manager:filter_chain_benchmark_test_benchmark_test`
in the `envoy-build` image (gcc 13.3.0): fails on main (5af8d91),
passes 5/5 with this change.
Docs Changes: N/A
Release Notes: N/A
Platform Specific Features: N/A

AI assistance: prepared with AI assistance (Cursor agent). We reviewed
and understand all of it.

---------

Signed-off-by: William Dauchy <[email protected]>
Signed-off-by: Ryan Northey <[email protected]>
phlax pushed a commit to phlax/envoy that referenced this pull request Nov 16, 2026
…nvoyproxy#48757)

Commit Message: listener: fix use-after-free in
filter_chain_benchmark_test at exit

Each `FilterChainBenchmarkFixture` held a `Logger::Context`, which
reactivates the previous context on destruction. The benchmark library
builds the fixtures at static initialization and destroys them at exit;
with libstdc++ this happens in registration order, so the second fixture
reactivates the first one's freed context. Under GCC this corrupts the
heap and tcmalloc aborts with `CHECK in BitmapPushBatch` (libc++
destroys them in reverse order, so clang builds are unaffected).

The fixture context is redundant since `test/benchmark/main.cc` already
installs one for the whole run. Remove it.

Additional Description:
The GCC job of `Envoy/Checks` fails after all benchmarks have run on PRs
that invalidate this test's cache entry, e.g. envoyproxy#48470
([job](https://github.com/envoyproxy/envoy/actions/runs/40478692516/job/122125067805))
and envoyproxy#48449
([job](https://github.com/envoyproxy/envoy/actions/runs/40354667795/job/121684997303)).
main looks green because its GCC runs take this result from the remote
cache. The bug is old; whether it aborts depends on heap layout.

```
33302 external/tcmalloc+/tcmalloc/span.h:465] CHECK in BitmapPushBatch: small_span_state_.bitmap.GetBit(idx) == 0 (true == 0)
... Aborted (core dumped) ... --skip_expensive_benchmarks -- --benchmark_min_time=0s
```

`Logger::Context` lifetimes traced with gdb on the GCC build:

```
CTOR     ...7740  FilterChainBenchmarkFixture_FilterChainManagerBuildTest_Benchmark   (static init)
CTOR     ...7bc0  FilterChainBenchmarkFixture_FilterChainFindTest_Benchmark           (static init)
CTOR     ...fb80  main
DTOR     ...fb80  main                         -> ACTIVATE ...7bc0
DTOR     ...7740  ~..._FilterChainManagerBuildTest_Benchmark (unique_ptr, freed)
DTOR     ...7bc0  ~..._FilterChainFindTest_Benchmark          -> ACTIVATE ...7740 (freed)
```

Risk Level: Low. Test only.
Testing: `bazel test --config=gcc --nocache_test_results
//test/common/listener_manager:filter_chain_benchmark_test_benchmark_test`
in the `envoy-build` image (gcc 13.3.0): fails on main (5af8d91),
passes 5/5 with this change.
Docs Changes: N/A
Release Notes: N/A
Platform Specific Features: N/A

AI assistance: prepared with AI assistance (Cursor agent). We reviewed
and understand all of it.

---------

Signed-off-by: William Dauchy <[email protected]>
(cherry picked from commit aedd2c4)
Signed-off-by: Ryan Northey <[email protected]>
phlax pushed a commit to phlax/envoy that referenced this pull request Nov 16, 2026
…nvoyproxy#48757)

Commit Message: listener: fix use-after-free in
filter_chain_benchmark_test at exit

Each `FilterChainBenchmarkFixture` held a `Logger::Context`, which
reactivates the previous context on destruction. The benchmark library
builds the fixtures at static initialization and destroys them at exit;
with libstdc++ this happens in registration order, so the second fixture
reactivates the first one's freed context. Under GCC this corrupts the
heap and tcmalloc aborts with `CHECK in BitmapPushBatch` (libc++
destroys them in reverse order, so clang builds are unaffected).

The fixture context is redundant since `test/benchmark/main.cc` already
installs one for the whole run. Remove it.

Additional Description:
The GCC job of `Envoy/Checks` fails after all benchmarks have run on PRs
that invalidate this test's cache entry, e.g. envoyproxy#48470
([job](https://github.com/envoyproxy/envoy/actions/runs/40478692516/job/122125067805))
and envoyproxy#48449
([job](https://github.com/envoyproxy/envoy/actions/runs/40354667795/job/121684997303)).
main looks green because its GCC runs take this result from the remote
cache. The bug is old; whether it aborts depends on heap layout.

```
33302 external/tcmalloc+/tcmalloc/span.h:465] CHECK in BitmapPushBatch: small_span_state_.bitmap.GetBit(idx) == 0 (true == 0)
... Aborted (core dumped) ... --skip_expensive_benchmarks -- --benchmark_min_time=0s
```

`Logger::Context` lifetimes traced with gdb on the GCC build:

```
CTOR     ...7740  FilterChainBenchmarkFixture_FilterChainManagerBuildTest_Benchmark   (static init)
CTOR     ...7bc0  FilterChainBenchmarkFixture_FilterChainFindTest_Benchmark           (static init)
CTOR     ...fb80  main
DTOR     ...fb80  main                         -> ACTIVATE ...7bc0
DTOR     ...7740  ~..._FilterChainManagerBuildTest_Benchmark (unique_ptr, freed)
DTOR     ...7bc0  ~..._FilterChainFindTest_Benchmark          -> ACTIVATE ...7740 (freed)
```

Risk Level: Low. Test only.
Testing: `bazel test --config=gcc --nocache_test_results
//test/common/listener_manager:filter_chain_benchmark_test_benchmark_test`
in the `envoy-build` image (gcc 13.3.0): fails on main (5af8d91),
passes 5/5 with this change.
Docs Changes: N/A
Release Notes: N/A
Platform Specific Features: N/A

AI assistance: prepared with AI assistance (Cursor agent). We reviewed
and understand all of it.

---------

Signed-off-by: William Dauchy <[email protected]>
(cherry picked from commit aedd2c4)
Signed-off-by: Ryan Northey <[email protected]>
phlax pushed a commit to phlax/envoy that referenced this pull request Nov 16, 2026
…nvoyproxy#48757)

Commit Message: listener: fix use-after-free in
filter_chain_benchmark_test at exit

Each `FilterChainBenchmarkFixture` held a `Logger::Context`, which
reactivates the previous context on destruction. The benchmark library
builds the fixtures at static initialization and destroys them at exit;
with libstdc++ this happens in registration order, so the second fixture
reactivates the first one's freed context. Under GCC this corrupts the
heap and tcmalloc aborts with `CHECK in BitmapPushBatch` (libc++
destroys them in reverse order, so clang builds are unaffected).

The fixture context is redundant since `test/benchmark/main.cc` already
installs one for the whole run. Remove it.

Additional Description:
The GCC job of `Envoy/Checks` fails after all benchmarks have run on PRs
that invalidate this test's cache entry, e.g. envoyproxy#48470
([job](https://github.com/envoyproxy/envoy/actions/runs/40478692516/job/122125067805))
and envoyproxy#48449
([job](https://github.com/envoyproxy/envoy/actions/runs/40354667795/job/121684997303)).
main looks green because its GCC runs take this result from the remote
cache. The bug is old; whether it aborts depends on heap layout.

```
33302 external/tcmalloc+/tcmalloc/span.h:465] CHECK in BitmapPushBatch: small_span_state_.bitmap.GetBit(idx) == 0 (true == 0)
... Aborted (core dumped) ... --skip_expensive_benchmarks -- --benchmark_min_time=0s
```

`Logger::Context` lifetimes traced with gdb on the GCC build:

```
CTOR     ...7740  FilterChainBenchmarkFixture_FilterChainManagerBuildTest_Benchmark   (static init)
CTOR     ...7bc0  FilterChainBenchmarkFixture_FilterChainFindTest_Benchmark           (static init)
CTOR     ...fb80  main
DTOR     ...fb80  main                         -> ACTIVATE ...7bc0
DTOR     ...7740  ~..._FilterChainManagerBuildTest_Benchmark (unique_ptr, freed)
DTOR     ...7bc0  ~..._FilterChainFindTest_Benchmark          -> ACTIVATE ...7740 (freed)
```

Risk Level: Low. Test only.
Testing: `bazel test --config=gcc --nocache_test_results
//test/common/listener_manager:filter_chain_benchmark_test_benchmark_test`
in the `envoy-build` image (gcc 13.3.0): fails on main (5af8d91),
passes 5/5 with this change.
Docs Changes: N/A
Release Notes: N/A
Platform Specific Features: N/A

AI assistance: prepared with AI assistance (Cursor agent). We reviewed
and understand all of it.

---------

Signed-off-by: William Dauchy <[email protected]>
(cherry picked from commit aedd2c4)
Signed-off-by: Ryan Northey <[email protected]>
phlax pushed a commit to phlax/envoy that referenced this pull request Nov 16, 2026
…nvoyproxy#48757)

Commit Message: listener: fix use-after-free in
filter_chain_benchmark_test at exit

Each `FilterChainBenchmarkFixture` held a `Logger::Context`, which
reactivates the previous context on destruction. The benchmark library
builds the fixtures at static initialization and destroys them at exit;
with libstdc++ this happens in registration order, so the second fixture
reactivates the first one's freed context. Under GCC this corrupts the
heap and tcmalloc aborts with `CHECK in BitmapPushBatch` (libc++
destroys them in reverse order, so clang builds are unaffected).

The fixture context is redundant since `test/benchmark/main.cc` already
installs one for the whole run. Remove it.

Additional Description:
The GCC job of `Envoy/Checks` fails after all benchmarks have run on PRs
that invalidate this test's cache entry, e.g. envoyproxy#48470
([job](https://github.com/envoyproxy/envoy/actions/runs/40478692516/job/122125067805))
and envoyproxy#48449
([job](https://github.com/envoyproxy/envoy/actions/runs/40354667795/job/121684997303)).
main looks green because its GCC runs take this result from the remote
cache. The bug is old; whether it aborts depends on heap layout.

```
33302 external/tcmalloc+/tcmalloc/span.h:465] CHECK in BitmapPushBatch: small_span_state_.bitmap.GetBit(idx) == 0 (true == 0)
... Aborted (core dumped) ... --skip_expensive_benchmarks -- --benchmark_min_time=0s
```

`Logger::Context` lifetimes traced with gdb on the GCC build:

```
CTOR     ...7740  FilterChainBenchmarkFixture_FilterChainManagerBuildTest_Benchmark   (static init)
CTOR     ...7bc0  FilterChainBenchmarkFixture_FilterChainFindTest_Benchmark           (static init)
CTOR     ...fb80  main
DTOR     ...fb80  main                         -> ACTIVATE ...7bc0
DTOR     ...7740  ~..._FilterChainManagerBuildTest_Benchmark (unique_ptr, freed)
DTOR     ...7bc0  ~..._FilterChainFindTest_Benchmark          -> ACTIVATE ...7740 (freed)
```

Risk Level: Low. Test only.
Testing: `bazel test --config=gcc --nocache_test_results
//test/common/listener_manager:filter_chain_benchmark_test_benchmark_test`
in the `envoy-build` image (gcc 13.3.0): fails on main (5af8d91),
passes 5/5 with this change.
Docs Changes: N/A
Release Notes: N/A
Platform Specific Features: N/A

AI assistance: prepared with AI assistance (Cursor agent). We reviewed
and understand all of it.

---------

Signed-off-by: William Dauchy <[email protected]>
(cherry picked from commit aedd2c4)
Signed-off-by: Ryan Northey <[email protected]>
phlax pushed a commit to phlax/envoy that referenced this pull request Nov 16, 2026
…nvoyproxy#48757)

Commit Message: listener: fix use-after-free in
filter_chain_benchmark_test at exit

Each `FilterChainBenchmarkFixture` held a `Logger::Context`, which
reactivates the previous context on destruction. The benchmark library
builds the fixtures at static initialization and destroys them at exit;
with libstdc++ this happens in registration order, so the second fixture
reactivates the first one's freed context. Under GCC this corrupts the
heap and tcmalloc aborts with `CHECK in BitmapPushBatch` (libc++
destroys them in reverse order, so clang builds are unaffected).

The fixture context is redundant since `test/benchmark/main.cc` already
installs one for the whole run. Remove it.

Additional Description:
The GCC job of `Envoy/Checks` fails after all benchmarks have run on PRs
that invalidate this test's cache entry, e.g. envoyproxy#48470
([job](https://github.com/envoyproxy/envoy/actions/runs/40478692516/job/122125067805))
and envoyproxy#48449
([job](https://github.com/envoyproxy/envoy/actions/runs/40354667795/job/121684997303)).
main looks green because its GCC runs take this result from the remote
cache. The bug is old; whether it aborts depends on heap layout.

```
33302 external/tcmalloc+/tcmalloc/span.h:465] CHECK in BitmapPushBatch: small_span_state_.bitmap.GetBit(idx) == 0 (true == 0)
... Aborted (core dumped) ... --skip_expensive_benchmarks -- --benchmark_min_time=0s
```

`Logger::Context` lifetimes traced with gdb on the GCC build:

```
CTOR     ...7740  FilterChainBenchmarkFixture_FilterChainManagerBuildTest_Benchmark   (static init)
CTOR     ...7bc0  FilterChainBenchmarkFixture_FilterChainFindTest_Benchmark           (static init)
CTOR     ...fb80  main
DTOR     ...fb80  main                         -> ACTIVATE ...7bc0
DTOR     ...7740  ~..._FilterChainManagerBuildTest_Benchmark (unique_ptr, freed)
DTOR     ...7bc0  ~..._FilterChainFindTest_Benchmark          -> ACTIVATE ...7740 (freed)
```

Risk Level: Low. Test only.
Testing: `bazel test --config=gcc --nocache_test_results
//test/common/listener_manager:filter_chain_benchmark_test_benchmark_test`
in the `envoy-build` image (gcc 13.3.0): fails on main (5af8d91),
passes 5/5 with this change.
Docs Changes: N/A
Release Notes: N/A
Platform Specific Features: N/A

AI assistance: prepared with AI assistance (Cursor agent). We reviewed
and understand all of it.

---------

Signed-off-by: William Dauchy <[email protected]>
(cherry picked from commit aedd2c4)
Signed-off-by: Ryan Northey <[email protected]>
phlax pushed a commit to phlax/envoy that referenced this pull request Nov 17, 2026
…nvoyproxy#48757)

Commit Message: listener: fix use-after-free in
filter_chain_benchmark_test at exit

Each `FilterChainBenchmarkFixture` held a `Logger::Context`, which
reactivates the previous context on destruction. The benchmark library
builds the fixtures at static initialization and destroys them at exit;
with libstdc++ this happens in registration order, so the second fixture
reactivates the first one's freed context. Under GCC this corrupts the
heap and tcmalloc aborts with `CHECK in BitmapPushBatch` (libc++
destroys them in reverse order, so clang builds are unaffected).

The fixture context is redundant since `test/benchmark/main.cc` already
installs one for the whole run. Remove it.

Additional Description:
The GCC job of `Envoy/Checks` fails after all benchmarks have run on PRs
that invalidate this test's cache entry, e.g. envoyproxy#48470
([job](https://github.com/envoyproxy/envoy/actions/runs/40478692516/job/122125067805))
and envoyproxy#48449
([job](https://github.com/envoyproxy/envoy/actions/runs/40354667795/job/121684997303)).
main looks green because its GCC runs take this result from the remote
cache. The bug is old; whether it aborts depends on heap layout.

```
33302 external/tcmalloc+/tcmalloc/span.h:465] CHECK in BitmapPushBatch: small_span_state_.bitmap.GetBit(idx) == 0 (true == 0)
... Aborted (core dumped) ... --skip_expensive_benchmarks -- --benchmark_min_time=0s
```

`Logger::Context` lifetimes traced with gdb on the GCC build:

```
CTOR     ...7740  FilterChainBenchmarkFixture_FilterChainManagerBuildTest_Benchmark   (static init)
CTOR     ...7bc0  FilterChainBenchmarkFixture_FilterChainFindTest_Benchmark           (static init)
CTOR     ...fb80  main
DTOR     ...fb80  main                         -> ACTIVATE ...7bc0
DTOR     ...7740  ~..._FilterChainManagerBuildTest_Benchmark (unique_ptr, freed)
DTOR     ...7bc0  ~..._FilterChainFindTest_Benchmark          -> ACTIVATE ...7740 (freed)
```

Risk Level: Low. Test only.
Testing: `bazel test --config=gcc --nocache_test_results
//test/common/listener_manager:filter_chain_benchmark_test_benchmark_test`
in the `envoy-build` image (gcc 13.3.0): fails on main (5af8d91),
passes 5/5 with this change.
Docs Changes: N/A
Release Notes: N/A
Platform Specific Features: N/A

AI assistance: prepared with AI assistance (Cursor agent). We reviewed
and understand all of it.

---------

Signed-off-by: William Dauchy <[email protected]>
(cherry picked from commit aedd2c4)
Signed-off-by: Ryan Northey <[email protected]>
phlax pushed a commit to phlax/envoy that referenced this pull request Nov 17, 2026
…nvoyproxy#48757)

Commit Message: listener: fix use-after-free in
filter_chain_benchmark_test at exit

Each `FilterChainBenchmarkFixture` held a `Logger::Context`, which
reactivates the previous context on destruction. The benchmark library
builds the fixtures at static initialization and destroys them at exit;
with libstdc++ this happens in registration order, so the second fixture
reactivates the first one's freed context. Under GCC this corrupts the
heap and tcmalloc aborts with `CHECK in BitmapPushBatch` (libc++
destroys them in reverse order, so clang builds are unaffected).

The fixture context is redundant since `test/benchmark/main.cc` already
installs one for the whole run. Remove it.

Additional Description:
The GCC job of `Envoy/Checks` fails after all benchmarks have run on PRs
that invalidate this test's cache entry, e.g. envoyproxy#48470
([job](https://github.com/envoyproxy/envoy/actions/runs/40478692516/job/122125067805))
and envoyproxy#48449
([job](https://github.com/envoyproxy/envoy/actions/runs/40354667795/job/121684997303)).
main looks green because its GCC runs take this result from the remote
cache. The bug is old; whether it aborts depends on heap layout.

```
33302 external/tcmalloc+/tcmalloc/span.h:465] CHECK in BitmapPushBatch: small_span_state_.bitmap.GetBit(idx) == 0 (true == 0)
... Aborted (core dumped) ... --skip_expensive_benchmarks -- --benchmark_min_time=0s
```

`Logger::Context` lifetimes traced with gdb on the GCC build:

```
CTOR     ...7740  FilterChainBenchmarkFixture_FilterChainManagerBuildTest_Benchmark   (static init)
CTOR     ...7bc0  FilterChainBenchmarkFixture_FilterChainFindTest_Benchmark           (static init)
CTOR     ...fb80  main
DTOR     ...fb80  main                         -> ACTIVATE ...7bc0
DTOR     ...7740  ~..._FilterChainManagerBuildTest_Benchmark (unique_ptr, freed)
DTOR     ...7bc0  ~..._FilterChainFindTest_Benchmark          -> ACTIVATE ...7740 (freed)
```

Risk Level: Low. Test only.
Testing: `bazel test --config=gcc --nocache_test_results
//test/common/listener_manager:filter_chain_benchmark_test_benchmark_test`
in the `envoy-build` image (gcc 13.3.0): fails on main (5af8d91),
passes 5/5 with this change.
Docs Changes: N/A
Release Notes: N/A
Platform Specific Features: N/A

AI assistance: prepared with AI assistance (Cursor agent). We reviewed
and understand all of it.

---------

Signed-off-by: William Dauchy <[email protected]>
(cherry picked from commit aedd2c4)
Signed-off-by: Ryan Northey <[email protected]>
phlax pushed a commit to phlax/envoy that referenced this pull request Nov 17, 2026
…nvoyproxy#48757)

Commit Message: listener: fix use-after-free in
filter_chain_benchmark_test at exit

Each `FilterChainBenchmarkFixture` held a `Logger::Context`, which
reactivates the previous context on destruction. The benchmark library
builds the fixtures at static initialization and destroys them at exit;
with libstdc++ this happens in registration order, so the second fixture
reactivates the first one's freed context. Under GCC this corrupts the
heap and tcmalloc aborts with `CHECK in BitmapPushBatch` (libc++
destroys them in reverse order, so clang builds are unaffected).

The fixture context is redundant since `test/benchmark/main.cc` already
installs one for the whole run. Remove it.

Additional Description:
The GCC job of `Envoy/Checks` fails after all benchmarks have run on PRs
that invalidate this test's cache entry, e.g. envoyproxy#48470
([job](https://github.com/envoyproxy/envoy/actions/runs/40478692516/job/122125067805))
and envoyproxy#48449
([job](https://github.com/envoyproxy/envoy/actions/runs/40354667795/job/121684997303)).
main looks green because its GCC runs take this result from the remote
cache. The bug is old; whether it aborts depends on heap layout.

```
33302 external/tcmalloc+/tcmalloc/span.h:465] CHECK in BitmapPushBatch: small_span_state_.bitmap.GetBit(idx) == 0 (true == 0)
... Aborted (core dumped) ... --skip_expensive_benchmarks -- --benchmark_min_time=0s
```

`Logger::Context` lifetimes traced with gdb on the GCC build:

```
CTOR     ...7740  FilterChainBenchmarkFixture_FilterChainManagerBuildTest_Benchmark   (static init)
CTOR     ...7bc0  FilterChainBenchmarkFixture_FilterChainFindTest_Benchmark           (static init)
CTOR     ...fb80  main
DTOR     ...fb80  main                         -> ACTIVATE ...7bc0
DTOR     ...7740  ~..._FilterChainManagerBuildTest_Benchmark (unique_ptr, freed)
DTOR     ...7bc0  ~..._FilterChainFindTest_Benchmark          -> ACTIVATE ...7740 (freed)
```

Risk Level: Low. Test only.
Testing: `bazel test --config=gcc --nocache_test_results
//test/common/listener_manager:filter_chain_benchmark_test_benchmark_test`
in the `envoy-build` image (gcc 13.3.0): fails on main (5af8d91),
passes 5/5 with this change.
Docs Changes: N/A
Release Notes: N/A
Platform Specific Features: N/A

AI assistance: prepared with AI assistance (Cursor agent). We reviewed
and understand all of it.

---------

Signed-off-by: William Dauchy <[email protected]>
(cherry picked from commit aedd2c4)
Signed-off-by: Ryan Northey <[email protected]>
phlax pushed a commit that referenced this pull request Nov 17, 2026
…48757)

Commit Message: listener: fix use-after-free in
filter_chain_benchmark_test at exit

Each `FilterChainBenchmarkFixture` held a `Logger::Context`, which
reactivates the previous context on destruction. The benchmark library
builds the fixtures at static initialization and destroys them at exit;
with libstdc++ this happens in registration order, so the second fixture
reactivates the first one's freed context. Under GCC this corrupts the
heap and tcmalloc aborts with `CHECK in BitmapPushBatch` (libc++
destroys them in reverse order, so clang builds are unaffected).

The fixture context is redundant since `test/benchmark/main.cc` already
installs one for the whole run. Remove it.

Additional Description:
The GCC job of `Envoy/Checks` fails after all benchmarks have run on PRs
that invalidate this test's cache entry, e.g. #48470
([job](https://github.com/envoyproxy/envoy/actions/runs/40478692516/job/122125067805))
and #48449
([job](https://github.com/envoyproxy/envoy/actions/runs/40354667795/job/121684997303)).
main looks green because its GCC runs take this result from the remote
cache. The bug is old; whether it aborts depends on heap layout.

```
33302 external/tcmalloc+/tcmalloc/span.h:465] CHECK in BitmapPushBatch: small_span_state_.bitmap.GetBit(idx) == 0 (true == 0)
... Aborted (core dumped) ... --skip_expensive_benchmarks -- --benchmark_min_time=0s
```

`Logger::Context` lifetimes traced with gdb on the GCC build:

```
CTOR     ...7740  FilterChainBenchmarkFixture_FilterChainManagerBuildTest_Benchmark   (static init)
CTOR     ...7bc0  FilterChainBenchmarkFixture_FilterChainFindTest_Benchmark           (static init)
CTOR     ...fb80  main
DTOR     ...fb80  main                         -> ACTIVATE ...7bc0
DTOR     ...7740  ~..._FilterChainManagerBuildTest_Benchmark (unique_ptr, freed)
DTOR     ...7bc0  ~..._FilterChainFindTest_Benchmark          -> ACTIVATE ...7740 (freed)
```

Risk Level: Low. Test only.
Testing: `bazel test --config=gcc --nocache_test_results
//test/common/listener_manager:filter_chain_benchmark_test_benchmark_test`
in the `envoy-build` image (gcc 13.3.0): fails on main (5af8d91),
passes 5/5 with this change.
Docs Changes: N/A
Release Notes: N/A
Platform Specific Features: N/A

AI assistance: prepared with AI assistance (Cursor agent). We reviewed
and understand all of it.

---------

Signed-off-by: William Dauchy <[email protected]>
(cherry picked from commit aedd2c4)
Signed-off-by: Ryan Northey <[email protected]>
phlax pushed a commit to phlax/envoy that referenced this pull request Nov 18, 2026
…nvoyproxy#48757)

Commit Message: listener: fix use-after-free in
filter_chain_benchmark_test at exit

Each `FilterChainBenchmarkFixture` held a `Logger::Context`, which
reactivates the previous context on destruction. The benchmark library
builds the fixtures at static initialization and destroys them at exit;
with libstdc++ this happens in registration order, so the second fixture
reactivates the first one's freed context. Under GCC this corrupts the
heap and tcmalloc aborts with `CHECK in BitmapPushBatch` (libc++
destroys them in reverse order, so clang builds are unaffected).

The fixture context is redundant since `test/benchmark/main.cc` already
installs one for the whole run. Remove it.

Additional Description:
The GCC job of `Envoy/Checks` fails after all benchmarks have run on PRs
that invalidate this test's cache entry, e.g. envoyproxy#48470
([job](https://github.com/envoyproxy/envoy/actions/runs/40478692516/job/122125067805))
and envoyproxy#48449
([job](https://github.com/envoyproxy/envoy/actions/runs/40354667795/job/121684997303)).
main looks green because its GCC runs take this result from the remote
cache. The bug is old; whether it aborts depends on heap layout.

```
33302 external/tcmalloc+/tcmalloc/span.h:465] CHECK in BitmapPushBatch: small_span_state_.bitmap.GetBit(idx) == 0 (true == 0)
... Aborted (core dumped) ... --skip_expensive_benchmarks -- --benchmark_min_time=0s
```

`Logger::Context` lifetimes traced with gdb on the GCC build:

```
CTOR     ...7740  FilterChainBenchmarkFixture_FilterChainManagerBuildTest_Benchmark   (static init)
CTOR     ...7bc0  FilterChainBenchmarkFixture_FilterChainFindTest_Benchmark           (static init)
CTOR     ...fb80  main
DTOR     ...fb80  main                         -> ACTIVATE ...7bc0
DTOR     ...7740  ~..._FilterChainManagerBuildTest_Benchmark (unique_ptr, freed)
DTOR     ...7bc0  ~..._FilterChainFindTest_Benchmark          -> ACTIVATE ...7740 (freed)
```

Risk Level: Low. Test only.
Testing: `bazel test --config=gcc --nocache_test_results
//test/common/listener_manager:filter_chain_benchmark_test_benchmark_test`
in the `envoy-build` image (gcc 13.3.0): fails on main (5af8d91),
passes 5/5 with this change.
Docs Changes: N/A
Release Notes: N/A
Platform Specific Features: N/A

AI assistance: prepared with AI assistance (Cursor agent). We reviewed
and understand all of it.

---------

Signed-off-by: William Dauchy <[email protected]>
(cherry picked from commit aedd2c4)
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.

2 participants