qa: check more socket API invariants for each platform we support #36737

Open
darosior wants to merge 7 commits from 2610_sock_invariants into master AGit
darosior commented 2026-11-02 23:24:55 +00:00 (Migrated from github.com)

This improves our Sock test coverage following CVE-2026-117350.

This leaves out the test for the specific case that led to the OOM until we fix select() reporting for urgent data, but i'm also trying not to fight the last battle too much. Instead i focused on trying to pin down all invariants Claude and I could come up with that could be reasonably tested. This will help us understand our code better, and get more assurance we do not break some assumption a (security critical) caller may be relying on further down the road.

Another goal is to tie the events our fuzzing mock can report to the events each OS actually reports, and when. A follow-up will extend the mock to match what these tests pin down. This wouldn’t have caught the CVE-2026-117350 bug: it was in the very logic the mock replaces, so a fuzz target could only have found it if the mock had been written with that bug in mind. But the next bug may well be somewhere else, and a mock that can report everything the real socket APIs can, lets the fuzzer reach corner cases which may lack a proper unit test.

A lot more coverage could be added. I chose not to add tests specific to the logic used for trusted interfaces (Tor control, the SOCKS5 proxy, I2P SAM) or to a single platform. I also left out the test which led me to find https://github.com/bitcoin/bitcoin/pull/36688#issuecomment-6509375262, as this needs to be fixed first.

