mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:47:36 +00:00
fuzz: improve ipc fuzz coverage #35916
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!35916
Loading…
Reference in a new issue
No description provided.
Delete branch "08-26-fuzz-ipc-coverage"
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?
This PR follows up on #35118 and continues the IPC fuzzing work proposed in #23015.
The initial ipc fuzz target exercised normal calls through a libmultiprocess client and server. This PR extends the target with
UniValuepayloads, which are deserialized by a normal libmultiprocess server.UniValuepayloads, which are deserialized by a normal libmultiprocess client.The raw request and response cases allow the fuzz target to exercise deserialization with data that was not first produced by libmultiprocess serialization.
The ipc setup and callback handling closely follow the existing
libmultiprocesstests, particularly their use ofEventLoop,ProxyClient,ProxyServer, two-way pipes, andinitThreadMap.The transaction and UniValue payload cases exercise the serialization hooks defined in
common-types.h.These files may provide useful background when reviewing the changes.
Generated coverage report after fuzzing the IPC target for a while using the qa-assets corpus.
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
Reviewers, 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.
tACK bd24122dfbfbaded49ef551c01184b4b5b48e27f
All green, and it matches the follow-up #35118 asked for.
Took me a bit to see why sendTransactionPayload swallows FAILED while sendUniValuePayload treats any kj error as fatal. That's correct, but you only get it by reading the hooks. A one-line comment would have helped, feel free to ignore.
Yes, I agree that this can be clarified a bit more, added the suggested comment to clarify why any KJ error is unexpected here. Thanks
🚧 At least one of the CI tasks failed.
Task
Windows native, fuzz, VS: https://github.com/bitcoin/bitcoin/actions/runs/32963804197/job/98161775031LLM reason (✨ experimental): CI failed because the fuzz target
rpccrashed with Windows exit code3221225477(access violation).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.
See the generated coverage report after fuzzing the IPC target for a while using the qa-assets corpus.
Also included in the pr description
🐙 This pull request conflicts with the target branch and needs rebase.
🚧 At least one of the CI tasks failed.
Task
macOS native, fuzz: https://github.com/bitcoin/bitcoin/actions/runs/34830127159/job/103931261872LLM reason (✨ experimental): CI failed because the fuzz test (
fuzztargetipc) crashed withstd::runtime_error: invalid JSON received over IPC(uncaught exception, exit code 1).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.
https://github.com/bitcoin/bitcoin/pull/35916/commits/1ea3507869869a93c136714d841fa5dd8788e8e0:
I'm not sure why random bytes are being used for CTransaction and UniValue; the chances of a randomly generated byte vector deserialising to a CTransaction are slim.
https://github.com/bitcoin/bitcoin/pull/35916/commits/f5db59400b7838beffef3cba34d6fbcf5df9a00c:
You should use
ConsumeTransactionfromsrc/test/fuzz/util.cpp. Most of the vectors produced will be invalid.https://github.com/bitcoin/bitcoin/pull/35916/commits/f5db59400b7838beffef3cba34d6fbcf5df9a00c:
Same as in my previous UniValue comment.
https://github.com/bitcoin/bitcoin/pull/35916/commits/1ea3507869869a93c136714d841fa5dd8788e8e0:
Use
ConsumeTransactioninsrc/test/fuzz/util.cppto create a random tx from aFuzzedDataProviderinstead of using a random lenght byte vector.https://github.com/bitcoin/bitcoin/pull/35916/commits/1ea3507869869a93c136714d841fa5dd8788e8e0:
Most of the generated data will be invalid JSON; this means the fuzzer will hit the "invalid JSON received over IPC" error most of the time. I think it's much better to construct a valid JSON payload, the same way we construct valid TXs with
ConsumeTransaction.We intentionally return arbitrary transaction bytes from the raw server so the client deserialization is exercised with malformed responses.
Using
ConsumeTransactionwould only generate valid transactions and duplicate the existing passTransaction coverage.I’ve added a comment clarifying the purpose of this branch.
Invalid json is intentional here because it tests client side rejection of malformed ipc responses.
Valid json round trips are covered separately by passUniValue, which parses arbitrary input and proceeds when it is valid.
I’ve added a comment clarifying the distinction.
Same rationale as https://github.com/bitcoin/bitcoin/pull/35916#discussion_r4028056645: this intentionally bypasses normal serialization to exercise malformed transaction payload handling.
Same reason as https://github.com/bitcoin/bitcoin/pull/35916#discussion_r4028056893
🔵 Suggestion · Transaction-request fuzz oracle accepts unrelated
FAILEDerrorsFor locally undecodable transaction bytes, the fuzz oracle would hide an unrelated remote
FAILEDerror; no current source of such a non-decoding error was found.Location:
src/ipc/test/fuzz/ipc.cpp:171(head).🔵 Suggestion · Check values returned by successful raw responses
When a raw response decodes successfully,
receiveTransactionPayloadandreceiveUniValuePayloaddiscard the client's result:(void)m_response_client->passTransaction(request)atsrc/ipc/test/fuzz/ipc.cpp:238and(void)m_response_client->passUniValue(request)at line 260. The locally decodedCTransaction txexists only inside the probe'stryblock and is dropped. The target checks only whether decoding succeeds or fails as expected, not whether the client received the right value. A deserializer regression that produced a wrong but well-formed transaction or JSON value would pass.Location:
src/ipc/test/fuzz/ipc.cpp:224(head).Review coverage was incomplete.
Reviewed:
966457f5feaa· Review report · Previous reportspermalink
Concept ACK
This might be accepting just about any server error (I believe you intend for it to accept only "bad tx bytes" errors). And could therefore hide a real server bug.
I tried a mutant on it (in
ipc_fuzz.h):Which seemingly did not crash this fuzz target.
Among the many approaches we could take to make it more effective could be to first decode the bytes locally. Then the server may only fail when the local decode fails.
Such as:
I tried this mutant (in
common-types.h), specifically to see if raw UniValue branches checks if invalid JSON is rejected. It removes the rejection completely:The fuzz target did not catch it for the corpus I generated.
One possible option of killing it is the same approach as the tx one above. I tried it, and the response-side check catches the mutant (I didn't test the request side on its own).
FWIW I tried to measure this and found raw bytes to reach a real tx in only under a minute, and a witness tx within a 10-minute duration of my run. I think the fuzzer does learn from coverage to build valid txs,
Agreed, accepting any failed error could hide an unexpected server failure.
Added the check on both the request and response sides, so ipc must succeed when the bytes decode locally and reject them when they don’t. Thanks for testing this.
The target was allowing invalid json to be accepted without failing.
Added local
UniValue::read()checks on both the request and response sides, so valid json succeeds and invalid json produces the expected rejection error. ThanksThanks for the review @frankomosh. Added local deserialization checks for transaction and UniValue payloads on both the request and response sides, so the fuzz target now fails when ipc accepts malformed data or rejects locally decodable data.
🐙 This pull request conflicts with the target branch and needs rebase.
🚧 At least one of the CI tasks failed.
Task
test ancestor commits: https://github.com/bitcoin/bitcoin/actions/runs/43205413018/job/131139208283LLM reason (✨ experimental): The build failed because fuzz target
ipc.cppcannot find the headeripc/util.h.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.
friendly ping @marcofleon @Crypt-iQ
@enochaz sorry, I can't meaningfully review. I have no idea how ipc works at all at the code level. I haven't reviewed marco's ipc-mining approach but I think we both had some moderate success in fuzzamoto by simply calling random ipc methods with random values. There's currently no merged support for IPC in fuzzamoto, though I'd be happy to review a fuzzamoto IPC PR assuming it simply did something like this (calling random methods like this is really the limit of my understanding here).
Thanks @Crypt-iQ, no worries.
This target is a bit lower level than calling random ipc methods. It runs a libmultiprocess client and server in process and sends malformed transaction and json payloads in both directions, checking that ipc accepts only what decodes locally and rejects the rest.
If you have time, the accept/reject checks in
sendTransactionPayloadandreceiveTransactionPayloadmight still be reviewable without much ipc background. Otherwise all good, thanks for the fuzzamoto pointer.Concept ACK (
966457f5fe) on focusing this on the types the Mining and Chain interfaces actually pass. The type-conversion layer is where in-process fuzz tests are most useful: several real IPC bugs were values the C++ side could never produce arriving over the wire, like aCFeeRatewith a negative size (#36816), a NaN read into a duration, or an out-of-range enum. Bugs involving object lifetimes, threads or disconnects are less likely to be found this way, and hard to reproduce when they are, because the fuzzer doesn't control which thread runs when. Those need tests that do control the schedule, either with hooks that pause calls at chosen points (as some libmultiprocess unit tests already do) or with a deterministic scheduler like Antithesis.For each type the Mining and Chain interfaces pass, I think it would be good to cover:
int, the callback case could pass the same types, which covers the conversions in that direction too without much extra work for the fuzzer.cross-ref to https://github.com/bitcoin/bitcoin/issues/37063