CVE-2024-0397 Overview
A memory race condition vulnerability was discovered in the Python ssl module affecting the ssl.SSLContext methods cert_store_stats() and get_ca_certs(). The race condition can be triggered when these methods are called simultaneously as certificates are loaded into the SSLContext, such as during the TLS handshake with a certificate directory configured. This timing-dependent vulnerability can lead to memory corruption, potentially exposing sensitive cryptographic information or causing application crashes.
Critical Impact
This race condition vulnerability in Python's core SSL module can lead to information disclosure of sensitive certificate data or denial of service through memory corruption, affecting any Python application using SSL/TLS connections with certificate directory configurations.
Affected Products
- CPython versions prior to 3.10.14
- CPython versions prior to 3.11.9
- CPython versions prior to 3.12.3
- CPython versions prior to 3.13.0a5
Discovery Timeline
- 2024-06-17 - CVE-2024-0397 published to NVD
- 2025-11-03 - Last updated in NVD database
Technical Details for CVE-2024-0397
Vulnerability Analysis
This vulnerability exists within Python's ssl module and is classified as CWE-362 (Race Condition). The flaw occurs in the interaction between certificate loading operations and the SSLContext introspection methods. When applications use certificate directories for TLS validation, the underlying certificate store can be modified during TLS handshakes as new certificates are dynamically loaded. If cert_store_stats() or get_ca_certs() is called concurrently during this loading process, a race condition occurs that can corrupt memory state.
The vulnerability requires network access but has high attack complexity due to the precise timing required to trigger the race condition. Successful exploitation does not require authentication or user interaction. The impact includes potential disclosure of sensitive certificate information stored in memory and application denial of service through crashes caused by memory corruption.
Root Cause
The root cause is improper synchronization in the ssl.SSLContext class when accessing the certificate store. The cert_store_stats() and get_ca_certs() methods read from the certificate store without proper locking mechanisms, while concurrent certificate loading operations during TLS handshakes modify the same data structures. This Time-of-Check Time-of-Use (TOCTOU) pattern creates a window where memory can be accessed in an inconsistent state.
Attack Vector
The attack vector is network-based and involves triggering concurrent TLS connections while the target application's certificate store is being accessed. An attacker could potentially exploit this by:
- Initiating multiple TLS connections to a Python-based server configured with a certificate directory
- Timing the connections to coincide with certificate store introspection operations
- Exploiting the resulting memory corruption to either extract certificate data or cause denial of service
The vulnerability is particularly relevant in multi-threaded Python applications that perform certificate validation while simultaneously querying certificate store statistics.
Detection Methods for CVE-2024-0397
Indicators of Compromise
- Unexpected crashes or segmentation faults in Python applications using SSL/TLS
- Memory corruption errors in application logs related to the ssl module
- Anomalous certificate-related error messages during TLS handshakes
- Application instability under high concurrent TLS connection loads
Detection Strategies
- Monitor Python application logs for SSL-related memory errors or crashes
- Implement application crash monitoring to detect patterns consistent with race condition exploitation
- Review system logs for repeated Python process restarts or memory-related failures
- Audit applications for use of cert_store_stats() or get_ca_certs() in multi-threaded contexts
Monitoring Recommendations
- Deploy runtime monitoring for Python applications using SSL/TLS to detect anomalous behavior
- Implement memory corruption detection tools in production environments
- Monitor network traffic for unusual patterns of TLS connection attempts that could indicate exploitation attempts
- Set up alerting for Python application crashes related to the ssl module
How to Mitigate CVE-2024-0397
Immediate Actions Required
- Upgrade CPython to version 3.10.14, 3.11.9, 3.12.3, or 3.13.0a5 or later
- Audit applications for usage of cert_store_stats() and get_ca_certs() methods
- Review multi-threaded Python applications that use SSL/TLS for potential exposure
- Implement external synchronization around certificate store access if immediate patching is not possible
Patch Information
The Python Software Foundation has released patches addressing this vulnerability across multiple CPython branches. The fixes introduce proper synchronization to prevent concurrent access issues in the SSL certificate store operations. Detailed patch commits are available through the GitHub CPython repository.
Fixed versions:
- CPython 3.10.14
- CPython 3.11.9
- CPython 3.12.3
- CPython 3.13.0a5
Additional vendor-specific patches are available:
Workarounds
- Avoid calling cert_store_stats() or get_ca_certs() in multi-threaded applications until patched
- Implement application-level locking around certificate store introspection methods
- Consider using static certificate files instead of certificate directories where feasible
- Reduce concurrent TLS connection handling in affected applications as a temporary measure
# Check current Python version for vulnerability
python3 --version
# Upgrade Python on Debian/Ubuntu systems
sudo apt update && sudo apt upgrade python3
# Verify the installed version meets minimum requirements
python3 -c "import sys; print(f'Python {sys.version}')"
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