This improves our `Sock` test coverage following CVE-2026-117350. This leaves out the test for the specific case that led to the OOM until we [fix `select()` reporting](https://github.com/bitcoin/bitcoin/pull/36688#issue-6085527087) for urgent data, but i'm also trying not to fight the last battle too much. Instead i focused on trying to pin down all invariants Claude and I could come up with that could be reasonably tested. This will help us understand our code better, and get more assurance we do not break some assumption a (security critical) caller may be relying on further down the road. Another goal is to tie the events our fuzzing mock can report to the events each OS actually reports, and when. A follow-up will extend the mock to match what these tests pin down. This wouldn’t have caught the CVE-2026-117350 bug: it was in the very logic the mock replaces, so a fuzz target could only have found it if the mock had been written with that bug in mind. But the next bug may well be somewhere else, and a mock that can report everything the real socket APIs can, lets the fuzzer reach corner cases which may lack a proper unit test. A lot more coverage could be added. I chose not to add tests specific to the logic used for trusted interfaces (Tor control, the SOCKS5 proxy, I2P SAM) or to a single platform. I also left out the test which led me to find https://github.com/bitcoin/bitcoin/pull/36688#issuecomment-6509375262, as this needs to be fixed first.
DrahtBot commented 2026-11-02 23:25:05 +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
Concept ACK sedited, jeanpablojp

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36946 (scripted-diff: [test] Add util/check.h includes for assertions by maflcko)
  • #35558 (p2p: Prefill compact blocks by davidgumberg)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

LLM Linter (✨ experimental)

Possible typos and grammar issues:

  • src/test/sock_tests.cpp: overriden → overridden [misspelling]

2026-11-03 03:58:39

<!--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/36737 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36737.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36737#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 | | ---- | --------- | | Concept ACK | [sedited](https://github.com/bitcoin/bitcoin/pull/36737#issuecomment-6640102674), [jeanpablojp](https://github.com/bitcoin/bitcoin/pull/36737#pullrequestreview-6115052059) | 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. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#36946](https://github.com/bitcoin/bitcoin/pull/36946) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36946.svg"></sub> (scripted-diff: [test] Add util/check.h includes for assertions by maflcko) * [#35558](https://github.com/bitcoin/bitcoin/pull/35558) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35558.svg"></sub> (p2p: Prefill compact blocks by davidgumberg) If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. <!--5faf32d7da4f0f540f40219e4f7537a3--> ### LLM Linter (✨ experimental) Possible typos and grammar issues: - `src/test/sock_tests.cpp`: `overriden` → `overridden` [misspelling] <sup>2026-11-03 03:58:39</sup>
First-time contributor

🔵 Suggestion · Readiness progress probe ignores events reported only by WaitMany()

In the readiness test, an optional SendEvent reported only by the aggregate WaitMany() can escape the send-progress check for a full, non-reset socket.

Location: src/test/sock_tests.cpp:581 (head).

🔵 Suggestion · Idle timeout tests do not detect early returns

The timeout test (sock_tests.cpp:667-679) only checks that 100ms waits return true and report no events, so an immediate return passes. large_timeout uses whole-second timeouts only (MAX_WAIT_TIMEOUT is in seconds). A broken sub-second path, such as MillisToTimeval's tv_usec branch, would go undetected.

Location: src/test/sock_tests.cpp:667 (head).

Review coverage was incomplete.


Reviewed: 7b4153b86ed8 · Full review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:965af1044d9e41839565702e4d9bd0a751eda81f6e8b6402747fa296ef84ebea:7efd3c3ba41667382004cfa7a7db56605da7d8f9b7ab69bc483f27117390ba48 --> <!-- ralph-base:ddea9196493d3b8fd841a36a6c53efd85dac7a05 --> <!-- ralph-head:7b4153b86ed841e27516a637531419b9d47fc16f --> <!-- ralph-case:bb790eb83b61023dc81ac40cb39ecf71852a20a05cfc2ba8c00f4f27c33927b1 --> **🔵 Suggestion · Readiness progress probe ignores events reported only by WaitMany()** In the readiness test, an optional SendEvent reported only by the aggregate WaitMany() can escape the send-progress check for a full, non-reset socket. Location: [`src/test/sock_tests.cpp:581`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/7b4153b86ed841e27516a637531419b9d47fc16f/src/test/sock_tests.cpp#L581>) (head). **🔵 Suggestion · Idle timeout tests do not detect early returns** The `timeout` test (sock_tests.cpp:667-679) only checks that 100ms waits return true and report no events, so an immediate return passes. large_timeout uses whole-second timeouts only (MAX_WAIT_TIMEOUT is in seconds). A broken sub-second path, such as MillisToTimeval's tv_usec branch, would go undetected. Location: [`src/test/sock_tests.cpp:667`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/7b4153b86ed841e27516a637531419b9d47fc16f/src/test/sock_tests.cpp#L667>) (head). Review coverage was incomplete. <!-- Review tier: routine --> --- Reviewed: [`7b4153b86ed8`](<https://git.fish.foo/bitcoin/bitcoin/commit/7b4153b86ed841e27516a637531419b9d47fc16f>) · [Full review report](<https://review.fish.foo/traces/36737-7b4153b86ed841e27516a637531419b9d47fc16f-2027-2.html>) · [Previous reports](<https://review.fish.foo/traces/36737/>) [permalink](<https://review.fish.foo/traces/36737-7b4153b86ed841e27516a637531419b9d47fc16f-2027-2.html>)
DrahtBot commented 2026-11-03 00:27:15 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task test ancestor commits: https://github.com/bitcoin/bitcoin/actions/runs/41545254532/job/125619164838
LLM reason (✨ experimental): The build failed because sock_tests.cpp references undeclared AcceptedSock and set_options identifiers.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `test ancestor commits`: https://github.com/bitcoin/bitcoin/actions/runs/41545254532/job/125619164838</sub> <sub>LLM reason (✨ experimental): The build failed because `sock_tests.cpp` references undeclared `AcceptedSock` and `set_options` identifiers.</sub> <details><summary>Hints</summary> Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example: * Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch. * A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test. * An intermittent issue. Leave a comment here, if you need help tracking down a confusing failure. </details>
sedited commented 2026-11-04 19:31:12 +00:00 (Migrated from github.com)

Nice, Concept ACK

Nice, Concept ACK
jeanpablojp (Migrated from github.com) reviewed 2026-11-30 15:29:43 +00:00
jeanpablojp (Migrated from github.com) left a comment

Concept ACK

Concept ACK
Lines 688-690
jeanpablojp (Migrated from github.com) commented 2026-11-30 15:29:43 +00:00

On Linux this test still passes with the cap removed from WaitMany(). With 2^32 ms, which reaches poll() as 0, the test fails without the cap.

    for (const std::chrono::milliseconds timeout : {std::chrono::milliseconds{Sock::MAX_WAIT_TIMEOUT},
                                                    std::chrono::milliseconds{Sock::MAX_WAIT_TIMEOUT + 1s},
                                                    std::chrono::milliseconds{int64_t{1} << 32},
                                                    std::chrono::milliseconds::max()}) {
On Linux this test still passes with the cap removed from `WaitMany()`. With 2^32 ms, which reaches `poll()` as 0, the test fails without the cap. ```suggestion for (const std::chrono::milliseconds timeout : {std::chrono::milliseconds{Sock::MAX_WAIT_TIMEOUT}, std::chrono::milliseconds{Sock::MAX_WAIT_TIMEOUT + 1s}, std::chrono::milliseconds{int64_t{1} << 32}, std::chrono::milliseconds::max()}) { ```
jeanpablojp (Migrated from github.com) commented 2026-11-30 15:29:43 +00:00

This check fails on macOS in 141 of 3200 runs with 8 processes at once. FillSendBuffer() already requires a would-block before it returns, so could this check go?

This check fails on macOS in 141 of 3200 runs with 8 processes at once. `FillSendBuffer()` already requires a would-block before it returns, so could this check go?
jeanpablojp (Migrated from github.com) commented 2026-11-30 15:29:43 +00:00

After #36716, the exception set, where FAILED_CONNECT_EVENTS expects Windows to report the failure, is only watched when ErrorEvent is requested. Once rebased on master, could this wait request ErrorEvent too?

    BOOST_REQUIRE(sock.Wait(LONG_WAIT, Sock::RecvEvent | Sock::SendEvent | Sock::ErrorEvent, &occurred));
After #36716, the exception set, where `FAILED_CONNECT_EVENTS` expects Windows to report the failure, is only watched when `ErrorEvent` is requested. Once rebased on master, could this wait request `ErrorEvent` too? ```suggestion BOOST_REQUIRE(sock.Wait(LONG_WAIT, Sock::RecvEvent | Sock::SendEvent | Sock::ErrorEvent, &occurred)); ```
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!36737
No description provided.