CVE-2021-29591
📋 TL;DR
This vulnerability in TensorFlow allows attackers to craft malicious TFLite models that cause infinite loops or stack overflows during evaluation. It affects TensorFlow users who process untrusted models, potentially leading to denial of service. The issue stems from improper validation of loops between nodes in TFLite graphs.
💻 Affected Systems
- TensorFlow
📦 What is this software?
⚠️ Risk & Real-World Impact
Worst Case
Complete denial of service through stack exhaustion, crashing the TensorFlow process and potentially affecting dependent applications.
Likely Case
Service disruption when processing malicious models, causing application crashes or unresponsiveness.
If Mitigated
No impact if proper input validation and model sanitization are implemented before processing.
🎯 Exploit Status
Exploitation requires crafting a malicious TFLite model with specific loop conditions. No public exploit code is known, but the vulnerability is well-documented.
🛠️ Fix & Mitigation
✅ Official Fix
Patch Version: TensorFlow 2.5.0, 2.4.2, 2.3.3, 2.2.3, 2.1.4
Vendor Advisory: https://github.com/tensorflow/tensorflow/security/advisories/GHSA-cwv3-863g-39vx
Restart Required: Yes
Instructions:
1. Identify current TensorFlow version. 2. Upgrade to patched version using pip: 'pip install --upgrade tensorflow==2.5.0' (or appropriate version). 3. Restart all services using TensorFlow. 4. Verify the fix by checking version and testing with known safe models.
🔧 Temporary Workarounds
Input Validation and Model Sanitization
allImplement strict validation of TFLite models before processing, rejecting models with suspicious graph structures.
Resource Limiting
linuxConfigure process resource limits (stack size, CPU time) to mitigate impact of infinite loops.
ulimit -s 8192
ulimit -t 30
🧯 If You Can't Patch
- Isolate TensorFlow processing in containers with strict resource limits
- Implement model provenance checking and only accept models from trusted sources
🔍 How to Verify
Check if Vulnerable:
Check TensorFlow version: if between 2.1.0-2.4.1 (excluding patched versions), the system is vulnerable.
Check Version:
python -c 'import tensorflow as tf; print(tf.__version__)'
Verify Fix Applied:
Verify TensorFlow version is 2.5.0, 2.4.2, 2.3.3, 2.2.3, or 2.1.4. Test with a sample TFLite model to ensure normal processing.
📡 Detection & Monitoring
Log Indicators:
- Process crashes with stack overflow errors
- Excessive CPU usage from TensorFlow processes
- Repeated model evaluation failures
Network Indicators:
- Unusual model uploads to TensorFlow services
- Increased error rates in model inference endpoints
SIEM Query:
source="tensorflow" AND ("stack overflow" OR "infinite loop" OR "Process terminated")
🔗 References
- https://github.com/tensorflow/tensorflow/commit/9c1dc920d8ffb4893d6c9d27d1f039607b326743
- https://github.com/tensorflow/tensorflow/commit/c6173f5fe66cdbab74f4f869311fe6aae2ba35f4
- https://github.com/tensorflow/tensorflow/security/advisories/GHSA-cwv3-863g-39vx
- https://github.com/tensorflow/tensorflow/commit/9c1dc920d8ffb4893d6c9d27d1f039607b326743
- https://github.com/tensorflow/tensorflow/commit/c6173f5fe66cdbab74f4f869311fe6aae2ba35f4
- https://github.com/tensorflow/tensorflow/security/advisories/GHSA-cwv3-863g-39vx