Skip to content
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

Cleanup before freeing FakeStream to prevent use-after-free #38509

Merged
merged 1 commit into from
Feb 21, 2025

Conversation

krinkinmu
Copy link
Contributor

Commit Message:

In SendGoAwayNotTriggerredByDecodingFilter it could happen that FakeStream will get destroyed (when the test ends) before FakeUpstream dispatcher thread (FakeUpstream::threadRoutine()) exits or before all processing on the connection is complete.

That leads to a situation when FakeUpstream dispatcher thread may try to call into the FakeStream::onResetStream when connection established by the test gets terminated after FakeStream was already destroyed.

This triggers MSAN issue on clang-18 pretty consistently, though I don't think it's deterministic and could potentially happen on clang-14 currently used by Envoy CIs.

This change makes sure that we do cleanup before exiting the test, thus preventing the use-after-free issue.

Additional Description:

Related to #37911 and fixes one of the issues that block clang-18 adoption in Envoy CI.

Risk Level: low
Testing: do_ci.sh msan using Envoy CI image with clang-18
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: n/a

In SendGoAwayNotTriggerredByDecodingFilter it could happen that
FakeStream will get destroyed (when the test ends) before FakeUpstream
dispatcher thread (FakeUpstream::threadRoutine()) exits or before all
processing on the connection is complete.

That leads to a situation when FakeUpstream dispatcher thread may try to
call into the FakeStream::onResetStream when connection established by
the test gets terminated *after* FakeStream was already destroyed.

This triggers MSAN issue on clang-18 pretty consistently, though I don't
think it's deterministic and could potentially happen on clang-14
currently used by Envoy CIs.

This change makes sure that we do cleanup before exiting the test, thus
preventing the use-after-free issue.

Signed-off-by: Mikhail Krinkin <mkrinkin@microsoft.com>
Copy link
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@adisuissa adisuissa merged commit 652f256 into envoyproxy:main Feb 21, 2025
24 checks passed
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