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.
What is the risk?
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.
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?
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.
How is it classified?
Which compliance frameworks are affected?
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.16%.
What is the AI security impact?
Affected AI Architectures
MITRE ATLAS Techniques
AML.T0010.001 AI Software AML.T0011.000 Unsafe AI Artifacts AML.T0049 Exploit Public-Facing Application Compliance Controls Affected
What are the technical details?
Original Advisory
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)
CWE-787 Out-of-bounds Write
Primary
CWE-120 Buffer Copy without Checking Size of Input ('Classic Buffer Overflow') CWE-787 — Out-of-bounds Write: The product writes data past the end, or before the beginning, of the intended buffer.
- [Requirements] Use a language that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid. For example, many languages that perform their own memory management, such as Java and Perl, are not subject to buffer overflows. Other languages, such as Ada and C#, typically provide overflow protection, but the protection can be disabled by the programmer. Be wary that a language's interface to native code may still be subject to overflows, even if the language itself is theoretically safe.
- [Architecture and Design] Use a vetted library or framework that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid. Examples include the Safe C String Library (SafeStr) by Messier and Viega [REF-57], and the Strsafe.h library from Microsoft [REF-56]. These libraries provide safer versions of overflow-prone string-handling functions.
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