CVE-2021-41221: TensorFlow Heap Buffer Overflow
Summary
CVE-2021-41221: TensorFlow is an open source platform for machine learning. Affects tensorflow across 5 version ranges.
< 2.4.4
>= 2.5.0, < 2.5.2
>= 2.6.0, < 2.6.1
>= 2.7.0rc0, < 2.7.0
< af5fcebb37c8b5d71c237f4e59c6477015c78ce6
Fixed in 4 releases; the minimum fixed version depends on the release line you run. How to fix ↓
Also tracked for
- tensorflow · Bitnami
- tensorflow-cpu · PyPI
- tensorflow-gpu · PyPI
The same CVE-2021-41221 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 open source platform for machine learning. It provides a comprehensive ecosystem of tools, libraries, and resources for developing and deploying machine learning models. TensorFlow is widely used in various domains, including research, industry, and academia. This vulnerability affects versions of TensorFlow that utilize the Cudnn* operations. These operations are used for deep learning tasks and are implemented using the cuDNN library, which provides highly optimized GPU-accelerated primitives for deep neural networks. The vulnerability arises from a lack of validation for the ranks of certain input parameters, leading to a heap buffer overflow.
Vulnerability Detail
The vulnerability in TensorFlow's shape inference code for the Cudnn* operations allows an attacker to trigger a heap buffer overflow by providing invalid values for the input, input_h, and input_c parameters. The code assumes certain values for these parameters without proper validation, leading to the overflow. This can be exploited by an attacker to execute arbitrary code, potentially compromising the integrity and confidentiality of the affected system. The vulnerability has been assigned the identifier CVE-2021-41221 and has been reported to the TensorFlow development team.
How To Fix
Latest published version: 2.21.0 as of 22 Oct 2026
pip install --upgrade "tensorflow==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.4.42.4.4pip install --upgrade "tensorflow==2.4.4" -
>= 2.5.0, < 2.5.22.5.2pip install --upgrade "tensorflow==2.5.2" -
>= 2.6.0, < 2.6.12.6.1pip install --upgrade "tensorflow==2.6.1" -
>= 2.7.0rc0, < 2.7.02.7.0pip install --upgrade "tensorflow==2.7.0"
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 known workaround for this vulnerability. It is recommended to update to the fixed versions of TensorFlow as soon as possible.
Conclusion
The vulnerability in TensorFlow's shape inference code for the Cudnn* operations can lead to a heap buffer overflow, potentially allowing an attacker to execute arbitrary code. Users of affected versions should update to the fixed versions of TensorFlow to mitigate the risk. For further support and assistance in vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for tensorflow →
FAQ
TensorFlow is an open source platform for machine learning that provides tools and libraries for developing and deploying machine learning models.
A heap buffer overflow is a type of vulnerability where a program writes data beyond the bounds of a dynamically allocated buffer in the heap, potentially overwriting adjacent memory and leading to a crash or arbitrary code execution.
An attacker can exploit this vulnerability by providing specially crafted input to the affected TensorFlow operations, triggering a heap buffer overflow and potentially executing arbitrary code.
No, only versions that utilize the Cudnn* operations are affected. The vulnerability has been fixed in TensorFlow 2.7.0, TensorFlow 2.6.1, TensorFlow 2.5.2, and TensorFlow 2.4.4.
No, there is no known workaround. It is recommended to update to the fixed versions of TensorFlow.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.