CVE-2021-41216: TensorFlow: heap overflow in Transpose via negative perm
HIGH PoC AVAILABLETensorFlow's Transpose op shape inference fails to validate negative indices in `perm`, triggering a heap buffer overflow exploitable by any low-privilege user who can submit computation graphs. Any shared ML infrastructure running TensorFlow below 2.7.0 is at risk of process compromise and credential exposure. Patch immediately to TF 2.7.0, 2.6.1, 2.5.2, or 2.4.4.
Risk Assessment
CVSS 7.8 High with local attack vector, low complexity, and low privileges required — no remote exploitation without prior access. Not in CISA KEV with no confirmed in-the-wild exploitation. Risk escalates significantly in multi-tenant environments (shared notebooks, batch training clusters) where low-privilege users can submit arbitrary computation graphs, enabling heap corruption that reaches arbitrary code execution within the ML process and its environment secrets.
Affected Systems
| Package | Ecosystem | Vulnerable Range | Patched |
|---|---|---|---|
| tensorflow | pip | — | No patch |
Do you use tensorflow? You're affected.
Severity & Risk
Attack Surface
Recommended Action
5 steps-
Patch: upgrade to TensorFlow 2.7.0, 2.6.1, 2.5.2, or 2.4.4 (commit c79ba87).
-
Validate inputs: reject Transpose perm arguments containing non-positive indices at API ingestion boundaries before they reach TF graph execution.
-
Sandbox: run untrusted model/graph execution in isolated containers with seccomp and AppArmor profiles to limit blast radius.
-
Audit: scan ML infrastructure for heap corruption indicators (SIGABRT, crash dumps) in TF serving processes.
-
Least privilege: ensure ML worker processes do not run with elevated OS privileges.
Classification
Compliance Impact
This CVE is relevant to:
Frequently Asked Questions
What is CVE-2021-41216?
TensorFlow's Transpose op shape inference fails to validate negative indices in `perm`, triggering a heap buffer overflow exploitable by any low-privilege user who can submit computation graphs. Any shared ML infrastructure running TensorFlow below 2.7.0 is at risk of process compromise and credential exposure. Patch immediately to TF 2.7.0, 2.6.1, 2.5.2, or 2.4.4.
Is CVE-2021-41216 actively exploited?
Proof-of-concept exploit code is publicly available for CVE-2021-41216, increasing the risk of exploitation.
How to fix CVE-2021-41216?
1. Patch: upgrade to TensorFlow 2.7.0, 2.6.1, 2.5.2, or 2.4.4 (commit c79ba87). 2. Validate inputs: reject Transpose perm arguments containing non-positive indices at API ingestion boundaries before they reach TF graph execution. 3. Sandbox: run untrusted model/graph execution in isolated containers with seccomp and AppArmor profiles to limit blast radius. 4. Audit: scan ML infrastructure for heap corruption indicators (SIGABRT, crash dumps) in TF serving processes. 5. Least privilege: ensure ML worker processes do not run with elevated OS privileges.
What systems are affected by CVE-2021-41216?
This vulnerability affects the following AI/ML architecture patterns: training pipelines, model serving, Jupyter notebook environments.
What is the CVSS score for CVE-2021-41216?
CVE-2021-41216 has a CVSS v3.1 base score of 7.8 (HIGH). The EPSS exploitation probability is 0.02%.
Technical Details
NVD Description
TensorFlow is an open source platform for machine learning. In affected versions the shape inference function for `Transpose` is vulnerable to a heap buffer overflow. This occurs whenever `perm` contains negative elements. The shape inference function does not validate that the indices in `perm` are all valid. 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 low-privilege access to a shared ML training cluster submits a TensorFlow SavedModel or computation graph containing a Transpose operation with perm=[0, -1, 2]. TensorFlow's shape inference code processes the negative index without bounds checking, writing out-of-bounds to heap memory. On a typical Linux ML worker, this corrupts adjacent heap structures, enabling the attacker to redirect execution flow, achieve arbitrary code execution within the training job process, and exfiltrate cloud credentials, model weights, and training data from the worker's environment.
Weaknesses (CWE)
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
AI Threat Alert