Read the docs

Use after free in FreeRDP server certificate signature computation

Priority LOW 38CWE-416Published · Updated

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 up to and including 3.22.2 contains a use after free (CWE-416) in the server proprietary certificate writer. The certificate signature is computed over a stream buffer that was freed when the stream grew, so the server reads freed heap memory and produces a wrong signature. A remote client that negotiates Standard RDP Security can trigger this when the server uses a 3072-bit or larger RSA key.

Written with Claude Haiku 5.5 from the sources below · 2026-11-12

Description from the GitHub advisory

**Affected:** master (2539d33da) and the 3.x releases that contain `cert_write_server_certificate_v1` in its current form (introduced with the certificate refactor, 9b51df8b1, 2023). ### Summary `cert_write_server_certificate_v1()` (`libfreerdp/crypto/certificate.c`) saves a pointer to the data to be signed before it writes the algorithm ids and the RSA public key blob. Both writes go through `Stream_EnsureRemainingCapacity()`. If the stream has to grow, the buffer is reallocated and `cert_write_rsa_signature()` then runs MD5 over the old, freed buffer. ### Reachability A server sends this certificate in the GCC server security data when a client negotiates Standard RDP Security. `mcs_send_connect_response()` writes the server data blocks into a 512-byte stream. With the default 2048-bit key the certificate fits. With a 3072-bit server key and at least four requested static channels, or with any 4096-bit key, the public key write reallocates, and the server reads freed heap memory for every such connection. The connecting client controls both the security protocol and the channel count. ### Impact A heap read of freed memory on the server (ASan: heap-buffer-overflow / use-after-free in `MD5_Update`). The bytes read are hashed and signed with the well-known terminal server key, so the certificate signature is wrong; clients that validate it should reject the connection. We did not find a way to read the freed data out, and outside sanitizer builds we saw no crash. ### Reproducer Unit test `TestServerCertificateWrite` (in the patch below) writes the v1 certificate for `libfreerdp/crypto/test/rsa_pkcs1_sha256_cert.pem` into a 16-byte stream. Under ASan it aborts in `cert_write_rsa_signature` -> `winpr_Digest`; with the fix it passes and the output matches a write into a large stream. ### Fix Take the signed-data pointer after the writes, from `Stream_Buffer()` and the saved offset. Patch (git format-patch, signed commit available on request as a PR once you're ready to publish): ```diff From f5090a185b73aa89a2c8d9d7786383fd627362d7 Mon Sep 17 00:00:00 2001 From: Mar <[email protected]> Date: Tue, 13 Oct 2026 11:10:06 +0200 Subject: [PATCH] [crypto,certificate] fix stale signature pointer in v1 cert writer cert_write_server_certificate_v1 took a pointer to the signed data (starting at dwVersion) before writing the key algorithm fields and the RSA public key blob. Both writes call Stream_EnsureRemainingCapacity, so when the output stream has to grow the buffer is reallocated and cert_write_rsa_signature hashes the old, freed buffer. The server hits this when it sends a proprietary certificate (standard RDP security) and the GCC server data stream (512 bytes initially) is too small for the public key, e.g. with a 3072 or 4096 bit RSA key. Take the pointer after the writes, from the stream base and the saved offset, and add a test that writes the certificate into a growing stream and compares it to one written into a large enough stream. --- libfreerdp/crypto/certificate.c | 4 +- libfreerdp/crypto/test/CMakeLists.txt | 2 +- .../crypto/test/TestServerCertificateWrite.c | 89 +++++++++++++++++++ 3 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 libfreerdp/crypto/test/TestServerCertificateWrite.c diff --git a/libfreerdp/crypto/certificate.c b/libfreerdp/crypto/certificate.c index 752a87b3d..82593c08c 100644 --- a/libfreerdp/crypto/certificate.c +++ b/libfreerdp/crypto/certificate.c @@ -959,7 +959,6 @@ static BOOL cert_write_rsa_signature(wStream* s, const void* sigData, size_t sig static BOOL cert_write_server_certificate_v1(wStream* s, const rdpCertificate* certificate) { const size_t start = Stream_GetPosition(s); - const BYTE* sigData = Stream_PointerAs(s, const BYTE) - sizeof(UINT32); WINPR_ASSERT(start >= 4); if (!Stream_EnsureRemainingCapacity(s, 10)) @@ -970,7 +969,10 @@ static BOOL cert_write_server_certificate_v1(wStream* s, const rdpCertificate* c if (!cert_write_rsa_public_key(s, certificate)) return FALSE; + /* The writes above may have reallocated the stream buffer, so only take + * the pointer to the signed data (starting at dwVersion) now. */ const size_t end = Stream_GetPosition(s); + const BYTE* sigData = Stream_BufferAs(s, const BYTE) + start - sizeof(UINT32); return cert_write_rsa_signature(s, sigData, end - start + sizeof(UINT32)); } diff --git a/libfreerdp/crypto/test/CMakeLists.txt b/libfreerdp/crypto/test/CMakeLists.txt index 184485eba..2f30e9533 100644 --- a/libfreerdp/crypto/test/CMakeLists.txt +++ b/libfreerdp/crypto/test/CMakeLists.txt @@ -8,7 +8,7 @@ set(DRIVER ${MODULE_NAME}.c) set(TESTS TestKnownHosts.c TestBase64.c) if(BUILD_TESTING_INTERNAL) - list(APPEND TESTS Test_x509_utils.c) + list(APPEND TESTS Test_x509_utils.c TestServerCertificateWrite.c) endif() create_test_sourcelist(SRCS ${DRIVER} ${TESTS}) diff --git a/libfreerdp/crypto/test/TestServerCertificateWrite.c b/libfreerdp/crypto/test/TestServerCertificateWrite.c new file mode 100644 index 000000000..0e132ed4c --- /dev/null +++ b/libfreerdp/crypto/test/TestServerCertificateWrite.c @@ -0,0 +1,89 @@ +#include <stdio.h> +#include <string.h> + +#include <winpr/crt.h> +#include <winpr/stream.h> +#include <freerdp/crypto/certificate.h> + +#include "../certificate.h" + +/* Write the certificate into a stream that starts with capacity bytes and + * return the bytes written (including the dwVersion field). */ +static BYTE* write_cert(const rdpCertificate* cert, UINT32 version, size_t capacity, size_t* plen) +{ + BYTE* data = nullptr; + wStream* s = Stream_New(nullptr, capacity); + if (!s) + return nullptr; + + const SSIZE_T len = freerdp_certificate_write_server_cert(cert, version, s); + if (len <= 0) + goto fail; + + *plen = Stream_GetPosition(s); + data = malloc(*plen); + if (data) + memcpy(data, Stream_Buffer(s), *plen); + +fail: + Stream_Free(s, TRUE); + return data; +} + +static BOOL test_version(const rdpCertificate* cert, UINT32 version) +{ + BOOL rc = FALSE; + size_t smallLen = 0; + size_t largeLen = 0; + + /* The small stream has to grow while the certificate is written. */ + BYTE* small = write_cert(cert, version, 16, &smallLen); + BYTE* large = write_cert(cert, version, 0x10000, &largeLen); + + if (!small || !large) + { + (void)fprintf(stderr, "failed to write server certificate version 0x%08" PRIx32 "\n", + version); + goto fail; + } + + if ((smallLen != largeLen) || (memcmp(small, large, smallLen) != 0)) + { + (void)fprintf(stderr, + "server certificate version 0x%08" PRIx32 + " depends on the initial stream capacity\n", + version); + goto fail; + } + + rc = TRUE; +fail: + free(small); + free(large); + return rc; +} + +int TestServerCertificateWrite(int argc, char* argv[]) +{ + int rc = -1; + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + + rdpCertificate* cert = + freerdp_certificate_new_from_file(TEST_SOURCE_DIR "/rsa_pkcs1_sha256_cert.pem"); + if (!cert) + { + (void)fprintf(stderr, "failed to load test certificate\n"); + return -1; + } + + if (!test_version(cert, CERT_TEMPORARILY_ISSUED | CERT_CHAIN_VERSION_1)) + goto fail; + if (!test_version(cert, CERT_CHAIN_VERSION_2)) + goto fail; + + rc = 0; +fail: + freerdp_certificate_free(cert); + return rc; +} -- 2.48.1 ```

Why it matters now

Fix Fixed FreeRDP (c): 3.33.0

SSVC decision points

Not available: CISA has not published SSVC decision points for this record.

Affected products

VendorProductAffected versionsFixed inStatusSource
—FreeRDP (c)<= 3.22.23.33.0Patch availableGHSA-8m87-jj8p-2fqc
  • FreeRDP (c) Vendor— Affected <= 3.22.2 Fixed in 3.33.0 Patch available GHSA-8m87-jj8p-2fqc

Remediation

Upgrade FreeRDP to version 3.33.0 or later. The sources list no advisory identifiers for this fix.

Written with Claude Haiku 5.5 from the sources below · 2026-11-12

  • Fix · GHSA-8m87-jj8p-2fqc FreeRDP (c) Fixed in 3.33.0 Advisory →

Timeline

  1. 2026-11-12 Threatist record created from GHSA-8m87-jj8p-2fqc

References

Sources

This product uses the NVD API but is not endorsed or certified by the NVD. Sources and licences