Skip to content

hysteria2: harden UDP datagram parsing against malformed input#145

Open
zytakeshi wants to merge 1 commit into
cfal:masterfrom
zytakeshi:fix/hysteria2-udp-dos-hardening
Open

hysteria2: harden UDP datagram parsing against malformed input#145
zytakeshi wants to merge 1 commit into
cfal:masterfrom
zytakeshi:fix/hysteria2-udp-dos-hardening

Conversation

@zytakeshi
Copy link
Copy Markdown

Summary

Two small robustness fixes in run_udp_remote_to_local_loop's parsing of attacker-controlled hysteria2 UDP datagrams. No behavior change for valid datagrams.

Changes

  1. assert! on datagram size -> graceful return. max_datagram_size is reported by the remote QUIC endpoint and can be attacker-influenced. A value at or below header_overhead previously hit an assert! (and would also underflow the subsequent max_datagram_size - header_overhead). It now returns an io::Error for that connection instead of panicking.

  2. Bounds-check the varint address-length read. When the length indicator selects a multi-byte varint, the code sliced &data[9..9 + (num_bytes - 1)] without confirming those bytes were present. A small/truncated datagram could make the varint claim more bytes than exist, slicing out of range and panicking. It now checks the remaining buffer length and, per the reference (malformed datagrams are ignored), skips the datagram instead of crashing.

Testing

cargo check passes (only pre-existing warnings unrelated to this change).

A crafted UDP datagram could trigger an assert! on the datagram size and an
out-of-range slice when reading the varint-prefixed fragment address. Replace
the assert! with a graceful return and bounds-check the fragment address
length against the remaining buffer, so malformed input is dropped instead
of panicking the server.
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