/

CVE-2026-24747

Severity:

HIGH RISK

(8.8)

Unsafe Deserialization in PyTorch weights_only Unpickler

CVE-2026-24747

Modified

Vulnerability type

Category:

Unsafe Deserialization

CWE:

CWE-94, CWE-502

Impact:

Arbitrary Code Execution via Memory Corruption

Severity:

HIGH RISK

(8.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

A flaw in PyTorch's weights_only unpickler allows specially crafted .pth model checkpoint files to corrupt memory when loaded with torch.load(..., weights_only=True).

Under certain conditions, this memory corruption can be steered into arbitrary code execution, enabling an attacker who controls checkpoint files to run code in the context of the loading process.

Affected context

This issue arises in environments that:

  • Use PyTorch to load model checkpoint files (.pth, .pt, or similar) with torch.load(..., weights_only=True)
  • Accept checkpoints from external, shared, or otherwise untrusted sources (e.g., downloads, user uploads, shared research artifacts)
  • Perform loading inside long-lived or privileged Python processes (training servers, inference services, notebooks with valuable credentials or data)

The vulnerability does not depend on a specific model architecture but on the deserialization of the untrusted checkpoint data.

Exploit preconditions

  • Attack surface: Any Python process calling torch.load(..., weights_only=True) on attacker-controlled checkpoint files.
  • Required access: Ability to supply or modify the checkpoint file being loaded (e.g., via file upload, shared storage, repository contribution, or compromised artifact store).
  • Trigger point: Invocation of the vulnerable weights_only unpickler during torch.load execution.
  • Why exploitation is possible: The custom unpickling logic does not fully enforce safety constraints, allowing crafted pickled data to reach unsafe code paths that corrupt memory and can be shaped into arbitrary code execution.

Why this happens

The root cause is an unsafe deserialization pattern in the weights_only unpickler that implicitly trusts the structure and semantics of incoming pickled data.

While weights_only=True is intended to limit deserialization to tensor weights, the implementation still processes complex pickled objects in a way that can violate memory safety guarantees.

This aligns with:

  • CWE-502: Deserialization of Untrusted Data, because untrusted binary data is interpreted as serialized Python objects without adequate isolation or validation.
  • CWE-94: Improper Control of Generation of Code, because the resulting memory corruption can allow execution flow to be redirected, effectively permitting attacker-controlled behavior.

Instead of enforcing a strict, schema-based representation of model weights, the code relies on general-purpose pickling mechanics, exposing low-level operations to attacker-controlled inputs.

Potential impact

  • Arbitrary code execution in the Python process that loads the malicious checkpoint
  • Compromise of training or inference servers, including access to API keys, credentials, and environment secrets
  • Tampering with model parameters, leading to data or model integrity failures (e.g., degraded accuracy, backdoored models)
  • Pivoting into broader infrastructure via compromised machines (e.g., lateral movement in a research cluster or CI pipeline)
  • Denial of service through forced crashes or memory corruption in long-running services

General mitigation guidance

Effective mitigation focuses on reducing trust in serialized artifacts and hardening deserialization logic:

  • Prefer strict, format-constrained serialization for model weights (e.g., tensor-only formats, structured formats like safetensors, or other non-executable encodings) instead of general-purpose pickle-based checkpoints.
  • Treat all external model checkpoints as untrusted inputs; introduce content validation layers that verify structure, expected keys, shapes, and types before loading into the main process.
  • Isolate checkpoint loading into low-privilege, sandboxed processes or containers so that a compromise has minimal impact on the host environment.
  • Apply the principle of least privilege to training and inference workloads: avoid running them with elevated OS permissions or direct access to sensitive data stores when loading untrusted artifacts.
  • Establish organizational policies discouraging ad-hoc loading of third-party checkpoints without review, and encourage the use of vetted model registries or artifact repositories.

How teams detect issues like this

High-level strategies to detect and manage this class of issue include:

  • Static analysis and code search to identify usages of torch.load (especially with weights_only=True) on inputs that may originate from users, external sources, or automated pipelines.
  • Code review checklists that flag generic serialization/deserialization APIs (pickle, torch serialization, etc.) and require justification and documentation of trust boundaries around model artifacts.
  • Runtime monitoring and logging of model loading operations, including the source of checkpoint files, to spot anomalous behavior or unexpected sources of artifacts.
  • Policy enforcement in CI/CD that:
  • Scans repositories for patterns involving torch.load and untrusted paths, and
  • Integrates SCA/SAST tools capable of identifying unsafe deserialization patterns in ML workflows.
  • Periodic security assessments of ML pipelines, focusing on artifact ingestion points, shared storage, and third-party model usage.

Sources

SourceLink
github.comgithub.com/pytorch/pytorch/163122/commit/954dc5183ee9205cbe79876ad05dd2d9ae752139
github.comgithub.com/pytorch/pytorch/issues/163105
github.comgithub.com/pytorch/pytorch/releases/tag/v2.10.0
github.comgithub.com/pytorch/pytorch/security/advisories/GHSA-63cw-57p8-fm3p
access.redhat.comaccess.redhat.com/errata/RHSA-2026:24977
access.redhat.comaccess.redhat.com/security/cve/CVE-2026-24747
bugzilla.redhat.combugzilla.redhat.com/show_bug.cgi?id=2433612
security.access.redhat.comsecurity.access.redhat.com/data/csaf/v2/vex/2026/cve-2026-24747.json

Frequently asked

questions

It can be, if a service accepts checkpoints or model files from remote users or external sources and then calls torch.load(..., weights_only=True) on them. In that case, a remote attacker could potentially trigger the vulnerability by supplying a malicious file.

The attacker needs the ability to influence or control the checkpoint file being loaded. This might occur through direct file uploads, access to shared storage, poisoned model repositories, or compromised artifact pipelines used by training or inference jobs.

The safest pattern is to avoid loading untrusted checkpoints with generic pickle-based mechanisms. Use strictly defined, non-executable formats for model weights, enforce schema validation before loading, and, when untrusted artifacts must be processed, perform the operation in an isolated, low-privilege environment.

Design ML pipelines around clear trust boundaries for artifacts, favor non-executable serialization formats, include unsafe deserialization in security review checklists, and use automated tooling to flag risky serialization APIs. Additionally, educate teams that model checkpoints are executable content and should be handled with the same caution as code.

Find out what's already
exploitable in your codebase.