net: fix use-after-free with v2->v1 reconnection logic

CConnman::Stop() resets semOutbound, yet m_reconnections is not
cleared in Stop. Each ReconnectionInfo contains a grant member
that points to the memory that semOutbound pointed to and ~CConnman
will attempt to access the grant field (memory that was already
freed) when destroying m_reconnections. Fix this by calling
m_reconnections.clear() in CConnman::Stop() and add appropriate
annotations.
This commit is contained in:
Eugene Siegel committed 2025-11-26 15:51:51 -05:00
1 parent 85d058dc53
commit 167df7a98c
2 files changed
+6 -2

No files matched your search

+3
View File
@@ -3483,6 +3483,8 @@ void CConnman::StopThreads()
void CConnman::StopNodes() void CConnman::StopNodes()
{ {
AssertLockNotHeld(m_reconnections_mutex);
if (fAddressesInitialized) { if (fAddressesInitialized) {
DumpAddresses(); DumpAddresses();
fAddressesInitialized = false; fAddressesInitialized = false;
@@ -3510,6 +3512,7 @@ void CConnman::StopNodes()
DeleteNode(pnode); DeleteNode(pnode);
} }
m_nodes_disconnected.clear(); m_nodes_disconnected.clear();
WITH_LOCK(m_reconnections_mutex, m_reconnections.clear());
vhListenSocket.clear(); vhListenSocket.clear();
semOutbound.reset(); semOutbound.reset();
semAddnode.reset(); semAddnode.reset();
+3 -2
View File
@@ -1138,9 +1138,10 @@ public:
bool Start(CScheduler& scheduler, const Options& options) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex, !m_added_nodes_mutex, !m_addr_fetches_mutex, !mutexMsgProc); bool Start(CScheduler& scheduler, const Options& options) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex, !m_added_nodes_mutex, !m_addr_fetches_mutex, !mutexMsgProc);
void StopThreads(); void StopThreads();
void StopNodes(); void StopNodes() EXCLUSIVE_LOCKS_REQUIRED(!m_reconnections_mutex);
void Stop() void Stop() EXCLUSIVE_LOCKS_REQUIRED(!m_reconnections_mutex)
{ {
AssertLockNotHeld(m_reconnections_mutex);
StopThreads(); StopThreads();
StopNodes(); StopNodes();
}; };