Critical PyTorch Vulnerability CVE-2025-32434 Allows Remote Code Execution

A critical security vulnerability, CVE-2025-32434, has been discovered in PyTorch, a popular deep learning framework. This flaw allows remote code execution (RCE) through the torch.load() function when the parameter weights_only=True
is used, affecting versions up to 2.5.1. Despite developers commonly using weights_only=True
to avoid security issues, this vulnerability demonstrates that it can still lead to RCE, enabling attackers to execute arbitrary commands on compromised systems. This could result in data breaches, system compromises, or lateral movement within cloud-hosted AI environments. PyTorch, originally developed by Meta AI and now under the Linux Foundation, is widely used due to its open-source nature and Python interface, making this vulnerability particularly concerning for the global research and development community. Fortunately, the PyTorch team has released a patched version, 2.6.0, to address this issue. Users are urged to update their installations to this version or higher immediately, using pip or conda for the upgrade.
This security issue in PyTorch gives an attacker the ability to achieve remote code execution by tricking a system into loading a specially crafted malicious model file, even when developers use the weights_only=True
setting in torch.load()
which is typically considered a safer option. The following protection guardrails from BlueRock can further prevent the following steps an attacker can take: When the malicious model file is loaded and attempts to execute arbitrary commands through the vulnerable Python torch.load()
function, Python OS Command Injection Prevention steps in to block these unauthorized OS commands directly within the Python process, preventing the initial code execution that could lead to system compromise. Should an attacker's initial payload, after bypassing the intended weights_only=True
safeguard, attempt to run from an unexpected or temporary location on the system where the malicious model might have been saved, Process Path Exec Allow ensures that only applications from approved, legitimate paths can be executed, thereby stopping malware or unauthorized tools dropped in unusual directories from running. If the PyTorch application is running within a containerized environment, and the attacker, having achieved initial execution, tries to introduce new malicious binaries or scripts not part of the original trusted container image—for instance, to establish persistence or escalate privileges—Container Drift Protection (Binaries & Scripts) would prevent these unauthorized executables from running, maintaining the integrity of the container. Following a successful command execution, if the attacker attempts to establish a persistent, interactive connection back to their own server by initiating a reverse shell from the compromised machine to gain direct control, Reverse Shell Protection actively detects and blocks this common post-exploitation technique. Furthermore, if the attacker's executed code attempts to exfiltrate stolen data, such as sensitive model parameters or proprietary datasets, or tries to move laterally by connecting to other systems within the network (e.g., to access cloud metadata services for credentials or other internal AI development servers), Process Socket Deny restricts the compromised process from making unauthorized network connections, effectively containing the threat and preventing data breaches or further network compromise.
- T1059: Command and Scripting Interpreter: The article describes a vulnerability in the PyTorch framework, specifically in the torch.load() function when used with the parameter weights_only=True. This allows an attacker to execute arbitrary commands on the target machine, which is indicative of Remote Code Execution. The attacker can craft a model file designed to exploit this flaw, thereby achieving execution of commands remotely on the victim's system. This aligns with the MITRE ATT&CK technique for Command and Scripting Interpreter (T1059), as it involves executing commands on a system.
- T1204: User Execution: The article mentions that malicious actors can exploit the vulnerability by crafting a model file designed to exploit the flaw in the torch.load() function. This involves modifying or creating files to achieve execution of arbitrary commands. This aligns with the MITRE ATT&CK technique for User Execution (T1204), as it requires the user to load a malicious model file which then executes the attacker's code.
- T1570: Lateral Tool Transfer: The vulnerability allows for remote command execution, which can lead to data breaches, system compromise, or lateral movement in cloud-hosted AI environments. This suggests that an attacker could use this flaw to move laterally within a network or cloud environment after initial compromise. This aligns with the MITRE ATT&CK technique for Lateral Movement (T1570), as it involves moving through a network after gaining initial access.
F1: Exploitation of CVE-2025-32434 by crafting a malicious PyTorch model file to achieve Remote Code Execution (RCE) even when torch.load()
is used with weights_only=True
, targeting systems running PyTorch versions ≤2.5.1.
- The attacker identifies a target system or application that utilizes PyTorch version ≤2.5.1. (Cited from: "It affects PyTorch versions ≤2.5.1")
- The attacker crafts a
malicious model file
specifically designed to exploit the vulnerability in thetorch.load()
function. (Cited from: "If a malicious actor crafts a model file designed to exploit this flaw") - The malicious model file is engineered to trigger RCE even when the
torch.load()
function is invoked with theweights_only=True
parameter, bypassing this intended security measure. (Cited from: "resides in the torch.load() function — specifically when invoked with the parameter weightsonly=True", "even if you use weightsonly=True, it still can achieve RCE") - The victim or a victim's application loads the malicious model file using
torch.load(filepath, weights_only=True)
. (Implicit from the context oftorch.load()
andweights_only=True
being used by developers)- BR-77: Python OS Command Injection Prevention - This mechanism is applicable because the vulnerability in PyTorch's
torch.load()
(a Python function) leads to Remote Code Execution, which is a form of OS command injection from a Python process. This aligns with the LLM rule requiring mention of 'Python' and 'OS command injection' or 'Python command execution'. - BR-82: Process Runtime Execution Guardrails - This mechanism is applicable because the RCE achieved through
torch.load()
could involve starting unauthorized new processes. This aligns with the LLM rule concerning 'unauthorized process execution'. - BR-54: Container Drift Protection (Binaries & Scripts) - If this software ran inside a container, then this mechanism applies because the RCE involves executing arbitrary commands, which could include new binaries or scripts not part of the original container image. This aligns with the LLM rule requiring 'remote code execution'.
- BR-62: Linux/Host Drift Protection - This mechanism is applicable because the RCE could lead to the execution of unauthorized files added to the system outside of trusted package managers. This aligns with the LLM rule for vulnerabilities allowing 'remote code execution'.
- BR-65: Container Host Drift Prevention - If this vulnerability affects container hosts, then this mechanism applies because RCE could lead to the execution of new or modified files by non-allow-listed privileged containers or host processes. This aligns with the LLM rule concerning 'remote code execution'.
- BR-77: Python OS Command Injection Prevention - This mechanism is applicable because the vulnerability in PyTorch's
- Upon loading the malicious model, arbitrary commands are executed on the target machine where the PyTorch code is running. (Cited from: "they can execute arbitrary commands on the target machine")
- BR-77: Python OS Command Injection Prevention - This mechanism is applicable because the execution of arbitrary commands via PyTorch (Python-based) constitutes Python OS command injection.
- BR-82: Process Runtime Execution Guardrails - This mechanism is applicable as the arbitrary commands represent unauthorized process execution.
- BR-54: Container Drift Protection (Binaries & Scripts) - If this software ran inside a container, then this mechanism applies because executing arbitrary commands matches the 'remote code execution' condition in its LLM rule, potentially involving new executables.
- BR-62: Linux/Host Drift Protection - This mechanism is applicable as executing arbitrary commands could involve files not installed via trusted package managers, fitting the 'remote code execution' aspect of its LLM rule.
- BR-65: Container Host Drift Prevention - If this vulnerability affects container hosts, then this mechanism applies because executing arbitrary commands fits the 'remote code execution' condition in its LLM rule.
- BR-88: Process Path Exec Allow - This mechanism is applicable because the RCE might attempt to execute commands or payloads from non-standard or temporary paths not on the allowlist, fitting the LLM rule for execution from a non-standard location.
- BR-90: Process Exec Deny - This mechanism is applicable if the arbitrary commands include attempts to execute processes with suffixes like '/nc', '/wget', or '/curl', which are denied by default.
- This execution can lead to severe consequences such as
data breaches
,system compromise
, or enablelateral movement
if the compromised system is part of a larger network, like cloud-hosted AI environments. (Cited from: "potentially leading to data breaches, system compromise, or even lateral movement in cloud-hosted AI environments")- BR-55: Reverse Shell Protection - This mechanism is applicable because RCE (as achieved in the previous step) can be used to establish a reverse shell for interactive command and control, aligning with the LLM rule that assumes RCE can lead to reverse shells.
- BR-87: Process Socket Deny - This mechanism is applicable because processes spawned by the RCE for data exfiltration or lateral movement would likely perform unauthorized network activity, which this mechanism can block based on an allow list policy, fitting the LLM rule.
- BR-59: Cloud IMDS Firewall (AWS) - If the vulnerable software ran inside an AWS EC2 or AWS EKS environment, then this mechanism applies because the RCE could be used to make unauthorized requests to the AWS IMDS, potentially for credential theft or SSRF, which this firewall protects against. The article mentions 'cloud-hosted AI environments'.
- BR-91: Sensitive File Access - This mechanism is applicable because a data breach often involves accessing sensitive files (e.g.,
/etc/shadow
, SSH keys). This mechanism monitors and can block access to predefined sensitive files. - BR-75: Critical Directory Write Protection - This mechanism is applicable if system compromise or data manipulation involves unauthorized write attempts to critical system directories. The LLM rule covers 'unauthorized write access'.
- BR-52: Data Resource Mandatory Access Control - This mechanism is applicable if the RCE leads to unauthorized binaries (part of the exploit chain) attempting to access or exfiltrate data from critical data directories. This fits the LLM rule regarding 'unauthorized code execution of native binaries' accessing protected resources.