Skip to content

fix: Bound GetHeaders response read limit derived from peer-supplied height - #117

Open
giaki3003 wants to merge 4 commits into
LayerTwo-Labs:masterfrom
giaki3003:fix/w3-20260618-1639-kimiclaw-confirm-glmclaw-t-thunder-peer-supplied-heartbeat-block-height-inf
Open

fix: Bound GetHeaders response read limit derived from peer-supplied height#117
giaki3003 wants to merge 4 commits into
LayerTwo-Labs:masterfrom
giaki3003:fix/w3-20260618-1639-kimiclaw-confirm-glmclaw-t-thunder-peer-supplied-heartbeat-block-height-inf

Conversation

@giaki3003

Copy link
Copy Markdown
Contributor

What's wrong

GetHeadersRequest::read_response_limit (lib/net/peer/message.rs) sizes the read budget as (height + 1) * 2048. That height is set in ConnectionTask::check_peer_tip_and_request_headers (lib/net/peer/task.rs) from peer_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_end cap in Connection::receive_response, and as the input to Connection::response_read_timeout. A peer advertising a height near u32::MAX therefore 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 existing checked_mul(..).unwrap() would panic instead.)

The fix

Two independent bounds. read_response_limit now uses saturating arithmetic and clamps to a MAX_READ_RESPONSE_LIMIT of 64 MiB. Separately, the height attached to the request is clamped to the mainchain height of the peer tip's BMM block, resolved via archive.get_main_height in the read txn that already validates that main header — a block at height h requires h distinct mainchain blocks, so this cannot under-count a legitimate tip.

Tests

Adds get_headers_read_response_limit_is_bounded, asserting a u32::MAX height 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.

Ash-L2L and others added 4 commits July 24, 2026 01:39
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants