CVE-2021-29515: TensorFlow MatrixDiag* Operations Validation Failure
Summary
CVE-2021-29515: TensorFlow is an end-to-end open source platform for machine learning. Affects tensorflow across 5 version ranges.
< 2.1.4
>= 2.2.0, < 2.2.3
>= 2.3.0, < 2.3.3
>= 2.4.0, < 2.4.2
< a7116dd3913c4a4afd2a3a938573aa7c785fdfc6
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-29515 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 set of tools, libraries, and resources for developing and deploying machine learning models. TensorFlow is widely used in various domains, including research, industry, and academia. The package offers functionalities for data preprocessing, model training, and model serving, making it a popular choice for machine learning practitioners. However, a vulnerability has been discovered in the implementation of the MatrixDiag* operations in TensorFlow.
Vulnerability Detail
The vulnerability in TensorFlow's MatrixDiag* operations arises from a lack of validation for non-empty tensor arguments. This oversight allows an attacker to pass empty tensors to these operations, leading to unexpected behavior or potential crashes. The issue affects versions of TensorFlow from 0 to 2.4.2, including 2.1.4, 2.2.3, and 2.3.3. The impact of this vulnerability can range from data corruption to denial of service attacks, depending on the specific usage of the affected operations.
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
As a temporary workaround, users can manually validate the tensor arguments before invoking the MatrixDiag* operations. This can be done by checking the dimensions of the tensors and ensuring they are not empty. Here is an example of how to perform the validation in Python:
import tensorflow as tf
def safe_matrix_diag(tensor):
if tf.size(tensor) == 0:
raise ValueError('Tensor argument cannot be empty.')
return tf.linalg.matrix_diag(tensor)
Conclusion
In conclusion, the vulnerability in TensorFlow's MatrixDiag* operations can be mitigated by updating to the patched versions of TensorFlow. It is crucial for users to promptly apply the necessary updates to ensure the security and stability of their machine learning workflows. For further support on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for tensorflow →
FAQ
TensorFlow is an open source platform for machine learning that provides a comprehensive set of tools and resources for developing and deploying machine learning models.
MatrixDiag* operations in TensorFlow are functions that manipulate tensors to create diagonal matrices or extract the diagonal elements from matrices.
The vulnerability in MatrixDiag* operations allows an attacker to pass empty tensors as arguments, leading to unexpected behavior or potential crashes in TensorFlow.
The impact of this vulnerability can range from data corruption to denial of service attacks, depending on the specific usage of the affected MatrixDiag* operations.
To fix this vulnerability, update your TensorFlow installation to one of the patched versions: 2.5.0, 2.4.2, 2.3.3, 2.2.3, or 2.1.4.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.