CVE-2021-29541: TensorFlow GPU - Null Pointer Dereference in StringNGrams
Summary
CVE-2021-29541: TensorFlow is an end-to-end open source platform for machine learning. Affects tensorflow-gpu 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
< ba424dd8f16f7110eea526a8086f1a155f14f22b
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-cpu · PyPI
The same CVE-2021-29541 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 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 widely used in various industries and research domains for deep learning tasks.
Vulnerability Detail
The vulnerability (CVE-2021-29541) exists in the tf.raw_ops.StringNGrams function of TensorFlow GPU. It arises due to insufficient validation of the data_splits argument in the implementation of the function. As a result, when the output is computed to have a size of 0 or negative, the ngrams_data pointer becomes null. Subsequent writes to the output tensor then trigger a null pointer dereference. This vulnerability can be exploited by an attacker to cause a denial-of-service (DoS) condition or potentially execute arbitrary code.
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.1.42.1.4pip install --upgrade "tensorflow-gpu==2.1.4" -
>= 2.2.0, < 2.2.32.2.3pip install --upgrade "tensorflow-gpu==2.2.3" -
>= 2.3.0, < 2.3.32.3.3pip install --upgrade "tensorflow-gpu==2.3.3" -
>= 2.4.0, < 2.4.22.4.2pip 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 temporary workaround, users can avoid passing inputs to the tf.raw_ops.StringNGrams function that would result in an output of 0 or negative size. By ensuring the input data meets the necessary requirements, the null pointer dereference can be prevented. Here is an example of how to validate the input data before invoking the function:
import tensorflow as tf
def safe_string_ngrams(data_splits):
if len(data_splits) <= 0:
raise ValueError('Invalid input: data_splits must have at least one element')
else:
return tf.raw_ops.StringNGrams(data_splits=data_splits)
Conclusion
In conclusion, the vulnerability (CVE-2021-29541) in TensorFlow GPU's tf.raw_ops.StringNGrams function can lead to a null pointer dereference, potentially resulting in a denial-of-service (DoS) condition or arbitrary code execution. Users should upgrade to the fixed versions or apply the provided workaround to mitigate the risk. For further support on vulnerability remediation, you can contact DevNack.com.
See every vulnerability recorded for tensorflow-gpu →
FAQ
TensorFlow GPU is a variant of TensorFlow that utilizes GPU acceleration for faster computation. It is commonly used in deep learning tasks to leverage the parallel processing power of GPUs.
This vulnerability can lead to a null pointer dereference in TensorFlow GPU's tf.raw_ops.StringNGrams function. It can result in a denial-of-service (DoS) condition or potentially allow an attacker to execute arbitrary code.
To fix this vulnerability, you should upgrade your TensorFlow GPU installation to version 2.5.0 or later. If you are using an older version within the supported range, you can also update to the respective fixed versions (2.4.2, 2.3.3, 2.2.3, or 2.1.4).
Yes, as a temporary workaround, you can ensure that the input data passed to the tf.raw_ops.StringNGrams function does not result in an output of 0 or negative size. By validating the input data, you can prevent the null pointer dereference.
For more information about TensorFlow vulnerabilities, you can visit the official TensorFlow website or refer to vulnerability databases like Vulert (https://vulert.com) that provide real-time monitoring and alerts for open-source vulnerabilities in software.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow-gpu.