CVE-2021-29565: TensorFlow: null ptr dereference crashes sparse ops
MEDIUM PoC AVAILABLEThis vulnerability allows any low-privileged local user (or remote attacker reaching TensorFlow ops through an application layer) to crash a TensorFlow process by passing an empty dense_shape tensor to SparseFillEmptyRows. Availability-only impact — no code execution or data leakage. Patch immediately to TF 2.5.0 or the backport releases; if patching is delayed, validate tensor inputs at the application boundary.
What is the risk?
Medium risk in isolation, but elevated in ML serving environments where untrusted inputs can reach TensorFlow ops through an API or data pipeline. CVSS 5.5 reflects local-only scope, but many production inference services effectively expose TF ops to external inputs through a thin application wrapper. No evidence of active exploitation; CWE-476 null pointer dereference is well-understood and exploitable by anyone who can craft a malformed tensor input.
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?
4 steps-
Patch: upgrade to TensorFlow 2.5.0, or apply cherry-pick patches to 2.4.2 / 2.3.3 / 2.2.3 / 2.1.4.
-
Workaround: add input validation before calling SparseFillEmptyRows — assert dense_shape tensor is non-empty before passing to the op.
-
Detection: monitor for process crashes or SIGABRT in TensorFlow serving processes; log and alert on malformed sparse tensor inputs at API boundaries.
-
Containment: run TF inference processes in isolated containers with automatic restart — limits blast radius to availability without service-level outage.
How is it classified?
Which compliance frameworks are affected?
This CVE is relevant to:
Frequently Asked Questions
What is CVE-2021-29565?
This vulnerability allows any low-privileged local user (or remote attacker reaching TensorFlow ops through an application layer) to crash a TensorFlow process by passing an empty dense_shape tensor to SparseFillEmptyRows. Availability-only impact — no code execution or data leakage. Patch immediately to TF 2.5.0 or the backport releases; if patching is delayed, validate tensor inputs at the application boundary.
Is CVE-2021-29565 actively exploited?
Proof-of-concept exploit code is publicly available for CVE-2021-29565, increasing the risk of exploitation.
How to fix CVE-2021-29565?
1. Patch: upgrade to TensorFlow 2.5.0, or apply cherry-pick patches to 2.4.2 / 2.3.3 / 2.2.3 / 2.1.4. 2. Workaround: add input validation before calling SparseFillEmptyRows — assert dense_shape tensor is non-empty before passing to the op. 3. Detection: monitor for process crashes or SIGABRT in TensorFlow serving processes; log and alert on malformed sparse tensor inputs at API boundaries. 4. Containment: run TF inference processes in isolated containers with automatic restart — limits blast radius to availability without service-level outage.
What systems are affected by CVE-2021-29565?
This vulnerability affects the following AI/ML architecture patterns: training pipelines, model serving, feature engineering pipelines, recommendation system inference.
What is the CVSS score for CVE-2021-29565?
CVE-2021-29565 has a CVSS v3.1 base score of 5.5 (MEDIUM). The EPSS exploitation probability is 0.19%.
What is the AI security impact?
Affected AI Architectures
MITRE ATLAS Techniques
AML.T0010.001 AI Software AML.T0029 Denial of AI Service 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. An attacker can trigger a null pointer dereference in the implementation of `tf.raw_ops.SparseFillEmptyRows`. This is because of missing validation(https://github.com/tensorflow/tensorflow/blob/fdc82089d206e281c628a93771336bf87863d5e8/tensorflow/core/kernels/sparse_fill_empty_rows_op.cc#L230-L231) that was covered under a `TODO`. If the `dense_shape` tensor is empty, then `dense_shape_t.vec<>()` would cause a null pointer dereference in the implementation of the op. 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 targeting an ML-powered recommendation system submits a crafted API request with an empty dense_shape parameter in the sparse feature tensor payload. The application passes this directly to tf.raw_ops.SparseFillEmptyRows without validation. TensorFlow dereferences a null pointer, crashing the inference worker. In a containerized deployment without auto-restart, this takes the inference endpoint offline. Repeated requests constitute a low-effort DoS with no rate limiting needed — a single malformed request triggers the crash.
Weaknesses (CWE)
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:N/I:N/A:H References
- github.com/tensorflow/tensorflow/commit/faa76f39014ed3b5e2c158593b1335522e573c7f Patch 3rd Party
- github.com/tensorflow/tensorflow/security/advisories/GHSA-r6pg-pjwc-j585 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