CVE-2021-29540: Heap buffer overflow in tensorflow
Summary
CVE-2021-29540: Heap buffer overflow in Conv2DBackpropFilter. Affects tensorflow across 4 version ranges.
< 2.1.4
>= 2.2.0, < 2.2.3
>= 2.3.0, < 2.3.3
>= 2.4.0, < 2.4.2
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-29540 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 machine learning framework used for building and training neural networks. It provides a comprehensive set of tools and libraries for numerical computation and data flow graphs. TensorFlow is widely used in various domains, including research, industry, and academia. However, a vulnerability has been discovered in TensorFlow that could potentially lead to a heap buffer overflow.
Vulnerability Detail
The vulnerability, identified as CVE-2021-29540, allows an attacker to trigger a heap buffer overflow in the Conv2DBackpropFilter function. This can be exploited by passing certain input tensors or empty tensors to the function. The issue arises due to a lack of validation for the number of elements in the filter_sizes tensor, leading to incorrect buffer size calculations. As a result, when reading or writing to this buffer, the code uses the incorrect size, causing a heap buffer overflow. An attacker could potentially exploit this vulnerability to execute arbitrary code or crash the application.
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.1.42.1.4pip install --upgrade "tensorflow==2.1.4" -
>= 2.2.0, < 2.2.32.2.3pip install --upgrade "tensorflow==2.2.3" -
>= 2.3.0, < 2.3.32.3.3pip install --upgrade "tensorflow==2.3.3" -
>= 2.4.0, < 2.4.22.4.2pip install --upgrade "tensorflow==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
If immediate updating is not possible, a workaround for this vulnerability is to avoid using the Conv2DBackpropFilter function with the specific input tensors or empty tensors mentioned in the vulnerability details. By avoiding these specific scenarios, the risk of triggering the heap buffer overflow can be mitigated.
Conclusion
The vulnerability in TensorFlow has been addressed by the TensorFlow team in the latest patched versions. It is recommended to update your TensorFlow installation to one of the fixed versions to mitigate the risk of exploitation. For further support or assistance with vulnerability remediation, you can contact DevNack.com.
See every vulnerability recorded for tensorflow →
FAQ
TensorFlow is an open-source machine learning framework used for building and training neural networks. It provides a comprehensive set of tools and libraries for numerical computation and data flow graphs.
The vulnerability allows an attacker to trigger a heap buffer overflow in TensorFlow, potentially leading to the execution of arbitrary code or application crashes.
To fix the vulnerability, update your TensorFlow installation to one of the patched versions: TensorFlow 2.5.0, TensorFlow 2.4.2, TensorFlow 2.3.3, TensorFlow 2.2.3, or TensorFlow 2.1.4.
Yes, if immediate updating is not possible, you can mitigate the risk by avoiding the specific input tensors or empty tensors mentioned in the vulnerability details when using the Conv2DBackpropFilter function.
For more information, you can refer to the TensorFlow security guide and the GitHub commit mentioned in the vulnerability details.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.