Skip to content

Commit 9ecf24b

Browse files
a-denoyellecapflam
authored andcommitted
BUG/MAJOR: quic: fix padding with short packets
QUIC sending functions were extended to be more flexible. Of all the changes, they support now iterating over a variable instance of QEL instance of only 2 previously. This change has rendered PADDING emission less previsible, which was adjusted via the following patch : a60609f BUG/MINOR: quic: fix padding of INITIAL packets Its main purpose was to ensure PADDING would only be generated for the last iterated QEL instance, to avoid unnecessary padding. In parallel, a BUG_ON() statement ensure that built INITIAL packets are always padded to 1.200 bytes as necessary before emitted them. This BUG_ON() statement caused crash in one particular occurence : when building datagrams that mixed Initial long packets and 1-RTT short packets. This last occurence type does not have a length field in its header, contrary to Long packets. This caused a miscalculation for the necessary padding size, with INITIAL packets not padded enough to reach the necessary 1.200 bytes size. This issue was detected on 3.0.2. It can be reproduced by using 0-RTT combined with latency. Here are the used commands : $ ngtcp2-client --tp-file=/tmp/ngtcp2-tp.txt \ --session-file=/tmp/ngtcp2-session.txt --exit-on-all-streams-close \ 127.0.0.1 20443 "https://[::]/?s=32o" $ sudo tc qdisc add dev lo root netem latency 500ms Note that this issue cannot be reproduced on current dev version. Indeed, it seems that the following patch introduce a slight change in packet building ordering : cdfceb1 MINOR: quic: refactor qc_prep_pkts() loop This must be backported to 3.0. This should fix github issue #2609. (cherry picked from commit c714b6b) Signed-off-by: Christopher Faulet <[email protected]>
1 parent acb50d3 commit 9ecf24b

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/quic_tx.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,20 +1889,23 @@ static int qc_do_build_pkt(unsigned char *pos, const unsigned char *end,
18891889
padding_len = 0;
18901890
len_sz = quic_int_getsize(len);
18911891
/* Add this packet size to <dglen> */
1892-
dglen += head_len + len_sz + len;
1893-
/* Note that <padding> is true only when building an Handshake packet
1894-
* coalesced to an Initial packet.
1895-
*/
1892+
dglen += head_len + len;
1893+
if (pkt->type != QUIC_PACKET_TYPE_SHORT)
1894+
dglen += len_sz;
1895+
18961896
if (padding && dglen < QUIC_INITIAL_PACKET_MINLEN) {
1897-
/* This is a maximum padding size */
18981897
padding_len = QUIC_INITIAL_PACKET_MINLEN - dglen;
1899-
/* The length field value is of this packet is <len> + <padding_len>
1900-
* the size of which may be greater than the initial computed size
1901-
* <len_sz>. So, let's deduce the difference between these to packet
1902-
* sizes from <padding_len>.
1903-
*/
1904-
padding_len -= quic_int_getsize(len + padding_len) - len_sz;
1898+
19051899
len += padding_len;
1900+
/* Update size of packet length field with new PADDING data. */
1901+
if (pkt->type != QUIC_PACKET_TYPE_SHORT) {
1902+
size_t len_sz_diff = quic_int_getsize(len) - len_sz;
1903+
if (len_sz_diff) {
1904+
padding_len -= len_sz_diff;
1905+
len_sz += len_sz_diff;
1906+
dglen += len_sz_diff;
1907+
}
1908+
}
19061909
}
19071910
else if (len_frms && len_frms < QUIC_PACKET_PN_MAXLEN) {
19081911
len += padding_len = QUIC_PACKET_PN_MAXLEN - len_frms;

0 commit comments

Comments
 (0)