CVE-2021-29536: TensorFlow: heap overflow in QuantizedReshape op
HIGH PoC AVAILABLEA heap buffer overflow in TensorFlow's QuantizedReshape kernel allows local attackers to trigger out-of-bounds writes via crafted empty quantization threshold tensors, potentially enabling code execution within ML pipeline processes. Organizations running TensorFlow-based training or inference workloads should patch to TF 2.5.0, 2.4.2, 2.3.3, 2.2.3, or 2.1.4 immediately. Multi-tenant ML environments such as shared Jupyter servers and GPU clusters carry the highest risk due to lateral movement potential post-exploitation.
Risk Assessment
Medium-high risk for organizations with shared or multi-tenant TensorFlow environments. CVSS 7.8 (High) reflects full CIA triad impact if exploited locally. Low attack complexity means any user with execution access to a TF environment can trigger heap corruption with crafted inputs. Risk escalates significantly in shared ML infrastructure (JupyterHub, Kubeflow, TF Serving endpoints) where post-exploitation lateral movement across co-located workloads is feasible. The 2021 publication date reduces urgency, but unpatched legacy TF deployments 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
5 steps-
PATCH
Upgrade to TensorFlow 2.5.0, or apply cherry-picks to 2.4.2, 2.3.3, 2.2.3, or 2.1.4 for in-support versions.
-
AUDIT
Inventory TensorFlow versions across all ML workloads — run
pip show tensorflowor query container images. -
WORKAROUND
Validate tensor shapes and assert non-empty inputs before passing to QuantizedReshape ops if immediate patching is not possible.
-
ACCESS CONTROL
Restrict who can submit custom TF graphs or execute arbitrary TF operations in shared ML environments.
-
DETECT
Alert on unexpected process crashes or crash-loop restarts in TF Serving pods as a potential indicator of exploitation attempts.
Classification
Compliance Impact
This CVE is relevant to:
Frequently Asked Questions
What is CVE-2021-29536?
A heap buffer overflow in TensorFlow's QuantizedReshape kernel allows local attackers to trigger out-of-bounds writes via crafted empty quantization threshold tensors, potentially enabling code execution within ML pipeline processes. Organizations running TensorFlow-based training or inference workloads should patch to TF 2.5.0, 2.4.2, 2.3.3, 2.2.3, or 2.1.4 immediately. Multi-tenant ML environments such as shared Jupyter servers and GPU clusters carry the highest risk due to lateral movement potential post-exploitation.
Is CVE-2021-29536 actively exploited?
Proof-of-concept exploit code is publicly available for CVE-2021-29536, increasing the risk of exploitation.
How to fix CVE-2021-29536?
1. PATCH: Upgrade to TensorFlow 2.5.0, or apply cherry-picks to 2.4.2, 2.3.3, 2.2.3, or 2.1.4 for in-support versions. 2. AUDIT: Inventory TensorFlow versions across all ML workloads — run `pip show tensorflow` or query container images. 3. WORKAROUND: Validate tensor shapes and assert non-empty inputs before passing to QuantizedReshape ops if immediate patching is not possible. 4. ACCESS CONTROL: Restrict who can submit custom TF graphs or execute arbitrary TF operations in shared ML environments. 5. DETECT: Alert on unexpected process crashes or crash-loop restarts in TF Serving pods as a potential indicator of exploitation attempts.
What systems are affected by CVE-2021-29536?
This vulnerability affects the following AI/ML architecture patterns: training pipelines, model serving, inference pipelines, edge deployment pipelines.
What is the CVSS score for CVE-2021-29536?
CVE-2021-29536 has a CVSS v3.1 base score of 7.8 (HIGH). The EPSS exploitation probability is 0.01%.
Technical Details
NVD Description
TensorFlow is an end-to-end open source platform for machine learning. An attacker can cause a heap buffer overflow in `QuantizedReshape` by passing in invalid thresholds for the quantization. This is because the implementation(https://github.com/tensorflow/tensorflow/blob/a324ac84e573fba362a5e53d4e74d5de6729933e/tensorflow/core/kernels/quantized_reshape_op.cc#L38-L55) assumes that the 2 arguments are always valid scalars and tries to access the numeric value directly. However, if any of these tensors is empty, then `.flat<T>()` is an empty buffer and accessing the element at position 0 results in overflow. 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 insider threat or attacker with access to a shared ML training cluster constructs a TensorFlow computation graph containing a QuantizedReshape op with deliberately empty (shape [0]) tensors as quantization min/max threshold arguments. When the graph executes, the kernel calls `.flat<T>()[0]` on an empty buffer, triggering a heap buffer overflow (CWE-787). With knowledge of the heap layout and a reliable primitive, an attacker could overwrite function pointers or control flow data to redirect execution — gaining code execution within the TF worker process and access to model weights, training datasets, or environment variables containing API keys and cloud credentials for downstream services.
Weaknesses (CWE)
CVSS Vector
CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H References
- github.com/tensorflow/tensorflow/commit/a324ac84e573fba362a5e53d4e74d5de6729933e Patch 3rd Party
- github.com/tensorflow/tensorflow/security/advisories/GHSA-2gfx-95x2-5v3x Exploit Patch 3rd Party
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