mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 09:38:38 +00:00
fuzz: Add a target that feeds arbitrary bytes to V2Transport #36635
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!36635
Loading…
Reference in a new issue
No description provided.
Delete branch "fuzz-v2-transport-arbitrary-bytes"
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?
No fuzz target feeds V2Transport bytes that an honest peer would not send past the v2 key exchange. I add p2p_transport_v2_receive. It knows the transport's keys, builds the input from arbitrary bytes and from parts of a valid handshake (the peer key, garbage, the terminator, encrypted packets that may be corrupted, and runs of empty decoys that force a rekey), and feeds it in pieces of arbitrary size. Once the transport reports v2, it checks that its session id matches the peer's.
It reaches the v2 receive states and their failures, except the fallback to v1 and the wrong-magic disconnect, which need a v1
versionheader at the start of the stream;p2p_transport_bidirectional_v1v2reaches the first. 15 minutes with libFuzzer, ASan and UBSan found no crash.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.
No verified findings are available from this review.
Review coverage was incomplete.
Reviewed:
b2636036e679· Review report · Previous reportspermalink
nit: I think
ConsumeFixedLengthByteVector<std::byte>(provider, 32)does the same consume-then-resize and lets these beconst:github.com/bitcoin/bitcoin@a773e1e33b/src/test/fuzz/util.h (L280)It should read the input the same way.
nit: the
BIP324Cipher(key, ent)constructor callskey.EllSwiftCreate(ent)and nothing else:github.com/bitcoin/bitcoin@a773e1e33b/src/bip324.cpp (L25-L29)Maybe call that instead of building a second cipher? It gives the same public key.
I think the transport never rekeys here. The loop stops at 100 actions, so a stream holds fewer than 100 packets, and the transport rekeys every 224:
github.com/bitcoin/bitcoin@a773e1e33b/src/bip324.h (L26)Maybe add an action that appends a run of empty decoys? With the diff below, libFuzzer's coverage report shows this rekey branch hit:
github.com/bitcoin/bitcoin@a773e1e33b/src/crypto/chacha20poly1305.cpp (L106-L108)nit: the code doesn't use
moreormsg_type.The target calls
transport.GetInfo()and drops the result.The transport reports v2 once it verifies the version packet:
github.com/bitcoin/bitcoin@a773e1e33b/src/net.cpp (L1595-L1600)At that point its session id should match the peer's. Would an assert on that work? I ran the check for 4 minutes and it didn't fail.
nit:
streamandaadholduint8_t, but most bytes going in arestd::byte. That forces casts both ways:UCharCastinappend_fn, andMakeByteSpan/MakeWritableByteSpanforEncrypt.Maybe store
std::byteand convert once withMakeUCharSpan(stream)beforeReceivedBytes()? I think that also removes the duplicate insert in the "Arbitrary bytes" and "Garbage" branches, and it reads the input the same way.diff:
@uqlidi thanks, all seven comments are applied in
984a01619e.Once the transport reports v2, the target asserts that its session id matches the peer's; with the check inverted it aborts on the new corpus, so the assert is reached. The old target never rekeyed: a new action appends a run of empty decoys, and replaying the corpora counted 0 rekeys before and 854 after, at about half the exec rate. Both entropies are
const, fromConsumeFixedLengthByteVector. The peer is initialized fromkey.EllSwiftCreate(ent).streamandaadholdstd::byte. The unused bindings are_moreand_msg_type. The refactors read the input the same way: a hash of the stream, the entropy and the bytes left was identical before and after them on all 601 old-corpus inputs with valid keys.One note on Ralph's report on
0b0fa362fe: its verifier says the target reaches the wrong-magic disconnect. That branch's log line,net.cpp:1144at984a01619e, had 0 hits in the gist's 10-minute run of the new target and its 5-minute run of the final one (results.txt). This is why the description says the target does not reach it: that path needs a v1versionheader at the start of the stream.I also rebased: master gave
initialize_p2p_transport_serializationa reachability goal this target never observes, so it now usesinitialize_p2p_transport. Commands and output: https://gist.github.com/fametrano/b1d9da3c3312cae5b1029679828ee023/e168d09e55328bc3b2955680154ea4b4687b8e5c🐙 This pull request conflicts with the target branch and needs rebase.
Concept ACK
The description says the stream is fed in pieces of arbitrary size, but once the build loop has used up the input
ConsumeIntegralInRangereturns 1 here, so 403 of the 430 inputs in your gist's corpus that build a stream are received one byte at a time.Should the pieces vary for every input, or should the description and the comment at the top of the target say they don't?