Redbot Labs / Attack Intelligence

AI Model Deserialization Code Execution

Record ID
RB-087
Severity
High
Category
AI Infrastructure
Confidence Score
95
Published
Updated

Summary

AI Model Deserialization Code Execution occurs when loading an untrusted model artifact causes attacker-controlled code to execute within the loading process. Some serialization formats can reconstruct executable objects rather than simply read numerical weights. A malicious artifact can therefore compromise a workstation, evaluation environment or deployment pipeline before the model processes its first inference request.

Executive Summary

Model files should not automatically be treated as passive data. Their security properties depend on the format, loading library, configuration and supporting code used to reconstruct them.

Python’s pickle documentation explicitly warns that malicious serialized data can execute arbitrary code during loading. This matters in AI environments where checkpoints and related artifacts are downloaded, evaluated, converted or promoted through automated pipelines.

The security boundary is crossed when content supplied by an untrusted party becomes executable behavior inside a trusted process. The resulting access is initially limited by that process’s permissions, available credentials and network connectivity.

This narrative focuses on execution during artifact loading. It differs from changes to a model’s learned behavior and from replacing a production model behind an existing endpoint.

Validation should examine the complete artifact-handling workflow, including evaluation and conversion stages. Restricting production deployment does not protect an earlier pipeline stage that already loads the same artifact with sensitive access.

Attack Overview

Primary objective

Execute unauthorized code in an environment that loads a model checkpoint or related serialized artifact.

Delivery opportunity

The attacker supplies or modifies an artifact that a developer, evaluator or automated pipeline will load. Distribution may occur through a repository, shared storage location, submitted model or compromised delivery process.

Execution condition

The selected loader interprets executable object-reconstruction behavior contained in the artifact. The risk depends on the actual loading path, not simply the filename extension.

Execution context

Code runs with the authority of the loading process. Potential exposure depends on accessible files, credentials, mounted storage, service permissions and permitted network destinations.

Distinction from related techniques

Malicious AI Model Supply Chain describes the broader delivery and trust problem. This narrative identifies a specific execution mechanism within that chain.

AI Production Model Substitution concerns unauthorized replacement of a serving model. Deserialization execution can occur during inspection or evaluation, before production deployment.

A behavioral backdoor changes how a model responds to inputs. Deserialization code execution compromises the environment loading the artifact.

Attack Flow

  1. Artifact delivery: An attacker introduces a malicious serialized model or checkpoint into a reachable workflow.
  2. Selection: A user or automated process chooses the artifact for evaluation, conversion or deployment.
  3. Unsafe loading: A loader accepts executable reconstruction behavior from the artifact.
  4. Code execution: Unauthorized actions occur within the loading process.
  5. Potential expansion: Available permissions may allow access to sensitive files, credentials or connected services.
  6. Investigation and recovery: Defenders identify the artifact, contain the affected environment and assess subsequent activity.

Successful loading or plausible model output does not establish that the loading operation was safe.

Affected Systems

  • Developer notebooks and AI workstations.
  • Model evaluation workers.
  • Checkpoint conversion services.
  • Automated model-import pipelines.
  • Training and fine-tuning environments.
  • Model registries with automated inspection jobs.
  • Inference deployment systems.
  • Shared storage and credentials accessible to loading processes.

Business Impact

Unsafe model loading can turn a routine evaluation or deployment task into an execution path within the organization’s AI infrastructure.

Potential consequences include:

  • Access to credentials available to the loading process.
  • Exposure or alteration of accessible datasets and source code.
  • Compromise of evaluation workers or deployment systems.
  • Modification of artifacts later promoted into production.
  • Interruption while affected environments are investigated and rebuilt.
  • Further access to connected systems where permissions allow it.

The impact depends on the permissions and isolation of the loading environment. Code execution in a restricted worker does not automatically establish compromise of its host or the wider enterprise.

Testing Methodology

Inventory loading paths

