net_processing: set fDisconnect instead of calling DisconnectNode
What changed, and why it matters
This commit fixes a bug where Bitcoin Core would disconnect every peer sharing the same IP address when one of them misbehaved. Because Tor exit nodes share a single IP address among many users, a malicious user could deliberately misbehave and force the node to disconnect innocent users arriving through the same Tor exit. The fix makes the node disconnect only the specific misbehaving peer instead of all peers with that IP.
Apply the patch. Operators running nodes that accept inbound Tor connections should upgrade to avoid the clearnet-over-Tor disconnect issue. No immediate incident response is required beyond normal patching.
Security signals we found
Denial-of-service via shared IP disconnect
Tor exit-node IP collision exploited to disconnect honest peers
Peer-disconnection logic changed from subnet match to single-node flag
Evidence from the diff
MaybeDiscourageAndDisconnect previously called CConnman::DisconnectNode(CSubNet{pnode.addr}, false), which iterates all connected CNode objects and sets fDisconnect on every node whose address matches the /32 subnet. For clearnet-over-Tor inbound peers, multiple distinct peers can legitimately share the same Tor exit-node IP. An attacker connecting through the same exit node could trigger this path (e.g., by sending an invalid message) and disconnect all other inbound peers sharing that exit IP. The patch removes the subnet-based disconnect and instead sets pnode.fDisconnect = true on the offending node only, while still discouraging the address via BanMan. It also simplifies DisconnectNode(const CSubNet&) by removing the disconnect_private_broadcast parameter, which is no longer used.
Changed components
src/net.cppsrc/net.hsrc/net_processing.cppCConnman::DisconnectNodePeerManagerImpl::MaybeDiscourageAndDisconnectInspect captured patch +5 / −5
### src/net.cpp
@@ -4001,13 +4001,13 @@ bool CConnman::DisconnectNode(std::string_view strNode)
return false;
}
-bool CConnman::DisconnectNode(const CSubNet& subnet, bool disconnect_private_broadcast)
+bool CConnman::DisconnectNode(const CSubNet& subnet)
{
AssertLockNotHeld(m_nodes_mutex);
bool disconnected = false;
LOCK(m_nodes_mutex);
for (CNode* pnode : m_nodes) {
- if (subnet.Match(pnode->addr) && (disconnect_private_broadcast || !pnode->IsPrivateBroadcastConn())) {
+ if (subnet.Match(pnode->addr)) {
LogDebug(BCLog::NET, "disconnect by subnet%s match, %s", (fLogIPs ? strprintf("=%s", subnet.ToString()) : ""), pnode->DisconnectMsg());
pnode->fDisconnect = true;
disconnected = true;
### src/net.h
@@ -1391,7 +1391,7 @@ class CConnman
uint32_t GetMappedAS(const CNetAddr& addr) const;
void GetNodeStats(std::vector<CNodeStats>& vstats) const EXCLUSIVE_LOCKS_REQUIRED(!m_nodes_mutex);
bool DisconnectNode(std::string_view node) EXCLUSIVE_LOCKS_REQUIRED(!m_nodes_mutex);
- bool DisconnectNode(const CSubNet& subnet, bool disconnect_private_broadcast = true) EXCLUSIVE_LOCKS_REQUIRED(!m_nodes_mutex);
+ bool DisconnectNode(const CSubNet& subnet) EXCLUSIVE_LOCKS_REQUIRED(!m_nodes_mutex);
bool DisconnectNode(const CNetAddr& addr) EXCLUSIVE_LOCKS_REQUIRED(!m_nodes_mutex);
bool DisconnectNode(NodeId id) EXCLUSIVE_LOCKS_REQUIRED(!m_nodes_mutex);
### src/net_processing.cpp
@@ -5398,10 +5398,10 @@ bool PeerManagerImpl::MaybeDiscourageAndDisconnect(CNode& pnode, Peer& peer)
return true;
}
- // Normal case: Disconnect the peer and discourage all nodes sharing the address
+ // Normal case: Disconnect the peer only, but discourage all nodes sharing the address
LogDebug(BCLog::NET, "Disconnecting and discouraging peer %d!\n", peer.m_id);
if (m_banman) m_banman->Discourage(pnode.addr);
- m_connman.DisconnectNode(CSubNet{pnode.addr}, /*disconnect_private_broadcast=*/false);
+ pnode.fDisconnect = true;
return true;
}
Why this scored 62/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.