/

CVE-2026-31253

Severity:

HIGH RISK

(7.3)

Unsafe Deserialization in Flash-Attention Training Framework

CVE-2026-31253

Deferred

Vulnerability type

Category:

Unsafe Deserialization

CWE:

CWE-94, CWE-502

Impact:

Arbitrary Code Execution

Severity:

HIGH RISK

(7.3)

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

Flash-attention's checkpoint loading mechanism uses torch.load() without enabling the security-restrictive weights_only=True parameter, allowing arbitrary Python object deserialization via pickle.

If an attacker can supply a malicious checkpoint file that is later loaded during model warmstarting or evaluation, this can result in arbitrary code execution on the victim's system.

Affected context

This vulnerability arises in environments where flash-attention is used to train or evaluate models and checkpoints are loaded from potentially untrusted or semi-trusted sources.

It is especially relevant in workflows that:

  • Download or share checkpoint files across teams, research groups, or from public repositories
  • Automatically resume training or warmstart from externally supplied checkpoints
  • Integrate evaluation pipelines that load arbitrary checkpoint paths without strict provenance checks

The issue resides in:

  • load_checkpoint() in checkpoint.py
  • Checkpoint loading logic in eval.py

Both rely on torch.load() without the weights_only=True safeguard, making the deserialization process trust the full pickle payload.

Exploit preconditions

  • Attack surface: Checkpoint loading functionality in training/evaluation scripts using flash-attention.
  • Required access: Ability to provide or influence the checkpoint file path or contents (e.g., via shared storage, artifact repositories, downloaded model weights, or compromised pipelines).
  • Trigger point: Invocation of load_checkpoint() or related code paths that call torch.load() on the attacker-controlled checkpoint file, during warmstarting or evaluation.
  • Why exploitation is possible: torch.load() by default uses Python's pickle module, which can instantiate arbitrary objects and execute attacker-controlled code during deserialization when weights_only=True is not enabled or when deserialization is not otherwise constrained.

Why this happens

The core issue is an unsafe deserialization pattern where generic object deserialization is performed on data that may not be fully trusted.

In this case, torch.load() is invoked without the weights_only=True parameter, which means it uses Python's pickle machinery to reconstruct arbitrary Python objects from a checkpoint file.

This maps to CWE-502: Deserialization of Untrusted Data and is closely related to CWE-94: Improper Control of Generation of Code, because the deserialization process can implicitly execute code embedded in the pickled payload.

Conceptually, the insecure pattern is:

  • Treating checkpoint files as passive data
  • While using a deserialization mechanism capable of executing logic during object reconstruction
  • Without isolating or narrowing what types are allowed or enforcing trust boundaries on the source of those files.

Potential impact

  • Arbitrary code execution on the machine running training or evaluation jobs
  • Compromise of developer workstations or research servers that load malicious checkpoints
  • Theft or manipulation of model parameters, training data, or credentials accessible from the compromised process
  • Introduction of backdoors into models, enabling later inference-time manipulation
  • Lateral movement within the hosting environment if the compromised process has broad privileges or access to other systems

General mitigation guidance

Mitigation usually focuses on constraining deserialization and tightening trust boundaries around model artifacts.

Pattern-based mitigations include:

  • Prefer checkpoint loading modes that restrict deserialization to tensor weights only, such as enabling parameters like weights_only=True where supported.
  • Introduce a strict format for checkpoints (e.g., pure tensor state dictionaries) and avoid storing arbitrary Python objects in persisted artifacts.
  • Enforce clear provenance and integrity checks for checkpoints, such as cryptographic signatures or checksums, before loading.
  • Run training and evaluation processes with least-privilege accounts and minimal filesystem and network access, so that damage from a compromised process is contained.
  • Separate the responsibilities of fetching checkpoints and loading them, so that untrusted artifacts can be validated or transformed into a safer representation before deserialization.

How teams detect issues like this

Detection centers on spotting unsafe deserialization APIs and high-risk artifact flows.

Possible approaches:

  • Static analysis rules that flag calls to torch.load() (or other pickle-based APIs) when they are applied to non-constant file paths or when safety-related options such as weights_only=True are not set.
  • Code review checklists that explicitly require reviewers to examine serialization/deserialization logic around checkpoints, models, and artifacts.
  • Organizational policies that forbid use of generic pickle-based deserialization for artifacts obtained from external or unverified sources, enforced via linters or pre-commit hooks.
  • Logging and monitoring of checkpoint loading events, including the origin/source of checkpoint files, to support forensic analysis in case of suspicious behavior.
  • Optional use of automated code review tools to scan for unsafe deserialization patterns across repositories, highlighting risky usage of torch.load(), pickle, or similar mechanisms.

Sources

SourceLink
github.comgithub.com/Dao-AILab/flash-attention
notion.sonotion.so/CVE-2026-31253-35d1e1393188813f9e77e2038104bc49

Frequently asked

questions

It can be, depending on how checkpoints are obtained. If an attacker can cause a system to download or receive a malicious checkpoint (for example, from a compromised repository, storage bucket, or CI artifact), and that checkpoint is subsequently loaded, exploitation can occur without the attacker having direct local access.

The attacker needs the ability to supply or modify checkpoint files that the victim will load. This might be through shared storage, code contributions that reference attacker-controlled checkpoints, tampering with artifact repositories, or compromising the distribution channel for pretrained models.

The safest pattern is to avoid generic object deserialization for untrusted data altogether. In practice, this means using restricted loading modes (such as weights_only=True when available), adopting formats that store only simple data structures and tensors, and validating the structure and integrity of any artifact before loading.

Treat model checkpoints and serialized artifacts as potentially executable content rather than pure data. Establish secure serialization practices, prohibit pickle-based deserialization for data from untrusted origins, enforce code review policies focused on deserialization, and incorporate automated checks that flag unsafe patterns in ML and training pipelines.

Find out what's already
exploitable in your codebase.