CVE-2021-37643: Null Pointer Dereference in TensorFlow
Summary
CVE-2021-37643: Null pointer dereference in MatrixDiagPartOp. Affects tensorflow across 3 version ranges.
< 2.3.4
>= 2.4.0, < 2.4.3
>= 2.5.0, < 2.5.1
Fixed in 2.3.4, 2.4.3 or 2.5.1, depending on the release line you run. How to fix ↓
Also tracked for
- tensorflow · Bitnami
- tensorflow-cpu · PyPI
- tensorflow-gpu · PyPI
The same CVE-2021-37643 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 developed by Google. It provides a comprehensive ecosystem of tools, libraries, and resources for building and deploying machine learning models. TensorFlow is widely used in various domains, including research, industry, and academia. However, a vulnerability has been discovered in TensorFlow that can lead to a null pointer dereference.
Vulnerability Detail
The vulnerability, identified as CVE-2021-37643, affects the MatrixDiagPartOp function in TensorFlow. When a user fails to provide a valid padding value to this function, it triggers a null pointer dereference if the input is empty or produces invalid behavior by ignoring all values after the first. This vulnerability can be exploited to cause a denial-of-service condition or potentially execute arbitrary code. The issue arises from the implementation of the function, which reads the first value from a tensor buffer without checking if the tensor has any values to read from.
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.3.42.3.4pip install --upgrade "tensorflow==2.3.4" -
>= 2.4.0, < 2.4.32.4.3pip install --upgrade "tensorflow==2.4.3" -
>= 2.5.0, < 2.5.12.5.1pip install --upgrade "tensorflow==2.5.1"
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 temporary workaround is to avoid using the MatrixDiagPartOp function with invalid padding values. Users should ensure that valid padding values are provided to prevent triggering the null pointer dereference. Here is an example of how to use the function with valid padding values:
import tensorflow as tf
tf.raw_ops.MatrixDiagPartV2(
input=tf.ones(2, dtype=tf.int32),
k=tf.ones(2, dtype=tf.int32),
padding_value=0)
Conclusion
The vulnerability in TensorFlow, identified as CVE-2021-37643, can lead to a null pointer dereference and potentially result in a denial-of-service condition or code execution. It is crucial for users to update their TensorFlow installation to the patched versions (2.6.0, 2.5.1, 2.4.3, or 2.3.4) to mitigate this vulnerability. If immediate updating is not possible, users should ensure valid padding values are provided to the MatrixDiagPartOp function. For further support or assistance, please contact the TensorFlow team through their official channels.
See every vulnerability recorded for tensorflow →
FAQ
The vulnerability can lead to a null pointer dereference, resulting in a denial-of-service condition or potential code execution. It is important to update TensorFlow to the patched versions to mitigate this risk.
The vulnerability affects TensorFlow versions 2.3.4, 2.4.3, 2.5.0, and 2.5.1. Users of these versions should update to the patched versions.
There are no known public exploits for this vulnerability at the time of this report. However, it is advisable to update TensorFlow to the patched versions to prevent potential exploitation.
Yes, this vulnerability can be exploited remotely if an attacker can provide malicious input to the vulnerable function. It is crucial to update TensorFlow to the patched versions to mitigate this risk.
For further assistance or questions regarding this vulnerability, you can contact the TensorFlow team through their official channels. Please refer to the TensorFlow project's security guide for more information on how to contact them.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.