CVE-2021-29515: Reference binding to null pointer in MatrixDiag* ops in TensorFlow
Summary
CVE-2021-29515: Reference binding to null pointer in MatrixDiag* ops. 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-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 open-source machine learning framework widely used for building and training neural networks. It provides a comprehensive set of tools and libraries for numerical computation and data flow graphs. The MatrixDiag* operations in TensorFlow are used for manipulating diagonal matrices. These operations take tensor inputs and produce diagonal matrices as outputs. However, a vulnerability has been discovered in the implementation of these operations, which allows for reference binding to a null pointer.
Vulnerability Detail
The vulnerability in the MatrixDiag* operations arises from the lack of validation for non-empty tensor arguments. The implementation does not check whether the tensor inputs are null before performing operations on them. This can lead to null pointer dereferences when the tensors are null. An attacker can exploit this vulnerability by providing null tensors as inputs to the MatrixDiag* operations, causing the program to crash or potentially execute arbitrary code. The impact of this vulnerability can range from denial of service to remote code execution.
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 workaround, users can avoid passing null tensors as inputs to the MatrixDiag* operations. It is recommended to validate the tensor inputs before using them in these operations. Here is an example of how to perform the validation in Python:
import tensorflow as tf
def matrix_diag_op(diagonal, k, num_rows, num_cols, padding_value):
if diagonal is None or k is None or num_rows is None or num_cols is None or padding_value is None:
raise ValueError('Invalid tensor inputs')
# Perform MatrixDiag* operations
...
By explicitly checking for null tensors, users can prevent the vulnerability from being exploited.
Conclusion
The vulnerability in the MatrixDiag* operations in TensorFlow allows for reference binding to a null pointer, which can lead to null pointer dereferences and potential code execution. It is crucial for users to update their TensorFlow installations to the patched versions or upgrade to TensorFlow 2.5.0 to mitigate this vulnerability. Additionally, validating tensor inputs before using them in the MatrixDiag* operations can serve as a workaround. For further support on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for tensorflow →
FAQ
The impact of this vulnerability can range from denial of service to remote code execution. An attacker can exploit the vulnerability by providing null tensors as inputs to the MatrixDiag* operations, causing the program to crash or potentially execute arbitrary code.
The vulnerability affects TensorFlow versions 2.1.4, 2.2.3, 2.3.3, and 2.4.2. These versions have been patched to address the vulnerability.
To fix the vulnerability, users should upgrade their TensorFlow installations to version 2.5.0 or later. Alternatively, they can update to the patched versions 2.4.2, 2.3.3, 2.2.3, or 2.1.4.
Yes, users can avoid passing null tensors as inputs to the MatrixDiag* operations. It is recommended to validate the tensor inputs before using them in these operations.
For more information, please refer to the TensorFlow security guide and the GitHub commit a7116dd3913c4a4afd2a3a938573aa7c785fdfc6.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.