llamaCVEVulnerability Intelligence
/
Advisory · GitHub · PyPI · libp2p

GHSA-34VQ-766Q-GC73

Unbounded length-prefixed read in Mplex muxer and Pubsub RPC reader allows persistent DoS (missing max_length/timeout)

Parche disponible
Descargar PNG JSON
CVSS 3.1
7.5
Alta
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H Fuente: GitHub
ExplotaciónSin evidenciaNo figura en CISA KEV
Exploits públicos0Ninguno conocido
Parche1 versiónPrimer parche a 55 d de la divulgación
Exposición109 dDesde la divulgación, 2 ago 2026, 10:59 a. m.
Detección108 dDesde la divulgación hasta su ingreso al índice
Timeline

Ciclo de vida de la vulnerabilidad

Hoy
Divulgación
Publicada +1
Explotación
Remediación
Parche 0.8.0
Monitoreo
Detectada +1
2 ago 26
26 sept 26
19 nov 26
20 nov 26
2 ago 26
30 ago 26
26 sept 26
23 oct 26
20 nov 26
FechaFaseEventoDetalle
Divulgación Publicada GHSA-34VQ-766Q-GC73 divulgada · CVSS 7.5 (GitHub)
Divulgación Modificada Última actualización del registro
Remediación Parche 0.8.0 libp2p · 55 d desde divulgación
Monitoreo Detectada Ingresó al índice
Monitoreo Verificada Última verificación contra las fuentes
Resumen
Descripción del advisory
Texto original · GitHub · en inglés

## Summary
py-libp2p's Mplex stream muxer and Pubsub (gossipsub/floodsub) RPC reader both read a length-prefixed message body using the async helper `read_varint_prefixed_bytes` (libp2p/utils/varint.py:117), which imposes no maximum length and no read timeout. A post-handshake peer that announces a large uvarint length prefix and then withholds the body (keeping the socket open) causes the victim's per-connection Mplex read loop — or per-peer Pubsub read task — to block forever in `read_exactly` (libp2p/io/utils.py:47). At scale this fills the connection table (default `max_connections=600`) with unkillable hung connections, denying service to legitimate peers.

This is the same vulnerability class as GHSA-hmj8-5xmh-5573 (yamux oversized/withheld DATA frame DoS), on two sibling code paths the yamux fix (commit 146ea87d, which touched only yamux.py) left unprotected. The async `read_varint_prefixed_bytes` notably lacks the `max_length=1MiB` guard that its own synchronous sibling `read_varint_prefixed_bytes_sync` (varint.py:143) already enforces — evidence the maintainer knows the guard but omitted it on the async path.

## Root Cause
`libp2p/utils/varint.py:117` — `async def read_varint_prefixed_bytes(reader)` decodes a 64-bit uvarint length then calls `read_exactly(reader, len_msg)` with no `max_length` and no `trio.fail_after`. `read_exactly` (io/utils.py:47) blocks on the first `reader.read(n)` until data or EOF arrives; on a fully-withheld body it blocks indefinitely (its `retry_count=100` only bounds *partial*/dribble reads, never triggering when the body is fully withheld).

Two unguarded call sites:
- Vector A (Mplex, default muxer): `Mplex.handle_incoming` (mplex.py:237) → `read_message` (mplex.py:254) → `read_varint_prefixed_bytes` (mplex.py:273). The muxer read loop is started via `self.manager.run_task(muxed_conn.start)` at swarm.py:1747 as a background task with no cancel scope, and *after* the `trio.fail_after(inbound_upgrade_timeout)` scope (swarm.py:1501–1535) has already exited at swarm.py:1591. No `fail_after`/`move_on_after` exists anywhere in mplex.py (verified on v0.7.0 and HEAD).
- Vector B (Pubsub, gossipsub/floodsub): `continuously_read_stream` (pubsub.py:490) loops `read_varint_prefixed_bytes(stream)` (pubsub.py:501), invoked via `handler(net_stream)` at basic_host.py:1295 with no surrounding timeout. (The `fail_after`s at pubsub.py:725/758 are in `wait_for_peer`/`wait_for_subscription`, not the read loop.)

