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 ConflictsNo conflicts as of last run. |
|
🚧 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. |
That's been merged now. |
4fcfd71 to
62b5ec1
Compare
62b5ec1 to
18b72e7
Compare
| std::unordered_set<const CNode*> paused; | ||
| for (CNode* node : connman.TestNodes()) { | ||
| LOCK(node->m_sock_mutex); | ||
| if (!node->m_sock) continue; |
There was a problem hiding this comment.
I think that the continue here is right for the fail-closed checks, but it also skips the readiness, m_recv_twice and m_send_after_short checks. Those describe what the handler did during the run, whether or not the socket survived.
The problem is that the bugs these checks look for usually end with the handler closing the socket. For example, a read without RecvEvent on a healthy FuzzedSock mostly returns 0 or an error, and the handler then calls CloseSocketDisconnect(). The node now has no socket, so the check never runs. The violation is only seen when the bad read happens to return data.
I tested this with a mutant that also reads on SendEvent:
diff --git a/src/net.cpp b/src/net.cpp
index f31604f6c5..b781371074 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -2218,7 +2218,7 @@ void CConnman::SocketHandlerConnected(const std::vector<CNode*>& nodes,
}
}
- if (recvSet || errorSet)
+ if (recvSet || errorSet || sendSet)
{
// typical socket buffer is 8K-64K
uint8_t pchBuf[0x10000];My clanker suggests to keep a reference to each socket before the handler runs, check behaviour on that reference, and only tie the fail-closed checks to whether the node still holds it.
There was a problem hiding this comment.
Great point. I updated the approach to keep a vector of the test nodes, along with a copy of the socket shared_ptr and whether that peer was paused. The second loop now iterates through that vector and asserts invariants for all of them, including when the connection was closed.
|
Concept ACK |
Prior to this commit, every FuzzedSock had one of two socket values and CConnman::SocketHandler() merged the entries of different peers in a single wait, which led the connman fuzz target to act on one peer with the events of another. This fixes it by using a different descriptor value for each socket, like the OS does for real sockets. This is achieved by numbering the sockets down from a global counter, restarted before each fuzz input to keep each run deterministic. A sanity check is added to CheckGlobalsImpl, in the same fashion as the it's done for the global PRNG and mocked time states.
FuzzedSock::Wait() and WaitMany() reported either nothing or exactly the requested events. The real OS reports more than that, and the fuzz targets never exercised the callers on it: - only some of the requested events, e.g. SendEvent alone on an idle connection; - ErrorEvent, with or without RecvEvent, to a socket that requested RecvEvent, as select() does for urgent data; - a failed connection, e.g. a reset one: poll() reports it as ErrorEvent whatever was requested, even nothing. Model these. A failed connection stays failed: waits keep reporting it, Recv() returns at most what was buffered before (a bounded amount picked when it fails) and then fails for good, and Send() fails. So a socket that did not request RecvEvent can be read from only once its connection failed, and only for a bounded amount, as on the real OS. WaitMany() now picks the outcome per socket, so that each socket keeps its own state. As before, the requested events occur when the fuzz input is exhausted, so that waits do not go on forever.
18b72e7 to
75f6da8
Compare
Flag a number of events in the FuzzedSock and assert corresponding invariants after running the handler.
|
Rebased and updated the approach per @brunoerg's point about closed connections. Will give that new approach a fair amount of CPU cycles overnight. |
frankomosh
left a comment
There was a problem hiding this comment.
Concept ACK. Giving each FuzzedSock its own descriptor and checking more of what the socket handler does, both look useful.
| // Check we only ever read (/send) data when Recv (/send) was reported. The converse | ||
| // does not always hold (for instance we may skip a recv() when we have too much to | ||
| // send). | ||
| Assert(!sock->m_last_recv || (sock->m_last_occurred & (Sock::RecvEvent | Sock::ErrorEvent))); |
There was a problem hiding this comment.
I counted locally, with help of a counter in SocketHandlerConnected(), how often the handler sends when replaying current qa-assets connman corpus:
- master: a node had data to send 264,266 times, with 192 real sends
- PR: 1 and 0
So existing corpus no longer reaches these checks on the send side. For example, Bruno's mutant that also reads on SendEvent survives the qa-assets corpus on this head, but a corpus I fuzzed locally catches it here (line 320).
I guess this is expected, since FuzzedSock now uses the input bytes differently, and the corpus will catch up eventually after merge. Noting it in case it's worth checking that the refreshed corpus reaches sends.
| // Mask using ConsumeBool() rather than ConsumeIntegral() because fuzzers generally | ||
| // operate at the byte level. | ||
| Event occurred{requested}; | ||
| for (size_t bit{0}; bit < sizeof(requested) * CHAR_BIT; ++bit) { |
There was a problem hiding this comment.
nit. only three event bits exist, so maybe loop over them directly?, same bits in the same order, so it should consume the fuzz input the same way:
for (const Event e : {RecvEvent, SendEvent, ErrorEvent}) {
if ((occurred & e) && m_fuzzed_data_provider.ConsumeBool()) {
occurred &= ~e;
}
}
On top of #36765, this extends FuzzedSock to report more events a real OS could report (see #36737 for some coverage of those), and improves the connman fuzz target to assert more socket handling invariants.
The first commit is also a fix to uniquely identify sockets, as currently each socket can only use one of two descriptor values, which means the fuzz target would act on one peer with the event of another.
See commit messages for details.