fix: Bound GetHeaders response read limit derived from peer-supplied height - #117
Open
giaki3003 wants to merge 4 commits into
Conversation
…ers` response read budget (memory-exhaustion sync DoS) Bug: w3-20260618-1639-kimiclaw-confirm-glmclaw-t (primary) Finding: findings/20260618-1639-kimiclaw-confirm-glmclaw-thunder-rust-getheaders-response-limit-inflation.md Severity: R3-T2 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> (cherry picked from commit a49be1d)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's wrong
GetHeadersRequest::read_response_limit(lib/net/peer/message.rs) sizes the read budget as(height + 1) * 2048. Thatheightis set inConnectionTask::check_peer_tip_and_request_headers(lib/net/peer/task.rs) frompeer_tip_info.block_height, which comes straight out of the peer's heartbeat and is not validated against anything.The resulting limit is used twice: as the
read_to_endcap inConnection::receive_response, and as the input toConnection::response_read_timeout. A peer advertising a height nearu32::MAXtherefore gets a multi-terabyte read cap and a read timeout measured in years, so it can buffer far more than a real header chain needs and pin the outbound request slot for that connection. (On 32-bit targets the existingchecked_mul(..).unwrap()would panic instead.)The fix
Two independent bounds.
read_response_limitnow uses saturating arithmetic and clamps to aMAX_READ_RESPONSE_LIMITof 64 MiB. Separately, the height attached to the request is clamped to the mainchain height of the peer tip's BMM block, resolved viaarchive.get_main_heightin the read txn that already validates that main header — a block at heighthrequireshdistinct mainchain blocks, so this cannot under-count a legitimate tip.Tests
Adds
get_headers_read_response_limit_is_bounded, asserting au32::MAXheight yields a limit under 64 MiB and a bounded read timeout.The 64 MiB cap is a judgement call — happy to adjust it.
Finding report (access-controlled): https://giaki3003.tech/#/findings/20260618-1639-kimiclaw-confirm-glmclaw-thunder-rust-getheaders-response-limit-inflation
First of a short series of 3 fixes for this repo, based on
master. The rest build on this branch and will follow.