## Impact
Remotely-triggerable, persistent Denial of Service. A single hung read loop wedges that connection/stream's processing permanently (no idle-reaping: the default ResourceManager enforces connection/stream *counts* only, and ConnectionPruner triggers only above the 550 high-watermark by peer-tag value). Repeated across many connections, the connection table fills with unkillable hung connections and new legitimate inbound connections are rejected (swarm.py:1436 "Maximum connections limit reached"). Same auth prerequisite as GHSA-hmj8-5xmh-5573: any network peer that completes the anonymous security handshake and muxer/protocol negotiation (PR:N).

Note: a "memory exhaustion via dribbled bytes" reading of this bug is overstated — `read_exactly`'s `retry_count=100` plus trio receive chunking bounds a single connection's transient buffer (freed on `IncompleteReadError`), and growth is 1:1 with bandwidth (no amplification). The reliable primitive is the persistent hang / connection-slot exhaustion, not memory growth.

Proof of Concept

import socket
def uvarint(n):
    out = b""
    while True:
        b = n & 0x7f; n >>= 7
        out += bytes([b | 0x80]) if n else bytes([b])
        if not n: return out
s = socket.create_connection((TARGET_HOST, TARGET_PORT))
# ... perform standard multistream + security handshake + negotiate /mplex/6.7.0 ...
header = uvarint((1 << 3) | 2)   # stream_id=1, flag=MessageInitiator
length = uvarint(1 << 40)        # announce ~1 TiB body
s.sendall(header + length)       # send header + length prefix, NO body
# keep the socket open forever -> victim's Mplex.handle_incoming blocks in read_exactly
# repeat across many sockets to exhaust max_connections (600)

For Vector B, open `/meshsub/1.1.0` (or `/floodsub/1.0.0`) against a pubsub-enabled node and send an RPC frame announcing a huge uvarint length with the body withheld.

## Attack Chain
### Vector A — Mplex muxer (default)
1. Entry: attacker TCP-connects to a public libp2p listener, completes the anonymous security handshake, muxer-negotiates `/mplex/6.7.0`.
- Guard: muxer multiselect + `negotiate_timeout`.
- Bypass proof: attacker is the dialer/initiator → chooses the protocol; Mplex is a registered default muxer (`__init__.py:238` fallback, `:249` primary); `negotiate_timeout` covers only protocol-id selection, not subsequent frame/body reads.
2. Loop start: swarm `add_conn` (swarm.py:1591) → `run_task(muxed_conn.start)` (swarm.py:1747).
- Guard: none — background `FunctionTask` in the service root nursery, no cancel scope; started *after* `fail_after(inbound_upgrade_timeout)` exited at swarm.py:1535.
- Bypass proof: `run_task` (trio_manager.py:389) attaches no timeout.
3. Sink: `handle_incoming` (mplex.py:237) → `read_message` (:254) → `read_varint_prefixed_bytes` (:273) → `read_exactly` (varint.py:119 → io/utils.py:47).
- Guard: none.
- Bypass proof: `grep fail_after|move_on_after mplex.py` = 0 (v0.7.0 and HEAD); varint.py:117 has no `max_length`; the sync sibling at :143 does take `max_length=1MiB`.
4. Impact: header + huge uvarint length + withheld body → `read_exactly` blocks on the first `reader.read()` forever → mux loop stalls permanently; repeat to fill `max_connections` (600) → legitimate peers rejected.

