CVE-2021-29554: TensorFlow Denial of Service Vulnerability

tensorflow Updated 02 Oct 2025

Summary

14/05/2021
Yes i
Low
2.5

CVE-2021-29554: TensorFlow is an end-to-end open source platform for machine learning. Affects tensorflow across 5 version ranges.

< 2.1.4 >= 2.2.0, < 2.2.3 >= 2.3.0, < 2.3.3 >= 2.4.0, < 2.4.2 < da5ff2daf618591f64b2b62d9d9803951b945e9f

Fixed in 4 releases; the minimum fixed version depends on the release line you run. How to fix ↓

Also tracked for

The same CVE-2021-29554 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.

Free scan

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.

Check my app free

No signup required · Results in about 60 seconds

Sponsored Devnack Penetration testing for web, API and mobile Manual testing by engineers who build software, not an auditor's checklist. Trusted by teams at Swift and Google Talk to Devnack

Background

TensorFlow is an end-to-end open source platform for machine learning. It provides a comprehensive ecosystem of tools, libraries, and resources for developing and deploying machine learning models. TensorFlow is widely used in various domains, including research, industry, and academia. This vulnerability affects the TensorFlow package, specifically versions 0 and above.

Vulnerability Detail

The vulnerability (CVE-2021-29554) in TensorFlow allows an attacker to cause a denial of service (DoS) by exploiting a runtime error in the tf.raw_ops.DenseCountSparseOutput function. The implementation of this function fails to check if the divisor value computed from user data is zero before performing the division. As a result, when the values argument is provided as input, and num_batch_elements is set to zero, a runtime error occurs, leading to a DoS condition. The impact of this vulnerability can disrupt the availability of TensorFlow applications and services.

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.4 2.1.4
    pip install --upgrade "tensorflow==2.1.4"
  • >= 2.2.0, < 2.2.3 2.2.3
    pip install --upgrade "tensorflow==2.2.3"
  • >= 2.3.0, < 2.3.3 2.3.3
    pip install --upgrade "tensorflow==2.3.3"
  • >= 2.4.0, < 2.4.2 2.4.2
    pip 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 the vulnerability by ensuring that the num_batch_elements parameter is not set to zero when calling the tf.raw_ops.DenseCountSparseOutput function. By providing a non-zero value for num_batch_elements, the division operation will not trigger the runtime error. Here is an example of how to use the function with a non-zero num_batch_elements value:

data = tf.constant([[1, 2], [3, 4]], dtype=tf.float32)
values = tf.constant([1, 2], dtype=tf.float32)
num_batch_elements = tf.constant(1, dtype=tf.int32)
result = tf.raw_ops.DenseCountSparseOutput(data=data, values=values, num_batch_elements=num_batch_elements)

Conclusion

In conclusion, the vulnerability (CVE-2021-29554) in TensorFlow can lead to a denial of service (DoS) condition by exploiting a runtime error in the tf.raw_ops.DenseCountSparseOutput function. It is crucial for users to update their TensorFlow installations to the latest patched versions or apply the provided workarounds to mitigate the risk. For further support and assistance in vulnerability remediation, please contact DevNack.com.

See every vulnerability recorded for tensorflow →

Share this vulnerability

FAQ

This vulnerability allows an attacker to cause a denial of service (DoS) condition in TensorFlow applications and services. By exploiting the vulnerability, an attacker can disrupt the availability of machine learning models and related functionality.

The vulnerability affects TensorFlow versions 0 and above. Specifically, versions 2.4.2, 2.3.3, and earlier are vulnerable. Users are advised to upgrade to the latest patched versions.

Yes, a workaround is available. Users can avoid the vulnerability by ensuring that the num_batch_elements parameter is set to a non-zero value when calling the tf.raw_ops.DenseCountSparseOutput function.

To fix this vulnerability, it is recommended to update TensorFlow to version 2.5.0. The fix has been included in this release. Alternatively, patches have been backported to versions 2.4.2 and 2.3.3. Users should upgrade their TensorFlow installations to the latest patched versions.

For more information about this vulnerability, you can refer to the official TensorFlow advisory (PYSEC-2021-191) available at https://github.com/pypa/advisory-database/blob/main/vulns/tensorflow/PYSEC-2021-191.yaml

Related vulnerabilities

Recent vulnerabilities recorded for tensorflow.

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.4 2.1.4
    pip install --upgrade "tensorflow==2.1.4"
  • >= 2.2.0, < 2.2.3 2.2.3
    pip install --upgrade "tensorflow==2.2.3"
  • >= 2.3.0, < 2.3.3 2.3.3
    pip install --upgrade "tensorflow==2.3.3"
  • >= 2.4.0, < 2.4.2 2.4.2
    pip 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 →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback