{"id":706,"cve":"CVE-2021-41213","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2021-41213","cwe":"CWE-662 Improper Synchronization","cwe_number":662,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/662","cvss_score":5.5,"published":"2021-11-05","owasp":"A08 Software and Data Integrity Failures","odc":"Timing\/Serialization","cdc":"Serialization Issues","category":"Race Conditions","subcategory":"Race Condition in File Operations","scope":"Remote","impact":"Denial of Service (DoS)","summary":"TensorFlow tf.function deadlock vulnerability due to mutual recursion","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2021-41213\/","description":"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.","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.","affected_component":"TensorFlow","fixed_by_upgrading":true,"vulnerable_code":"import tensorflow as tf\n\n@tf.function\ndef func_a():\n    return func_b()\n\n@tf.function\ndef func_b():\n    return func_a()\n\ntry:\n    func_a()\nexcept RuntimeError as e:\n    print(\"Caught a RuntimeError, indicating a potential deadlock:\", e)\n\nfunc_a()","patched_code":"import tensorflow as tf\n\n@tf.function\ndef func_a(n):\n    if n <= 0:\n        return tf.constant(\"Base case from A\")\n    return func_b(n - 1)\n\n@tf.function\ndef func_b(n):\n    if n <= 0:\n        return tf.constant(\"Base case from B\")\n    return func_a(n - 1)\n\ntry:\n    result = func_a(5)\n    tf.print(result)\nexcept RuntimeError as e:\n    print(\"Caught a RuntimeError, indicating a potential issue:\", e)\n","payload_needed":false,"payload":null,"payload_status":"none","published_fix":[{"repository":"tensorflow\/tensorflow","commit_url":"https:\/\/github.com\/tensorflow\/tensorflow\/commit\/afac8158d43691661ad083f6dd9e56f327c1dcb7","commit_subject":"Fix the deadlock issue of recursive tf.function.","units":[{"file":"tensorflow\/python\/eager\/def_function.py","function":"Function.__init__"},{"file":"tensorflow\/python\/eager\/def_function.py","function":"Function.__setstate__"},{"file":"tensorflow\/python\/eager\/function.py","function":"Function.__init__"}]}],"references":null}