Use-after-free in FreeRDP smartcard channel after worker creation failure
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 versions up to and including 3.30.0 have a use-after-free in the RDPDR smartcard channel. The smartcard device is registered with devman before its worker thread is created, so when thread creation fails, the device is freed while devman still holds a pointer to it (CWE-416). Normal channel teardown then dereferences the freed pointer. The sources do not describe the attacker requirements.
Written with Claude Haiku 5.5 from the sources below · 2026-11-12
Description from the GitHub advisory
## Summary The smartcard RDPDR device is registered with devman before its worker thread is created. If `CreateThread(..., CREATE_SUSPENDED, ...)` fails, `DeviceServiceEntry()` frees the already registered `SMARTCARD_DEVICE` and returns. Devman retains the freed pointer and dereferences its `DEVICE.Free` callback during normal channel teardown, causing a use-after-free. Affected revision tested: `9415f2d11e4cbc4e25d3d9fd0c4271e2e05d5c58` (current `master` at the time of testing). ## Source sequence In `channels/smartcard/client/smartcard_main.c`, `DeviceServiceEntry()` publishes the object first: ```c status = pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*)smartcard); if (status != CHANNEL_RC_OK) goto fail; ``` It then creates the worker: ```c smartcard->thread = CreateThread(NULL, 0, smartcard_thread_func, smartcard, CREATE_SUSPENDED, NULL); if (!smartcard->thread) goto fail; ``` The shared failure path calls `smartcard_free_(smartcard)`. Registration has no matching rollback, so the devman list still contains that address. Later, `devman_device_free()` reads and calls `device->Free` through the stale pointer. ## Live-pipeline reproduction I reproduced this through a real loopback TCP/TLS/RDP session with the RDPDR smartcard channel enabled. The path was: ```text RDP connection and channel negotiation -> RDPDR smartcard DeviceServiceEntry -> RegisterDevice succeeds -> first CreateThread(CREATE_SUSPENDED) fails -> smartcard_free_ releases the registered device -> normal RDPDR disconnect -> devman_device_free dereferences device->Free ``` The only fault control is a small `LD_PRELOAD` helper that returns `NULL` for the first `CreateThread` call carrying `CREATE_SUSPENDED`; all FreeRDP allocation, registration, channel, and teardown functions are real. Build the helper as follows and preload it for an AddressSanitizer-enabled client: ```sh cc -shared -fPIC -O1 -g fail-suspended-thread.c \ -I/path/to/FreeRDP/winpr/include -ldl -o fail-suspended-thread.so LD_PRELOAD=$PWD/fail-suspended-thread.so <normal /smartcard client command> ``` Three fresh live sessions reproduced the same ASan failure. The relevant stack was: ```text ERROR: AddressSanitizer: heap-use-after-free READ of size 8 #0 devman_device_free channels/rdpdr/client/devman.c:51 #1 ... normal RDPDR/devman teardown ... freed by: #0 free #1 smartcard_free_ channels/smartcard/client/smartcard_main.c #2 DeviceServiceEntry channels/smartcard/client/smartcard_main.c ``` An otherwise identical session without the injected thread-creation failure completes cleanly. <details> <summary>Complete failure helper</summary> ```c #define _GNU_SOURCE #include <winpr/thread.h> #include <dlfcn.h> #include <stdatomic.h> #include <stdio.h> static atomic_bool armed = true; HANDLE CreateThread(LPSECURITY_ATTRIBUTES attributes, size_t stackSize, LPTHREAD_START_ROUTINE start, LPVOID parameter, DWORD flags, LPDWORD threadId) { typedef HANDLE (*create_thread_fn)(LPSECURITY_ATTRIBUTES, size_t, LPTHREAD_START_ROUTINE, LPVOID, DWORD, LPDWORD); static create_thread_fn real_create; if (!real_create) real_create = (create_thread_fn)dlsym(RTLD_NEXT, "CreateThread"); if (!real_create) return NULL; if ((flags & CREATE_SUSPENDED) && atomic_exchange(&armed, false)) { fprintf(stderr, "selected CreateThread(CREATE_SUSPENDED) failure parameter=%p\n", parameter); return NULL; } return real_create(attributes, stackSize, start, parameter, flags, threadId); } ``` </details> ## Native impact check In an unsanitized build without forced heap reuse, the same thread failure produced a connection failure rather than a process crash in 5/5 runs. To verify that the stale callback is still consumed in a native build, I used a second local diagnostic helper that reallocated the just-freed 96-byte slot at the same address and placed an invalid value in the replacement `DEVICE.Free` field. In 3/3 real TCP/TLS/RDP/RDPDR sessions, teardown reached the replaced callback and terminated with `SIGSEGV` (exit status 139). This demonstrates that the post-free indirect call is real. It does **not** establish that a remote RDP peer can force local thread creation failure, control allocator reuse, or supply replacement callback bytes. I have no evidence of remote code execution. ## Expected behavior and repair direction A device that has been successfully registered must not be freed while devman still owns its pointer. Possible repair directions are: - create and initialize the worker before `RegisterDevice`; or - add a reliable unregister/rollback operation and use it before freeing on every post-registration failure. The error path should also be covered by a test that forces worker creation failure and then performs normal devman teardown. ## Classification and scope - CWE-416: Use After Free - Suggested severity: Low pending maintainer assessment - Requires smartcard redirection and a local worker-creation failure after registration - Confirmed: live-pipeline ASan UAF and conditional native indirect-call crash - Not confirmed: peer-only trigger, information disclosure, arbitrary read/write, or code execution I searched existing issues, pull requests, and commit history for `devman_device_free`, smartcard `CREATE_SUSPENDED`, post-registration rollback, and related UAF reports. I found smartcard issue #12481 and general UAF reports #9877/#9898, but their code paths and failure modes are different.
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 | <= 3.30.0 | 3.31.0 | Patch available | GHSA-j5mq-3349-gwmm |
- FreeRDP Vendor— Affected <= 3.30.0 Fixed in 3.31.0 Patch available GHSA-j5mq-3349-gwmm
Remediation
FreeRDP 3.31.0 fixes this issue. The sources list no fixed version for FreeRDP earlier than 3.31.0.
Written with Claude Haiku 5.5 from the sources below · 2026-11-12
- Fix · GHSA-j5mq-3349-gwmm FreeRDP Fixed in 3.31.0 Advisory →
Timeline
- 2026-11-12 Threatist record created from GHSA-j5mq-3349-gwmm
References
Sources
This product uses the NVD API but is not endorsed or certified by the NVD. Sources and licences