fix(p2p): bound peer-supplied vector sizes in three NOTIFY handlers#194
fix(p2p): bound peer-supplied vector sizes in three NOTIFY handlers#194raw391 wants to merge 1 commit into
Conversation
handle_notify_new_master_node_vote, handle_notify_new_transactions and handle_request_fluffy_missing_tx iterate a peer-supplied vector without a size cap. The codebase already defines CURRENCY_PROTOCOL_MAX_OBJECT_REQUEST_COUNT and CURRENCY_PROTOCOL_MAX_TXS_REQUEST_COUNT for the same pattern in handle_request_get_blocks and handle_notify_request_get_txs. Adds CURRENCY_PROTOCOL_MAX_VOTES_COUNT and CURRENCY_PROTOCOL_MAX_FLASHES_COUNT, drops oversized messages with LOG_ERROR_CCONTEXT matching the existing sibling pattern.
e72939d to
c96063c
Compare
|
With 30s blocks: So worst-case checkpoint vote backlog is roughly: That is above: So with 30s blocks, it is possible to exceed the max limit if enough checkpoint votes accumulate into one P2P relay batch. @raw391 |
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughSummary by CodeRabbit
WalkthroughNew maximum count constants for votes and flashes are added, and three P2P protocol handlers now validate incoming request sizes against these and existing limits, disconnecting peers whose requests exceed the thresholds. ChangesOversized request rejection
Estimated code review effort: 1 (Trivial) | ~5 minutes Sequence Diagram(s)sequenceDiagram
participant Peer
participant ProtocolHandler
participant Connection
Peer->>ProtocolHandler: notify_new_master_node_vote / request_fluffy_missing_tx / notify_new_transactions
ProtocolHandler->>ProtocolHandler: check size against MAX_* limit
alt size exceeds limit
ProtocolHandler->>Connection: drop_connection(context, false, false)
ProtocolHandler-->>Peer: return 1
else size within limit
ProtocolHandler->>ProtocolHandler: continue normal processing
end
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Three NOTIFY handlers in
cryptonote_protocol_handler.inliterate a peer-supplied vector without checking its size first:handle_notify_new_master_node_voteat line 937 walksarg.votesdoing signature verification per elementhandle_notify_new_transactionsat line 1081 parsesarg.txsunderincoming_tx_lockhandle_request_fluffy_missing_txat line 980 does per-index dup check + block tx lookup overarg.missing_tx_indicesThe codebase already defines
CURRENCY_PROTOCOL_MAX_OBJECT_REQUEST_COUNTandCURRENCY_PROTOCOL_MAX_TXS_REQUEST_COUNTatcryptonote_protocol_handler.h:56-57and uses them inhandle_request_get_blocks(line 1190) andhandle_notify_request_get_txs(line 1737). This PR adds the same pattern to the three vote/tx/fluffy handlers, plusCURRENCY_PROTOCOL_MAX_FLASHES_COUNTfor the flash batch size inhandle_notify_new_transactions.Cap values: 1000 votes (50x current max quorum), 5000 txs and 500 missing-tx indices reuse existing constants, 1000 flashes matches the votes ceiling.
LOG_ERROR_CCONTEXTmatches the existing sibling pattern at lines 1190 and 1737.