Merge bitcoin/bitcoin#36894: net_processing: set fDisconnect instead of calling DisconnectNode
What changed, and why it matters
This change fixes a bug where Bitcoin Core would disconnect every peer sharing the same IP address when one peer misbehaved. The problem is especially bad for users connecting through Tor, because all Tor traffic exits through a small set of public 'exit nodes.' An attacker could use the same Tor exit node as honest users, send an invalid message, and get every honest inbound peer using that exit node kicked off. The fix makes the node disconnect only the specific misbehaving connection while still discouraging (reducing trust in) that IP address.
Apply the patch. Operators running listening nodes that accept inbound Tor connections should upgrade, as they are the primary targets of the described disconnection attack. No immediate workaround is described.
Security signals we found
Denial of service via shared IP disconnect
Tor exit-node IP collision exploited to disconnect honest peers
Peer-to-peer network isolation of inbound connections
Fix narrows disconnect scope from subnet to single CNode
Evidence from the diff
MaybeDiscourageAndDisconnect previously called CConnman::DisconnectNode(CSubNet{pnode.addr}, false), which matches and flags fDisconnect on every CNode whose address falls in the /32 subnet. For clearnet-over-Tor peers, multiple distinct peers share the exit relay’s IP, so one malicious peer could disconnect all inbound connections from that exit. The patch removes the subnet-disconnect path in this code path and instead sets pnode.fDisconnect = true on the offending CNode only. It also simplifies DisconnectNode(const CSubNet&, bool) by removing the now-unused disconnect_private_broadcast parameter.
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 68/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.