Skip to content

feat(gossip): Add RPC limits#350

Open
bismuth01 wants to merge 1 commit into
libp2p:masterfrom
bismuth01:gossip-memory
Open

feat(gossip): Add RPC limits#350
bismuth01 wants to merge 1 commit into
libp2p:masterfrom
bismuth01:gossip-memory

Conversation

@bismuth01

Copy link
Copy Markdown
Contributor

The current gossip protocol implementation takes the whole RPC message and processes them. The lack of an upper bound on the amount of each type of message creates the possibility of memory exhaustion attacks as reported in #349 by @tonghuaroot.

What this PR adds: -

  • struct libp2p::protocol::gossip::RPCLimits which defines the possible RPC message parsing limits.
  • Modification of libp2p::protocol::gossip::MessageParser to enforce usage of these limits. Logically, the parsing process counts the number of messages processed and once it reaches the defined limits, it ignores the rest.
  • A lot of test cases defined in test/libp2p/protocol/gossip/gossip_rpc_limits_test.cpp for reproducable testing of the modified RPC message parsing logic.

How I checked if everything works correctly: -

  • All test cases pass and use controlled randomness to ensure functionality and reproducability.
  • The gossip_chat_example whose source code lies in example/03-gossip compiles without any modifications and works as expected showing that the current changes add a default limit to the RPC message parsing and does not hinder existing code either.

The default value for the limits were copied from js-libp2p interface default values.

NOTE: This PR solves only half the problem of memory exhaustion attacks as defined in #349 and another layer of configuration must be added to gossip to limit in increase of size libp2p::protocol::gossip::RemoteSubscriptions and related classes & structs which handle information about remote peers.

Thanks to @tonghuaroot for identifying and reporting the issue.

Added RPC limit options to Gossip protocol to control the amount of
processing of each message type and message id. This helps prevent
memory exhaustion attacks.
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.

1 participant