CVE-2021-29597: TensorFlow TFLite: div-by-zero crash via crafted model
HIGH PoC AVAILABLEAny system loading TFLite models from untrusted or third-party sources is vulnerable to a crash or potential code execution via a single crafted model file. Patch to TensorFlow 2.5.0 immediately, or apply the cherry-picked fix for 2.1.4/2.2.3/2.3.3/2.4.2. Enforce strict model provenance controls—sign and verify all TFLite artifacts before loading.
Risk Assessment
Risk is HIGH in environments that dynamically ingest third-party or user-supplied TFLite models. The local attack vector is deceptive: in ML pipelines, 'local' includes loading a model downloaded from a registry, a federated update channel, or an internal artifact store—all reachable by a supply chain attacker. CVSS 7.8 with full C/I/A impact means exploitation may extend beyond DoS to code execution depending on heap layout at crash time. Unpatched edge and mobile deployments face the highest exposure due to frequent dynamic model updates with limited code-signing enforcement.
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-
Upgrade to TensorFlow 2.5.0 or cherry-pick commit 6d36ba6 for 2.1.4/2.2.3/2.3.3/2.4.2.
-
Enforce model signing: require cryptographic signatures on all TFLite files loaded at runtime; reject unsigned or unverified artifacts.
-
Add input validation in any pipeline accepting externally sourced models—validate operator dimensions before graph initialization.
-
For edge fleets, audit model update delivery channels; restrict to signed artifacts from controlled registries only.
-
Detection: monitor TFLite inference processes for unexpected crashes or SIGFPE signals; treat repeated model-load failures as a potential indicator of artifact tampering.
Classification
Compliance Impact
This CVE is relevant to:
Frequently Asked Questions
What is CVE-2021-29597?
Any system loading TFLite models from untrusted or third-party sources is vulnerable to a crash or potential code execution via a single crafted model file. Patch to TensorFlow 2.5.0 immediately, or apply the cherry-picked fix for 2.1.4/2.2.3/2.3.3/2.4.2. Enforce strict model provenance controls—sign and verify all TFLite artifacts before loading.
Is CVE-2021-29597 actively exploited?
Proof-of-concept exploit code is publicly available for CVE-2021-29597, increasing the risk of exploitation.
How to fix CVE-2021-29597?
1. Upgrade to TensorFlow 2.5.0 or cherry-pick commit 6d36ba6 for 2.1.4/2.2.3/2.3.3/2.4.2. 2. Enforce model signing: require cryptographic signatures on all TFLite files loaded at runtime; reject unsigned or unverified artifacts. 3. Add input validation in any pipeline accepting externally sourced models—validate operator dimensions before graph initialization. 4. For edge fleets, audit model update delivery channels; restrict to signed artifacts from controlled registries only. 5. Detection: monitor TFLite inference processes for unexpected crashes or SIGFPE signals; treat repeated model-load failures as a potential indicator of artifact tampering.
What systems are affected by CVE-2021-29597?
This vulnerability affects the following AI/ML architecture patterns: edge inference, mobile ML deployments, model serving, federated learning clients, training pipelines.
What is the CVSS score for CVE-2021-29597?
CVE-2021-29597 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 implementation of the `SpaceToBatchNd` TFLite operator is [vulnerable to a division by zero error](https://github.com/tensorflow/tensorflow/blob/412c7d9bb8f8a762c5b266c9e73bfa165f29aac8/tensorflow/lite/kernels/space_to_batch_nd.cc#L82-L83). An attacker can craft a model such that one dimension of the `block` input is 0. Hence, the corresponding value in `block_shape` is 0. 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 organization's edge fleet or mobile ML deployment crafts a .tflite model file with a SpaceToBatchNd operator whose block input has a zero-valued dimension. The adversary introduces this model via a compromised model hub, a poisoned internal artifact registry, or a man-in-the-middle attack on an unprotected model update channel. When the device or server initializes the model graph, the TFLite kernel computes block_shape from the zero dimension, triggering an unguarded division by zero. The runtime crashes, causing a denial of service; on targets with exploitable heap layouts, the memory corruption at crash time may be leveraged for code execution under the local user context.
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/6d36ba65577006affb272335b7c1abd829010708 Patch 3rd Party
- github.com/tensorflow/tensorflow/security/advisories/GHSA-v52p-hfjf-wg88 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