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

Merge bitcoin/bitcoin#36716: net: only monitor select exceptions while connecting

Public commit record

What the developer wrote

Authored by merge-script

91/100 · Strong
Merge bitcoin/bitcoin#36716: net: only monitor select exceptions while connecting

97e3c9562291f5bbc2b03fef1c70e4975eb2a8c6 net: only use the select error set while connecting (Sjors Provoost)

Pull request description:

Alternative approach to #36688, citing the relevant parts of its description:

> There is currently nothing preventing us to receive TCP urgent data, which would never be returned by `recv()`. Linux's `poll()` is indifferent to this, but the `select()` socket monitoring may keep reporting it as pending on some platforms.
>
> This would not prevent progress nor lead to a crash anymore after #36665, but it's still undesirable.

Fix this by only adding a socket to the `select()` exception set while waiting for a non-blocking `connect()` to complete. Windows needs that to detect a failed connection. Established connections no longer monitor the exception set on any platform. This approach was suggested by theuni in https://github.com/bitcoin/bitcoin/pull/36716#issuecomment-6931290348.

To opt in, `ErrorEvent` can now be requested from `Sock::Wait()`, like `RecvEvent` and `SendEvent`. With `select()` that adds the socket to the exception set. `ConnectToSocket()` is the only caller that requests it. There is no behavior change with `poll()`, which reports errors whether or not they are requested. Using `ErrorEvent` for this was suggested by vasild in https://github.com/bitcoin/bitcoin/pull/36716#discussion_r4692637894.

We could instead have set `SO_OOBINLINE` on our sockets, so `recv()` returns any urgent data sent to us (and likely leads us to disconnect the peer). RFC 6093 doesn't forbid this, but the current approach seems more clear and direct to me.

A new unit test in `sock_tests` covers the fix itself: with an urgent byte pending, waiting for `RecvEvent` must not report `ErrorEvent`. Without the fix it fails on a `select()` build.

Backports until 29.x are straight-forward, but for 31.x and before require compensating for the scripted-diff in https://github.com/bitcoin/bitcoin/commit/f395acdeeeaa1f3fd75d3cedbf2731fa24083e9f.

ACKs for top commit:
theuni:
ACK 97e3c9562291f5bbc2b03fef1c70e4975eb2a8c6
darosior:
re-utACK 97e3c9562291f5bbc2b03fef1c70e4975eb2a8c6
vasild:
ACK 97e3c9562291f5bbc2b03fef1c70e4975eb2a8c6

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

What changed, and why it matters

This change fixes a networking quirk in Bitcoin Core where the program could be woken up repeatedly by a rare TCP 'urgent data' signal, even though there was no real data to read. The fix makes the program only watch for that signal while a connection is still being established, not afterward. It is more of a robustness and denial-of-service-hardening fix than an exploitable remote code execution bug.

Recommended action

Backport to supported release branches as indicated by the PR (straightforward backport to 29.x; 31.x and earlier need adjustment for a prior scripted diff). No immediate emergency response is warranted, but the fix should ride the normal release/backport process.

Security signals we found

01

Avoids spurious wakeups from TCP urgent data on select()-based builds

02

Reduces CPU-waste / small-scale denial-of-service surface from malicious or misbehaving peers

03

Adds explicit ErrorEvent opt-in to Sock::Wait() API

04

Includes regression unit test for urgent-data behavior

Risk score

Why this scored 37/100

Our methodology →
Potential impact 8/30
Exploitability 5/25
Stealth signal 6/15
Affected reach 7/15
Confidence 7/10
Evidence quality 4/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.