Fix UAF in SSLTest.connect_on_create#3311
Merged
Merged
Conversation
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.
What problem does this PR solve?
Issue Number: resolve
Problem Summary:
SSLTest.ssl_sni(and any case that runs afterSSLTest.connect_on_create)can crash with
SIGSEGV:https://github.com/chenBright/brpc/actions/runs/26140916096/job/76886067647
The main test thread is still preparing
ssl_sni(executingGetRawPemString("cert2.crt")), while the backgroundEventDispatcherthread is dispatching an EPOLL event for a leftover socket from the
previous case
connect_on_create.Root cause:
connect_on_createstores the address of a stack-allocatedbrpc::InputMessenger messenger;insocket_options.userand then callsSocket::Create(...)but never closes the resulting client socket. Whenthe test function returns:
messengeris destroyed, but the socket's_userpointer stillreferences its now-invalid storage.
serveris destroyed, causing the server side of the SSL connection tobe torn down, which delivers
EPOLLHUP/EPOLLERRto the client fd.EventDispatcher, soSocket::OnOutputEventis invoked. There,dynamic_cast<EpollOutRequest*>(s->user())reads the vtable of thedestroyed
messengerand segfaults.The crash is therefore a use-after-free on
socket_options.user, exposedas a flake in subsequent SSL test cases.
What is changed and the side effects?
Changed:
test/brpc_ssl_unittest.cpp: at the end ofSSLTest.connect_on_create, explicitly close the client socket viaptr->SetFailed()(which unregisters the fd from theEventDispatcherand schedules the socket for recycling) and thenStop/Jointhe server, matching the cleanup pattern used by everyother
SSLTestcase.Side effects:
Performance effects:
Breaking backward compatibility:
Check List: