Repository navigation
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
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:
2026-11-03 03:58:39 |
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
cbfd014 to
7b4153b
Compare
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.
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.
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.
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.
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.
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.
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.
|
Nice, Concept ACK |
| for (const std::chrono::milliseconds timeout : {std::chrono::milliseconds{Sock::MAX_WAIT_TIMEOUT}, | ||
| std::chrono::milliseconds{Sock::MAX_WAIT_TIMEOUT + 1s}, | ||
| std::chrono::milliseconds::max()}) { |
There was a problem hiding this comment.
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::max()}) { | |
| 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()}) { |
| char c; | ||
| BOOST_CHECK(WouldBlock(conn.sock->Recv(&c, 1, MSG_DONTWAIT))); | ||
| conn.FillSendBuffer(MSG_NOSIGNAL | MSG_DONTWAIT); | ||
| BOOST_CHECK(WouldBlock(conn.sock->Send("x", 1, MSG_NOSIGNAL | MSG_DONTWAIT))); |
There was a problem hiding this comment.
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?
|
|
||
| // Otherwise, it must fail eventually. NOTE: Windows retries for about two seconds before giving up. | ||
| Sock::Event occurred{0xff}; | ||
| BOOST_REQUIRE(sock.Wait(LONG_WAIT, Sock::RecvEvent | Sock::SendEvent, &occurred)); |
There was a problem hiding this comment.
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, &occurred)); | |
| BOOST_REQUIRE(sock.Wait(LONG_WAIT, Sock::RecvEvent | Sock::SendEvent | Sock::ErrorEvent, &occurred)); |

This improves our
Socktest 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.