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 disconnected. Fix this by only disconnecting the misbehaving CNode rather than every CNode sharing the IP.
net_processing: set fDisconnect instead of calling DisconnectNode #36894
pull Crypt-iQ wants to merge 1 commits into bitcoin:master from Crypt-iQ:2026-11/tor-disconnect-fix changing 3 files +5 −5-
Crypt-iQ commented at 6:58 PM on November 16, 2026: contributor
-
DrahtBot commented at 6:58 PM on November 16, 2026: contributor
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--006a51241073e994b41acfe9ec718e94-->
External sites
- Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36894
- Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36894.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36894#author-ralph
<!--021abf342d371248e50ceaed478a90ca-->
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste <code><!--meta-tag:bot-skip--></code> into the comment that the bot should ignore.
<!--5faf32d7da4f0f540f40219e4f7537a3-->
-
andrewtoth commented at 7:26 PM on November 16, 2026: contributor
There seems to be a prior attempt to do something similar #25257.
-
darosior commented at 7:47 PM on November 16, 2026: member
Concept ACK
-
ajtowns commented at 11:06 PM on November 16, 2026: contributor
ACK d698b75f8bd20a634f66b0307fd18b79ebbda9c0
Misbehaviour used to result in an address ban prior to #19219, but now it just optimises who gets disconnected when our connections are full; so I think disconnecting all peers on the same address used to be consistent behaviour but now is not.
- DrahtBot requested review from darosior on Nov 16, 2026
- fanquake added this to the milestone 33.0 on Nov 17, 2026
-
in src/net_processing.cpp:5404 in d698b75f8b outdated
5397 | @@ -5398,10 +5398,10 @@ bool PeerManagerImpl::MaybeDiscourageAndDisconnect(CNode& pnode, Peer& peer) 5398 | return true; 5399 | } 5400 | 5401 | - // Normal case: Disconnect the peer and discourage all nodes sharing the address 5402 | + // Normal case: Disconnect the peer only, but discourage all nodes sharing the address 5403 | LogDebug(BCLog::NET, "Disconnecting and discouraging peer %d!\n", peer.m_id); 5404 | if (m_banman) m_banman->Discourage(pnode.addr); 5405 | - m_connman.DisconnectNode(CSubNet{pnode.addr}, /*disconnect_private_broadcast=*/false);
mzumsande commented at 1:48 PM on November 17, 2026:looks like
disconnect_private_broadastis unused now and could be removed.
Crypt-iQ commented at 5:13 PM on November 17, 2026:thanks, fixed in d63068c58ec9fcc94876bce30865d1a7266d64d4
mzumsande commented at 1:49 PM on November 17, 2026: contributorConcept ACK
d63068c58enet_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.
Crypt-iQ force-pushed on Nov 17, 2026Crypt-iQ commented at 5:14 PM on November 17, 2026: contributord698b75f8bd20a634f66b0307fd18b79ebbda9c0 -> d63068c
removes the
disconnect_private_broadcastargument fromDisconnectNodeHusteem commented at 6:49 PM on November 17, 2026: noneDid well addressing earlier concerns.
Approach ACK / tACK d63068c
maflcko commented at 7:48 PM on November 17, 2026: memberlgtm ACK d63068c58ec9fcc94876bce30865d1a7266d64d4
Tested on my server with two addnode connections from a single IPv4.
If someone wants to test this with a unit test:
diff --git a/src/test/denialofservice_tests.cpp b/src/test/denialofservice_tests.cpp index a5e7c90..86c5271 100644 --- a/src/test/denialofservice_tests.cpp +++ b/src/test/denialofservice_tests.cpp @@ -402,3 +402,3 @@ BOOST_AUTO_TEST_CASE(peer_discouragement) /*addrNameIn=*/"", - /*conn_type_in=*/ConnectionType::PRIVATE_BROADCAST, + /*conn_type_in=*/ConnectionType::INBOUND, /*inbound_onion=*/false,DrahtBot requested review from ajtowns on Nov 17, 2026DrahtBot requested review from mzumsande on Nov 17, 2026darosior approveddarosior commented at 7:51 PM on November 17, 2026: memberutACK d63068c58ec9fcc94876bce30865d1a7266d64d4
ajtowns commented at 2:01 AM on November 18, 2026: contributorre utACK d63068c58ec9fcc94876bce30865d1a7266d64d4
fanquake merged this on Nov 18, 2026fanquake closed this on Nov 18, 2026fanquake referenced this in commit 5e9ce8a3e3 on Nov 18, 2026Crypt-iQ commented at 3:35 PM on November 18, 2026: contributorLeaving a note in case it interests anybody:
I haven't tested this, I think this change also prevents an attacker from disconnecting a normal A <-> B connection where A is running linux and the attacker knows they are connected:
- attacker sends ~4096 SYN packets to A to fill up the half-open queue
- A falls back to SYN cookies
- attacker sends ACK packets to A that guess the cookie value to try and forge another connection between A <-> B
- the ACK packets also contain in their data a version, verack, and invalid headers message (all in a single packet)
- A will accept the connection if the cookie value is correct (a 8 in 2^32 guess, the probability of guessing a cookie value is greater than guessing the ephemeral port number, a sequence number in the window, and an ack number in the window)
- if A processes the version, verack, and headers message before B can send a RST (if B does this, it depends), A will disconnect all CNode's matching B's IP including the honest, pre-existing A <-> B connection
fanquake referenced this in commit c6dbc0e480 on Nov 18, 2026fanquake referenced this in commit 35f34a31a6 on Nov 18, 2026Milestone
33.0
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-11-19 19:51 UTC
More mirrored repositories can be found on mirror.b10c.me