CVE-2022-24302 Overview
CVE-2022-24302 is a race condition vulnerability affecting Paramiko, a popular Python SSH library. The vulnerability exists in the write_private_key_file function where a Time-of-Check Time-of-Use (TOCTOU) race condition occurs between the file creation and the subsequent chmod operation. This timing window could allow an attacker to read sensitive private key material before proper file permissions are applied, resulting in unauthorized information disclosure.
Critical Impact
Private SSH keys may be exposed to unauthorized users due to a race condition in file permission handling, potentially compromising authentication credentials and enabling unauthorized system access.
Affected Products
- Paramiko versions before 2.10.1
- Debian Linux 9.0 and 10.0
- Fedora 34, 35, and 36
Discovery Timeline
- March 17, 2022 - CVE-2022-24302 published to NVD
- December 16, 2025 - Last updated in NVD database
Technical Details for CVE-2022-24302
Vulnerability Analysis
This vulnerability is classified as CWE-362 (Concurrent Execution using Shared Resource with Improper Synchronization). The core issue lies in the write_private_key_file function within Paramiko's pkey.py module. When writing a private key to a file, the function first creates the file and then applies restrictive permissions via a separate chmod call. This two-step process creates a brief window during which the file exists with potentially insecure default permissions.
The race condition can be exploited in multi-user environments where an attacker with local access can monitor file creation events. By timing their access attempt to occur after file creation but before chmod completes, an attacker could potentially read the contents of newly written private key files.
Root Cause
The root cause is the non-atomic file creation and permission-setting operations in the write_private_key_file function. The vulnerable code path creates a file with default permissions inherited from the process umask, then subsequently calls chmod to restrict access. This sequential approach violates secure coding practices for handling sensitive cryptographic material, where atomic operations or pre-setting secure permissions are recommended.
Attack Vector
The attack requires network-adjacent or local access to exploit the timing window. An attacker would need to:
- Monitor the target system for file creation events in directories where Paramiko may write private keys
- Race to read the file contents during the window between file creation and permission modification
- Extract private key material before the chmod operation completes
The vulnerability's exploitation complexity is considered high due to the precise timing required, but successful exploitation could expose SSH private keys used for authentication to remote systems.
The vulnerable code pattern can be found in the Paramiko pkey.py source, where the file write and permission modification occur as separate operations rather than an atomic sequence.
Detection Methods for CVE-2022-24302
Indicators of Compromise
- Unexpected file access attempts to newly created SSH key files in temporary or user directories
- Audit logs showing rapid successive file operations on private key files by different processes
- Evidence of file monitoring tools or scripts watching for key file creation events
Detection Strategies
- Monitor for abnormal file system activity patterns around SSH key generation operations
- Implement file integrity monitoring on directories where private keys are stored
- Enable detailed auditing of file access events, particularly focusing on timing between creation and permission changes
- Review application logs for Paramiko usage patterns that involve key file generation
Monitoring Recommendations
- Deploy endpoint detection solutions to monitor for suspicious file access patterns during key generation
- Configure audit rules to track file permission changes on sensitive directories
- Implement runtime application self-protection (RASP) to detect potential race condition exploitation attempts
How to Mitigate CVE-2022-24302
Immediate Actions Required
- Upgrade Paramiko to version 2.10.1 or later immediately
- Audit systems for any potentially compromised SSH private keys generated before patching
- Rotate SSH keys that may have been created using vulnerable Paramiko versions
- Review access logs for any suspicious file access patterns around key generation events
Patch Information
Paramiko version 2.10.1 addresses this vulnerability by implementing atomic file operations for private key writing. The fix ensures proper file permissions are set at creation time rather than applied after the fact. Refer to the Paramiko Changelog for complete release notes and upgrade instructions.
For Linux distributions, security updates are available:
- Debian users should apply updates per the Debian LTS Announcement
- Fedora users should update via standard package management as per Fedora Package Announcements
Workarounds
- Set a restrictive umask (e.g., 0077) before invoking Paramiko key generation operations
- Store private keys in directories with restricted access permissions at the directory level
- Use memory-only key storage when possible to avoid writing private keys to disk
- Implement additional access controls on systems where Paramiko is used to generate keys
# Set restrictive umask before key generation
umask 0077
# Verify Paramiko version
pip show paramiko | grep Version
# Upgrade Paramiko to patched version
pip install --upgrade paramiko>=2.10.1
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

