VAITP Dataset

← Back to the dataset

CVE-2021-29539

Segfault in TensorFlow tf.raw_ops.ImmutableConst for tf.resource and tf.variant dtype

  • CVSS 5.5
  • CWE-681 Incorrect Conversion between Numeric Types
  • Input Validation and Sanitization
  • Local

TensorFlow is an end-to-end open source platform for machine learning. Calling `tf.raw_ops.ImmutableConst`(https://www.tensorflow.org/api_docs/python/tf/raw_ops/ImmutableConst) with a `dtype` of `tf.resource` or `tf.variant` results in a segfault in the implementation as code assumes that the tensor contents are pure scalars. We have patched the issue in 4f663d4b8f0bec1b48da6fa091a7d29609980fa4 and will release TensorFlow 2.5.0 containing the patch. TensorFlow nightly packages after this commit will also have the issue resolved. If using `tf.raw_ops.ImmutableConst` in code, you can prevent the segfault by inserting a filter for the `dtype` argument.

CVSS base score
5.5
Published
2021-05-14
OWASP
A06 Vulnerable and Outdated Components
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Input Validation and Sanitization
Subcategory
Insecure Parsing or Deserialization
Accessibility scope
Local
Impact
Denial of Service (DoS)
Affected component
TensorFlow
Fixed by upgrading
Yes

Solution

Update to TensorFlow version 2.5.0 or higher.

Vulnerable code sample

import tensorflow as tf

# This code demonstrates the vulnerability by calling ImmutableConst with an invalid dtype
tensor = tf.raw_ops.ImmutableConst(value=[1, 2, 3], dtype=tf.resource)  # This will cause a segfault

Patched code sample

import tensorflow as tf

def safe_immutable_const(value, dtype):
    # Check if dtype is tf.resource or tf.variant
    if dtype in [tf.resource, tf.variant]:
        raise ValueError("Invalid dtype: tf.resource or tf.variant is not allowed.")
    return tf.raw_ops.ImmutableConst(value=value, dtype=dtype)

# Example usage
try:
    # This will raise an error
    tensor = safe_immutable_const(value=[1, 2, 3], dtype=tf.resource)
except ValueError as e:
    print(e)

Cite this entry

@misc{vaitp:cve202129539,
  title        = {{Segfault in TensorFlow tf.raw_ops.ImmutableConst for tf.resource and tf.variant dtype}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2021},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2021-29539},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2021-29539/}}
}

Download this entry as JSON Download the whole dataset

Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::

Before you use the VAITP AI models

Please read and accept the following disclaimer:

By choosing "I understand and accept", you acknowledge that you understand and agree to these terms.