CVE-2025-3121
Executive Summary
CVE-2025-3121 is a memory corruption vulnerability in PyTorch version 2.6.0, specifically within the torch.jit.jit_module_from_flatbuffer function. This flaw allows an attacker with local access to trigger memory corruption, potentially leading to a denial of service or arbitrary code execution. The vulnerability has been publicly disclosed, increasing the risk of exploitation. As of this report, no official patch is available, and the CVSS score is 0.0 (likely unassigned or pending), but the technical impact is significant due to the memory corruption nature.
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 ecosystem. Users of PyTorch 2.6.0 are at risk. Since PyTorch is a widely used machine learning framework, supply chain attacks could involve distributing malicious .flatbuffer files that exploit this flaw. Organizations should verify the integrity of PyTorch installations and monitor for unusual JIT module loading.
CVSS Breakdown & Threat Level
- CVSS Vector: CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
- Base Score: 6.2 (Medium)
- Attack Vector: Local (AV:L) – Requires local access to the system.
- Attack Complexity: Low (AC:L) – No special conditions needed.
- Privileges Required: None (PR:N) – No authentication needed.
- User Interaction: None (UI:N) – No user action required.
- Scope: Unchanged (S:U) – Impact confined to the vulnerable component.
- Confidentiality Impact: None (C:N) – No data exposure.
- Integrity Impact: None (I:N) – No data modification.
- Availability Impact: High (A:H) – Memory corruption can crash the application or system.
Threat Level: Medium. The local access requirement reduces the attack surface, but the public exploit disclosure and lack of patch elevate the urgency for mitigation.
Deep Dive & Mechanics
The vulnerability resides in the torch.jit.jit_module_from_flatbuffer function, which deserializes a PyTorch model from a FlatBuffer binary format. The function fails to properly validate the input data, leading to a memory corruption issue. Specifically, the manipulation of certain fields within the FlatBuffer can cause out-of-bounds writes or reads, corrupting heap memory.
Root Cause: Insufficient bounds checking when parsing the FlatBuffer structure. An attacker can craft a malicious .flatbuffer file that, when loaded via torch.jit.jit_module_from_flatbuffer, triggers a write beyond allocated memory.
Attack Vector: Local access. The attacker must be able to load a malicious FlatBuffer file into the PyTorch process. This could be achieved through social engineering (e.g., convincing a user to load a model) or by exploiting another vulnerability to inject the file.
Impact: Successful exploitation can lead to:
- Denial of service (application crash).
- Potential arbitrary code execution if the attacker can control the corrupted memory.
Vulnerable vs. Patched Code
Since no patch is available, the vulnerable code is the entire torch.jit.jit_module_from_flatbuffer function in PyTorch 2.6.0. A patched version would likely include additional validation checks on the FlatBuffer input.
Vulnerable Code (Conceptual):
def jit_module_from_flatbuffer(flatbuffer_data):
# Directly parse without validation
model = parse_flatbuffer(flatbuffer_data)
return model
Patched Code (Hypothetical):
def jit_module_from_flatbuffer(flatbuffer_data):
# Validate size and structure before parsing
if not validate_flatbuffer(flatbuffer_data):
raise ValueError("Invalid FlatBuffer data")
model = parse_flatbuffer(flatbuffer_data)
return model
Exploitation & Lab Setup
Red Team
Objective: Exploit the memory corruption to achieve denial of service or code execution.
Lab Setup:
- Install PyTorch 2.6.0:
pip install torch==2.6.0 - Create a malicious FlatBuffer file using a crafted script.
Exploit Code (Proof of Concept):
import torch
import struct
# Craft a malicious FlatBuffer that triggers memory corruption
# This is a simplified example; actual exploit requires reverse engineering the FlatBuffer schema
malicious_data = b'\x00' * 1000 # Placeholder for crafted payload
try:
model = torch.jit.jit_module_from_flatbuffer(malicious_data)
except Exception as e:
print(f"Exploit triggered: {e}")
Execution:
- Save the malicious FlatBuffer to a file (e.g.,
malicious.flatbuffer). - Run the script:
python exploit.py - Observe the crash or unexpected behavior.
Blue Team
Objective: Detect and prevent exploitation.
Detection:
- Monitor for unusual calls to
torch.jit.jit_module_from_flatbufferin application logs. - Use file integrity monitoring to detect unexpected FlatBuffer files.
- Implement behavioral analysis for processes loading JIT modules.
Prevention:
- Restrict local access to the system.
- Use application whitelisting to prevent untrusted code from loading.
- Apply memory protection mechanisms (e.g., ASLR, DEP).
Indicators of Compromise (IOCs)
- File Hashes: (Example – actual hashes depend on the exploit)
malicious.flatbufferSHA256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
- Process Behavior:
- Python process crash with segmentation fault.
- High memory usage or corruption.
- Network: No network indicators (local vulnerability).
- Logs:
- Application logs showing
jit_module_from_flatbuffercalls with unusual file sizes. - System logs showing
segfaulterrors in Python processes.
- Application logs showing
Detection Engineering
YARA Rule
rule CVE_2025_3121_PyTorch_Flatbuffer {
meta:
description = "Detects malicious FlatBuffer files targeting CVE-2025-3121"
author = "Valters IT"
date = "2025-04-10"
reference = "CVE-2025-3121"
strings:
$magic = { 4C 49 54 45 } // "LITE" FlatBuffer magic bytes
$suspicious_size = { 00 00 00 00 } // Placeholder for size check
condition:
$magic at 0 and filesize > 1000000 // Example: large file size
}
Sigma Rule
title: PyTorch JIT FlatBuffer Memory Corruption Attempt
id: 7a8b9c0d-1e2f-3a4b-5c6d-7e8f9a0b1c2d
status: experimental
description: Detects attempts to exploit CVE-2025-3121 by loading malicious FlatBuffer files
author: Valters IT
logsource:
category: process_creation
product: windows
detection:
selection:
Image|endswith: '\python.exe'
CommandLine|contains: 'jit_module_from_flatbuffer'
condition: selection
falsepositives:
- Legitimate use of JIT module loading
level: high
Suricata Rule
alert tcp any any -> any any (msg:"CVE-2025-3121 PyTorch Flatbuffer Exploit Attempt"; flow:to_server; content:"|4C 49 54 45|"; depth:4; content:"|00 00 00 00|"; within:100; classtype:attempted-admin; sid:1000001; rev:1;)
Remediation & Mitigation
Immediate Actions:
- Isolate affected systems: Disconnect systems running PyTorch 2.6.0 from untrusted networks.
- Restrict local access: Limit user permissions to prevent loading of untrusted FlatBuffer files.
- Monitor for exploitation: Deploy the detection rules above to identify attacks.
Long-term Fix:
- Apply patch: Monitor PyTorch releases for a security update. Once available, upgrade to a patched version.
- Workaround: Avoid using
torch.jit.jit_module_from_flatbufferwith untrusted data. Validate all FlatBuffer inputs before loading.
Compensating Controls:
- Use memory-safe languages or sandboxing for JIT module loading.
- Implement application-level input validation.
Valters IT