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
  1. Crypt-iQ commented at 6:58 PM on November 16, 2026: contributor

    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.

  2. 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

    <!--021abf342d371248e50ceaed478a90ca-->

    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 <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  3. andrewtoth commented at 7:26 PM on November 16, 2026: contributor

    There seems to be a prior attempt to do something similar #25257.

  4. darosior commented at 7:47 PM on November 16, 2026: member

    Concept ACK

  5. 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.

  6. DrahtBot requested review from darosior on Nov 16, 2026
  7. fanquake added this to the milestone 33.0 on Nov 17, 2026
  8. 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_broadast is unused now and could be removed.


    Crypt-iQ commented at 5:13 PM on November 17, 2026:

    thanks, fixed in d63068c58ec9fcc94876bce30865d1a7266d64d4

  9. mzumsande commented at 1:49 PM on November 17, 2026: contributor

    Concept ACK

  10. 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.
    d63068c58e
  11. Crypt-iQ force-pushed on Nov 17, 2026
  12. Crypt-iQ commented at 5:14 PM on November 17, 2026: contributor

    d698b75f8bd20a634f66b0307fd18b79ebbda9c0 -> d63068c

    removes the disconnect_private_broadcast argument from DisconnectNode

  13. Husteem commented at 6:49 PM on November 17, 2026: none

    Did well addressing earlier concerns.

    Approach ACK / tACK d63068c

  14. maflcko commented at 7:48 PM on November 17, 2026: member

    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 --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,
    
  15. DrahtBot requested review from ajtowns on Nov 17, 2026
  16. DrahtBot requested review from mzumsande on Nov 17, 2026
  17. darosior approved
  18. darosior commented at 7:51 PM on November 17, 2026: member

    utACK d63068c58ec9fcc94876bce30865d1a7266d64d4

  19. ajtowns commented at 2:01 AM on November 18, 2026: contributor

    re utACK d63068c58ec9fcc94876bce30865d1a7266d64d4

  20. fanquake merged this on Nov 18, 2026
  21. fanquake closed this on Nov 18, 2026

  22. fanquake referenced this in commit 5e9ce8a3e3 on Nov 18, 2026
  23. fanquake commented at 11:59 AM on November 18, 2026: member

    Backported to 32.x in #36727.

  24. Crypt-iQ commented at 3:35 PM on November 18, 2026: contributor

    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
  25. fanquake referenced this in commit c6dbc0e480 on Nov 18, 2026
  26. fanquake referenced this in commit 35f34a31a6 on Nov 18, 2026
  27. fanquake commented at 4:55 PM on November 18, 2026: member

    Backported to 31.x in #36901.


github-metadata-mirror

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

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me