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

pull darosior wants to merge 7 commits into bitcoin:master from darosior:2610_sock_invariants changing 1 files +722 −11
  1. darosior commented at 11:24 PM on November 2, 2026: member

    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 #36688 (comment), as this needs to be fixed first.

  2. DrahtBot added the label Tests on Nov 2, 2026
  3. DrahtBot commented at 11:25 PM on November 2, 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. A summary of reviews will appear here.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #36843 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36843.svg"></sub> (scripted-diff: [test] Add util/check.h includes for assertions by maflcko)
    • #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>

  4. DrahtBot added the label CI failed on Nov 3, 2026
  5. DrahtBot commented at 12:27 AM on November 3, 2026: contributor

    <!--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>

  6. darosior force-pushed on Nov 3, 2026
  7. qa: pin down the socket readiness that callers of Sock::Wait() rely on
    Test what Sock::Wait() and Sock::WaitMany() report, under a matrix of
    different conditions about the state of the socket and the requested
    events.
    
    A few notable invariants exercised here:
    - Only what's requested is reported (in particular, no unrequested
      RecvEvent when we took care not to ask for it, see CVE-2026-117350).
    - Nothing readable means no RecvEvent (an idle connection never wakes a
      wait for receiving).
    - A reset wakes a wait for SendEvent, and the send() fails for good.
    - A reported event always means we can make progress (avoid spins).
    - Wait() and WaitMany() are equivalent.
    
    Readiness is level-triggered, so the tests first make sure that what the
    peer did has arrived and then check what a wait reports. They do not
    rely on anything not happening within some time, which would be brittle.
    
    Where the select() and poll() backends differ, the difference is spelled
    out in one place ahead of the tests, so that a change of backend has to
    update it. Callers cope with these differences, except with known
    quirks. For instance, Windows' select() fails when no socket requests
    anything.
    f35f2d576a
  8. qa: check that WaitMany() reports each socket's own events
    With many connections in random states, each waiting for random events,
    check that a single WaitMany() reports for each socket the events of
    that socket.
    70dde177ed
  9. qa: check the timeouts of Sock::Wait() and Sock::WaitMany()
    Without events, a wait returns true once its timeout expires and reports
    nothing, also when a socket on which nothing is requested is readable.
    Callers rely on it to pace their loops (net.cpp, httpserver.cpp) and to
    detect a timeout (ConnectToSocket() in netbase.cpp, i2p.cpp, pcp.cpp).
    
    A negative timeout is not tested: poll() would wait forever and select()
    fails. No caller passes one.
    
    Remove the wait test: it exercises strictly less than the long_timeout
    test introduced in this commit.
    bcb7560f07
  10. qa: check what a listening socket reports
    A listening socket reports RecvEvent when, and only when, accept() will
    succeed. net.cpp accepts one connection per wake-up and httpserver.cpp
    accepts until accept() fails.
    4bfdde59f4
  11. qa: check what a non-blocking connect() reports
    A non-blocking connect() that succeeds, or that is refused, wakes up a
    wait for RecvEvent | SendEvent and SO_ERROR then tells the outcome, as
    ConnectToSocket() expects.
    6a692f6b76
  12. qa: check that socket readiness is level-triggered
    What is left after a partial read, and then the end of the stream, are
    reported again. net.cpp reads at most 64 KiB per wake-up and relies on
    this.
    b458bbea89
  13. qa: pin down the options of CreateSockOS() and accepted sockets
    Check that CreateSockOS() sockets are non-blocking and have TCP_NODELAY
    and, where it exists, SO_NOSIGPIPE, and which of these a socket accepted
    from one inherits.
    
    net.cpp and httpserver.cpp do not make accepted sockets non-blocking.
    On Linux they are not, as accept() does not pass O_NONBLOCK on, and the
    callers rely on MSG_DONTWAIT instead. Check that Recv() and Send() with
    MSG_DONTWAIT return would-block rather than wait on a socket as accept()
    returns it. Where MSG_DONTWAIT does not exist (Windows), check at compile
    time that accepted sockets inherit non-blocking mode, and at run time
    that they do.
    7b4153b86e
  14. DrahtBot removed the label CI failed on Nov 3, 2026
  15. sedited commented at 7:31 PM on November 4, 2026: contributor

    Nice, Concept ACK


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-18 16:51 UTC

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