Fix data race on RspConnector lifetime - #1169
Open
xusheng6 wants to merge 2 commits into
Open
Conversation
m_rspConnector was a raw pointer with no synchronization on the read or the delete, so a call already in flight could use a freed connector. Wrap it in AtomicRspConnector, a mutex-guarded shared_ptr. Callers load a strong reference before use, and teardown just stores nullptr, so the connector is destroyed only when the last reference drops. Fixes #1074
Runs GdbAdapter::AddBreakpoint against GdbAdapter::Quit over a fake RSP server. Use-after-free on the first iteration before the fix, 25 iterations clean after. Refs #1074
Member
Author
|
@bdash would you please review this? I had a closer look at sentry, and it seems to me that it is still happening |
bdash
approved these changes
Aug 12, 2026
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.
Fixes #1074
m_rspConnectoris a raw pointer in the Gdb, Corellium and Esreven adapters, with nosynchronization on the read or the delete. A call already in flight can end up using a
freed connector. This is the top debugger crash cluster in Sentry (BINARYNINJA-4E, C1,
E1, E4, ...), which faults inside
mtx_do_lockwhile lockingm_socketLockon a deadconnector.
The existing null checks cannot fix this, because the pointer can be freed between the
check and the use.
Change
Wrap the field in
AtomicRspConnector, a mutex-guardedshared_ptr. Callers load astrong reference before use, and teardown just stores nullptr, so the connector is
destroyed only when the last reference drops.
This is 73e6517 from
fix-rspconnector-lifetime-race, rebased onto dev. One conflict inEsrevenAdapter::GetTTDCallsForSymbols, plus four places where the newer bare!m_rspConnectorguards were folded into theload()-then-check pattern.Testing
test/repro/adds an ASan driver that runsAddBreakpointagainstQuitover a fakeRSP server. Same harness and settings both sides:
The failing stack matches the Sentry reports: freed in
GdbAdapter::Quit, read fromAddBreakpoint->TransmitAndReceive->SendPayload->SendRaw.