CVE-2021-29521: TensorFlow GPU - Segmentation Fault in SparseCountSparseOutput

tensorflow-gpu Updated 02 Oct 2025

Summary

14/05/2021
Yes i
Unrated
Not published

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

>= 2.3.0, < 2.3.3 >= 2.4.0, < 2.4.2 < c57c0b9f3a4f8684f3489dd9a9ec627ad8b599f5

Fixed in 2.3.3 or 2.4.2, depending on the release line you run. How to fix ↓

Also tracked for

The same CVE-2021-29521 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 Your last release was probably never penetration tested 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 GPU is a variant of TensorFlow that leverages GPU acceleration for faster computation. It is commonly used in scenarios where large-scale machine learning tasks require high-performance computing capabilities.

Vulnerability Detail

The vulnerability (CVE-2021-29521) in TensorFlow GPU arises when specifying a negative dense shape in the tf.raw_ops.SparseCountSparseOutput function. This leads to a segmentation fault being thrown from the standard library due to broken invariants in the implementation. The issue stems from the assumption made in the implementation that the first element of the dense shape is always positive, which is used to initialize a BatchedMap<T> data structure. If the shape tensor has more than one element, num_batches is the first value in shape. By ensuring that the dense_shape argument is a valid tensor shape with all non-negative elements, this vulnerability can be mitigated. The fix for this issue will be included in TensorFlow 2.5.0, and it has also been backported to TensorFlow 2.4.2 and TensorFlow 2.3.3.

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.3.0, < 2.3.3 2.3.3
    pip install --upgrade "tensorflow-gpu==2.3.3"
  • >= 2.4.0, < 2.4.2 2.4.2
    pip install --upgrade "tensorflow-gpu==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 dense_shape argument before passing it to the tf.raw_ops.SparseCountSparseOutput function. This can be done by checking if all elements of the dense_shape tensor are non-negative. If any negative element is found, it should be replaced with a valid non-negative value. Here is an example code snippet in Python:

import tensorflow as tf

def validate_dense_shape(dense_shape):
    return tf.where(dense_shape < 0, 0, dense_shape)

# Usage
input_dense_shape = tf.constant([-1, 10, 20])
valid_dense_shape = validate_dense_shape(input_dense_shape)
output = tf.raw_ops.SparseCountSparseOutput(dense_shape=valid_dense_shape, ...)

Conclusion

In conclusion, the vulnerability (CVE-2021-29521) in TensorFlow GPU can result in a segmentation fault when specifying a negative dense shape. It is crucial to update TensorFlow GPU to the recommended versions or apply the provided patches to mitigate this vulnerability. Additionally, validating the dense_shape argument can serve as a temporary workaround. For further assistance or support in vulnerability remediation, please reach out to DevNack.com.

See every vulnerability recorded for tensorflow-gpu →

Share this vulnerability

FAQ

TensorFlow GPU is a variant of TensorFlow that utilizes GPU acceleration for faster computation in machine learning tasks.

The vulnerability can lead to a segmentation fault in TensorFlow GPU when specifying a negative dense shape, potentially causing crashes or instability in machine learning applications.

To fix this vulnerability, update TensorFlow GPU to version 2.5.0 or apply the respective patches for TensorFlow 2.4.2 and TensorFlow 2.3.3 as recommended by the TensorFlow project.

Yes, a workaround is to validate the dense_shape argument before passing it to the vulnerable function, ensuring that all elements are non-negative.

You can find more information about this vulnerability in the official TensorFlow documentation, security advisories, or the vulnerability database maintained by the Python Packaging Authority (PyPA).

Related vulnerabilities

Recent vulnerabilities recorded for tensorflow-gpu.

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.3.0, < 2.3.3 2.3.3
    pip install --upgrade "tensorflow-gpu==2.3.3"
  • >= 2.4.0, < 2.4.2 2.4.2
    pip install --upgrade "tensorflow-gpu==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