CVE-2021-41219: TensorFlow GPU - Sparse Matrix Multiplication Code Vulnerability
Summary
CVE-2021-41219: 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
< e6cf28c72ba2eb949ca950d834dd6d66bb01cfae
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-41219 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 specific package that enables GPU acceleration for TensorFlow. It allows users to leverage the power of GPUs to accelerate their machine learning computations, resulting in faster training and inference times. However, the TensorFlow GPU package is vulnerable to a specific issue related to sparse matrix multiplication.
Vulnerability Detail
The vulnerability in TensorFlow GPU arises from the code for sparse matrix multiplication. When the dimensions of the input matrices are 0 or less, the code binds a reference to a null pointer (nullptr), leading to undefined behavior. In such cases, an empty output tensor should be allocated to maintain the invariant that output tensors are always allocated when the operation is successful. However, the code fails to handle this scenario correctly, resulting in attempts to write to the empty tensor. This can lead to heap out-of-bounds access, potentially causing crashes or arbitrary code execution. The vulnerability affects multiple versions of TensorFlow GPU, including 2.4.4, 2.5.2, 2.6.1, and 2.7.0.
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
As a temporary workaround, users can manually check the dimensions of the input matrices before performing sparse matrix multiplication. If any of the dimensions are 0 or less, the operation should be skipped, and appropriate error handling should be implemented. Here's an example of how to perform this check in Python:
import tensorflow as tf
def safe_sparse_matrix_multiplication(a, b):
if a.shape[0] <= 0 or a.shape[1] <= 0 or b.shape[0] <= 0 or b.shape[1] <= 0:
raise ValueError('Invalid dimensions for sparse matrix multiplication')
else:
return tf.sparse.sparse_dense_matmul(a, b)
Conclusion
The vulnerability in TensorFlow GPU's sparse matrix multiplication code can lead to heap out-of-bounds access and potential security risks. It is important for users to update their TensorFlow GPU package to the fixed versions once they are released. Regularly checking for updates and applying them promptly is essential for maintaining a secure and stable machine learning environment. For further support on vulnerability remediation, you can reach out to DevNack.com.
See every vulnerability recorded for tensorflow-gpu →
FAQ
TensorFlow GPU is a package that enables GPU acceleration for TensorFlow, allowing users to leverage the power of GPUs for faster machine learning computations.
Sparse matrix multiplication is a mathematical operation that involves multiplying two matrices where one or both matrices have a large number of zero elements. It is commonly used in various scientific and engineering applications.
The vulnerability can lead to heap out-of-bounds access, which may result in crashes or arbitrary code execution. Attackers could potentially exploit this vulnerability to gain unauthorized access or disrupt machine learning workflows.
The vulnerability affects TensorFlow GPU versions 2.4.4, 2.5.2, 2.6.1, and 2.7.0. Users of these versions should update to the fixed versions once they are available.
To protect your machine learning workflows, it is recommended to update your TensorFlow GPU package to the latest fixed version as soon as it becomes available. Regularly checking for updates and applying them promptly is crucial for maintaining the security and stability of your machine learning environment.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow-gpu.