CVE-2021-29609: TensorFlow: SparseAdd heap OOB write and null deref
HIGH PoC AVAILABLEIf your ML environment runs TensorFlow < 2.5.0 and accepts user-influenced sparse tensor inputs, patch immediately to 2.5.0 or the backported fixes (2.4.2, 2.3.3, 2.2.3, 2.1.4). Low attack complexity means any caller with tensor access to the runtime can trigger this. Shared GPU clusters and multi-tenant inference services are highest risk.
What is the risk?
CVSS 7.8 High with local attack vector and low complexity/privileges. In ML contexts 'local' frequently maps to inference server processes or training jobs where user-submitted data reaches TF ops directly — effectively elevating the practical attack surface beyond what the CVSS vector implies. Risk is highest in multi-tenant GPU clusters or inference APIs that accept raw tensor inputs without pre-validation at the application boundary.
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 TF 2.5.0, 2.4.2, 2.3.3, 2.2.3, or 2.1.4.
-
Validate all incoming tensor shapes and indices at the application boundary before passing to SparseAdd — reject tensors where indices second dimension does not match the corresponding shape tensor.
-
Isolate TF inference workers in containers with no-new-privileges and seccomp profiles to contain blast radius.
-
Audit inference APIs and gRPC endpoints that accept sparse tensor formats from external callers.
-
Monitor for unexpected TF serving process crashes as a detection signal for exploitation attempts.
How is it classified?
Which compliance frameworks are affected?
This CVE is relevant to:
Frequently Asked Questions
What is CVE-2021-29609?
If your ML environment runs TensorFlow < 2.5.0 and accepts user-influenced sparse tensor inputs, patch immediately to 2.5.0 or the backported fixes (2.4.2, 2.3.3, 2.2.3, 2.1.4). Low attack complexity means any caller with tensor access to the runtime can trigger this. Shared GPU clusters and multi-tenant inference services are highest risk.
Is CVE-2021-29609 actively exploited?
Proof-of-concept exploit code is publicly available for CVE-2021-29609, increasing the risk of exploitation.
How to fix CVE-2021-29609?
1. Patch: Upgrade to TF 2.5.0, 2.4.2, 2.3.3, 2.2.3, or 2.1.4. 2. Validate all incoming tensor shapes and indices at the application boundary before passing to SparseAdd — reject tensors where indices second dimension does not match the corresponding shape tensor. 3. Isolate TF inference workers in containers with no-new-privileges and seccomp profiles to contain blast radius. 4. Audit inference APIs and gRPC endpoints that accept sparse tensor formats from external callers. 5. Monitor for unexpected TF serving process crashes as a detection signal for exploitation attempts.
What systems are affected by CVE-2021-29609?
This vulnerability affects the following AI/ML architecture patterns: training pipelines, model serving, inference endpoints.
What is the CVSS score for CVE-2021-29609?
CVE-2021-29609 has a CVSS v3.1 base score of 7.8 (HIGH). The EPSS exploitation probability is 0.23%.
What is the AI security impact?
Affected AI Architectures
MITRE ATLAS Techniques
AML.T0010.001 AI Software AML.T0043 Craft Adversarial Data AML.T0049 Exploit Public-Facing Application Compliance Controls Affected
What are the technical details?
Original Advisory
TensorFlow is an end-to-end open source platform for machine learning. Incomplete validation in `SparseAdd` results in allowing attackers to exploit undefined behavior (dereferencing null pointers) as well as write outside of bounds of heap allocated data. The implementation(https://github.com/tensorflow/tensorflow/blob/656e7673b14acd7835dc778867f84916c6d1cac2/tensorflow/core/kernels/sparse_add_op.cc) has a large set of validation for the two sparse tensor inputs (6 tensors in total), but does not validate that the tensors are not empty or that the second dimension of `*_indices` matches the size of corresponding `*_shape`. This allows attackers to send tensor triples that represent invalid sparse tensors to abuse code assumptions that are not protected by validation. 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 TensorFlow inference endpoint (TF Serving, custom gRPC API, or shared Jupyter environment) submits a crafted SparseTensor triple where the indices tensor shape does not match the corresponding shape tensor, or sends empty tensors. The SparseAdd kernel, lacking these validation checks, dereferences a null pointer or writes beyond heap-allocated bounds. At minimum this crashes the inference server (DoS); in a memory-unsafe runtime it enables heap exploitation for code execution on the ML host — from which the attacker can exfiltrate model weights, training data, or pivot to internal infrastructure.
Weaknesses (CWE)
CWE-476 NULL Pointer Dereference
Primary
CWE-787 Out-of-bounds Write
Primary
CWE-665 Improper Initialization CWE-476 — NULL Pointer Dereference: The product dereferences a pointer that it expects to be valid but is NULL.
- [Implementation] For any pointers that could have been modified or provided from a function that can return NULL, check the pointer for NULL before use. When working with a multithreaded or otherwise asynchronous environment, ensure that proper locking APIs are used to lock before the check, and unlock when it has finished [REF-1484].
- [Requirements] Select a programming language that is not susceptible to these issues.
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
- github.com/tensorflow/tensorflow/commit/41727ff06111117bdf86b37db198217fd7a143cc Patch 3rd Party
- github.com/tensorflow/tensorflow/commit/6fd02f44810754ae7481838b6a67c5df7f909ca3 Patch 3rd Party
- github.com/tensorflow/tensorflow/security/advisories/GHSA-cjc7-49v2-jp64 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