Skip to content

test: fix use-after-free in fake upstream#14067

Merged
yanavlasov merged 4 commits intoenvoyproxy:masterfrom
akonradi:fake-upstream-msan-fix
Nov 23, 2020
Merged

test: fix use-after-free in fake upstream#14067
yanavlasov merged 4 commits intoenvoyproxy:masterfrom
akonradi:fake-upstream-msan-fix

Conversation

@akonradi
Copy link
Contributor

Commit Message: Fix a test-only use-after-free that causes flakes of //test/integration:tcp_tunneling_integration_test.
Additional Description:
The bug causes rare flakes of tcp_tunneling_integration_test, on the order of 0.5-1% under msan. The ReadFilter gets registered with the connection but shouldn't call into its parent after the parent has been deleted. This is done by using a weak_ptr proxy to the parent.

Risk Level: low
Testing: ran affected test
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: n/a

Fix a use-after-free that causes rare (1%) flakes of
//test/integration:tcp_tunneling_integration_test.

The ReadFilter gets registered with the connection but shouldn't call
into its parent after the parent has been deleted. This can be done by
using a weak_ptr proxy to the parent.

Signed-off-by: Alex Konradi <akonradi@google.com>
@akonradi akonradi changed the title [test] fix use-after-free in fake upstream test: fix use-after-free in fake upstream Nov 18, 2020
@yanavlasov
Copy link
Contributor

Seems like some clean-up order issue. I would think that FakeConnection should always be destroyed before the Network::Connection

@akonradi
Copy link
Contributor Author

That's exactly the issue. FakeRawConnection gets destroyed before the ReadFilter object it registers with the Network::Connection, resulting in the use-after-free

@yanavlasov
Copy link
Contributor

That's exactly the issue. FakeRawConnection gets destroyed before the ReadFilter object it registers with the Network::Connection, resulting in the use-after-free

Can't the FakeRawConnection call removeReadFilter before it is destroyed? I would rather figure lifecycle management of these objects that create a shared_ptr to this as it is super hacky.

Signed-off-by: Alex Konradi <akonradi@google.com>
@akonradi
Copy link
Contributor Author

Thanks, didn't know that was a thing. That's a whole lot cleaner than the weak proxy.

Signed-off-by: Alex Konradi <akonradi@google.com>
yanavlasov
yanavlasov previously approved these changes Nov 20, 2020
@akonradi
Copy link
Contributor Author

It looks like there were some asan and tsan failures in a different test, though related to this change. I'm currently debugging.

This allows the SharedConnectionWrapper to be delted first or second. If
the wrapper is deleted first, the read filter will be deleted and the
FakeHttpConnection will not attempt to remove it. If the
FakeHttpConnection is deleted first, it will remove the filter from the
SharedConnectionWrapper, preventing the original use-after-free.

Signed-off-by: Alex Konradi <akonradi@google.com>
@akonradi
Copy link
Contributor Author

Okay, fixed the failures with a different weak_ptr. This is much less weird than the originally proposed change.

@yanavlasov yanavlasov merged commit 7bea2d2 into envoyproxy:master Nov 23, 2020
@akonradi akonradi deleted the fake-upstream-msan-fix branch November 23, 2020 21:07
qqustc pushed a commit to qqustc/envoy that referenced this pull request Nov 24, 2020
Fix a test-only use-after-free that causes flakes of //test/integration:tcp_tunneling_integration_test.

Signed-off-by: Alex Konradi <akonradi@google.com>
Signed-off-by: Qin Qin <qqin@google.com>
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