CVE-2021-29587: TensorFlow TFLite: divide-by-zero via crafted model file

HIGH PoC AVAILABLE
Published May 14, 2021
CISO Take

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.

What is the risk?

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.

What systems are affected?

Package Ecosystem Vulnerable Range Patched
TensorFlow pip No patch
195.8K OpenSSF 7.1 3.7K dependents Pushed 3d ago 4% patched ~1372d to patch Full package profile →

Do you use TensorFlow? You're affected.

How severe is it?

CVSS 3.1
7.8 / 10
EPSS
0.2%
chance of exploitation in 30 days
Higher than 10% of all CVEs
Exploitation Status
Exploit Available
Exploitation: MEDIUM
Sophistication
Trivial
Exploitation Confidence
medium
Public PoC indexed (trickest/cve)
Composite signal derived from CISA KEV, VulnCheck KEV, CISA SSVC, EPSS, Metasploit, Exploit-DB, trickest/cve, Nuclei templates, and inthewild.io exploitation reports.

What is the attack surface?

AV AC PR UI S C I A
AV Local
AC Low
PR Low
UI None
S Unchanged
C High
I High
A High

What should I do?

5 steps
  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.

How is it classified?

Which compliance frameworks are affected?

This CVE is relevant to:

EU AI Act
Article 9 - Risk management system for high-risk AI
ISO 42001
6.1.2 - AI risk assessment 8.4 - AI system operation
NIST AI RMF
GOVERN-6.2 - Policies and procedures are in place for AI risk management across the supply chain MANAGE-2.2 - Mechanisms to sustain the value of deployed AI systems are evaluated and in place

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.20%.

What is the AI security impact?

Affected AI Architectures

edge/mobile AI deploymentsmodel servingtraining pipelinesMLOps model validation pipelinesembedded AI systems

MITRE ATLAS Techniques

AML.T0010.001 AI Software
AML.T0011.000 Unsafe AI Artifacts
AML.T0018 Manipulate AI Model
AML.T0049 Exploit Public-Facing Application

Compliance Controls Affected

EU AI Act: Article 9
ISO 42001: 6.1.2, 8.4
NIST AI RMF: GOVERN-6.2, MANAGE-2.2

What are the technical details?

Original Advisory

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)

CWE-369 — Divide By Zero: The product divides a value by zero.

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

Timeline

Published
May 14, 2021
Last Modified
November 21, 2024
First Seen
May 14, 2021

Related Vulnerabilities