CVE-2021-29540: TensorFlow: heap buffer overflow in Conv2D gradient op

HIGH PoC AVAILABLE
Published May 14, 2021
CISO Take

A heap buffer overflow in TensorFlow's Conv2DBackpropFilter allows local attackers with low privileges to achieve full process compromise (RCE, data exfiltration, crash). Patch immediately to TensorFlow 2.1.4+/2.2.3+/2.3.3+/2.4.2+/2.5.0+ on any system running training workloads. Shared ML training infrastructure—JupyterHub clusters, MLOps platforms, multi-tenant GPU farms—are the highest-risk environments.

What is the risk?

Risk is HIGH for organizations operating shared ML training infrastructure where multiple users or workloads submit training jobs. The local attack vector (AV:L) limits exposure versus network-exploitable CVEs, but in practice most ML training environments are accessible via notebooks, REST APIs, or job schedulers that effectively provide remote code paths. Low privilege requirement (PR:L) means any authenticated cluster user can exploit this. Full C/I/A impact means a compromised training node could exfiltrate model weights, training data, and credentials. The 2021 publication date raises concern that unpatched legacy training environments remain exposed.

What systems are affected?

Package Ecosystem Vulnerable Range Patched
TensorFlow pip No patch
195.8K OpenSSF 7.1 3.7K dependents Pushed 4d 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 12% 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?

6 steps
  1. PATCH

    Upgrade TensorFlow to 2.5.0 or cherrypick fixes into 2.1.4, 2.2.3, 2.3.3, or 2.4.2. Verify installed version with pip show tensorflow.

  2. ISOLATE

    Run training workloads in containers with seccomp/AppArmor profiles and no-new-privileges flags to limit post-exploitation lateral movement.

  3. VALIDATE INPUTS

    Add explicit validation that len(filter_sizes) matches expected filter tensor shape before invoking Conv2D gradient operations.

  4. AUDIT

    Scan all training environments for TensorFlow < 2.5.0 using pip list | grep tensorflow or SBOM tooling.

  5. DETECT

    Monitor for anomalous process spawning or memory corruption signals (SIGSEGV/SIGBUS) in training job logs.

  6. NETWORK CONTROLS

    Ensure training nodes are not directly internet-exposed; require VPN or bastion access.

How is it classified?

Which compliance frameworks are affected?

This CVE is relevant to:

EU AI Act
Article 15 - Accuracy, robustness and cybersecurity Article 9 - Risk management system
ISO 42001
8.4 - AI system operation A.6.2.6 - AI system software integrity
NIST AI RMF
GOVERN 1.1 - Policies for AI risk management MANAGE 2.2 - Mechanisms to respond to AI risks
OWASP LLM Top 10
LLM06 - Sensitive Information Disclosure

Frequently Asked Questions

What is CVE-2021-29540?

A heap buffer overflow in TensorFlow's Conv2DBackpropFilter allows local attackers with low privileges to achieve full process compromise (RCE, data exfiltration, crash). Patch immediately to TensorFlow 2.1.4+/2.2.3+/2.3.3+/2.4.2+/2.5.0+ on any system running training workloads. Shared ML training infrastructure—JupyterHub clusters, MLOps platforms, multi-tenant GPU farms—are the highest-risk environments.

Is CVE-2021-29540 actively exploited?

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

How to fix CVE-2021-29540?

1. PATCH: Upgrade TensorFlow to 2.5.0 or cherrypick fixes into 2.1.4, 2.2.3, 2.3.3, or 2.4.2. Verify installed version with `pip show tensorflow`. 2. ISOLATE: Run training workloads in containers with seccomp/AppArmor profiles and no-new-privileges flags to limit post-exploitation lateral movement. 3. VALIDATE INPUTS: Add explicit validation that len(filter_sizes) matches expected filter tensor shape before invoking Conv2D gradient operations. 4. AUDIT: Scan all training environments for TensorFlow < 2.5.0 using `pip list | grep tensorflow` or SBOM tooling. 5. DETECT: Monitor for anomalous process spawning or memory corruption signals (SIGSEGV/SIGBUS) in training job logs. 6. NETWORK CONTROLS: Ensure training nodes are not directly internet-exposed; require VPN or bastion access.

What systems are affected by CVE-2021-29540?

This vulnerability affects the following AI/ML architecture patterns: training pipelines, shared ML platforms, model serving.

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

CVE-2021-29540 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 pipelinesshared ML platformsmodel serving

MITRE ATLAS Techniques

AML.T0010.001 AI Software
AML.T0043 Craft Adversarial Data
AML.T0049 Exploit Public-Facing Application

Compliance Controls Affected

EU AI Act: Article 15, Article 9
ISO 42001: 8.4, A.6.2.6
NIST AI RMF: GOVERN 1.1, MANAGE 2.2
OWASP LLM Top 10: LLM06

What are the technical details?

Original Advisory

TensorFlow is an end-to-end open source platform for machine learning. An attacker can cause a heap buffer overflow to occur in `Conv2DBackpropFilter`. This is because the implementation(https://github.com/tensorflow/tensorflow/blob/1b0296c3b8dd9bd948f924aa8cd62f87dbb7c3da/tensorflow/core/kernels/conv_grad_filter_ops.cc#L495-L497) computes the size of the filter tensor but does not validate that it matches the number of elements in `filter_sizes`. Later, when reading/writing to this buffer, code uses the value computed here, instead of the number of elements in the tensor. The fix will be included in TensorFlow 2.5.0. We will also cherrypick this commit on TensorFlow 2.4.2, TensorFlow 2.3.3, TensorFlow 2.2.3 and TensorFlow 2.1.4, as these are also affected and still in supported range.

Exploitation Scenario

An adversary with access to a shared Jupyter notebook environment (e.g., a disgruntled data scientist, a compromised notebook session via XSS/SSRF, or a malicious training job submitted via MLflow/Kubeflow) crafts a TensorFlow call where filter_sizes specifies a shape larger than the actual filter tensor. When Conv2DBackpropFilter computes the expected buffer size from filter_sizes and writes gradient data, it overflows into adjacent heap memory. On a predictable heap layout, the attacker overwrites a function pointer or vtable entry to redirect execution. From the training node, they exfiltrate model weights, training datasets (potentially PII), and environment secrets (cloud credentials, API keys in env vars). In a GPU cluster with shared NFS storage, this becomes lateral movement across all training jobs.

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
May 14, 2021
Last Modified
November 21, 2024
First Seen
May 14, 2021

Related Vulnerabilities