CVE-2024-45158 Overview
A critical stack buffer overflow vulnerability has been identified in Mbed TLS 3.6 before 3.6.1. The vulnerability exists in the mbedtls_ecdsa_der_to_raw() and mbedtls_ecdsa_raw_to_der() functions, which can be exploited when the bits parameter exceeds the largest supported curve. In certain configurations where PSA (Platform Security Architecture) is disabled, all values of the bits parameter are affected. While this vulnerability does not manifest in internal library calls, applications that directly invoke these functions are at risk.
Critical Impact
This stack buffer overflow vulnerability could allow remote attackers to execute arbitrary code, crash applications, or corrupt memory in systems using affected versions of Mbed TLS with direct function calls to the vulnerable ECDSA conversion routines.
Affected Products
- Arm Mbed TLS 3.6.0
- Applications using mbedtls_ecdsa_der_to_raw() directly
- Applications using mbedtls_ecdsa_raw_to_der() directly
Discovery Timeline
- 2024-09-05 - CVE CVE-2024-45158 published to NVD
- 2025-05-16 - Last updated in NVD database
Technical Details for CVE-2024-45158
Vulnerability Analysis
This vulnerability is classified as CWE-121 (Stack-based Buffer Overflow), a memory corruption flaw that occurs when data written to a stack buffer exceeds its allocated size. The vulnerable functions mbedtls_ecdsa_der_to_raw() and mbedtls_ecdsa_raw_to_der() are responsible for converting ECDSA signatures between DER (Distinguished Encoding Rules) format and raw format. When an attacker provides a bits parameter larger than the maximum supported elliptic curve size, the functions fail to properly validate this input, leading to a buffer overflow condition on the stack.
The network-accessible nature of this vulnerability makes it particularly dangerous, as cryptographic operations using these functions could be triggered remotely through TLS handshakes or certificate processing operations in applications that directly call these APIs.
Root Cause
The root cause stems from insufficient input validation in the mbedtls_ecdsa_der_to_raw() and mbedtls_ecdsa_raw_to_der() functions. When processing the bits parameter, these functions do not adequately verify that the provided value falls within the bounds of supported elliptic curve sizes. This is exacerbated in configurations where PSA (Platform Security Architecture) is disabled, where all bits values become affected. The absence of proper boundary checks allows oversized data to overflow the fixed-size stack buffer allocated for signature conversion operations.
Attack Vector
The vulnerability is exploitable over the network without requiring authentication or user interaction. An attacker can craft malicious input that triggers calls to the vulnerable ECDSA conversion functions with an oversized bits parameter. In scenarios where applications directly expose these functions through network-accessible interfaces (such as custom TLS implementations or certificate processing services), remote exploitation becomes feasible. The attack complexity is low, requiring only the ability to supply malformed cryptographic data to the target application.
The vulnerable functions are used for signature format conversion, meaning any application that processes external ECDSA signatures and directly uses these Mbed TLS functions could be vulnerable. Successful exploitation could result in arbitrary code execution with the privileges of the affected application.
Detection Methods for CVE-2024-45158
Indicators of Compromise
- Unexpected application crashes or segmentation faults in processes using Mbed TLS
- Memory corruption errors or stack smashing detection alerts
- Abnormal behavior in TLS handshake processing or certificate validation
- Log entries indicating buffer overflow protections being triggered
Detection Strategies
- Monitor applications using Mbed TLS for unexpected crashes or memory errors
- Implement stack canary protection to detect overflow attempts
- Review application code for direct calls to mbedtls_ecdsa_der_to_raw() or mbedtls_ecdsa_raw_to_der()
- Deploy runtime application self-protection (RASP) solutions to detect memory corruption
Monitoring Recommendations
- Enable AddressSanitizer (ASan) in development and testing environments to catch buffer overflows
- Monitor system logs for stack-smashing protection alerts from applications using Mbed TLS
- Implement anomaly detection for cryptographic operation failures
- Review network traffic for malformed ECDSA signature payloads targeting TLS connections
How to Mitigate CVE-2024-45158
Immediate Actions Required
- Upgrade Mbed TLS to version 3.6.1 or later immediately
- Audit application code for direct usage of mbedtls_ecdsa_der_to_raw() and mbedtls_ecdsa_raw_to_der()
- Enable PSA (Platform Security Architecture) if feasible, as this reduces the attack surface
- Consider temporarily disabling or restricting access to applications making direct calls to vulnerable functions until patched
Patch Information
Arm has released Mbed TLS version 3.6.1 which addresses this stack buffer overflow vulnerability. The patch implements proper bounds checking for the bits parameter in both affected functions. Users should upgrade to version 3.6.1 or later as soon as possible. For detailed patch information, refer to the MbedTLS Security Advisory 2024-08-2 and the GitHub MbedTLS Releases page.
Workarounds
- Avoid direct calls to mbedtls_ecdsa_der_to_raw() and mbedtls_ecdsa_raw_to_der() functions until patched
- Enable PSA (Platform Security Architecture) in Mbed TLS configuration to limit vulnerability exposure
- Implement application-level input validation to ensure bits parameter does not exceed maximum supported curve sizes
- Deploy the application with stack protection mechanisms enabled (e.g., -fstack-protector-strong)
# Upgrade Mbed TLS to patched version
# Clone the latest release and rebuild
git clone --branch v3.6.1 https://github.com/Mbed-TLS/mbedtls.git
cd mbedtls
mkdir build && cd build
cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On ..
make
sudo make install
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.


