Out-of-bounds read in FreeRDP smartcard response handling
Key facts
- Attack vector
- Network
- Privileges required
- Low
- User interaction
- None
- Attack complexity
- Low
- Impact type
- Denial of service
- Confidentiality · integrity · availability
- None · None · High
- Fix status
- Fixed
Attack profile from CVSS 3.1 · GHSA-q65v-4w7q-hx3r. Fix status from GitHub. Impact type from CWE-125 and the CVSS impact.
Summary
FreeRDP versions 3.28.0 through 3.30.0 do not check the length of smartcard ATR data in device I/O completion responses (CWE-125). A remote, authenticated RDP client with low privileges can send an oversized ATR length, causing reads beyond the fixed buffers, which affects availability. The server must enable smartcard redirection and have an outstanding status request for the flaw to be reached.
Written with Claude Haiku 5.5 from the sources below · 2026-11-12
Description from the GitHub advisory
# Smartcard response lengths are not bounded to their inline ATR arrays Discovery credit: Bynario Atlas CVSS v3.1 (standalone root cause): `CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H` (6.5, Medium) - `A:H` is scored on inferred process termination; no crash was observed in a live server session. See Impact. CWE(s): CWE-125 (Out-of-bounds Read); CWE-20 (Improper Input Validation) ## Summary > Disclosure note: This finding was identified and validated by Bynario Atlas, > an AI automated pipeline. The technical claims and supporting evidence were > manually reviewed before submission. An authenticated RDP client controls the ATR length in smartcard device-I/O completion responses. FreeRDP's server-side decoder accepts lengths larger than the fixed arrays holding the ATR and passes them unchanged to logging and server callbacks. FreeRDP's debug-level WLog path and a length-trusting callback then read beyond stack or heap objects. AddressSanitizer reproduced both array cases on FreeRDP 3.30.0 and current master. ## Affected versions and preconditions Source-confirmed affected: FreeRDP 3.28.0, 3.29.0, 3.30.0, and master at `9626564421df72c84f891afdbc0b20bf702f369f`. Runtime testing under AddressSanitizer covered FreeRDP 3.30.0 and that master revision. The server-response helpers are absent from 3.27.1, and a fresh upstream fetch found no fix as of 2026-08-23. The server must enable RDPDR smartcard redirection and have an outstanding `Status` or `GetStatusChange` request. A malicious, normally authenticated RDP client returns a structurally valid response with an oversized ATR length. Authentication policy is controlled by the embedding server. ## Technical analysis ### Wire reachability The affected values come from a client-sent RDPDR `PAKID_CORE_DEVICE_IOCOMPLETION`, not from server configuration or test-only state. For a matching outstanding request, the production path is: ```text client DEVICE_IOCOMPLETION -> rdpdr_server_receive_device_io_completion() -> rdpdr_server_smartcard_{status,get_status_change}_callback() -> smartcard_irp_device_control_decode_response() -> smartcard_unpack_{status,get_status_change}_return() ``` The outer decoder verifies that the advertised output buffer is present, but does not constrain `cbAtrLen` or `cbAtr`. The client receives the completion ID in the server's request and controls the corresponding response body. An unsolicited completion is therefore rejected, but a malicious response to a real outstanding `Status` or `GetStatusChange` request reaches the affected decoders. ### Missing bounds `Status_Return` contains `BYTE pbAtr[32]`; `ReaderState_Return` contains `BYTE rgbAtr[36]`. Their decoders — `smartcard_unpack_status_return()` and `smartcard_unpack_get_status_change_return()` in `libfreerdp/utils/smartcard_pack.c` — accept independent wire lengths without checking those capacities: ```c Stream_Read(s, ret->pbAtr, sizeof(ret->pbAtr)); Stream_Read_UINT32(s, ret->cbAtrLen); /* no cbAtrLen <= 32 check */ ``` `ReaderState_Return` entries are not read field by field. `smartcard_unpack_get_status_change_return()` obtains them through `smartcard_ndr_read_state()` (`smartcard_pack.c:305-315`), a bare `smartcard_ndr_read()` passthrough that performs no per-element `cbAtr` check. Its direct structural analogue is instructive. `smartcard_ndr_read_atrmask()` (`smartcard_pack.c:317-348`) reads `LocateCards_ATRMask` the same way, then loops over the decoded elements and rejects `cbAtr > ARRAYSIZE(rgbAtr)`. Its comment cites "[MS-RDPESC] 2.2.1.5: cbAtr is range(0..36)." PR #12928 added that check. The equivalent loop in `smartcard_ndr_read_state()` is the natural fix for the 36-byte case. Two consumers then use the unchecked length. FreeRDP's own `smartcard_create_array_dump()` is a sink when debug-level WLog is enabled; `smartcard_pack.c:36` sets the dump level to `WLOG_DEBUG`. `smartcard_trace_status_return()` passes `ret->pbAtr` and `ret->cbAtrLen` to `smartcard_dump_array()` (`smartcard_pack.c:1406`). It forwards both to `smartcard_create_array_dump()` (`smartcard_pack.c:568-576`), where the bytes are read. `smartcard_trace_get_status_change_return()` does the same for every reader state, passing `rgbAtr` with the unchecked `cbAtr` (`smartcard_pack.c:976-978`). The decoded object is also handed to the embedding server through the `OnSmartcardStatusComplete` and `OnSmartcardGetStatusChangeComplete` callbacks of `RdpdrServerContext`, with the same unchecked length. In the `Status` case, the embedder receives a stack-local object from `rdpdr_server_smartcard_status_callback()`. An oversized length therefore reads beyond the stack object rather than a heap allocation. Debug logging is optional, normally controlled by the server operator, and is not attacker-controlled. It is only a simple FreeRDP-owned diagnostic sink for reproduction. An embedding callback that trusts the decoded length can reach the same out-of-bounds read without debug logging; the real GNOME Remote Desktop consumer described under Coordination does so. ## Reproduction 1. Build FreeRDP 3.30.0 or current master with AddressSanitizer. 2. Decode production-shaped `Status` responses declaring 32, 33, and 4096 bytes for the 32-byte array. Decode `GetStatusChange` states declaring 36, 37, and 4096 bytes for the 36-byte array. 3. Exercise a callback-equivalent consumer that reads the fixed ATR array using the decoded length; debug logging need not be enabled for this test sink. 4. As an additional FreeRDP-internal diagnostic sink, enable debug-level WLog and repeat. The validation used `WLOG_LEVEL=TRACE`, which includes `WLOG_DEBUG` messages. Lengths 33 and 37 were accepted. Length 4096 produced a stack-buffer-overflow for `Status`, a heap-buffer-overflow for `GetStatusChange`, and an out-of-bounds read inside FreeRDP's debug-level logging path. Appendix A contains the complete 140-line focused reproducer. It drives the affected decoders and a callback-equivalent consumer; it is not a complete TCP/RDP handshake. The harness can be used to regenerate full sanitizer traces. ## Impact Observed: the focused AddressSanitizer reproducer accepted oversized ATR lengths and detected out-of-bounds reads in a callback-equivalent consumer and FreeRDP's debug-level logging sink. This was not a complete server session, so a network-triggered server-process crash was not observed. Inferred: in a network-facing server with smartcard redirection enabled and a matching request outstanding, the same reads may terminate the server process. Adjacent bytes may be copied to a local consumer, but no return path to the malicious client was demonstrated. This report therefore claims potential denial of service, not a remote disclosure oracle or code execution. The availability-only CVSS vector is intentional: an out-of-bounds read establishes neither attacker-controlled memory modification nor a path that returns adjacent bytes to the remote peer. ## Remediation Suggestions Reject `Status_Return.cbAtrLen > 32` and every `ReaderState_Return.cbAtr > 36` immediately after decode and before logging or callback use. Server consumers should also reject or clamp invalid lengths defensively. The patch sketch below was applied to current master `9626564421df72c84f891afdbc0b20bf702f369f`, compiled successfully in an isolated AddressSanitizer build, and exercised with Appendix A. Lengths 32 and 36 remained accepted; 33, 37, and 4096 returned `STATUS_DATA_ERROR` before consumption, with no sanitizer error. It has not been run through FreeRDP's full CI matrix. ```diff @@ smartcard_ndr_read_state(...) - return smartcard_ndr_read(log, s, u.ppv, min, sizeof(ReaderState_Return), type); + const LONG status = + smartcard_ndr_read(log, s, u.ppv, min, sizeof(ReaderState_Return), type); + if (status != SCARD_S_SUCCESS) + return status; + + ReaderState_Return* states = *data; + for (size_t x = 0; x < min; x++) + { + const UINT32 val = winpr_Data_Get_UINT32(&states[x].cbAtr); + if (val > ARRAYSIZE(states[x].rgbAtr)) + { + WLog_Print(log, WLOG_ERROR, + "ReaderState_Return[%" PRIuz "]::cbAtr %" PRIu32 " exceeds %" PRIuz, + x, val, (size_t)ARRAYSIZE(states[x].rgbAtr)); + free(*data); + *data = nullptr; + return STATUS_DATA_ERROR; + } + } + return SCARD_S_SUCCESS; @@ smartcard_unpack_status_return(...) Stream_Read(s, ret->pbAtr, sizeof(ret->pbAtr)); Stream_Read_UINT32(s, ret->cbAtrLen); + if (ret->cbAtrLen > ARRAYSIZE(ret->pbAtr)) + { + WLog_Print(log, WLOG_ERROR, + "Status_Return::cbAtrLen %" PRIu32 " exceeds %" PRIuz, + ret->cbAtrLen, (size_t)ARRAYSIZE(ret->pbAtr)); + return STATUS_DATA_ERROR; + } ``` Add decoder tests for the 32/33 and 36/37 boundaries, plus a multi-reader case where a later element is invalid and the allocated array must be released. ## Related Issues The parser fix belongs in FreeRDP. PR #12928 hardened the sibling call-side ATR structures: `LocateCards_ATRMask` and `SCARD_READERSTATE{A,W}` now reject `cbAtr > ARRAYSIZE(rgbAtr)`. It leaves these server-response objects unvalidated, so the decoders still hand embedders a fixed 32- or 36-byte array together with an attacker-chosen length. That the unchecked length escapes the library is not hypothetical. One real embedder, GNOME Remote Desktop, passes `Status_Return.cbAtrLen` and each `ReaderState_Return.cbAtr` straight into `g_variant_new_fixed_array()` over those same fixed arrays with no clamp. That code was authored in July 2026, landed in the tree on 19 August 2026, and appears so far only in the 51.beta pre-release and the development branch, in no stable release. The resulting value is returned to a local PC/SC D-Bus consumer rather than to the RDP peer, so we claim no remote disclosure from it. We cite it only as evidence that a production consumer trusts the decoded length verbatim, which is why the bound belongs in the decoder and not solely in each embedder. No GNOME issue is filed, none is referenced here, and FreeRDP needs no coordination with GNOME to fix the decoder. ## Appendix A: focused decoder/consumer reproducer Compile this against an AddressSanitizer-instrumented FreeRDP build. With an installed build, the link command is typically: ```sh cc -g -O1 -fsanitize=address -fno-omit-frame-pointer \ $(pkg-config --cflags freerdp3 winpr3) smartcard_cbatr_harness.c \ $(pkg-config --libs freerdp3 winpr3) -o smartcard_cbatr_harness ``` Run `status-parse 32`, `status-parse 33`, `status-consume 4096`, and the corresponding `getstatus-*` modes at 36, 37, and 4096. This exact appendix was compiled and run on Linux with GCC 15.2.0 against an AddressSanitizer-instrumented FreeRDP 3.30.0 build. The boundary controls and first invalid lengths produced: ```text decoder=status wire_cbAtrLen=32 result=0x00000000 decoded_cbAtrLen=32 array_bytes=32 decoder=status wire_cbAtrLen=33 result=0x00000000 decoded_cbAtrLen=33 array_bytes=32 decoder=get-status-change wire_cbAtr=36 result=0x00000000 decoded_cbAtr=36 array_bytes=36 decoder=get-status-change wire_cbAtr=37 result=0x00000000 decoded_cbAtr=37 array_bytes=36 ``` The `status-consume 4096` and `getstatus-consume 4096` runs then terminated with these respective sanitizer summaries: ```text ERROR: AddressSanitizer: stack-buffer-overflow READ of size 1 in consume_atr; ret_storage is 60 bytes SUMMARY: AddressSanitizer: stack-buffer-overflow in consume_atr ERROR: AddressSanitizer: heap-buffer-overflow READ of size 1 in consume_atr; decoded ReaderState_Return allocation is 50 bytes SUMMARY: AddressSanitizer: heap-buffer-overflow in consume_atr ``` ```c /* * Focused decoder/consumer harness for FreeRDP smartcard ATR lengths. * * Build this against an ASan/UBSan FreeRDP build. "parse" modes show that * the decoder accepts the first out-of-range value; "consume" modes model a * callback which trusts the decoded length and should trip ASan. */ #include <freerdp/channels/scard.h> #include <freerdp/utils/smartcard_pack.h> #include <winpr/stream.h> #include <inttypes.h> #include <stdio.h> #include <stdlib.h> #include <string.h> static volatile unsigned long g_checksum; #if defined(__clang__) || defined(__GNUC__) __attribute__((noinline)) #endif static void consume_atr(const BYTE* atr, size_t length) { for (size_t x = 0; x < length; x++) g_checksum += atr[x]; } static wStream* status_wire(UINT32 cbAtrLen) { wStream* s = Stream_New(NULL, 52); if (!s) return NULL; Stream_Write_UINT32(s, 0); /* cBytes */ Stream_Write_UINT32(s, 0); /* null mszReaderNames */ Stream_Write_UINT32(s, 1); /* dwState */ Stream_Write_UINT32(s, 2); /* dwProtocol */ for (size_t x = 0; x < 32; x++) Stream_Write_UINT8(s, (BYTE)x); Stream_Write_UINT32(s, cbAtrLen); Stream_SealLength(s); Stream_SetPosition(s, 0); return s; } static wStream* get_status_change_wire(UINT32 cbAtr) { wStream* s = Stream_New(NULL, 60); if (!s) return NULL; Stream_Write_UINT32(s, 1); /* cReaders */ Stream_Write_UINT32(s, 0x20000); /* rgReaderStates NDR pointer */ Stream_Write_UINT32(s, 1); /* simple-pointer element count */ Stream_Write_UINT32(s, 1); /* dwCurrentState */ Stream_Write_UINT32(s, 2); /* dwEventState */ Stream_Write_UINT32(s, cbAtr); for (size_t x = 0; x < 36; x++) Stream_Write_UINT8(s, (BYTE)x); Stream_SealLength(s); Stream_SetPosition(s, 0); return s; } static int run_status(UINT32 length, int consume) { int rc = 1; /* The RDPDR completion path embeds this return object in a stack-local * SMARTCARD_OPERATION before invoking the consumer callback. */ Status_Return ret_storage = { 0 }; Status_Return* ret = &ret_storage; wStream* s = status_wire(length); if (!s) goto out; const LONG status = smartcard_unpack_status_return(s, ret, FALSE); printf("decoder=status wire_cbAtrLen=%" PRIu32 " result=0x%08" PRIx32 " decoded_cbAtrLen=%" PRIu32 " array_bytes=%zu\n", length, (UINT32)status, ret->cbAtrLen, sizeof(ret->pbAtr)); if (status != SCARD_S_SUCCESS) goto out; if (consume) consume_atr(ret->pbAtr, ret->cbAtrLen); rc = 0; out: Stream_Free(s, TRUE); return rc; } static int run_get_status_change(UINT32 length, int consume) { int rc = 1; GetStatusChange_Return ret = { 0 }; wStream* s = get_status_change_wire(length); if (!s) return rc; const LONG status = smartcard_unpack_get_status_change_return(s, &ret, FALSE); const UINT32 decoded = ret.rgReaderStates ? ret.rgReaderStates[0].cbAtr : 0; printf("decoder=get-status-change wire_cbAtr=%" PRIu32 " result=0x%08" PRIx32 " decoded_cbAtr=%" PRIu32 " array_bytes=%zu\n", length, (UINT32)status, decoded, ret.rgReaderStates ? sizeof(ret.rgReaderStates[0].rgbAtr) : 0U); if (status != SCARD_S_SUCCESS || !ret.rgReaderStates) goto out; if (consume) consume_atr(ret.rgReaderStates[0].rgbAtr, ret.rgReaderStates[0].cbAtr); rc = 0; out: free(ret.rgReaderStates); Stream_Free(s, TRUE); return rc; } int main(int argc, char** argv) { if (argc != 3) { fprintf(stderr, "usage: %s status-parse|status-consume|getstatus-parse|getstatus-consume LENGTH\n", argv[0]); return 2; } char* end = NULL; const unsigned long value = strtoul(argv[2], &end, 0); if (!end || *end != '\0' || value > UINT32_MAX) return 2; if (strcmp(argv[1], "status-parse") == 0) return run_status((UINT32)value, 0); if (strcmp(argv[1], "status-consume") == 0) return run_status((UINT32)value, 1); if (strcmp(argv[1], "getstatus-parse") == 0) return run_get_status_change((UINT32)value, 0); if (strcmp(argv[1], "getstatus-consume") == 0) return run_get_status_change((UINT32)value, 1); return 2; } ```
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 |
|---|---|---|---|---|---|
| — | FreeRPD | >= 3.28.0, <= 3.30.0 | 3.31.0 | Patch available | GHSA-q65v-4w7q-hx3r |
- FreeRPD Vendor— Affected >= 3.28.0, <= 3.30.0 Fixed in 3.31.0 Patch available GHSA-q65v-4w7q-hx3r
Remediation
Update FreeRDP to version 3.31.0.
Written with Claude Haiku 5.5 from the sources below · 2026-11-12
- Fix · GHSA-q65v-4w7q-hx3r FreeRPD Fixed in 3.31.0 Advisory →
Timeline
- 2026-11-12 Threatist record created from GHSA-q65v-4w7q-hx3r
References
Sources
This product uses the NVD API but is not endorsed or certified by the NVD. Sources and licences