VAITP Dataset

← Back to the dataset

CVE-2020-26268

TensorFlow ImmutableConst type check vulnerability

  • CVSS 4.4
  • CWE-471 Modification of Assumed-Immutable Data (MAID)
  • Memory Corruption
  • Local

In affected versions of TensorFlow the tf.raw_ops.ImmutableConst operation returns a constant tensor created from a memory mapped file which is assumed immutable. However, if the type of the tensor is not an integral type, the operation crashes the Python interpreter as it tries to write to the memory area. If the file is too small, TensorFlow properly returns an error as the memory area has fewer bytes than what is needed for the tensor it creates. However, as soon as there are enough bytes, the above snippet causes a segmentation fault. This is because the allocator used to return the buffer data is not marked as returning an opaque handle since the needed virtual method is not overridden. This is fixed in versions 1.15.5, 2.0.4, 2.1.3, 2.2.2, 2.3.2, and 2.4.0.

CVSS base score
4.4
Published
2020-12-10
OWASP
A08 Software and Data Integrity Failures
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Memory Corruption
Subcategory
Buffer Overflows
Accessibility scope
Local
Impact
Denial of Service (DoS)
Affected component
TensorFlow
Fixed by upgrading
Yes

Solution

Update TensorFlow to version 1.15.5, 2.0.4, 2.1.3, 2.2.2, 2.3.2, or 2.4.0.

Vulnerable code sample

import tensorflow as tf
import numpy as np
import tempfile

temp_file = tempfile.NamedTemporaryFile(delete=False)
data = np.random.rand(10).astype(np.float32)
data.tofile(temp_file.name)

tensor = tf.raw_ops.ImmutableConst(file=temp_file.name, dtype=tf.float32)
print(tensor)

temp_file.close()

Patched code sample

import tensorflow as tf
import numpy as np
import tempfile
import os
import shutil

def create_temp_file(data):
    temp_dir = tempfile.mkdtemp()
    temp_file_path = os.path.join(temp_dir, "temp_data.bin")
    data.tofile(temp_file_path)
    return temp_file_path, temp_dir

try:
    data = np.random.rand(10).astype(np.float32)
    temp_file_path, temp_dir = create_temp_file(data)
    
    tensor = tf.raw_ops.ImmutableConst(file=temp_file_path, dtype=tf.float32)
    print(tensor)
    
finally:
    if os.path.exists(temp_file_path):
        os.remove(temp_file_path)
    if os.path.isdir(temp_dir):
        shutil.rmtree(temp_dir)

Cite this entry

@misc{vaitp:cve202026268,
  title        = {{TensorFlow ImmutableConst type check vulnerability}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2020},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2020-26268},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2020-26268/}}
}
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 ::