Skip to content

Commit f903bfe

Browse files
authored
Tentative fix for a deadlock from 4169 (#4245)
1 parent 64c43fb commit f903bfe

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/core/packet_builder.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ QuicPacketBuilderInitialize(
101101
Builder->Path = Path;
102102
Builder->PacketBatchSent = FALSE;
103103
Builder->PacketBatchRetransmittable = FALSE;
104+
Builder->WrittenConnectionCloseFrame = FALSE;
104105
Builder->Metadata = &Builder->MetadataStorage.Metadata;
105106
Builder->EncryptionOverhead = CXPLAT_ENCRYPTION_OVERHEAD;
106107
Builder->TotalDatagramsLength = 0;
@@ -493,9 +494,12 @@ QuicPacketBuilderGetPacketTypeAndKeyForControlFrames(
493494
? QUIC_PACKET_KEY_HANDSHAKE
494495
: QUIC_PACKET_KEY_INITIAL;
495496

496-
if ((Builder->Datagram == NULL || Builder->DatagramLength == 0) &&
497+
if (!Builder->WrittenConnectionCloseFrame &&
497498
Connection->Crypto.TlsState.WriteKeys[PreviousKeyType] != NULL) {
498-
MaxKeyType = PreviousKeyType; // Use the lower key for the first packet in a datagram.
499+
//
500+
// Downgrade the key so that we send the CLOSE frame on previous protection level.
501+
//
502+
MaxKeyType = PreviousKeyType;
499503
}
500504
}
501505

src/core/packet_builder.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ typedef struct QUIC_PACKET_BUILDER {
7878
//
7979
uint8_t EcnEctSet : 1;
8080

81+
//
82+
// Indicates that a CONNECTION_CLOSE frame was written in some packet.
83+
//
84+
uint8_t WrittenConnectionCloseFrame : 1;
85+
8186
//
8287
// The total number of datagrams that have been created.
8388
//

src/core/send.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ QuicSendWriteFrames(
532532
char* CloseReasonPhrase = Connection->CloseReasonPhrase;
533533

534534
if (IsApplicationClose && ! Is1RttEncryptionLevel) {
535-
//
535+
//
536536
// A CONNECTION_CLOSE of type 0x1d MUST be replaced by a CONNECTION_CLOSE of
537537
// type 0x1c when sending the frame in Initial or Handshake packets. Otherwise,
538538
// information about the application state might be revealed. Endpoints MUST
@@ -558,6 +558,8 @@ QuicSendWriteFrames(
558558
AvailableBufferLength,
559559
Builder->Datagram->Buffer)) {
560560

561+
Builder->WrittenConnectionCloseFrame = TRUE;
562+
561563
//
562564
// We potentially send the close frame on multiple protection levels.
563565
// We send in increasing encryption level so clear the flag only once

0 commit comments

Comments
 (0)