VAITP Dataset

← Back to the dataset

CVE-2021-29567

TensorFlow SparseDenseCwiseMul validation vulnerability

  • CVSS 5.5
  • CWE-617 Reachable Assertion
  • Memory Corruption
  • Remote

TensorFlow is an end-to-end open source platform for machine learning. Due to lack of validation in `tf.raw_ops.SparseDenseCwiseMul`, an attacker can trigger denial of service via `CHECK`-fails or accesses to outside the bounds of heap allocated data. Since the implementation(https://github.com/tensorflow/tensorflow/blob/38178a2f7a681a7835bb0912702a134bfe3b4d84/tensorflow/core/kernels/sparse_dense_binary_op_shared.cc#L68-L80) only validates the rank of the input arguments but no constraints between dimensions(https://www.tensorflow.org/api_docs/python/tf/raw_ops/SparseDenseCwiseMul), an attacker can abuse them to trigger internal `CHECK` assertions (and cause program termination, denial of service) or to write to memory outside of bounds of heap allocated tensor buffers. The fix will be included in TensorFlow 2.5.0. We will also cherrypick this commit on TensorFlow 2.4.2, TensorFlow 2.3.3, TensorFlow 2.2.3 and TensorFlow 2.1.4, as these are also affected and still in supported range.

CVSS base score
5.5
Published
2021-05-14
OWASP
A08 Software and Data Integrity Failures
Orthogonal defect classification
Checking
Code defect classification
Incorrect Check
Category
Memory Corruption
Subcategory
Out-of-Bound Accesses
Accessibility scope
Remote
Impact
Denial of Service (DoS)
Affected component
TensorFlow
Fixed by upgrading
Yes

Solution

Update TensorFlow to version 2.5.0 or higher.

Vulnerable code sample

import tensorflow as tf

sparse_tensor = tf.sparse.SparseTensor(indices=[[0, 0], [1, 1]], values=[1.0, 2.0], dense_shape=[2, 2])
dense_tensor = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])

result = tf.raw_ops.SparseDenseCwiseMul(sparse_indices=sparse_tensor.indices,
                                         sparse_values=sparse_tensor.values,
                                         sparse_shape=sparse_tensor.dense_shape,
                                         dense=dense_tensor)

print(result)

Patched code sample

import tensorflow as tf

sparse_tensor = tf.sparse.SparseTensor(indices=[[0, 0], [1, 1]],
                                       values=[1.0, 2.0],
                                       dense_shape=[2, 2])

dense_tensor = tf.constant([[1.0, 2.0],
                            [4.0, 5.0]])

result = tf.raw_ops.SparseDenseCwiseMul(
    sparse_indices=sparse_tensor.indices,
    sparse_values=sparse_tensor.values,
    sparse_shape=sparse_tensor.dense_shape,
    dense=dense_tensor
)

print(result)

Cite this entry

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