CVE-2021-29557: Denial of Service Vulnerability in TensorFlow

tensorflow Updated 02 Oct 2025

Summary

06/03/2024
Yes i
Medium
Not published

CVE-2021-29557: Division by 0 in SparseMatMul. 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

The same CVE-2021-29557 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 community resources that enable researchers and developers to build and deploy machine learning models. TensorFlow is widely used in various industries and applications, including image and speech recognition, natural language processing, and recommendation systems. However, a vulnerability has been identified in TensorFlow that can lead to a denial of service (DoS) attack.

Vulnerability Detail

The vulnerability, identified as CVE-2021-29557, exists in the tf.raw_ops.SparseMatMul function of TensorFlow. An attacker can exploit this vulnerability by causing a runtime error in the function, resulting in a division by zero error deep in the Eigen code. This error occurs when the b tensor is empty. The impact of this vulnerability is a DoS condition, where the affected TensorFlow application becomes unresponsive or crashes. The vulnerability has been assigned a CVSSv3 severity score of 6.5 (Medium).

How To Fix

Fixed versions by release line

The minimum fixed version depends on the release line you run.

  • < 2.1.4 2.1.4
  • >= 2.2.0, < 2.2.3 2.2.3
  • >= 2.3.0, < 2.3.3 2.3.3
  • >= 2.4.0, < 2.4.2 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 temporary workaround, you can avoid the vulnerability by ensuring that the b tensor used in the tf.raw_ops.SparseMatMul function is not empty. You can do this by validating the input data and ensuring that the b tensor is populated with valid values before invoking the function. Here is an example code snippet that demonstrates this workaround:

import tensorflow as tf

# Validate and populate the 'b' tensor
b = validate_and_populate_b()

# Invoke the 'tf.raw_ops.SparseMatMul' function
result = tf.raw_ops.SparseMatMul(a, b)

Conclusion

In conclusion, TensorFlow is vulnerable to a denial of service (DoS) attack due to a runtime error in the tf.raw_ops.SparseMatMul function. The vulnerability can be mitigated by upgrading to the fixed versions of TensorFlow or implementing the provided workaround. It is recommended to stay updated with the latest security patches and follow best practices for securing TensorFlow applications. For further support on vulnerability remediation, please contact DevNack.com.

See every vulnerability recorded for tensorflow →

Share this vulnerability

FAQ

TensorFlow is an open source platform for machine learning that provides a comprehensive ecosystem of tools and libraries.

The vulnerability can lead to a denial of service (DoS) condition in TensorFlow applications, causing them to become unresponsive or crash.

TensorFlow versions 2.1.4, 2.2.3, 2.3.3, and 2.4.2 are affected by this vulnerability.

Upgrade to the fixed versions of TensorFlow (2.5.0 or later) as soon as they are available. Follow the official TensorFlow documentation for upgrading.

Yes, you can avoid the vulnerability by ensuring that the b tensor used in the tf.raw_ops.SparseMatMul function is not empty. Validate and populate the b tensor with valid values before invoking the function.

Related vulnerabilities

Recent vulnerabilities recorded for tensorflow.

How To Fix

Fixed versions by release line

The minimum fixed version depends on the release line you run.

  • < 2.1.4 2.1.4
  • >= 2.2.0, < 2.2.3 2.2.3
  • >= 2.3.0, < 2.3.3 2.3.3
  • >= 2.4.0, < 2.4.2 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