From e03f0f13c810fb10cda5bb9eadced36e538103d7 Mon Sep 17 00:00:00 2001 From: Benjamin Saunders Date: Sat, 19 Nov 2022 18:40:26 -0800 Subject: [PATCH] Pad packets enough to permit stealthy stateless resets --- quinn-proto/src/connection/packet_builder.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/quinn-proto/src/connection/packet_builder.rs b/quinn-proto/src/connection/packet_builder.rs index cce404800..8c1d81faa 100644 --- a/quinn-proto/src/connection/packet_builder.rs +++ b/quinn-proto/src/connection/packet_builder.rs @@ -128,13 +128,18 @@ impl PacketBuilder { unreachable!("tried to send {:?} packet without keys", space_id); }; - // Each packet must be large enough for header protection sampling, i.e. the - // combined lengths of the encoded packet number and protected payload must be at - // least 4 bytes longer than the sample required for header protection + // Each packet must be large enough for header protection sampling, i.e. the combined + // lengths of the encoded packet number and protected payload must be at least 4 bytes + // longer than the sample required for header protection. Further, each packet should be at + // least tag_len + 6 bytes larger than the destination CID on incoming packets so that the + // peer may send stateless resets that are indistinguishable from regular traffic. // pn_len + payload_len + tag_len >= sample_size + 4 // payload_len >= sample_size + 4 - pn_len - tag_len - let min_size = buffer.len() + (sample_size + 4).saturating_sub(number.len() + tag_len); + let min_size = Ord::max( + buffer.len() + (sample_size + 4).saturating_sub(number.len() + tag_len), + partial_encode.start + conn.rem_cids.active().len() + 6, + ); let max_size = buffer_capacity - partial_encode.start - partial_encode.header_len - tag_len; Some(PacketBuilder {