CVE-2022-41908
Non-UTF-8 bytestrings in TensorFlow's tf.raw_ops.PyFunc
- CVSS 7.5
- CWE-20 Improper Input Validation
- Input Validation and Sanitization
- Local
TensorFlow is an open source platform for machine learning. An input `token` that is not a UTF-8 bytestring will trigger a `CHECK` fail in `tf.raw_ops.PyFunc`. We have patched the issue in GitHub commit 9f03a9d3bafe902c1e6beb105b2f24172f238645. The fix will be included in TensorFlow 2.11. We will also cherrypick this commit on TensorFlow 2.10.1, 2.9.3, and TensorFlow 2.8.4, as these are also affected and still in supported range.
- CVSS base score
- 7.5
- Published
- 2022-11-18
- OWASP
- A06 Vulnerable and Outdated Components
- Orthogonal defect classification
- Checking
- Code defect classification
- Incorrect Check
- 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 TensorFlow to version 2.11 or higher.
Vulnerable code sample
import tensorflow as tf
# This function demonstrates the vulnerability by directly passing an invalid token
def vulnerable_py_func(token):
# No check for UTF-8 bytestring, leading to potential CHECK fail
return tf.raw_ops.PyFunc(func='your_function', inp=[token], Tout=tf.float32)
# Example usage with an invalid token
invalid_token = b'\x80\x81' # Invalid UTF-8 bytes
result = vulnerable_py_func(invalid_token)Patched code sample
import tensorflow as tf
def safe_py_func(token):
# Ensure the input token is a valid UTF-8 bytestring
if not isinstance(token, bytes) or not token.decode('utf-8', errors='ignore'):
raise ValueError("Input token must be a valid UTF-8 bytestring.")
# Proceed with the PyFunc operation
return tf.raw_ops.PyFunc(func='your_function', inp=[token], Tout=tf.float32)
# Example usage
try:
result = safe_py_func(b'valid_utf8_token')
print(result)
except ValueError as e:
print(e)Cite this entry
@misc{vaitp:cve202241908,
title = {{Non-UTF-8 bytestrings in TensorFlow's tf.raw_ops.PyFunc}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2022},
note = {VAITP Python Vulnerability Dataset, entry CVE-2022-41908},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2022-41908/}}
}
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 ::
