net_processing: set fDisconnect instead of calling DisconnectNode #36894

Manually merged
Crypt-iQ merged 1 commit from 2026-11/tor-disconnect-fix into master 2026-11-18 10:20:56 +00:00 AGit
Crypt-iQ commented 2026-11-16 18:58:45 +00:00 (Migrated from github.com)

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.

`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.
DrahtBot commented 2026-11-16 18:58:53 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK maflcko, darosior, ajtowns
Concept ACK mzumsande
Approach ACK Husteem

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

<!--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](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [maflcko](https://github.com/bitcoin/bitcoin/pull/36894#issuecomment-6959082706), [darosior](https://github.com/bitcoin/bitcoin/pull/36894#pullrequestreview-5945500559), [ajtowns](https://github.com/bitcoin/bitcoin/pull/36894#issuecomment-6966748632) | | Concept ACK | [mzumsande](https://github.com/bitcoin/bitcoin/pull/36894#pullrequestreview-5939629215) | | Approach ACK | [Husteem](https://github.com/bitcoin/bitcoin/pull/36894#issuecomment-6957628290) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--5faf32d7da4f0f540f40219e4f7537a3-->
First-time contributor

🔵 Suggestion · peer_discouragement misses ordinary same-IP sibling coverage

The existing assertions would not detect restoring the old address-wide disconnect with its private-broadcast exclusion, leaving the PR's main behavior change unguarded.

Location: src/net_processing.cpp:5404 (head).

Review coverage was incomplete.


Reviewed: d63068c58ec9 · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:2b20819f882b885f79f242c01722f54f2a55e27dcfa7d5e13701b4a0b5214248:c39fdacfa3b84799844a5e841c04997e3cd1142653dfad8e36dbb07c4b1e684b --> <!-- ralph-base:e211dd0186e9646167d063a16f0da88e5f72e05f --> <!-- ralph-head:d63068c58ec9fcc94876bce30865d1a7266d64d4 --> <!-- ralph-case:df1bb78bfceceee65bff24249da8c7166481b4e44b26abdf7dbd01515b8699a7 --> **🔵 Suggestion · `peer_discouragement` misses ordinary same-IP sibling coverage** The existing assertions would not detect restoring the old address-wide disconnect with its private-broadcast exclusion, leaving the PR's main behavior change unguarded. Location: [`src/net_processing.cpp:5404`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/d63068c58ec9fcc94876bce30865d1a7266d64d4/src/net_processing.cpp#L5404>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`d63068c58ec9`](<https://git.fish.foo/bitcoin/bitcoin/commit/d63068c58ec9fcc94876bce30865d1a7266d64d4>) · [Review report](<https://review.fish.foo/report/36894-d63068c58ec9fcc94876bce30865d1a7266d64d4-2763-2.html>) · [Previous reports](<https://review.fish.foo/traces/36894/>) [permalink](<https://review.fish.foo/report/36894-d63068c58ec9fcc94876bce30865d1a7266d64d4-2763-2.html>)
andrewtoth commented 2026-11-16 19:26:19 +00:00 (Migrated from github.com)
There seems to be a prior attempt to do something similar https://github.com/bitcoin/bitcoin/pull/25257.
darosior (Migrated from github.com) reviewed 2026-11-16 19:47:28 +00:00
darosior (Migrated from github.com) left a comment

Concept ACK

Concept ACK
ajtowns commented 2026-11-16 23:06:31 +00:00 (Migrated from github.com)

ACK d698b75f8b

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.

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.
mzumsande (Migrated from github.com) reviewed 2026-11-17 13:49:01 +00:00
mzumsande (Migrated from github.com) left a comment

Concept ACK

Concept ACK
mzumsande (Migrated from github.com) commented 2026-11-17 13:48:42 +00:00

looks like disconnect_private_broadast is unused now and could be removed.

looks like `disconnect_private_broadast` is unused now and could be removed.
Crypt-iQ (Migrated from github.com) reviewed 2026-11-17 17:13:41 +00:00
Crypt-iQ (Migrated from github.com) commented 2026-11-17 17:13:41 +00:00

thanks, fixed in d63068c58e

thanks, fixed in d63068c58ec9fcc94876bce30865d1a7266d64d4
Crypt-iQ commented 2026-11-17 17:14:25 +00:00 (Migrated from github.com)

d698b75f8b -> d63068c

removes the disconnect_private_broadcast argument from DisconnectNode

d698b75f8bd20a634f66b0307fd18b79ebbda9c0 -> d63068c removes the `disconnect_private_broadcast` argument from `DisconnectNode`
Husteem commented 2026-11-17 18:49:05 +00:00 (Migrated from github.com)

Did well addressing earlier concerns.

Approach ACK / tACK d63068c

Did well addressing earlier concerns. Approach ACK / tACK d63068c
maflcko commented 2026-11-17 19:48:45 +00:00 (Migrated from github.com)

lgtm ACK d63068c58e

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,
lgtm 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 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,
darosior (Migrated from github.com) approved these changes 2026-11-17 19:51:37 +00:00
darosior (Migrated from github.com) left a comment

utACK d63068c58e

utACK d63068c58ec9fcc94876bce30865d1a7266d64d4
ajtowns commented 2026-11-18 02:01:45 +00:00 (Migrated from github.com)

re utACK d63068c58e

re utACK d63068c58ec9fcc94876bce30865d1a7266d64d4
fanquake commented 2026-11-18 11:59:23 +00:00 (Migrated from github.com)

Backported to 32.x in #36727.

Backported to `32.x` in #36727.
Crypt-iQ commented 2026-11-18 15:35:02 +00:00 (Migrated from github.com)

Leaving 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
Leaving 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
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36894
No description provided.