CVE-2021-29567: Lack of validation in SparseDenseCwiseMul in TensorFlow
Summary
CVE-2021-29567: Lack of validation in SparseDenseCwiseMul. 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-29567 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 that provides a comprehensive ecosystem of tools, libraries, and community resources. It is widely used for developing and deploying machine learning models. The SparseDenseCwiseMul function in TensorFlow is responsible for performing element-wise multiplication between a sparse tensor and a dense tensor. This vulnerability affects versions of TensorFlow prior to 2.1.4, 2.2.3, 2.3.3, and 2.4.2.
Vulnerability Detail
The vulnerability arises from a lack of validation in the SparseDenseCwiseMul function. Attackers can exploit this vulnerability to trigger denial of service by causing CHECK-fails or accessing memory outside the bounds of heap allocated data. The implementation of the function only validates the rank of the input arguments, but does not enforce constraints between dimensions. This allows attackers to abuse the function and potentially cause program termination or write to memory outside the allocated tensor buffers.
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 validate the input arguments manually before calling the SparseDenseCwiseMul function. This can be done by checking the dimensions of the input tensors and ensuring they meet the required constraints. Here is an example of how to perform the validation:
import tensorflow as tf
indices = tf.constant([], shape=[10, 0], dtype=tf.int64)
values = tf.constant([], shape=[0], dtype=tf.int64)
shape = tf.constant([0, 0], shape=[2], dtype=tf.int64)
dense = tf.constant([], shape=[0], dtype=tf.int64)
if indices.shape[1] != values.shape[0] or indices.shape[0] != shape[0] or shape[1] != dense.shape[0]:
raise ValueError('Invalid dimensions for input tensors')
# Call the patched version of SparseDenseCwiseMul
# ...
Note: This workaround is not a substitute for applying the official patch.
Conclusion
The lack of validation in the SparseDenseCwiseMul function in TensorFlow can be exploited by attackers to trigger denial of service or access memory outside the allocated tensor buffers. It is crucial to update to the patched version of TensorFlow or apply the fix on the affected versions to mitigate this vulnerability. For further support on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for tensorflow →
FAQ
The vulnerability can lead to denial of service by triggering program termination or accessing memory outside the allocated tensor buffers.
To fix the vulnerability, update TensorFlow to the patched version once it is available or apply the fix by cherrypicking the relevant commit on the affected versions.
No, only versions prior to 2.1.4, 2.2.3, 2.3.3, and 2.4.2 are affected.
Yes, users can manually validate the input arguments before calling the SparseDenseCwiseMul function to mitigate the vulnerability.
This vulnerability was reported by Yakun Zhang and Ying Wang of Baidu X-Team.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.