CVE-2021-41216: TensorFlow GPU - Heap Buffer Overflow in Transpose Shape Inference
Summary
CVE-2021-41216: TensorFlow is an open source platform for machine learning. Affects tensorflow-gpu 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
< c79ba87153ee343401dbe9d1954d7f79e521eb14
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-cpu · PyPI
The same CVE-2021-41216 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 GPU is a variant of TensorFlow that leverages the power of GPUs for accelerated computation. It allows users to train and run machine learning models on GPUs, enabling faster and more efficient processing of large datasets. However, TensorFlow GPU is vulnerable to a heap buffer overflow in the shape inference function for Transpose.
Vulnerability Detail
The vulnerability in TensorFlow GPU arises when the shape inference function for Transpose is called with a perm parameter that contains negative elements. The function does not validate the indices in perm, allowing negative values to be used. This leads to a heap buffer overflow, where data is written beyond the bounds of allocated memory. An attacker can exploit this vulnerability to execute arbitrary code, potentially compromising the integrity and confidentiality of the system. The vulnerability affects versions of TensorFlow GPU up to and including 2.7.0rc0.
How To Fix
Latest published version: 2.12.0 as of 22 Oct 2026
pip install --upgrade "tensorflow-gpu==2.12.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-gpu==2.4.4" -
>= 2.5.0, < 2.5.22.5.2pip install --upgrade "tensorflow-gpu==2.5.2" -
>= 2.6.0, < 2.6.12.6.1pip install --upgrade "tensorflow-gpu==2.6.1" -
>= 2.7.0rc0, < 2.7.02.7.0pip install --upgrade "tensorflow-gpu==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 apply the official patches provided by the TensorFlow development team.
Conclusion
The vulnerability in TensorFlow GPU's shape inference function for Transpose can lead to a heap buffer overflow, allowing an attacker to execute arbitrary code. To mitigate this vulnerability, users should update their TensorFlow GPU installations to one of the patched versions: TensorFlow 2.7.0, TensorFlow 2.6.1, TensorFlow 2.5.2, or TensorFlow 2.4.4. No known workarounds exist for this vulnerability. For further support on vulnerability remediation, contact DevNack.com.
See every vulnerability recorded for tensorflow-gpu →
FAQ
TensorFlow GPU is a variant of TensorFlow that utilizes GPUs for accelerated machine learning computations. It provides improved performance and efficiency compared to running TensorFlow on CPUs.
A heap buffer overflow occurs when data is written beyond the bounds of an allocated memory buffer. This can lead to memory corruption and potentially allow an attacker to execute arbitrary code.
An attacker can exploit this vulnerability by crafting a malicious input that triggers the shape inference function for Transpose with a perm parameter containing negative elements. This can lead to a heap buffer overflow and potentially allow the attacker to execute arbitrary code.
The vulnerability affects TensorFlow GPU versions up to and including 2.7.0rc0. Users of these versions are advised to update to the patched versions: TensorFlow 2.7.0, TensorFlow 2.6.1, TensorFlow 2.5.2, or TensorFlow 2.4.4.
The official patches provided by the TensorFlow development team include a fix that validates the indices in perm to prevent negative values and mitigate the heap buffer overflow. It is recommended to update to one of the patched versions.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow-gpu.