Invalid free in FreeRDP RD Gateway websocket context handling
Key facts
- Attack vector
- —
- Privileges required
- —
- User interaction
- —
- Attack complexity
- —
- Impact type
- —
- Confidentiality · integrity · availability
- —
- Fix status
- Fixed
No CVSS vector from any source. Fix status from GitHub.
Summary
FreeRDP from 3.10.0 before 3.33.0 has a memory management flaw in its RD Gateway client code. The websocket context pointer and the chunked transfer-encoding decoder state share one union, so when the gateway answers the data channel with chunked encoding, the decoder overwrites the saved pointer. On teardown, rdg_free frees a value taken from the gateway's chunk sizes and the real websocket context is leaked. The sources do not report exploitation.
Written with Claude Haiku 5.5 from the sources below · 2026-11-12
Description from the GitHub advisory
### Summary In `libfreerdp/core/gateway/rdg.c`, `rdg_http_encoding_context` keeps the `websocket_context*` pointer and the chunked transfer-encoding decoder state (`http_encoding_chunked_context`) in one union. The websocket context is allocated in `rdg_new` and freed unconditionally in `rdg_free`. When the RD Gateway data connection uses `Transfer-Encoding: chunked`, `rdg_establish_data_connection` initialises the chunked state and `http_chuncked_read` keeps updating it; both write over the saved pointer (its storage is shared with `chunked.nextOffset`, which holds the current chunk length the gateway sent). On teardown `rdg_free` passes that value to `websocket_context_free`, which dereferences and frees it, and the real websocket context is leaked. So a client that connects through an RD Gateway answering its data channel with chunked encoding ends with an invalid free of a value taken from the gateway's chunk sizes. The union was introduced in 3.10.0 (4cbdd2c17) and is still on master. ### Fix Store the two as separate members, so the websocket context is never aliased by the chunked decoder state. Each transport keeps its own state, and `rdg_new`/`rdg_free` own the websocket context independently of the encoding in use. The patch below (against current master) is from our tree; we would be grateful if you could apply it as written (`git am`) so it lands with its author, changing whatever you like in review. ~~~diff From e545d12706a620156638c46f16a273902496a215 Mon Sep 17 00:00:00 2001 From: Mar <[email protected]> Date: Thu, 15 Oct 2026 02:42:10 +0200 Subject: [PATCH] [core,gateway] keep websocket context and chunked state apart rdg_http_encoding_context stored the websocket_context pointer and the chunked decoder state in one union. The websocket context is allocated in rdg_new and freed in rdg_free, but when the data connection uses chunked transfer encoding, initialising and updating the chunked decoder state overwrites the saved pointer. rdg_free then passes that value to websocket_context_free and the real context is leaked. Store both as separate members so each transport keeps its own state. --- libfreerdp/core/gateway/rdg.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/libfreerdp/core/gateway/rdg.c b/libfreerdp/core/gateway/rdg.c index 6ac5081ac..e6b52af48 100644 --- a/libfreerdp/core/gateway/rdg.c +++ b/libfreerdp/core/gateway/rdg.c @@ -113,11 +113,8 @@ typedef struct { TRANSFER_ENCODING httpTransferEncoding; BOOL isWebsocketTransport; - union context - { - http_encoding_chunked_context chunked; - websocket_context* websocket; - } context; + http_encoding_chunked_context chunked; + websocket_context* websocket; } rdg_http_encoding_context; struct rdp_rdg @@ -371,7 +368,7 @@ WINPR_ATTR_NODISCARD static BOOL rdg_write_packet(rdpRdg* rdg, wStream* sPacket) { if (rdg->transferEncoding.isWebsocketTransport) - return websocket_context_write_wstream(rdg->transferEncoding.context.websocket, + return websocket_context_write_wstream(rdg->transferEncoding.websocket, rdg->tlsOut->bio, sPacket, WebsocketBinaryOpcode); return rdg_write_chunked(rdg->tlsIn->bio, sPacket); @@ -386,7 +383,7 @@ static int rdg_socket_read(BIO* bio, rdpContext* context, BYTE* pBuffer, size_t return -1; if (encodingContext->isWebsocketTransport) - return websocket_context_read(encodingContext->context.websocket, bio, pBuffer, size); + return websocket_context_read(encodingContext->websocket, bio, pBuffer, size); switch (encodingContext->httpTransferEncoding) { @@ -395,7 +392,7 @@ static int rdg_socket_read(BIO* bio, rdpContext* context, BYTE* pBuffer, size_t return BIO_read(bio, pBuffer, (int)size); case TransferEncodingChunked: return http_chuncked_read(bio, context, pBuffer, size, - &encodingContext->context.chunked); + &encodingContext->chunked); default: WLog_ERR(TAG, "Unknown HTTP transfer encoding %u, aborting", encodingContext->httpTransferEncoding); @@ -1634,7 +1631,7 @@ static BOOL rdg_establish_data_connection(rdpRdg* rdg, rdpTls* tls, const char* } rdg->transferEncoding.isWebsocketTransport = TRUE; - if (!websocket_context_reset(rdg->transferEncoding.context.websocket)) + if (!websocket_context_reset(rdg->transferEncoding.websocket)) return FALSE; if (rdg->extAuth == HTTP_EXTENDED_AUTH_SSPI_NTLM) @@ -1656,9 +1653,9 @@ static BOOL rdg_establish_data_connection(rdpRdg* rdg, rdpTls* tls, const char* if (encoding == TransferEncodingChunked) { rdg->transferEncoding.httpTransferEncoding = TransferEncodingChunked; - rdg->transferEncoding.context.chunked.nextOffset = 0; - rdg->transferEncoding.context.chunked.headerFooterPos = 0; - rdg->transferEncoding.context.chunked.state = ChunkStateLenghHeader; + rdg->transferEncoding.chunked.nextOffset = 0; + rdg->transferEncoding.chunked.headerFooterPos = 0; + rdg->transferEncoding.chunked.state = ChunkStateLenghHeader; } if (!rdg_skip_seed_payload(rdg->context, tls, bodyLength, &rdg->transferEncoding)) { @@ -2428,8 +2425,8 @@ rdpRdg* rdg_new(rdpContext* context) rdg->transferEncoding.httpTransferEncoding = TransferEncodingIdentity; rdg->transferEncoding.isWebsocketTransport = FALSE; - rdg->transferEncoding.context.websocket = websocket_context_new(); - if (!rdg->transferEncoding.context.websocket) + rdg->transferEncoding.websocket = websocket_context_new(); + if (!rdg->transferEncoding.websocket) goto rdg_alloc_error; return rdg; @@ -2458,7 +2455,7 @@ void rdg_free(rdpRdg* rdg) smartcardCertInfo_Free(rdg->smartcard); - websocket_context_free(rdg->transferEncoding.context.websocket); + websocket_context_free(rdg->transferEncoding.websocket); free(rdg); } -- 2.53.0 ~~~ ### Testing ASan+UBSan Debug build of the patched tree (`BUILD_TESTING=ON`, `BUILD_TESTING_INTERNAL=ON`); `libfreerdp/core/test` passes except `TestSettings`, which stops on an existing UBSan report in `winpr/libwinpr/crt/unicode_builtin.c:246` unrelated to this change. There is no existing unit test that reaches the RDG encoding context without a gateway connection, so the patch adds none; happy to add one if you have a preferred seam.
Why it matters now
SSVC decision points
Not available: CISA has not published SSVC decision points for this record.
Affected products
| Vendor | Product | Affected versions | Fixed in | Status | Source |
|---|---|---|---|---|---|
| — | FreeRDP (c) | >= 3.10.0, <= 3.32.2 | 3.33.0 | Patch available | GHSA-pq35-c472-69w2 |
- FreeRDP (c) Vendor— Affected >= 3.10.0, <= 3.32.2 Fixed in 3.33.0 Patch available GHSA-pq35-c472-69w2
Remediation
FreeRDP fixed in 3.33.0. The sources list no fixed version for other FreeRDP releases.
Written with Claude Haiku 5.5 from the sources below · 2026-11-12
- Fix · GHSA-pq35-c472-69w2 FreeRDP (c) Fixed in 3.33.0 Advisory →
Timeline
- 2026-11-12 Threatist record created from GHSA-pq35-c472-69w2
References
Sources
This product uses the NVD API but is not endorsed or certified by the NVD. Sources and licences