Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tighten reset loop prevention #1665

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions picoquic/packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,13 @@ void picoquic_prepare_version_negotiation(
* Per draft 14, the stateless reset starts with the packet code 0K110000.
* The packet has after the first byte at least 23 random bytes, and then
* the 16 bytes reset token.
*
* The "pad size" is computed so that the packet length is always at least
* 1 byte shorter than the incoming packet. Since the minimum size of a
* stateless reset is PICOQUIC_RESET_PACKET_MIN_SIZE, this code only
* respond to packets that are strictly larger than the size.
*
*
*/
void picoquic_process_unexpected_cnxid(
picoquic_quic_t* quic,
Expand All @@ -1158,20 +1165,16 @@ void picoquic_process_unexpected_cnxid(
quic->stateless_reset_next_time <= current_time) {
picoquic_stateless_packet_t* sp = picoquic_create_stateless_packet(quic);
if (sp != NULL) {
size_t pad_size = length - PICOQUIC_RESET_SECRET_SIZE -1;
size_t pad_size = length - PICOQUIC_RESET_SECRET_SIZE - 2;
uint8_t* bytes = sp->bytes;
size_t byte_index = 0;

if (pad_size > PICOQUIC_RESET_PACKET_PAD_SIZE) {
pad_size = (size_t)picoquic_public_uniform_random(pad_size - PICOQUIC_RESET_PACKET_PAD_SIZE)
+ PICOQUIC_RESET_PACKET_PAD_SIZE;
}
else {
pad_size = PICOQUIC_RESET_PACKET_PAD_SIZE;
if (pad_size > PICOQUIC_RESET_PACKET_MIN_SIZE - PICOQUIC_RESET_SECRET_SIZE - 1) {
pad_size -= (size_t)picoquic_public_uniform_random(pad_size - (PICOQUIC_RESET_PACKET_MIN_SIZE - PICOQUIC_RESET_SECRET_SIZE - 1));
}

/* Packet type set to short header, randomize the 5 lower bits */
bytes[byte_index++] = 0x30 | (uint8_t)(picoquic_public_random_64() & 0x1F);
bytes[byte_index++] = 0x40 | (uint8_t)(picoquic_public_random_64() & 0x3F);

/* Add the random bytes */
picoquic_public_random(bytes + byte_index, pad_size);
Expand Down
1 change: 1 addition & 0 deletions picoquic/port_blocking.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ const uint16_t picoquic_blocked_port_list[] = {
53, /* DNS */
19, /* Chargen */
17, /* Quote of the Day */
7, /* Echo */
0, /* Unusable */
};

Expand Down
Loading