CVE-2021-41219: TensorFlow CPU - Sparse Matrix Multiplication Code Vulnerability
Summary
CVE-2021-41219: TensorFlow is an open source platform for machine learning. Affects tensorflow-cpu 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-gpu · 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 CPU is a specific package within TensorFlow that focuses on running TensorFlow on CPUs. It is widely used in various industries and research domains for machine learning tasks.
Vulnerability Detail
The vulnerability (CVE-2021-41219) in TensorFlow CPU's sparse matrix multiplication code allows for undefined behavior when binding a reference to nullptr. This vulnerability arises when the dimensions of the input matrices are 0 or less. 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, leading to attempts to write to the empty tensor and resulting in a heap out-of-bounds access. This vulnerability can potentially be exploited by an attacker to execute arbitrary code or cause a denial-of-service condition.
How To Fix
Latest published version: 2.21.0 as of 22 Oct 2026
pip install --upgrade "tensorflow-cpu==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.4.42.4.4pip install --upgrade "tensorflow-cpu==2.4.4" -
>= 2.5.0, < 2.5.22.5.2pip install --upgrade "tensorflow-cpu==2.5.2" -
>= 2.6.0, < 2.6.12.6.1pip install --upgrade "tensorflow-cpu==2.6.1" -
>= 2.7.0rc0, < 2.7.02.7.0pip install --upgrade "tensorflow-cpu==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 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 multiplication operation should be skipped, and appropriate error handling should be implemented. Here is an example of how to perform this check in Python:
import tensorflow as tf
def safe_sparse_matrix_multiply(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 matrix dimensions')
else:
return tf.sparse.matmul(a, b)
Conclusion
The vulnerability in TensorFlow CPU's sparse matrix multiplication code can lead to undefined behavior and heap out-of-bounds access. It is crucial for users to update their TensorFlow CPU package to the fixed versions (2.7.0, 2.6.1, 2.5.2, or 2.4.4) once they are released. Regularly updating the TensorFlow package is recommended to stay protected against potential security vulnerabilities. For further support on vulnerability remediation, you can reach out to DevNack.com.
See every vulnerability recorded for tensorflow-cpu →
FAQ
TensorFlow is an open source platform for machine learning that provides a comprehensive ecosystem of tools, libraries, and resources for developing and deploying machine learning models.
TensorFlow CPU is a specific package within TensorFlow that focuses on running TensorFlow on CPUs. It is widely used in various industries and research domains for machine learning tasks.
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 applications, including machine learning and scientific computing.
This vulnerability can potentially be exploited by an attacker to execute arbitrary code or cause a denial-of-service condition. It is important to update the TensorFlow CPU package to the fixed versions to mitigate these risks.
To protect your application from this vulnerability, it is recommended to update the TensorFlow CPU package to the fixed versions once they are released. Regularly updating the TensorFlow package is also advised to ensure the latest security patches are applied.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow-cpu.