VAITP Dataset

← Back to the dataset

CVE-2021-41213

TensorFlow tf.function deadlock vulnerability due to mutual recursion

  • CVSS 5.5
  • CWE-662 Improper Synchronization
  • Race Conditions
  • Remote

TensorFlow is an open source platform for machine learning. In affected versions the code behind `tf.function` API can be made to deadlock when two `tf.function` decorated Python functions are mutually recursive. This occurs due to using a non-reentrant `Lock` Python object. Loading any model which contains mutually recursive functions is vulnerable. An attacker can cause denial of service by causing users to load such models and calling a recursive `tf.function`, although this is not a frequent scenario. The fix will be included in TensorFlow 2.7.0. We will also cherrypick this commit on TensorFlow 2.6.1, TensorFlow 2.5.2, and TensorFlow 2.4.4, as these are also affected and still in supported range.

CVSS base score
5.5
Published
2021-11-05
OWASP
A08 Software and Data Integrity Failures
Orthogonal defect classification
Timing/Serialization
Code defect classification
Serialization Issues
Category
Race Conditions
Subcategory
Race Condition in File Operations
Accessibility scope
Remote
Impact
Denial of Service (DoS)
Affected component
TensorFlow
Fixed by upgrading
Yes

Solution

Update TensorFlow to version 2.7.0 or apply the fix in TensorFlow 2.6.1, TensorFlow 2.5.2, or TensorFlow 2.4.4.

Vulnerable code sample

import tensorflow as tf

@tf.function
def func_a():
    return func_b()

@tf.function
def func_b():
    return func_a()

try:
    func_a()
except RuntimeError as e:
    print("Caught a RuntimeError, indicating a potential deadlock:", e)

func_a()

Patched code sample

import tensorflow as tf

@tf.function
def func_a(n):
    if n <= 0:
        return tf.constant("Base case from A")
    return func_b(n - 1)

@tf.function
def func_b(n):
    if n <= 0:
        return tf.constant("Base case from B")
    return func_a(n - 1)

try:
    result = func_a(5)
    tf.print(result)
except RuntimeError as e:
    print("Caught a RuntimeError, indicating a potential issue:", e)

Cite this entry

@misc{vaitp:cve202141213,
  title        = {{TensorFlow tf.function deadlock vulnerability due to mutual recursion}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2021},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2021-41213},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2021-41213/}}
}
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 ::