CVE-2021-41216: TensorFlow: heap overflow in Transpose via negative perm

HIGH PoC AVAILABLE
Published November 5, 2021
CISO Take

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.

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
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 5% of all CVEs
Exploitation Status
Exploit Available
Exploitation: MEDIUM
Sophistication
Moderate
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?

5 steps
  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.

How is it classified?

Which compliance frameworks are affected?

This CVE is relevant to:

EU AI Act
Art. 15 - Accuracy, Robustness and Cybersecurity
ISO 42001
A.10.1 - AI System Security
NIST AI RMF
MANAGE 2.2 - Mechanisms for AI Risk Response
OWASP LLM Top 10
LLM05 - Supply Chain Vulnerabilities

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

training pipelinesmodel servingJupyter notebook environments

MITRE ATLAS Techniques

AML.T0010.001 AI Software
AML.T0011.000 Unsafe AI Artifacts
AML.T0049 Exploit Public-Facing Application

Compliance Controls Affected

EU AI Act: Art. 15
ISO 42001: A.10.1
NIST AI RMF: MANAGE 2.2
OWASP LLM Top 10: LLM05

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: 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

Timeline

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

Related Vulnerabilities