Skip to content

Commit

Permalink
Update Schannel Logic to Handler Larger Output Buffers (microsoft#4083)
Browse files Browse the repository at this point in the history
  • Loading branch information
nibanks authored Jan 26, 2024
1 parent 718d051 commit a6b8120
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 4 deletions.
18 changes: 18 additions & 0 deletions src/generated/linux/tls_schannel.c.clog.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@ tracepoint(CLOG_TLS_SCHANNEL_C, SchannelAchCompleteInline , arg2);\



/*----------------------------------------------------------
// Decoder Ring for SchannelOutBufferTooSmall
// [conn][%p] Increasing TLS output buffer size
// QuicTraceLogConnInfo(
SchannelOutBufferTooSmall,
TlsContext->Connection,
"Increasing TLS output buffer size");
// arg1 = arg1 = TlsContext->Connection = arg1
----------------------------------------------------------*/
#ifndef _clog_3_ARGS_TRACE_SchannelOutBufferTooSmall
#define _clog_3_ARGS_TRACE_SchannelOutBufferTooSmall(uniqueId, arg1, encoded_arg_string)\
tracepoint(CLOG_TLS_SCHANNEL_C, SchannelOutBufferTooSmall , arg1);\

#endif




/*----------------------------------------------------------
// Decoder Ring for SchannelHandshakeComplete
// [conn][%p] Handshake complete (resume=%hu)
Expand Down
19 changes: 19 additions & 0 deletions src/generated/linux/tls_schannel.c.clog.h.lttng.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,25 @@ TRACEPOINT_EVENT(CLOG_TLS_SCHANNEL_C, SchannelAchCompleteInline,



/*----------------------------------------------------------
// Decoder Ring for SchannelOutBufferTooSmall
// [conn][%p] Increasing TLS output buffer size
// QuicTraceLogConnInfo(
SchannelOutBufferTooSmall,
TlsContext->Connection,
"Increasing TLS output buffer size");
// arg1 = arg1 = TlsContext->Connection = arg1
----------------------------------------------------------*/
TRACEPOINT_EVENT(CLOG_TLS_SCHANNEL_C, SchannelOutBufferTooSmall,
TP_ARGS(
const void *, arg1),
TP_FIELDS(
ctf_integer_hex(uint64_t, arg1, arg1)
)
)



/*----------------------------------------------------------
// Decoder Ring for SchannelHandshakeComplete
// [conn][%p] Handshake complete (resume=%hu)
Expand Down
17 changes: 17 additions & 0 deletions src/manifest/clog.sidecar
Original file line number Diff line number Diff line change
Expand Up @@ -9310,6 +9310,18 @@
],
"macroName": "QuicTraceLogConnInfo"
},
"SchannelOutBufferTooSmall": {
"ModuleProperites": {},
"TraceString": "[conn][%p] Increasing TLS output buffer size",
"UniqueId": "SchannelOutBufferTooSmall",
"splitArgs": [
{
"DefinationEncoding": "p",
"MacroVariableName": "arg1"
}
],
"macroName": "QuicTraceLogConnInfo"
},
"SchannelProcessingData": {
"ModuleProperites": {},
"TraceString": "[conn][%p] Processing %u received bytes",
Expand Down Expand Up @@ -15279,6 +15291,11 @@
"TraceID": "SchannelMissingData",
"EncodingString": "[conn][%p] TLS message missing %u bytes of data"
},
{
"UniquenessHash": "71eb6726-56e9-ad9d-83d2-930ce22a51f3",
"TraceID": "SchannelOutBufferTooSmall",
"EncodingString": "[conn][%p] Increasing TLS output buffer size"
},
{
"UniquenessHash": "183e91b7-6ad7-7a8b-0d77-94004bde6757",
"TraceID": "SchannelProcessingData",
Expand Down
39 changes: 39 additions & 0 deletions src/platform/tls_schannel.c
Original file line number Diff line number Diff line change
Expand Up @@ -2123,6 +2123,45 @@ CxPlatTlsWriteDataToSchannel(
}

switch (SecStatus) {
case SEC_E_BUFFER_TOO_SMALL: {
//
// The output buffer for the TLS response is too small. We need to grow
// the buffer and try again.
//
QuicTraceLogConnInfo(
SchannelOutBufferTooSmall,
TlsContext->Connection,
"Increasing TLS output buffer size");
uint16_t NewBufferLength = State->BufferAllocLength << 1;
if (NewBufferLength < State->BufferAllocLength) { // Integer overflow.
QuicTraceEvent(
TlsError,
"[ tls][%p] ERROR, %s.",
TlsContext->Connection,
"TLS buffer too large");
Result |= CXPLAT_TLS_RESULT_ERROR;
break;
}
uint8_t* NewBuffer = CXPLAT_ALLOC_NONPAGED(NewBufferLength, QUIC_POOL_TLS_BUFFER);
if (NewBuffer == NULL) {
QuicTraceEvent(
AllocFailure,
"Allocation of '%s' failed. (%llu bytes)",
"New TLS RX Buffer",
NewBufferLength);
Result |= CXPLAT_TLS_RESULT_ERROR;
break;
}
if (State->BufferLength) {
CxPlatCopyMemory(NewBuffer, State->Buffer, State->BufferLength);
}
CXPLAT_FREE(State->Buffer, QUIC_POOL_TLS_BUFFER);
State->Buffer = NewBuffer;
State->BufferAllocLength = NewBufferLength;
Result |= CXPLAT_TLS_RESULT_CONTINUE;
break;
}

case SEC_E_OK:

//
Expand Down
2 changes: 1 addition & 1 deletion src/test/lib/HandshakeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ QuicTestConnect(
}

StatelessRetryHelper RetryHelper(ServerStatelessRetry);
PrivateTransportHelper TpHelper(MultiPacketClientInitial);
PrivateTransportHelper TpHelper(MultiPacketClientInitial, !!ResumptionTicket);
RandomLossHelper LossHelper(RandomLossPercentage);

{
Expand Down
7 changes: 4 additions & 3 deletions src/test/lib/TestHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,15 @@ struct StatelessRetryHelper

#define PRIVATE_TP_TYPE 77
#define PRIVATE_TP_LENGTH 2345
#define PRIVATE_TP_LENGTH_HUGE 4134

struct PrivateTransportHelper : QUIC_PRIVATE_TRANSPORT_PARAMETER
{
PrivateTransportHelper(bool Enabled) {
PrivateTransportHelper(bool Enabled, bool Resumption = false) {
if (Enabled) {
Type = PRIVATE_TP_TYPE;
Length = PRIVATE_TP_LENGTH;
Buffer = new(std::nothrow) uint8_t[PRIVATE_TP_LENGTH];
Length = Resumption ? PRIVATE_TP_LENGTH : PRIVATE_TP_LENGTH_HUGE;
Buffer = new(std::nothrow) uint8_t[Length];
TEST_TRUE(Buffer != nullptr);
} else {
Buffer = nullptr;
Expand Down

0 comments on commit a6b8120

Please sign in to comment.