Identify where external artifacts are downloaded, inspected, converted and loaded. Include background jobs and developer utilities, not only production-serving code.

Review loader behavior

Document the library version, serialization format, loading options and permitted object types. Determine whether errors cause the workflow to retry using less restrictive settings.

Assess trust decisions

Verify how the organization approves publishers and artifact versions. Determine whether approval applies to an exact artifact or merely to a repository name or mutable download location.

Validate restrictions

In an isolated, authorized environment, use a controlled test artifact with a harmless execution indicator. Confirm whether each workflow rejects unexpected executable behavior before it occurs.

Inspect execution boundaries

Review the loading process’s identity, mounted files, credentials and network access. Use synthetic secrets and controlled destinations to assess containment.

Evaluate conversion workflows

Confirm that converting an artifact to another format does not first load it unsafely in a privileged environment.

Document evidence

Record the artifact digest, loading path, configuration and observed behavior. Distinguish confirmed execution from scanner warnings or unsupported file formats.

Testing should use disposable environments without production credentials or access to sensitive datasets.

Detection Guidance

Associate behavior with artifact loading

Correlate model-import and evaluation events with process activity, file access and network connections.

Investigate unexpected execution

Review child processes, script execution or command interpreters launched by a loading workflow.

Monitor sensitive access

Alert on evaluation workers accessing credential stores, unrelated repositories or files outside their intended working directory.

Track protection changes

Investigate changes that disable restricted loading or expand permitted object types without review.

Preserve artifact identity

Retain the exact artifact digest, origin and pipeline execution record needed to identify affected systems.

Interpret findings carefully

Unexpected imports or scanner detections require investigation. They do not independently prove malicious intent or successful compromise.

Mitigation Guidance

Associate behavior with artifact loading

Correlate model-import and evaluation events with process activity, file access and network connections.

Investigate unexpected execution

Review child processes, script execution or command interpreters launched by a loading workflow.

Monitor sensitive access

Alert on evaluation workers accessing credential stores, unrelated repositories or files outside their intended working directory.

Track protection changes

Investigate changes that disable restricted loading or expand permitted object types without review.

Preserve artifact identity

Retain the exact artifact digest, origin and pipeline execution record needed to identify affected systems.

Interpret findings carefully

Unexpected imports or scanner detections require investigation. They do not independently prove malicious intent or successful compromise.

MITRE Mapping

MITRE ATT&CK T1204.002: User Execution: Malicious File Applicable when an attacker relies on a user loading a malicious artifact to obtain execution. This mapping does not automatically apply to fully automated ingestion. MITRE ATLAS AML.T0010: Supply Chain Compromise Relevant when the malicious artifact is introduced through a compromised or attacker-controlled AI supply-chain component. Mappings should reflect the delivery and execution behavior established by the evidence.

OWASP Mapping

OWASP LLM03:2025: Supply Chain Relevant to the trust, provenance and security of externally sourced model artifacts and the components used to load them. This attack does not require poisoned training data, prompt injection or a change to the model’s learned behavior.

Technical References

Python: Pickle Serialization Documentation
Documents the possibility of arbitrary code execution when unpickling malicious data.
https://docs.python.org/3/library/pickle.html

PyTorch: Serialization Semantics
Describes checkpoint loading, weights-only restrictions and their security limitations.
https://docs.pytorch.org/docs/stable/notes/serialization.html

Hugging Face: Pickle Scanning
Explains model-artifact serialization risks and inspection considerations.
https://huggingface.co/docs/hub/security-pickle

MITRE ATT&CK T1204.002: User Execution: Malicious File
https://attack.mitre.org/techniques/T1204/002/

MITRE ATLAS AML.T0010: Supply Chain Compromise
https://atlas.mitre.org/techniques/AML.T0010

OWASP LLM03:2025: Supply Chain
https://genai.owasp.org/llmrisk/llm032025-supply-chain/

Related Attack Intelligence