CVE-2021-29591: TensorFlow CPU - Infinite Loop and Stack Overflow Vulnerability
Summary
CVE-2021-29591: TensorFlow is an end-to-end open source platform for machine learning. Affects tensorflow-cpu across 6 version ranges.
< 2.1.4
>= 2.2.0, < 2.2.3
>= 2.3.0, < 2.3.3
>= 2.4.0, < 2.4.2
< 9c1dc920d8ffb4893d6c9d27d1f039607b326743
< c6173f5fe66cdbab74f4f869311fe6aae2ba35f4
Fixed in 4 releases; the minimum fixed version depends on the release line you run. How to fix ↓
Also tracked for
- tensorflow · Bitnami
- tensorflow · PyPI
- tensorflow · PyPI
- tensorflow-gpu · PyPI
The same CVE-2021-29591 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
TensorFlow is an end-to-end open source platform for machine learning. It provides a comprehensive ecosystem of tools, libraries, and resources for developing and deploying machine learning models. TensorFlow CPU is a specific package that focuses on running TensorFlow on CPUs. It is widely used in various industries and applications for machine learning tasks.
Vulnerability Detail
The vulnerability identified as CVE-2021-29591 affects TensorFlow CPU. TFlite graphs in TensorFlow must not have loops between nodes. However, this condition was not properly checked, allowing an attacker to craft malicious models that would result in an infinite loop during evaluation. In certain cases, the infinite loop could lead to a stack overflow due to excessive recursive calls. The vulnerability specifically affects the While implementation in TensorFlow. By tricking the implementation into a scenario where both the body and loop subgraphs are the same, an attacker can exhaust the stack space by repeatedly calling the Eval function. This vulnerability can have severe consequences, including denial of service (DoS) attacks and potential remote code execution.
How To Fix
Latest published version: 2.21.0 as of 22 Oct 2026
pip install --upgrade "tensorflow-cpu==2.21.0"
Upgrading to it may include breaking changes; the versions below are the minimum fixed release for this vulnerability.
If you can't move to the latest
The minimum fixed version depends on the release line you run.
-
< 2.1.42.1.4pip install --upgrade "tensorflow-cpu==2.1.4" -
>= 2.2.0, < 2.2.32.2.3pip install --upgrade "tensorflow-cpu==2.2.3" -
>= 2.3.0, < 2.3.32.3.3pip install --upgrade "tensorflow-cpu==2.3.3" -
>= 2.4.0, < 2.4.22.4.2pip install --upgrade "tensorflow-cpu==2.4.2"
Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →
Workaround
There is no specific workaround provided for this vulnerability. However, users can mitigate the risk by ensuring they are using the latest patched version of TensorFlow CPU.
Conclusion
The vulnerability identified as CVE-2021-29591 in TensorFlow CPU can lead to an infinite loop and stack overflow, potentially resulting in denial of service (DoS) attacks or remote code execution. It is crucial for users of TensorFlow CPU to update to the latest patched version, which includes the fix for this vulnerability. By keeping the software up to date, users can ensure the security and stability of their machine learning applications. For further support and assistance in vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for tensorflow-cpu →
FAQ
TensorFlow CPU is a package that allows running TensorFlow on CPUs. It provides optimized CPU support for machine learning tasks.
The vulnerability can lead to an infinite loop during evaluation of TFlite graphs, potentially resulting in a denial of service (DoS) or remote code execution.
The vulnerability affects TensorFlow CPU versions 2.1.4 and above, including versions 2.2.3, 2.3.3, and 2.4.2.
There are no known public exploits for this vulnerability at the time of this report. However, it is important to apply the necessary patches and updates to mitigate the risk.
Users can update TensorFlow CPU by following the recommended upgrade process provided by the TensorFlow team. This typically involves updating the package using package managers like pip or conda.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow-cpu.