CVE-2021-29539: TensorFlow - Segfault in tf.raw_ops.ImmutableConst
Summary
CVE-2021-29539: Segfault in tf.raw_ops.ImmutableConst. 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 · PyPI
- tensorflow · PyPI
- tensorflow-cpu · PyPI
- tensorflow-gpu · PyPI
The same CVE-2021-29539 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 set of tools, libraries, and resources for developing and deploying machine learning models. TensorFlow allows users to build and train neural networks, perform data preprocessing and augmentation, and deploy models in various environments. It is widely used in both research and production settings.
Vulnerability Detail
The vulnerability (CVE-2021-29539) in TensorFlow arises when calling the tf.raw_ops.ImmutableConst function with a dtype of tf.resource or tf.variant. This triggers a segmentation fault (segfault) in the implementation because the code assumes that the tensor contents are pure scalars. The issue has been patched in the commit 4f663d4b8f0bec1b48da6fa091a7d29609980fa4 and will be included in TensorFlow 2.5.0. Nightly packages after this commit will also have the issue resolved. The vulnerability can lead to crashes or instability in TensorFlow applications that use tf.raw_ops.ImmutableConst with the mentioned dtype values.
How To Fix
Fixed versions by release line
The minimum fixed version depends on the release line you run.
-
< 2.1.42.1.4 -
>= 2.2.0, < 2.2.32.2.3 -
>= 2.3.0, < 2.3.32.3.3 -
>= 2.4.0, < 2.4.22.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
If you are unable to update TensorFlow immediately, you can apply a workaround by filtering the dtype argument when using tf.raw_ops.ImmutableConst. This can be done by checking the dtype value before calling the function and only allowing valid scalar types. Here is an example workaround in Python:
def safe_immutable_const(value, dtype):
valid_dtypes = [tf.float32, tf.float64, tf.int32, tf.int64, tf.bool, tf.string]
if dtype in valid_dtypes:
return tf.raw_ops.ImmutableConst(value=value, dtype=dtype)
else:
raise ValueError('Invalid dtype')
Conclusion
In conclusion, the vulnerability (CVE-2021-29539) in TensorFlow can result in a segfault when using tf.raw_ops.ImmutableConst with a dtype of tf.resource or tf.variant. It is recommended to update TensorFlow to version 2.5.0 or later, or use TensorFlow nightly packages after the commit 4f663d4b8f0bec1b48da6fa091a7d29609980fa4 to mitigate the issue. If you are unable to update immediately, you can apply a workaround by filtering the dtype argument. For further support on vulnerability remediation, you can reach out to DevNack.com.
See every vulnerability recorded for tensorflow →
FAQ
TensorFlow is an open source platform for machine learning that provides tools and libraries for building and deploying machine learning models.
The vulnerability can lead to crashes or instability in TensorFlow applications that use tf.raw_ops.ImmutableConst with a dtype of tf.resource or tf.variant.
To fix the vulnerability, update TensorFlow to version 2.5.0 or later once it is released. Alternatively, use TensorFlow nightly packages after the commit 4f663d4b8f0bec1b48da6fa091a7d29609980fa4.
Yes, you can apply a workaround by filtering the dtype argument when using tf.raw_ops.ImmutableConst. Check the dtype value and only allow valid scalar types.
You can find more information about this vulnerability in the official TensorFlow documentation and the CVE entry (CVE-2021-29539).
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.