mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:47:36 +00:00
fuzz: report more events, and check more invariants in connman target #36786
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36786
Loading…
Reference in a new issue
No description provided.
Delete branch "2610_fuzz_sock_wait"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.
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.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
No conflicts as of last run.
🔵 Suggestion · The reset guard permits descriptor reuse after socket creation
Although current callers reset first,
CheckGlobalsaccepts a lateResetFuzzedSockets()call that can give two live sockets the same descriptor.Location:
src/test/fuzz/util/net.cpp:126(head).Review coverage was incomplete.
Reviewed:
75f6da8ea338· Review report · Previous reportspermalink
🚧 At least one of the CI tasks failed.
Task
lint: https://github.com/bitcoin/bitcoin/actions/runs/42099583336/job/127498536190LLM reason (✨ experimental): CI failed because the lint check detected a newly introduced circular dependency in
test/fuzzutilities.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.
That's been merged now.
style-nit: I guess this works, but design-wise this struct was more meant to be a no-op linter (only crash on a bug), not a behavior-changing cleanup utility 😅
Either:
g_used_socketandg_reset_socket(and use it to lint and enforce a call toResetFuzzedSocketsin the affected fuzz targets)ResetFuzzedSocketsin the affected fuzz targets and hope it is sufficient without a linterUp to you.
Happy to change this, but i'm not sure how CheckGlobalsImpl() is a no-op linter? It is already resetting state that fuzz targets depend on. Resetting the starting descriptor value for created sockets does not seem that different from resetting the mock time(s).
The idea is that this is resetting the mock time, so that system time is used. However, if system time was used, it would fail the fuzz run due to non-determinism.
Conversely, if the two time-clear toggles were removed, the fuzz run would just run normally and still deterministically, because all fuzz targets set their mock time explicitly.
This is just a style preference of mine to have each test case fully list all dependencies or requirements by itself, so that it is self-contained and doesn't depend on implicit global setup.
Make sense, i'll move the Reset to targets making use of fuzzed sockets then.
Done, along with a sanity check akin to that used for the global PRNG / mocked time states.
I think that the
continuehere is right for the fail-closed checks, but it also skips the readiness,m_recv_twiceandm_send_after_shortchecks. 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:
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.
Concept ACK
🐙 This pull request conflicts with the target branch and needs rebase.
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.
Rebased and updated the approach per @brunoerg's point about closed connections. Will give that new approach a fair amount of CPU cycles overnight.
Concept ACK. Giving each FuzzedSock its own descriptor and checking more of what the socket handler does, both look useful.
I counted locally, with help of a counter in
SocketHandlerConnected(), how often the handler sends when replaying current qa-assets connman corpus:So existing corpus no longer reaches these checks on the send side. For example, Bruno's mutant that also reads on
SendEventsurvives 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.
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: