CVE-2021-41228: TensorFlow: eval() in saved_model_cli allows RCE

HIGH PoC AVAILABLE
Published November 5, 2021
CISO Take

Any environment using TensorFlow's saved_model_cli on versions prior to 2.7.0/2.6.1/2.5.2/2.4.4 is vulnerable to arbitrary code execution via Python eval() on attacker-controlled input. The local attack vector limits exposure but is a real risk in shared ML infrastructure — JupyterHub clusters, CI/CD runners, and data science workstations. Patch immediately and audit any pipeline that invokes saved_model_cli programmatically.

What is the risk?

CVSS 7.8 High. Local attack vector reduces broad internet exposure, but ML environments routinely run shared compute (JupyterHub, MLflow, Kubeflow) where local access is not a high bar. Exploitation requires zero AI/ML knowledge — any attacker with shell access can craft a malicious string argument. Not in CISA KEV and patched since Nov 2021; unpatched instances represent neglected technical debt with tangible blast radius on ML infrastructure.

What systems are affected?

Package Ecosystem Vulnerable Range Patched
TensorFlow pip No patch
195.8K OpenSSF 7.1 3.7K dependents Pushed 2d ago 4% patched ~1372d to patch Full package profile →

Do you use TensorFlow? You're affected.

How severe is it?

CVSS 3.1
7.8 / 10
EPSS
0.2%
chance of exploitation in 30 days
Higher than 11% of all CVEs
Exploitation Status
Exploit Available
Exploitation: MEDIUM
Sophistication
Trivial
Exploitation Confidence
medium
Public PoC indexed (trickest/cve)
Composite signal derived from CISA KEV, VulnCheck KEV, CISA SSVC, EPSS, Metasploit, Exploit-DB, trickest/cve, Nuclei templates, and inthewild.io exploitation reports.

What is the attack surface?

AV AC PR UI S C I A
AV Local
AC Low
PR Low
UI None
S Unchanged
C High
I High
A High

What should I do?

1 step
  1. 1) Upgrade to TensorFlow 2.7.0+ or cherry-pick patches for 2.6.1, 2.5.2, 2.4.4. 2) Verify the patched --safe flag is active (defaults True post-patch) — this disables eval() on untrusted input. 3) Audit CI/CD pipelines and automation scripts calling saved_model_cli; ensure all inputs originate from trusted, controlled sources. 4) Isolate saved_model_cli execution to containers with no network egress and no cloud credential access. 5) Detect exploitation by monitoring for unexpected child processes spawned from Python or TensorFlow CLI processes, or anomalous outbound connections from ML workstations.

How is it classified?

Which compliance frameworks are affected?

This CVE is relevant to:

EU AI Act
Article 15 - Accuracy, robustness and cybersecurity
ISO 42001
A.6.2 - AI system risk management
NIST AI RMF
MANAGE-2.4 - Residual risks and vulnerabilities are managed
OWASP LLM Top 10
LLM03:2025 - Supply Chain Vulnerabilities

Frequently Asked Questions

What is CVE-2021-41228?

Any environment using TensorFlow's saved_model_cli on versions prior to 2.7.0/2.6.1/2.5.2/2.4.4 is vulnerable to arbitrary code execution via Python eval() on attacker-controlled input. The local attack vector limits exposure but is a real risk in shared ML infrastructure — JupyterHub clusters, CI/CD runners, and data science workstations. Patch immediately and audit any pipeline that invokes saved_model_cli programmatically.

Is CVE-2021-41228 actively exploited?

Proof-of-concept exploit code is publicly available for CVE-2021-41228, increasing the risk of exploitation.

How to fix CVE-2021-41228?

1) Upgrade to TensorFlow 2.7.0+ or cherry-pick patches for 2.6.1, 2.5.2, 2.4.4. 2) Verify the patched --safe flag is active (defaults True post-patch) — this disables eval() on untrusted input. 3) Audit CI/CD pipelines and automation scripts calling saved_model_cli; ensure all inputs originate from trusted, controlled sources. 4) Isolate saved_model_cli execution to containers with no network egress and no cloud credential access. 5) Detect exploitation by monitoring for unexpected child processes spawned from Python or TensorFlow CLI processes, or anomalous outbound connections from ML workstations.

What systems are affected by CVE-2021-41228?

This vulnerability affects the following AI/ML architecture patterns: training pipelines, model serving, MLOps CI/CD pipelines, data science workstations.

What is the CVSS score for CVE-2021-41228?

CVE-2021-41228 has a CVSS v3.1 base score of 7.8 (HIGH). The EPSS exploitation probability is 0.21%.

What is the AI security impact?

Affected AI Architectures

training pipelinesmodel servingMLOps CI/CD pipelinesdata science workstations

MITRE ATLAS Techniques

AML.T0010.001 AI Software
AML.T0011 User Execution
AML.T0050 Command and Scripting Interpreter

Compliance Controls Affected

EU AI Act: Article 15
ISO 42001: A.6.2
NIST AI RMF: MANAGE-2.4
OWASP LLM Top 10: LLM03:2025

What are the technical details?

Original Advisory

TensorFlow is an open source platform for machine learning. In affected versions TensorFlow's `saved_model_cli` tool is vulnerable to a code injection as it calls `eval` on user supplied strings. This can be used by attackers to run arbitrary code on the plaform where the CLI tool runs. However, given that the tool is always run manually, the impact of this is not severe. We have patched this by adding a `safe` flag which defaults to `True` and an explicit warning for users. The fix will be included in TensorFlow 2.7.0. We will also cherrypick this commit on TensorFlow 2.6.1, TensorFlow 2.5.2, and TensorFlow 2.4.4, as these are also affected and still in supported range.

Exploitation Scenario

An attacker with local access to a shared JupyterHub environment or data science workstation crafts a malicious argument string for saved_model_cli — e.g., by poisoning a shared model directory or intercepting a CI/CD artifact. When the ML engineer runs the tool as part of their normal model validation workflow, the eval() call executes attacker-supplied Python: establishing a reverse shell, exfiltrating saved model weights and training datasets, or dumping cloud credentials (AWS keys, GCP service accounts) stored in the environment to enable lateral movement.

Weaknesses (CWE)

CWE-94 — Improper Control of Generation of Code ('Code Injection'): The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.

  • [Architecture and Design] Refactor your program so that you do not have to dynamically generate code.
  • [Architecture and Design] Run your code in a "jail" or similar sandbox environment that enforces strict boundaries between the process and the operating system. This may effectively restrict which code can be executed by your product. Examples include the Unix chroot jail and AppArmor. In general, managed code may provide some protection. This may not be a feasible solution, and it only limits the impact to the operating system; the rest of your application may still be subject to compromise. Be careful to avoid CWE-243 and other weaknesses related to jails.

Source: MITRE CWE corpus.

CVSS Vector

CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H

Timeline

Published
November 5, 2021
Last Modified
November 21, 2024
First Seen
November 5, 2021

Related Vulnerabilities