Skip to content

Use randomized HashMap for yamux stream IDs#441

Open
Officeyutong wants to merge 1 commit into
nervosnetwork:masterfrom
Officeyutong:fix-intmap-cpu-consumption
Open

Use randomized HashMap for yamux stream IDs#441
Officeyutong wants to merge 1 commit into
nervosnetwork:masterfrom
Officeyutong:fix-intmap-cpu-consumption

Conversation

@Officeyutong

Copy link
Copy Markdown
Collaborator

Summary

Replace the yamux active stream map with the standard HashMap and remove the nohash-hasher dependency from tokio-yamux.

Remote peers control inbound yamux stream IDs through frame headers. Using nohash_hasher::IntMap for those keys removes randomized hashing and makes insertion/lookup behavior dependent on attacker-chosen integer values. Switching back to the default HashMap restores randomized hashing for externally controlled stream IDs.

Testing

  • cargo fmt
  • cargo test -p tokio-yamux

@Officeyutong Officeyutong requested a review from eval-exec as a code owner June 23, 2026 08:15

@driftluo driftluo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand this. The purpose of using nohasher is to reduce the overhead of frequent hashing. If an attacker provides an existing ID, it will directly throw an error. Only non-existent IDs can start the stream. So what serious consequences could the attacker's wrong behavior lead to?

@quake

quake commented Jun 23, 2026

Copy link
Copy Markdown
Member

I don't quite understand this. The purpose of using nohasher is to reduce the overhead of frequent hashing. If an attacker provides an existing ID, it will directly throw an error. Only non-existent IDs can start the stream. So what serious consequences could the attacker's wrong behavior lead to?

This is a hash flooding dos issue, the StreamId is controlled by remote peer, attacker can create excessive hash collisions and degrade hash-table operations from expected O(1) to O(n).

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.

3 participants