net: reject oversized outbound messages #35888

pull l0rinc wants to merge 4 commits into bitcoin:master from l0rinc:l0rinc/net-reject-oversized-message-types changing 7 files +79 −13
  1. l0rinc commented at 10:36 PM on August 4, 2026: contributor

    Problem: Outbound transports do not enforce the protocol's 12-byte message type and 4 MB payload limits. A longer type can abort V1 or overwrite V2's encoding buffer, while an oversized payload can be sent only to make the receiving peer disconnect. Normal production code sends fixed P2P message types only, while the testing-only sendmsgtopeer RPC can reach the oversized payload case.

    Fix: Apply both limits before messages are queued or encoded, leave rejected messages unchanged, and return an error from sendmsgtopeer. This addresses the fuzz failure discussed in #35880 in the production send path instead of filtering the input in the harness.

  2. test: characterize outbound message limits
    Cover the accepted 12-byte type and 4 MB payload boundaries for both outbound transports.
    V2 accepts a 13-byte type when a non-empty payload keeps the copy in bounds.
    The `connman` fuzzer stops at 12 bytes, and both transports accept a 4,000,001-byte payload while consuming the input message.
    
    Extend the existing two-node `sendmsgtopeer` test to confirm the oversized payload is sent and makes the peer disconnect.
    bcd14432f9
  3. net: reject oversized transport message types
    `Transport::SetMessageToSend()` encodes message types in a fixed 12-byte wire field.
    V1 aborts on a longer name, while V2 can overwrite the first payload byte or write past its encoding buffer.
    
    Reject oversized names before either transport encodes them and before `CConnman` queues them.
    Verify both transports reject the message unchanged, and let the `connman` fuzzer exercise the first oversized length.
    
    Normal outbound messages use fixed `NetMsgType` values, and `sendmsgtopeer` already rejects names longer than 12 bytes.
    f52038c145
  4. test: propagate rejected outbound messages
    `ConnmanTestMsg::ReceiveMsgFrom()` asserted whenever the transport declined a message.
    Return false for messages outside the wire limits so fuzz targets can exercise transport rejection without aborting.
    Retain the assertion for every other queue failure.
    d84fdc0ae8
  5. net: reject oversized outbound payloads
    Incoming transports reject payloads larger than 4 MB, while outbound transports accepted them.
    The testing-only sendmsgtopeer RPC could send a 4,000,001-byte payload that made the peer disconnect.
    
    Use one predicate to apply the payload limit before messages are queued or encoded, and log rejections from the void `PushMessage()` interface.
    Return an RPC error from sendmsgtopeer.
    
    The existing characterization now verifies that both transports reject the input unchanged, and the OSS-Fuzz input from #35880 passes without a harness restriction.
    d849c8e97c
  6. DrahtBot added the label P2P on Aug 4, 2026
  7. DrahtBot commented at 10:37 PM on August 4, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35888.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process. A summary of reviews will appear here.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-08-05 04:50 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me