Skip to content

Boxo bitswap/server: DOS unbounded persistent memory leak

High severity GitHub Reviewed Published May 10, 2023 in ipfs/boxo • Updated Nov 5, 2023

Package

gomod github.com/ipfs/go-libipfs (Go)

Affected versions

>= 0.5.0, < 0.6.0
< 0.4.1

Patched versions

0.6.0
0.4.1

Description

Impact

An attacker is able allocate arbitrarily many bytes in the Bitswap server by sending many WANT_BLOCK and or WANT_HAVE requests which are queued in an unbounded queue, with allocations that persist even if the connection is closed.
This affects users accepting untrusted connections with the Bitswap server, this also affects users using the old API stubs at github.com/ipfs/boxo/bitswap because it transitively uses github.com/ipfs/boxo/bitswap/server.

We have renamed go-libipfs to boxo; this document uses both terms interchangeably. The version numbers for both are applicable, as they share the same historical timeline.

Remediation

Apply one of:

  • Update boxo to v0.6.0 or later
  • Update boxo to v0.4.1
    Note that v0.5.0 is NOT safe, v0.4.1 is a backport of the v0.6.0 security fixes on top of v0.4.0.

Mitigations

  1. The server now limits how many wantlist entries per peer it knows.
    The MaxQueuedWantlistEntriesPerPeer option allows configuring how many wantlist entries the server remembers; if a peer sends a wantlist bigger than this (including a sum of multiple delta updates) the server will truncate the wantlist to the match the limit.
    This defaults to 1024 entries per peer.
  2. The server now properly clears state about peers when they disconnect.
    Peer state is more lazily allocated (only when a wantlist is received in the first place) and is properly cleared when the PeerDisconnected callback is received.
  3. The server now ignores CIDs above some size.
    Clients were able to send any CID as long as the total protobuf message were bellow the 4MiB limit. This is allowed to allocate lots of memory with very little entries.
    This can be configured using the MaxCidSize option and defaults to 168 bytes.
  4. The server now closes the connection if an inline CID is requested (either as WANT_* or CANCEL).
    The attack were more effective if done with CIDs that are present in target's blockstore, this is because this will push longer-lasting jobs on some priority queue.
    Since inline CID are literal data (instead of hashes of data), everyone always "has" any inline CID (since instead of loading the data from disk, it can be extracted from the CID). It makes no sense for anyone to ever ask you about an inline CID since they could also just parse it themselves. Thus, as a defensive measure, we kill the connection with peers that ask about an inline CID.

Vulnerable symbols

  • github.com/ipfs/go-libipfs/bitswap/server/internal/decision.(*Engine).MessageReceived
  • github.com/ipfs/go-libipfs/bitswap/server/internal/decision.(*Engine).NotifyNewBlocks
  • github.com/ipfs/go-libipfs/bitswap/server/internal/decision.(*Engine).findOrCreate
  • github.com/ipfs/go-libipfs/bitswap/server/internal/decision.(*Engine).PeerConnected

Patches

Workarounds

If you are using the stubs at github.com/ipfs/go-libipfs/bitswap and not taking advantage of the features provided by the server, refactoring your code to use the new split API will allow you to run in a client-only mode using: github.com/ipfs/boxo/bitswap/client.

References

@Jorropo Jorropo published to ipfs/boxo May 10, 2023
Published by the National Vulnerability Database May 10, 2023
Published to the GitHub Advisory Database May 11, 2023
Reviewed May 11, 2023
Last updated Nov 5, 2023

Severity

High

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
None
User interaction
None
Scope
Unchanged
Confidentiality
None
Integrity
Low
Availability
High

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:H

EPSS score

0.178%
(56th percentile)

CVE ID

CVE-2023-25568

GHSA ID

GHSA-m974-xj4j-7qv5

Source code

Credits

Loading Checking history
See something to contribute? Suggest improvements for this vulnerability.