CVE-2021-29587: TensorFlow TFLite: divide-by-zero via crafted model file
HIGH PoC AVAILABLEAny environment loading untrusted TFLite models is exposed to a crash or potential code execution via a crafted SpaceToDepth operator with block_size=0. The primary risk vector is AI/ML pipelines or mobile deployments that ingest externally-sourced models. Patch immediately to TF 2.5.0, 2.4.2, 2.3.3, 2.2.3, or 2.1.4 and audit model provenance controls.
Risk Assessment
CVSS 7.8 High but local attack vector constrains real-world risk somewhat. Exploitation is trivial — an attacker only needs to craft a TFLite model with a zero block_size parameter and get a target system to load it. Risk elevates significantly in pipelines that consume third-party or user-supplied models without validation, common in MLOps and edge deployment scenarios. No evidence of active exploitation in the wild, but the technique is easily weaponizable.
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 cherry-picked fixes in 2.4.2, 2.3.3, 2.2.3, 2.1.4.
-
Model validation: Implement pre-load validation of TFLite models — reject models with block_size=0 in SpaceToDepth ops before inference.
-
Isolation: Run TFLite inference in sandboxed processes so a crash doesn't propagate to the host system.
-
Provenance controls: Enforce cryptographic signing and allowlisting of approved model sources.
-
Detection: Alert on process crashes in inference services; log model hashes at load time for forensic tracing.
Classification
Compliance Impact
This CVE is relevant to:
Frequently Asked Questions
What is CVE-2021-29587?
Any environment loading untrusted TFLite models is exposed to a crash or potential code execution via a crafted SpaceToDepth operator with block_size=0. The primary risk vector is AI/ML pipelines or mobile deployments that ingest externally-sourced models. Patch immediately to TF 2.5.0, 2.4.2, 2.3.3, 2.2.3, or 2.1.4 and audit model provenance controls.
Is CVE-2021-29587 actively exploited?
Proof-of-concept exploit code is publicly available for CVE-2021-29587, increasing the risk of exploitation.
How to fix CVE-2021-29587?
1. Patch: Upgrade to TensorFlow 2.5.0 or cherry-picked fixes in 2.4.2, 2.3.3, 2.2.3, 2.1.4. 2. Model validation: Implement pre-load validation of TFLite models — reject models with block_size=0 in SpaceToDepth ops before inference. 3. Isolation: Run TFLite inference in sandboxed processes so a crash doesn't propagate to the host system. 4. Provenance controls: Enforce cryptographic signing and allowlisting of approved model sources. 5. Detection: Alert on process crashes in inference services; log model hashes at load time for forensic tracing.
What systems are affected by CVE-2021-29587?
This vulnerability affects the following AI/ML architecture patterns: edge/mobile AI deployments, model serving, training pipelines, MLOps model validation pipelines, embedded AI systems.
What is the CVSS score for CVE-2021-29587?
CVE-2021-29587 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. The `Prepare` step of the `SpaceToDepth` TFLite operator does not check for 0 before division(https://github.com/tensorflow/tensorflow/blob/5f7975d09eac0f10ed8a17dbb6f5964977725adc/tensorflow/lite/kernels/space_to_depth.cc#L63-L67). An attacker can craft a model such that `params->block_size` would be zero. 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 MLOps pipeline or mobile AI backend crafts a TFLite model file with a SpaceToDepth layer where block_size is set to zero. The model is published to a public model hub or injected into a supply chain (e.g., a compromised model registry or poisoned dependency). When the victim system loads the model for inference or validation, the TFLite runtime hits the unguarded division in the Prepare step, triggering a crash. In edge deployments on IoT or mobile devices, this enables persistent denial-of-service or, if memory corruption is exploitable on the target platform, potential code execution with the privileges of the inference process.
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/0d45ea1ca641b21b73bcf9c00e0179cda284e7e7 Patch 3rd Party
- github.com/tensorflow/tensorflow/security/advisories/GHSA-j7rm-8ww4-xx2g 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