From aaa1878350b7bcc09ade7db691a8f5bda9ede6fb Mon Sep 17 00:00:00 2001 From: Nithin Jose <3701787+nijosmsft@users.noreply.github.com> Date: Tue, 3 Nov 2026 13:41:20 -0800 Subject: [PATCH] Guard certificate completion after crypto cleanup (#6445) ## Description While application certificate validation is pending, MsQuic pauses TLS processing and may buffer additional CRYPTO data. When the application completes validation, `QuicCryptoCustomCertValidationComplete` synchronously resumes TLS processing. That nested processing can complete the handshake and uninitialize the crypto receive state before returning to the completion function. The certificate path now guards that `QuicRecvBufferHasUnreadData` query with Crypto->Initialized . Ticket-validation assertion A similar code is present here too, but ticket validation occurs earlier in handshake processing, before handshake completion is expected to discard crypto state. Therefore, crypto state should always remain initialized when QuicCryptoCustomTicketValidationComplete reaches its unread-data query. The debug assertion is added for this invariant. ICM 31000000772553 ## Testing BVT and CI ## Documentation N/A Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: bd06d130-070d-44d0-a470-092953f341f3 --- src/core/crypto.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/core/crypto.c b/src/core/crypto.c index 1b2daf6325..1c6a97df58 100644 --- a/src/core/crypto.c +++ b/src/core/crypto.c @@ -1774,7 +1774,9 @@ QuicCryptoCustomCertValidationComplete( "Custom cert validation succeeded"); QuicCryptoProcessDataComplete(Crypto, Crypto->PendingValidationBufferLength); - if (QuicRecvBufferHasUnreadData(&Crypto->RecvBuffer)) { + // The handshake completion above can uninitialize the crypto state. + if (Crypto->Initialized && + QuicRecvBufferHasUnreadData(&Crypto->RecvBuffer)) { // // More data was received while waiting for user to perform the validation. // @@ -1830,6 +1832,11 @@ QuicCryptoCustomTicketValidationComplete( Crypto->TicketValidationPending = FALSE; QuicCryptoProcessDataComplete(Crypto, Crypto->PendingValidationBufferLength); + // Ticket validation pauses ClientHello processing. The client cannot send its Finished + // until after receiving the server flight, so the QuicCryptoProcessDataComplete call above + // cannot finish the handshake and uninitialize the crypto state. + CXPLAT_DBG_ASSERT(Crypto->Initialized); + if (QuicRecvBufferHasUnreadData(&Crypto->RecvBuffer)) { // // More data was received while waiting for user to perform the validation.