Repository navigation
fix(http3): bound connect-udp datagram events per control stream read - #4182
larseggert wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
Static review found no blocking defects in the bounded accounting, continued parsing, or regression tests; tests were not executed.
No open issues 🎉
What changed in this PR
This PR limits CONNECT-UDP datagram events generated by a single control-stream read, reducing memory amplification while continuing to consume the stream.
Changes:
- Adds a 256 KiB per-read budget, charging each datagram’s payload size plus 64 bytes of overhead.
- Drops datagrams that exceed the remaining budget without stopping capsule parsing.
- Adds regression tests for both directions, budget boundaries, and subsequent datagram delivery.
| File | Description |
|---|---|
neqo-http3/src/features/extended_connect/tests/webtransport/mod.rs |
Exposes the connection helper for reuse in CONNECT-UDP tests. |
neqo-http3/src/features/extended_connect/tests/mod.rs |
Makes the WebTransport test module accessible to sibling tests. |
neqo-http3/src/features/extended_connect/connect_udp_session.rs |
Enforces the per-read event budget and adds regression tests. |
Review effort: Balanced
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4182 +/- ##
==========================================
- Coverage 96.97% 96.80% -0.17%
==========================================
Files 113 118 +5
Lines 42253 42711 +458
Branches 42253 42711 +458
==========================================
+ Hits 40976 41348 +372
- Misses 1263 1339 +76
- Partials 14 24 +10
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Merging this PR will improve performance by 2.8%1 warning
Performance Changes
Tip Curious why performance improved? Comment Comparing |
5932039 to
74929eb
Compare
Drop datagram capsules once one read of the control stream has queued 256 KiB of datagram events, so a peer cannot make the receiver queue an event per tiny capsule across a whole flow-control window. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-76JLDZJA.
74929eb to
20f6f35
Compare
Failed Interop TestsQUIC Interop Runner, client vs. server, differences relative to
All resultsSucceeded Interop TestsQUIC Interop Runner, client vs. server neqo-pr as client
neqo-pr as server
Unsupported Interop TestsQUIC Interop Runner, client vs. server neqo-pr as client
neqo-pr as server
|
Client/server transfer resultsPerformance differences relative to db74969. Transfer of 33554432 bytes over loopback, min. 100 runs. All unit-less numbers are in milliseconds.
Table above only shows statistically significant changes. See all results below. All resultsTransfer of 33554432 bytes over loopback, min. 100 runs. All unit-less numbers are in milliseconds.
Download data for |
Benchmark resultsNo significant performance differences relative to db74969. All resultstransfer/1-conn/1-100mb-req (aka. Upload)/mtu-1500 time: [57.234 ms 57.279 ms 57.329 ms]
thrpt: [1.7034 GiB/s 1.7049 GiB/s 1.7063 GiB/s]
Found 4 outliers among 100 measurements (4.00%)
3 (3.00%) high mild
1 (1.00%) high severetransfer/1-conn/1-100mb-resp (aka. Download)/mtu-1500 time: [57.211 ms 57.266 ms 57.322 ms]
thrpt: [1.7037 GiB/s 1.7053 GiB/s 1.7070 GiB/s]transfer/1-conn/1-1b-resp (aka. HPS)/mtu-1500 time: [3.5174 ms 3.5181 ms 3.5189 ms]
thrpt: [284.18 B/s 284.24 B/s 284.30 B/s]
Found 11 outliers among 100 measurements (11.00%)
7 (7.00%) high mild
4 (4.00%) high severetransfer/1-conn/10_000-parallel-1b-resp (aka. RPS)/mtu-1500 time: [81.114 ms 81.242 ms 81.371 ms]
thrpt: [122.89 Kelem/s 123.09 Kelem/s 123.28 Kelem/s]
Found 1 outliers among 100 measurements (1.00%)
1 (1.00%) low mildstreams-flow-controlled/walltime/1-streams/each-4194304-bytes time: [12.614 ms 12.619 ms 12.624 ms]
thrpt: [316.85 MiB/s 316.99 MiB/s 317.12 MiB/s]
Found 6 outliers among 100 measurements (6.00%)
6 (6.00%) high mildstreams-flow-controlled/walltime/10-streams/each-1048576-bytes time: [34.300 ms 34.333 ms 34.368 ms]
thrpt: [290.97 MiB/s 291.27 MiB/s 291.54 MiB/s]
Found 14 outliers among 100 measurements (14.00%)
9 (9.00%) high mild
5 (5.00%) high severestreams/walltime/1-streams/each-1000-bytes time: [155.65 µs 156.28 µs 157.09 µs]
thrpt: [6.0707 MiB/s 6.1022 MiB/s 6.1269 MiB/s]
Found 2 outliers among 100 measurements (2.00%)
2 (2.00%) high mildstreams/walltime/1000-streams/each-1-bytes time: [4.4836 ms 4.4894 ms 4.4950 ms]
thrpt: [217.25 KiB/s 217.53 KiB/s 217.81 KiB/s]
Found 2 outliers among 100 measurements (2.00%)
2 (2.00%) low mildstreams/walltime/1000-streams/each-1000-bytes time: [14.731 ms 14.744 ms 14.757 ms]
thrpt: [64.624 MiB/s 64.681 MiB/s 64.737 MiB/s]
Found 1 outliers among 100 measurements (1.00%)
1 (1.00%) high mildtransfer/walltime/pacing-false/same-seed time: [3.8820 ms 3.8852 ms 3.8890 ms]
thrpt: [1.0044 GiB/s 1.0054 GiB/s 1.0063 GiB/s]transfer/walltime/pacing-false/varying-seeds time: [3.8854 ms 3.8927 ms 3.9013 ms]
thrpt: [1.0013 GiB/s 1.0035 GiB/s 1.0054 GiB/s]
Found 23 outliers among 100 measurements (23.00%)
23 (23.00%) low mildtransfer/walltime/pacing-true/same-seed time: [4.1921 ms 4.2008 ms 4.2085 ms]
thrpt: [950.46 MiB/s 952.20 MiB/s 954.18 MiB/s]transfer/walltime/pacing-true/varying-seeds time: [4.1185 ms 4.1216 ms 4.1251 ms]
thrpt: [969.66 MiB/s 970.50 MiB/s 971.22 MiB/s]Instructions per cycleCriterion reported no significant timing changes. All benchmarks
Profiles for profiler.firefox.com (64)
Download data for |
| control_stream_recv: &mut Box<dyn RecvStream>, | ||
| now: Instant, | ||
| ) -> Res<Option<State>> { | ||
| let mut budget = MAX_DATAGRAM_BYTES_PER_READ; |
There was a problem hiding this comment.
This bounds the events queued per read_control_stream call, but not the events outstanding. The budget starts fresh on every call (from both Session::receive and header_unblocked), and consuming the stream data reopens flow control, so a peer can send another window of tiny capsules every RTT. If the application doesn't poll events between process calls, or polls more slowly than the peer sends, each read adds up to another ~4096 Datagram events and the queue still grows without bound.
Would it work to track outstanding queued bytes per session, released as events are polled, like transport's max_buffered_datagrams? That bounds memory regardless of how reads are batched.
| Some(Capsule::Datagram { payload }) => match self.dgram_context_id(payload) { | ||
| Ok(slice) => { | ||
| events.new_datagram(self.session_id, slice, self.connect_type()); | ||
| let cost = slice.len().saturating_add(PER_DATAGRAM_OVERHEAD); |
There was a problem hiding this comment.
This will also drop legitimate traffic. With an multi-MB stream receive window, a single lost packet blocks the stream; when the retransmission fills the gap, everything buffered behind it becomes readable in one read, and anything past the first 256 KB is discarded even though the peer sent it within flow control and we've already ACKed it. A tunneled flow would see a burst loss after every recovery event. That's the same scenario the hold_first tests construct, just with benign traffic.
A cap on outstanding (unpolled) events, per the comment above, avoids this, since a well-behaved application drains between reads.
Also, this undercounts actual memory per event. Each queued event is an Http3ClientEvent/Http3ServerEvent in a VecDeque slot plus a Bytes header, and the backing allocation is the full capsule payload including the context-ID prefix (not just slice.len()). For an empty datagram I suspect that's well over 64 bytes, so the real bound per read is a multiple of the documented 256 KB. The 64 was chosen for transport's queue entries, not HTTP/3 events.
| events.new_datagram(self.session_id, slice, self.connect_type()); | ||
| } else { | ||
| // RFC 9221 Section 5.3 lets the receiver drop datagrams. | ||
| debug!("[{self}]: dropped datagram over the per-read budget"); |
There was a problem hiding this comment.
Two concerns: there's no counter, stat or event for these drops, so the application can't tell that it's losing datagrams (which makes the case in the previous comment hard to diagnose), and under the flood this is guarding against it logs once per dropped capsule, which can be hundreds of thousands of lines per read with debug logging on. Could we count the drops and log once per read (and ideally surface the count in stats)?
| @@ -75,7 +82,14 @@ impl Protocol for Session { | |||
| match capsule { | |||
| Some(Capsule::Datagram { payload }) => match self.dgram_context_id(payload) { | |||
There was a problem hiding this comment.
Datagrams over the budget are still fully decoded before being dropped: Capsule::decode does Bytes::from(payload.to_vec()) (frames/capsule.rs:59), and the context ID is parsed, then the allocation is freed. The loop also keeps reading after the budget is exhausted. So under a flood each read still does work proportional to the whole flow-control window, and the CPU side of the amplification is unchanged. Could we stop reading once the budget is exhausted, or check the length before allocating?
| const MAX_DATAGRAM_BYTES_PER_READ: usize = 256 * 1024; | ||
|
|
||
| /// Per-event bookkeeping charge, as `PER_DATAGRAM_OVERHEAD` in neqo-transport's datagram queue. | ||
| const PER_DATAGRAM_OVERHEAD: usize = 64; |
There was a problem hiding this comment.
This duplicates the private constant in neqo-transport/src/datagram_queue.rs:62, and the doc comment says it mirrors it, but nothing ties them together; if transport changes its value this silently diverges. Maybe export the transport one (or a cost helper) instead? However, see below -- using PER_DATAGRAM_OVERHEAD from transport probably isn't what we want, so perhaps just use a different constant (and name)
| } | ||
|
|
||
| /// Establishes a session that carries datagrams in capsules. | ||
| fn capsule_session() -> (Http3Client, Http3Server, ServerSession) { |
There was a problem hiding this comment.
This is largely the same as establish_capsule_session in neqo-http3/tests/connect_udp.rs:770. It also requires making tests::webtransport and its connect() public so connect-udp unit tests can reach into the WebTransport test module. Could the two setups share one helper, or the flood tests live alongside the existing integration tests in tests/connect_udp.rs?
| if hold_first { | ||
| held.push(flight.remove(0)); | ||
| } | ||
| flight = sender.exchange(receiver.exchange(flight)); | ||
| } |
There was a problem hiding this comment.
hold_first withholds the first datagram of every flight, not just the one carrying the first stream data, so later ACK-only or MAX_STREAM_DATA packets are held as well and delivered together with the gap-filler. The exact assertions (== budgeted, == budgeted - 1) depend on the capsules landing so that everything becomes readable in exactly one read. A change in packetization or pacing could break them for reasons unrelated to the budget logic. Holding only the first packet of the first flight would make the tests less sensitive to that.
|
@jesup please make the changes you think this PR needs to land it. |
mxinden
left a comment
There was a problem hiding this comment.
I don't think this low severity attack warants the complexity this fix introduces.
A connect-udp session turned every DATAGRAM capsule readable on its control stream into an event in a single read, so a peer could make the receiver queue one event per few bytes of a whole flow-control window. Each read now charges every datagram its payload size plus 64 bytes of overhead against a 256 KiB budget and drops datagrams beyond it, as RFC 9298 Section 5 and RFC 9221 Section 5.3 allow. Parsing continues, so the stream is still consumed and the session stays usable. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-76JLDZJA.
Also reported independently by @gadievron, as H3Q-037.