CVE-2021-29591: TFLite: crafted model causes infinite loop / stack overflow
HIGH PoC AVAILABLEAny pipeline that loads untrusted TFLite models is exposed to a denial-of-service or potential stack-smash via a maliciously crafted .tflite file with self-referencing While subgraphs. Patch to TF 2.5.0 / 2.4.2 / 2.3.3 / 2.2.3 / 2.1.4 immediately. Until patched, gate model ingestion with a validator that detects cyclic subgraph references before evaluation.
Risk Assessment
CVSS 7.8 (High) with local attack vector and low complexity — exploitability is straightforward once the attacker can get a malicious model loaded. The main exposure window is model-serving infrastructure, MLOps pipelines that pull models from registries, and mobile/edge devices running TFLite inference. Not in CISA KEV and no public exploit code confirmed, keeping operational urgency moderate. The C:H/I:H/A:H CVSS subscores indicate that if the stack overflow is exploitable beyond pure DoS, privilege escalation or memory corruption on the inference host is theoretically in scope.
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 TensorFlow to 2.5.0, or cherry-pick patches to 2.4.2 / 2.3.3 / 2.2.3 / 2.1.4 as appropriate.
-
Implement pre-evaluation graph validation: scan TFLite flatbuffer subgraph references for cycles before calling Interpreter::Invoke().
-
Run TFLite inference in a sandboxed process with resource limits (ulimit stack size, process timeout) to contain blast radius.
-
Enforce model provenance: only load models from signed, trusted sources; reject unsigned or externally sourced .tflite files.
-
Detection: monitor inference worker processes for runaway CPU or stack exhaustion signals (SIGSEGV/SIGABRT from stack overflow) as anomaly indicators.
Classification
Compliance Impact
This CVE is relevant to:
Frequently Asked Questions
What is CVE-2021-29591?
Any pipeline that loads untrusted TFLite models is exposed to a denial-of-service or potential stack-smash via a maliciously crafted .tflite file with self-referencing While subgraphs. Patch to TF 2.5.0 / 2.4.2 / 2.3.3 / 2.2.3 / 2.1.4 immediately. Until patched, gate model ingestion with a validator that detects cyclic subgraph references before evaluation.
Is CVE-2021-29591 actively exploited?
Proof-of-concept exploit code is publicly available for CVE-2021-29591, increasing the risk of exploitation.
How to fix CVE-2021-29591?
1. Upgrade TensorFlow to 2.5.0, or cherry-pick patches to 2.4.2 / 2.3.3 / 2.2.3 / 2.1.4 as appropriate. 2. Implement pre-evaluation graph validation: scan TFLite flatbuffer subgraph references for cycles before calling Interpreter::Invoke(). 3. Run TFLite inference in a sandboxed process with resource limits (ulimit stack size, process timeout) to contain blast radius. 4. Enforce model provenance: only load models from signed, trusted sources; reject unsigned or externally sourced .tflite files. 5. Detection: monitor inference worker processes for runaway CPU or stack exhaustion signals (SIGSEGV/SIGABRT from stack overflow) as anomaly indicators.
What systems are affected by CVE-2021-29591?
This vulnerability affects the following AI/ML architecture patterns: model serving, training pipelines, edge/mobile inference.
What is the CVSS score for CVE-2021-29591?
CVE-2021-29591 has a CVSS v3.1 base score of 7.8 (HIGH). The EPSS exploitation probability is 0.02%.
Technical Details
NVD Description
TensorFlow is an end-to-end open source platform for machine learning. TFlite graphs must not have loops between nodes. However, this condition was not checked and an attacker could craft models that would result in infinite loop during evaluation. In certain cases, the infinite loop would be replaced by stack overflow due to too many recursive calls. For example, the `While` implementation(https://github.com/tensorflow/tensorflow/blob/106d8f4fb89335a2c52d7c895b7a7485465ca8d9/tensorflow/lite/kernels/while.cc) could be tricked into a scneario where both the body and the loop subgraphs are the same. Evaluating one of the subgraphs means calling the `Eval` function for the other and this quickly exhaust all stack space. 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. Please consult our security guide(https://github.com/tensorflow/tensorflow/blob/master/SECURITY.md) for more information regarding the security model and how to contact us with issues and questions.
Exploitation Scenario
An adversary crafts a .tflite model where the While op's body_subgraph_index and cond_subgraph_index both point to the same subgraph, triggering mutual recursion in the TFLite evaluator. The attacker uploads this model to a shared model registry (e.g., an internal MLflow or Hugging Face private hub). A CI/CD pipeline pulls the model for acceptance testing, loads it via the TFLite Interpreter, and the evaluation thread either spins indefinitely (DoS) or exhausts the call stack and crashes the inference worker — taking down the serving tier or blocking the deployment pipeline. In a mobile context, an attacker distributing a malicious app update embedding the crafted .tflite could crash the on-device inference runtime.
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/9c1dc920d8ffb4893d6c9d27d1f039607b326743 Patch 3rd Party
- github.com/tensorflow/tensorflow/commit/c6173f5fe66cdbab74f4f869311fe6aae2ba35f4 Patch 3rd Party
- github.com/tensorflow/tensorflow/security/advisories/GHSA-cwv3-863g-39vx Exploit Patch 3rd Party
- github.com/ARPSyndicate/cvemon Exploit
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