Skip to content

Commit a6b8120

Browse files
authored
Update Schannel Logic to Handler Larger Output Buffers (#4083)
1 parent 718d051 commit a6b8120

File tree

6 files changed

+98
-4
lines changed

6 files changed

+98
-4
lines changed

src/generated/linux/tls_schannel.c.clog.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,24 @@ tracepoint(CLOG_TLS_SCHANNEL_C, SchannelAchCompleteInline , arg2);\
9999

100100

101101

102+
/*----------------------------------------------------------
103+
// Decoder Ring for SchannelOutBufferTooSmall
104+
// [conn][%p] Increasing TLS output buffer size
105+
// QuicTraceLogConnInfo(
106+
SchannelOutBufferTooSmall,
107+
TlsContext->Connection,
108+
"Increasing TLS output buffer size");
109+
// arg1 = arg1 = TlsContext->Connection = arg1
110+
----------------------------------------------------------*/
111+
#ifndef _clog_3_ARGS_TRACE_SchannelOutBufferTooSmall
112+
#define _clog_3_ARGS_TRACE_SchannelOutBufferTooSmall(uniqueId, arg1, encoded_arg_string)\
113+
tracepoint(CLOG_TLS_SCHANNEL_C, SchannelOutBufferTooSmall , arg1);\
114+
115+
#endif
116+
117+
118+
119+
102120
/*----------------------------------------------------------
103121
// Decoder Ring for SchannelHandshakeComplete
104122
// [conn][%p] Handshake complete (resume=%hu)

src/generated/linux/tls_schannel.c.clog.h.lttng.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,25 @@ TRACEPOINT_EVENT(CLOG_TLS_SCHANNEL_C, SchannelAchCompleteInline,
6868

6969

7070

71+
/*----------------------------------------------------------
72+
// Decoder Ring for SchannelOutBufferTooSmall
73+
// [conn][%p] Increasing TLS output buffer size
74+
// QuicTraceLogConnInfo(
75+
SchannelOutBufferTooSmall,
76+
TlsContext->Connection,
77+
"Increasing TLS output buffer size");
78+
// arg1 = arg1 = TlsContext->Connection = arg1
79+
----------------------------------------------------------*/
80+
TRACEPOINT_EVENT(CLOG_TLS_SCHANNEL_C, SchannelOutBufferTooSmall,
81+
TP_ARGS(
82+
const void *, arg1),
83+
TP_FIELDS(
84+
ctf_integer_hex(uint64_t, arg1, arg1)
85+
)
86+
)
87+
88+
89+
7190
/*----------------------------------------------------------
7291
// Decoder Ring for SchannelHandshakeComplete
7392
// [conn][%p] Handshake complete (resume=%hu)

src/manifest/clog.sidecar

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9310,6 +9310,18 @@
93109310
],
93119311
"macroName": "QuicTraceLogConnInfo"
93129312
},
9313+
"SchannelOutBufferTooSmall": {
9314+
"ModuleProperites": {},
9315+
"TraceString": "[conn][%p] Increasing TLS output buffer size",
9316+
"UniqueId": "SchannelOutBufferTooSmall",
9317+
"splitArgs": [
9318+
{
9319+
"DefinationEncoding": "p",
9320+
"MacroVariableName": "arg1"
9321+
}
9322+
],
9323+
"macroName": "QuicTraceLogConnInfo"
9324+
},
93139325
"SchannelProcessingData": {
93149326
"ModuleProperites": {},
93159327
"TraceString": "[conn][%p] Processing %u received bytes",
@@ -15279,6 +15291,11 @@
1527915291
"TraceID": "SchannelMissingData",
1528015292
"EncodingString": "[conn][%p] TLS message missing %u bytes of data"
1528115293
},
15294+
{
15295+
"UniquenessHash": "71eb6726-56e9-ad9d-83d2-930ce22a51f3",
15296+
"TraceID": "SchannelOutBufferTooSmall",
15297+
"EncodingString": "[conn][%p] Increasing TLS output buffer size"
15298+
},
1528215299
{
1528315300
"UniquenessHash": "183e91b7-6ad7-7a8b-0d77-94004bde6757",
1528415301
"TraceID": "SchannelProcessingData",

src/platform/tls_schannel.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,6 +2123,45 @@ CxPlatTlsWriteDataToSchannel(
21232123
}
21242124

21252125
switch (SecStatus) {
2126+
case SEC_E_BUFFER_TOO_SMALL: {
2127+
//
2128+
// The output buffer for the TLS response is too small. We need to grow
2129+
// the buffer and try again.
2130+
//
2131+
QuicTraceLogConnInfo(
2132+
SchannelOutBufferTooSmall,
2133+
TlsContext->Connection,
2134+
"Increasing TLS output buffer size");
2135+
uint16_t NewBufferLength = State->BufferAllocLength << 1;
2136+
if (NewBufferLength < State->BufferAllocLength) { // Integer overflow.
2137+
QuicTraceEvent(
2138+
TlsError,
2139+
"[ tls][%p] ERROR, %s.",
2140+
TlsContext->Connection,
2141+
"TLS buffer too large");
2142+
Result |= CXPLAT_TLS_RESULT_ERROR;
2143+
break;
2144+
}
2145+
uint8_t* NewBuffer = CXPLAT_ALLOC_NONPAGED(NewBufferLength, QUIC_POOL_TLS_BUFFER);
2146+
if (NewBuffer == NULL) {
2147+
QuicTraceEvent(
2148+
AllocFailure,
2149+
"Allocation of '%s' failed. (%llu bytes)",
2150+
"New TLS RX Buffer",
2151+
NewBufferLength);
2152+
Result |= CXPLAT_TLS_RESULT_ERROR;
2153+
break;
2154+
}
2155+
if (State->BufferLength) {
2156+
CxPlatCopyMemory(NewBuffer, State->Buffer, State->BufferLength);
2157+
}
2158+
CXPLAT_FREE(State->Buffer, QUIC_POOL_TLS_BUFFER);
2159+
State->Buffer = NewBuffer;
2160+
State->BufferAllocLength = NewBufferLength;
2161+
Result |= CXPLAT_TLS_RESULT_CONTINUE;
2162+
break;
2163+
}
2164+
21262165
case SEC_E_OK:
21272166

21282167
//

src/test/lib/HandshakeTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ QuicTestConnect(
221221
}
222222

223223
StatelessRetryHelper RetryHelper(ServerStatelessRetry);
224-
PrivateTransportHelper TpHelper(MultiPacketClientInitial);
224+
PrivateTransportHelper TpHelper(MultiPacketClientInitial, !!ResumptionTicket);
225225
RandomLossHelper LossHelper(RandomLossPercentage);
226226

227227
{

src/test/lib/TestHelpers.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,14 +319,15 @@ struct StatelessRetryHelper
319319

320320
#define PRIVATE_TP_TYPE 77
321321
#define PRIVATE_TP_LENGTH 2345
322+
#define PRIVATE_TP_LENGTH_HUGE 4134
322323

323324
struct PrivateTransportHelper : QUIC_PRIVATE_TRANSPORT_PARAMETER
324325
{
325-
PrivateTransportHelper(bool Enabled) {
326+
PrivateTransportHelper(bool Enabled, bool Resumption = false) {
326327
if (Enabled) {
327328
Type = PRIVATE_TP_TYPE;
328-
Length = PRIVATE_TP_LENGTH;
329-
Buffer = new(std::nothrow) uint8_t[PRIVATE_TP_LENGTH];
329+
Length = Resumption ? PRIVATE_TP_LENGTH : PRIVATE_TP_LENGTH_HUGE;
330+
Buffer = new(std::nothrow) uint8_t[Length];
330331
TEST_TRUE(Buffer != nullptr);
331332
} else {
332333
Buffer = nullptr;

0 commit comments

Comments
 (0)