CVE-2021-29540: TensorFlow: heap buffer overflow in Conv2D gradient op
HIGH PoC AVAILABLEA 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.
Risk Assessment
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.
Affected Systems
| Package | Ecosystem | Vulnerable Range | Patched |
|---|---|---|---|
| tensorflow | pip | — | No patch |
Do you use tensorflow? You're affected.
Severity & Risk
Attack Surface
Recommended Action
6 steps-
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. -
ISOLATE
Run training workloads in containers with seccomp/AppArmor profiles and no-new-privileges flags to limit post-exploitation lateral movement.
-
VALIDATE INPUTS
Add explicit validation that len(filter_sizes) matches expected filter tensor shape before invoking Conv2D gradient operations.
-
AUDIT
Scan all training environments for TensorFlow < 2.5.0 using
pip list | grep tensorflowor SBOM tooling. -
DETECT
Monitor for anomalous process spawning or memory corruption signals (SIGSEGV/SIGBUS) in training job logs.
-
NETWORK CONTROLS
Ensure training nodes are not directly internet-exposed; require VPN or bastion access.
Classification
Compliance Impact
This CVE is relevant to:
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.03%.
Technical Details
NVD Description
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)
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