CVE-2021-29513
Type confusion in TensorFlow, leads to null pointer dereference, fixed in TensorFlow 2.5.0 with backports
- CVSS 7.8
- CWE-476 NULL Pointer Dereference
- Input Validation and Sanitization
- Local
TensorFlow is an end-to-end open source platform for machine learning. Calling TF operations with tensors of non-numeric types when the operations expect numeric tensors result in null pointer dereferences. The conversion from Python array to C++ array(https://github.com/tensorflow/tensorflow/blob/ff70c47a396ef1e3cb73c90513da4f5cb71bebba/tensorflow/python/lib/core/ndarray_tensor.cc#L113-L169) is vulnerable to a type confusion. 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
- 7.8
- Published
- 2021-05-14
- OWASP
- A08 Software and Data Integrity Failures
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Input Validation and Sanitization
- Subcategory
- Insecure Parsing or Deserialization
- Accessibility scope
- Local
- Impact
- Arbitrary Code Execution
- Affected component
- TensorFlow
- Fixed by upgrading
- Yes
Solution
Update TensorFlow to version 2.5.0 or higher.
Vulnerable code sample
import tensorflow as tf
# Creating a tensor with a non-numeric type
non_numeric_tensor = tf.constant(['a', 'b', 'c'])
# Attempting to perform a numeric operation on a non-numeric tensor
# This will lead to a null pointer dereference vulnerability
result = tf.add(non_numeric_tensor, 1) # This operation is expected to fail
print(result)Patched code sample
import tensorflow as tf
# Example of creating a tensor with a non-numeric type
# This can lead to the vulnerability CVE-2021-29513
non_numeric_tensor = tf.constant(['a', 'b', 'c'])
# Attempting to perform a numeric operation on a non-numeric tensor
try:
result = tf.add(non_numeric_tensor, 1) # This should raise an error
except Exception as e:
print(f"Error encountered: {e}")
# To fix the vulnerability, ensure that the tensor is of a numeric type before performing operations
numeric_tensor = tf.constant([1.0, 2.0, 3.0]) # Use numeric values
result_fixed = tf.add(numeric_tensor, 1) # This will work correctly
print(f"Fixed result: {result_fixed.numpy()}")Cite this entry
@misc{vaitp:cve202129513,
title = {{Type confusion in TensorFlow, leads to null pointer dereference, fixed in TensorFlow 2.5.0 with backports}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2021},
note = {VAITP Python Vulnerability Dataset, entry CVE-2021-29513},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2021-29513/}}
}
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 ::
