Make sure lists are unique in zebra-network Request
s and Response
s
#2244
Labels
A-network
Area: Network protocol updates or fixes
A-rust
Area: Updates to Rust code
C-security
Category: Security issues
I-invalid-data
Zebra relies on invalid or untrusted data, or sends invalid data
Motivation
Most of
zebra-network
's internalRequest
s useHashSet
s to deduplicate outbound Zebra requests and inbound peer requests.But we don't do the same for Zebra's internal
Response
s. (Outbound Zebra responses to peers, and inbound peer responses to Zebra.)We also don't ensure uniqueness in ordered maps (like
known_blocks
lists inRequest
s).Scheduling
This risk is acceptable for the stable release, but we need to fix it before we support lightwalletd.
Specifications
This change impacts Bitcoin-style data and control messages:
https://developer.bitcoin.org/reference/p2p_networking.html#data-messages
https://developer.bitcoin.org/reference/p2p_networking.html#control-messages
The specs for each message type are linked below.
Solution
Parsing
Duplicates in inbound messages should be:
Duplicates in outbound messages are structurally impossible. The code that generates these lists should be modified to use the same indexes.
Request Types
Update the request types to ensure:
FindBlocks
known_blocks
contains unique BlockHashes in chain order:IndexMap
https://developer.bitcoin.org/reference/p2p_networking.html#getblocks
FindHeaders
known_blocks
contains unique BlockHashes in chain order:IndexMap
https://developer.bitcoin.org/reference/p2p_networking.html#getheaders
Response Types
Update the response types to ensure:
Peers
Having different times or services for the same address is also an error.
Unique peer addresses
Peers(Vec<MetaAddr>)
toPeers(HashMap<SocketAddr, MetaAddr>)
- order is not importanthttps://developer.bitcoin.org/reference/p2p_networking.html#addr
Blocks
Unique blocks
Blocks(Vec<Arc<Block>>)
toBlocks(IndexMap<block::Hash, Arc<Block>>)
- download order could be important for performancehttps://developer.bitcoin.org/reference/p2p_networking.html#block
BlockHashes
Unique BlockHashes in chain order:
IndexMap
https://developer.bitcoin.org/reference/p2p_networking.html#inv
BlockHeaders
Unique block headers
BlockHeaders(Vec<block::CountedHeader>)
toBlockHeaders(HashMap<block::Hash, block::CountedHeader>)
- download order could be important for performancehttps://developer.bitcoin.org/reference/p2p_networking.html#headers
Transactions
Unique transactions
Transactions(Vec<Arc<Transaction>>)
toTransactions(HashMap<transaction::Hash, Arc<Transaction>>)
https://developer.bitcoin.org/reference/p2p_networking.html#tx
TransactionHashes
Unique transaction hashes
TransactionHashes(Vec<_>)
toTransactionHashes(HashSet<_>)
https://developer.bitcoin.org/reference/p2p_networking.html#inv
Unlike
BlockHashes
, loose transactions don't have any chain or block ordering.Request HashMaps
HashSet
s that could becomeHashMap
s, because part of the data structure is unique, not the whole thingAlternatives
We could drop duplicates instead, which reduces the impact of attacks where malicious peers trick honest peers into sending duplicates. But it also allows malicious peers to perform more attacks directly.
We could de-duplicate when processing messages.
This change is not strictly required, but it does improve security in some edge-cases.
The text was updated successfully, but these errors were encountered: