AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Moderate 62 Bitcoin

Merge bitcoin/bitcoin#36305: net: Use exclusive P2P listen sockets on Windows

Public commit record

What the developer wrote

Authored by Hennadii Stepanov

100/100 · Strong
Merge bitcoin/bitcoin#36305: net: Use exclusive P2P listen sockets on Windows

db31a3ad1f75538d07707d373adbfbe90ba8e328 test: check P2P listen port exclusivity (winterrdog)
0dbd271eb4a3263b8b81ccf22876429076bae574 net: use exclusive P2P listen sockets on Windows (winterrdog)

Pull request description:

on Windows, `SO_REUSEADDR` does not carry over the same semantics as on
POSIX systems. a second socket can set `SO_REUSEADDR` and bind to a
port that is _already in use_ by another process running under
the _same_ user account. this means another local process could bind to
the P2P listen port and receive incoming connections intended for
`bitcoind`.

this matters because the P2P listener is expected to have exclusive
ownership of its address and port. allowing another process to bind to
it could let that process _intercept_ incoming P2P connections. this is
in a similar spirit to #36169, which made the RPC listener exclusive on
Windows.

to fix this, we use `SO_EXCLUSIVEADDRUSE` for the P2P listen socket on
Windows instead of `SO_REUSEADDR`, while retaining `SO_REUSEADDR` on
other platforms. the added test verifies the expected behaviour by
attempting to bind a second socket to the same port. on Windows, this
fails with `WSAEACCES` (`10013`), which Python exposes as
`PermissionError` (an `OSError` subclass).

references:

- https://learn.microsoft.com/en-us/windows/win32/winsock/using-so-reuseaddr-and-so-exclusiveaddruse
- https://stackoverflow.com/questions/14388706/how-do-so-reuseaddr-and-so-reuseport-differ/14388707#14388707

ACKs for top commit:
jpk68:
ACK db31a3ad1f75538d07707d373adbfbe90ba8e328
hodlinator:
re-ACK db31a3ad1f75538d07707d373adbfbe90ba8e328
hebasto:
ACK db31a3ad1f75538d07707d373adbfbe90ba8e328.

Tree-SHA512: cc73358bb4f1ecaf7246a8803e50ef8b5139bb348094a55dd2d5deb7d4a8d9082a028f342d6dc63d731a441c393739ed41c1039022a7463080830d83e978d34b
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference
The short version

What changed, and why it matters

This change fixes a Windows-specific networking issue in Bitcoin Core. Previously, another program running on the same Windows computer under the same user account could hijack Bitcoin's peer-to-peer network port, potentially intercepting incoming connections meant for the Bitcoin node. The fix makes the listening socket exclusive on Windows, similar to a change already made for the RPC port. Other operating systems are unaffected because their behavior was already safe.

Recommended action

No immediate user action is required beyond upgrading to a release containing this fix. Windows node operators who rely on rapid restart during TIME_WAIT may notice slightly stricter port binding behavior, but this is the intended security improvement. Review whether any custom scripts or local services attempt to reuse bitcoind's P2P port and adjust them if necessary.

Security signals we found

01

Local port hijacking / connection interception on Windows

02

Incorrect socket option semantics on Windows (SO_REUSEADDR not exclusive)

03

Defense in depth for P2P listener ownership

04

Follow-up to similar RPC listener hardening (#36169)

Risk score

Why this scored 62/100

Our methodology →
Potential impact 18/30
Exploitability 12/25
Stealth signal 10/15
Affected reach 8/15
Confidence 9/10
Evidence quality 5/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.