Skip to content

Commit 35f34a3

Browse files
Crypt-iQfanquake
authored andcommitted
net_processing: set fDisconnect instead of calling DisconnectNode
MaybeDiscourageAndDisconnect calls DisconnectNode which creates a CSubNet containing only the CNode's address. This will disconnect every CNode with the same IP address. This is normally not a problem, except for clearnet-over-tor. If a node has an honest clearnet-over-tor inbound connection, the IP of the inbound peer will be the exit node's IP address. If an attacker connects to the node through the same exit node and sends an invalid message, they can cause every inbound peer sharing the exit node's IP to get disconnect. Fix this by only disconnecting the misbehaving CNode rather than every CNode sharing the IP. Github-Pull: #36894 Rebased-From: d63068c
1 parent 1a38585 commit 35f34a3

3 files changed

Lines changed: 5 additions & 5 deletions

File tree

‎src/net.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3867,12 +3867,12 @@ bool CConnman::DisconnectNode(std::string_view strNode)
38673867
return false;
38683868
}
38693869

3870-
bool CConnman::DisconnectNode(const CSubNet& subnet, bool disconnect_private_broadcast)
3870+
bool CConnman::DisconnectNode(const CSubNet& subnet)
38713871
{
38723872
bool disconnected = false;
38733873
LOCK(m_nodes_mutex);
38743874
for (CNode* pnode : m_nodes) {
3875-
if (subnet.Match(pnode->addr) && (disconnect_private_broadcast || !pnode->IsPrivateBroadcastConn())) {
3875+
if (subnet.Match(pnode->addr)) {
38763876
LogDebug(BCLog::NET, "disconnect by subnet%s match, %s", (fLogIPs ? strprintf("=%s", subnet.ToString()) : ""), pnode->DisconnectMsg(fLogIPs));
38773877
pnode->fDisconnect = true;
38783878
disconnected = true;

‎src/net.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ class CConnman
13641364
uint32_t GetMappedAS(const CNetAddr& addr) const;
13651365
void GetNodeStats(std::vector<CNodeStats>& vstats) const;
13661366
bool DisconnectNode(std::string_view node);
1367-
bool DisconnectNode(const CSubNet& subnet, bool disconnect_private_broadcast = true);
1367+
bool DisconnectNode(const CSubNet& subnet);
13681368
bool DisconnectNode(const CNetAddr& addr);
13691369
bool DisconnectNode(NodeId id);
13701370

‎src/net_processing.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5224,10 +5224,10 @@ bool PeerManagerImpl::MaybeDiscourageAndDisconnect(CNode& pnode, Peer& peer)
52245224
return true;
52255225
}
52265226

5227-
// Normal case: Disconnect the peer and discourage all nodes sharing the address
5227+
// Normal case: Disconnect the peer only, but discourage all nodes sharing the address
52285228
LogDebug(BCLog::NET, "Disconnecting and discouraging peer %d!\n", peer.m_id);
52295229
if (m_banman) m_banman->Discourage(pnode.addr);
5230-
m_connman.DisconnectNode(CSubNet{pnode.addr}, /*disconnect_private_broadcast=*/false);
5230+
pnode.fDisconnect = true;
52315231
return true;
52325232
}
52335233

0 commit comments

Comments
 (0)