CVE-2021-41228: TensorFlow: eval() in saved_model_cli allows RCE
HIGH PoC AVAILABLEAny 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 |
Do you use TensorFlow? You're affected.
How severe is it?
What is the attack surface?
What should I do?
1 step-
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:
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
MITRE ATLAS Techniques
AML.T0010.001 AI Software AML.T0011 User Execution AML.T0050 Command and Scripting Interpreter Compliance Controls Affected
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')
Primary
CWE-78 Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') 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 References
Timeline
Related Vulnerabilities
CVE-2020-15196 9.9 TensorFlow: heap OOB read in sparse/ragged count ops
Same package: tensorflow CVE-2020-15205 9.8 TensorFlow: heap overflow in StringNGrams, ASLR bypass
Same package: tensorflow CVE-2020-15208 9.8 TFLite: OOB read/write via tensor dimension mismatch
Same package: tensorflow CVE-2019-16778 9.8 TensorFlow: heap overflow in UnsortedSegmentSum op
Same package: tensorflow CVE-2022-23587 9.8 TensorFlow: integer overflow in Grappler enables RCE
Same package: tensorflow