mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:47:36 +00:00
net: reject oversized outbound messages #35888
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!35888
Loading…
Reference in a new issue
No description provided.
Delete branch "l0rinc/net-reject-oversized-message-types"
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?
Problem: Outbound transports encode message types in a fixed 12-byte field, but
CConnmandid not ensure internal callers respected this limit before queuing messages.An oversized type aborts V1 encoding. V2 sends it under a truncated type with its payload intact, or writes past its encoding buffer when the payload is shorter than the excess type bytes.
The send path also did not enforce the 4 MB payload limit.
Private broadcast could reach this path with an oversized witness variant of a transaction already in the mempool.
Fix: Treat oversized types and payloads as failed assumptions in
CConnman::PushMessage()before they enter the send queue.Use the validated mempool transaction when privately rebroadcasting a transaction already in the mempool.
The testing-only
sendmsgtopeerRPC rejects oversized payloads before callingPushMessage().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.
Assume(MessageIsWithinLimits(msg))might read better? Should this test be part of theCSerializedNetMsgclass in protocol.h? Would probably be a useful place to add documentation that code constructing these msgs must ensure they're not oversized.would be easier for the reader I think.
Concept ACK
Can you explain your thinking / where you were coming from in relation to https://github.com/bitcoin/bitcoin/pull/35880#pullrequestreview-4858213755 some more? Even if whatever the concerns were are resolved to your satisfaction already, it makes me think there's a hole in my understanding here that I'd like to fill before reviewing properly.
I don't think you're missing anything on the receive side. I had already found that the related send path was missing checks, so when this fuzz failure showed another oversized-message case, I wanted to verify both paths before excluding it. At that point I hadn't established that the fuzzer was bypassing a receive-side guarantee, so I treated the outbound failure as something the send path should reject.
There was also a more directly related reason I did not want to assume every receive-side limit was enforced early: https://github.com/bitcoin/bitcoin/pull/35936 found that
getblocksandgetheadersenforcedMAX_LOCATOR_SZonly after deserialization, so a truncated oversized locator could allocate and throw before reaching the disconnect check. (edited)I was also cautious because similar fuzz constraints and sanitizer workarounds had hidden actual problems before:
After tracing this case, I agree that an oversized transaction cannot reach this path from a real peer, so restricting the fuzz target is correct. Thanks for the pushback and feedback.
Addressed your suggestions, thanks, pushed.
Edit: it seems libc++ has some problems with
constexprstrings, so I changed it tostd::string_viewand materialized on call site.🚧 At least one of the CI tasks failed.
Task
No wallet: https://github.com/bitcoin/bitcoin/actions/runs/31127401132/job/92703875334LLM reason (✨ experimental): CI failed due to a Clang build error in
src/test/net_tests.cpp: aconstexpr std::stringis not a constant expression, causingstatic_assert(MAX_MESSAGE_TYPE.size()...)to fail.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.
What is the reason for the non-debug build
returninstead of only adding the Assume?I think if this was somehow reached in production, returning false would result in a stall of the connection for minutes (until it get disconnected for inactivity), since
SocketSendDatawill never make progress.Also, wouldn't it be nicer from an architectural point of view if arbitrary application-level rules such as the 4MB maximum message length wouldn't be enforced at the transport level, but only at the higher level (
PushMessage) anyway?Then we wouldn't need the same assumption 3 different places.
I don't think it's a "problem" per se that
sendmsgtopeeraccepts payloads above the 4 MB protocol limit - it's a test RPC after all. The story should be that you want to add the assumption to prevent future regressions etc., and need to change the rpc for that - which is no loss because it's just a test rpc and oversized messages are being tested elsewhere.🐙 This pull request conflicts with the target branch and needs rebase.
Rebased and addressed @mzumsande's review: outbound limits are now enforced only in
CConnman::PushMessage(), before messages enter the send queue, so a permanent rejection cannot stallSocketSendData()throughSetMessageToSend(false). Thesendmsgtopeerbehavior and the PR rationale now reflect the RPC's testing-only role.It was suggested in https://github.com/bitcoin/bitcoin/pull/35880#issuecomment-5185966715.
I initially applied it because
SetMessageToSend()already returns a boolean, and I treatedfalseas a safe fallback in release builds whileAssumeexposed invalid callers in debug and fuzz builds.Good catch that
falsewill just try again later, so a permanently invalid message would remain queued and stall the connection.I moved both size assumptions to
PushMessage(), before the message enters the send queue.This also keeps the 4 MB application-level rule out of the transports - added you as coauthor, thanks for the review.
Pushed, let me know if I understood the request.
AI review flagged that I was missing coverage so added
PushMessage()tests because the transport tests bypassed the guard and didn’t verify rejection before queueing. Also rebased and split the type and payload characterization/fix pairs so each fix updates its own expectations (otherwise it's not obvious why multiple fixes are needed).Concept ACK
nit: Maybe it also makes sense to restrict the message type copy to
MESSAGE_TYPE_SIZE?Earlier concerns remain unresolved; see the Run archive linked from the Review report.
🟠 Minor · Private broadcast can acknowledge a TX dropped locally
With relaxed test-chain policy, private broadcast can record reception of an oversized transaction that the new send guard drops; abort-on-failed-Assume builds instead abort, and no default-configuration trigger was found.
Location:
src/net.cpp:4246(head).🔵 Suggestion · Outbound-limit test does not require failed assumptions
Replacing
Assumewith a plain size check and early return would leave all assertions inoutbound_message_limitspassing, losing coverage of the intended debug-build failure.Location:
src/test/net_tests.cpp:1448(head).Review coverage was incomplete.
Reviewed:
da042ca607fb· Review report · Previous reportspermalink
Rebased and simplified the tests and fuzz setup, production fix is unchanged, with the message type added to the log.
PushMessagealready rejects oversized types before they reach v2, and clamping there would silently truncate an invalid type, so it's not required for this fix🐙 This pull request conflicts with the target branch and needs rebase.
Looks like the Ralph finding ("With -privatebroadcast, an oversized witness variant of a mempool transaction can reach the new assumption.") is real., so the added
Assumecould be hit by a user.This is probably more of a minor private broadcast bug and not a real problem because the user themselves would need to create a version of a mempool tx with its witness padded past 4 MB, and rpc is a trusted interface.
Not sure how to best fix this, if at all. Maybe privately broadcast the mempool's version of the transaction in this case, not the user-supplied one?
Thanks mr Ralph (cc: @willcl-ark) and @mzumsande: private rebroadcast now uses the validated mempool transaction when available, with a regression test covering oversized witness variants (cc: @vasild, @andrewtoth).
I've also re-reviewed and simplified the code and tests with latest LLMs before push - removing redundant hash state, reusing the transport fixture, and sharing the fuzz setup.
🚧 At least one of the CI tasks failed.
Task
ASan + LSan + UBSan + integer: https://github.com/bitcoin/bitcoin/actions/runs/43509977467/job/132177388263LLM reason (✨ experimental): The build fails because
net_tests.cppdeclares aconstexpr std::stringthat Clang cannot evaluate as a constant expression.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.