### Vector B — Pubsub RPC reader (conditional on gossipsub/floodsub enabled)
1. Entry: attacker peers with a pubsub-enabled victim, opens `/meshsub/1.1.0`.
- Guard: victim must run a pubsub router (NOT bare `new_host()`).
- Bypass proof: handler registered unconditionally once a router exists (pubsub.py:403); no per-peer allowlist. Non-default config narrows the population but exploitation is deterministic → AC:L.
2. Loop: `stream_handler` (:674) → `continuously_read_stream` (:490), invoked via `handler(net_stream)` at basic_host.py:1295.
- Guard: none — no `fail_after` around the loop (the :725/:758 `fail_after`s are in `wait_for_peer`/`wait_for_subscription`).
3. Sink: `read_varint_prefixed_bytes(stream)` (:501) → `read_exactly` (varint.py:119) — same unbounded sink as Vector A.
4. Impact: RPC frame announces huge length, body withheld → `read_exactly` blocks forever → that peer's pubsub read task starved permanently.

## Bypass Evidence
- `grep -c "fail_after\|move_on_after" libp2p/stream_muxer/mplex/mplex.py` = 0 (v0.7.0 and HEAD).
- `read_varint_prefixed_bytes` (varint.py:117) has no `max_length`/timeout; sync sibling `read_varint_prefixed_bytes_sync` (varint.py:143) enforces `max_length=1MiB` — maintainer-known guard omitted on the async path.
- The yamux fix commit `146ea87d` touched only `stream_muxer/yamux/yamux.py` (+ test) — mplex/pubsub/varint/io paths untouched (`git show --stat`).
- `inbound_upgrade_timeout` (default 10s) exits at swarm.py:1535, before the muxer loop starts at swarm.py:1747 — does not cover the loop.
- `read_exactly` `retry_count=100` bounds only dribble/partial reads; a fully-withheld body blocks on the first `reader.read()` and never enters the retry loop.
- No idle/read reaping in `libp2p/rcmgr/*`; ConnectionPruner triggers only above the 550 high-watermark by peer-tag value.

## Affected Versions
`<= 0.7.0` (latest release). Verified: the vulnerable code is present on tag v0.7.0; the yamux fix `146ea87d` is contained in NO released tag (`git tag --contains 146ea87d` → empty), so v0.7.0 is vulnerable on yamux, mplex, and pubsub. No fix for the mplex/pubsub/varint read paths exists on any tag or on HEAD (`git log v0.7.0..HEAD` on the four files → no relevant change). Vector B additionally requires a pubsub router (gossipsub/floodsub) to be enabled by the application.

## Suggested Fix
Add a `max_length` parameter to `read_varint_prefixed_bytes` (mirroring `read_varint_prefixed_bytes_sync`'s 1 MiB cap) and reject over-large announced lengths, AND/OR wrap the Mplex and Pubsub body-read loops in a `trio.fail_after(...)` timeout — exactly as the yamux fix (146ea87d) did with `MAX_WINDOW_SIZE` and a `_read_data_body` `fail_after`.

---
Reported by zx (Jace) — GitHub: @manus-use

Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.

Vector CVSS 3.1

Desglose de métricas

Opción resaltada = valor del vector · izquierda = peor caso · GitHub
Vector de ataqueAV:N
RedAdyacenteLocalFísica
ComplejidadAC:L
BajaAlta
PrivilegiosPR:N
NingunoBajosAltos
InteracciónUI:N
NingunaRequerida
AlcanceS:U
CambiadoSin cambio
ConfidencialidadC:N
AltoBajoNinguno
IntegridadI:N
AltoBajoNinguno
DisponibilidadA:H
AltoBajoNinguno
Versiones

Rangos afectados

Afectada Corregida Última
libp2p≤ 0.7.0
0.7.0
0.8.1
Remediación

Estado del parche por paquete

Paquete / productoEstadoCorregida enDesde divulgaciónÚltima versión
pypilibp2p
Corregida 0.8.0 55 d 0.8.1 no afectada
Versiones corregidas0.8.0
Explotación

Arsenal público

Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.

Referencias
Advisoryhttps://github.com/libp2p/py-libp2p/security/advisories/GHSA-34vq-766q-gc73

Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.