CVE-2021-41213
JSON

5.5medium

Deadlock in mutually recursive `tf.function` objects

Severity
5.5medium CVSS:3.1 by GitHub_M
Exploit likelihood
0.24% (higher than 16% of CVEs; EPSS, by FIRST)
Published
Last changed
Assigned by
GitHub_M
Also known as
GHSA-h67m-xg8f-fxcfBIT-TENSORFLOW-2021-41213PYSEC-2021-405PYSEC-2021-622PYSEC-2021-820

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.

Affected

Product or packageVersionsReported by
tensorflow tensorflow>= 2.6.0, < 2.6.1, >= 2.5.0, < 2.5.2, < 2.4.4CVE List
tensorflow (PyPI)from 2.6.0 before 2.6.1, from 2.5.0 before 2.5.2, before 2.4.4, before afac8158d43691661ad083f6dd9e56f327c1dcb7, from 2.7.0rc0 before 2.7.0GitHub Advisory Database, PyPA Advisory Database
tensorflow-cpu (PyPI)from 2.6.0 before 2.6.1, from 2.5.0 before 2.5.2, before 2.4.4, before afac8158d43691661ad083f6dd9e56f327c1dcb7, from 2.7.0rc0 before 2.7.0GitHub Advisory Database, PyPA Advisory Database
tensorflow-gpu (PyPI)from 2.6.0 before 2.6.1, from 2.5.0 before 2.5.2, before 2.4.4, before afac8158d43691661ad083f6dd9e56f327c1dcb7, from 2.7.0rc0 before 2.7.0GitHub Advisory Database, PyPA Advisory Database
google tensorflowfrom 2.4.0 before 2.4.4, from 2.5.0 before 2.5.2, from 2.6.0 before 2.6.1, 2.7.0NVD
tensorflow (Bitnami)from 2.4.0 before 2.4.4, from 2.5.0 before 2.5.2, from 2.6.0 before 2.6.1Bitnami Vulnerability Database

All scores

GitHub_M5.5medium CVSS:3.1CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H
GitHub5.5medium CVSS:3.1CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H
NVD5.5medium CVSS:3.1CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H
NVD4.3medium CVSS:2.0AV:N/AC:M/Au:N/C:N/I:N/A:P
Bitnami Vulnerability Databasemedium rating

Classification

What each source says

CVE List

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.

GitHub Advisory Database
Impact

The code behind tf.function API can be made to deadlock when two tf.function decorated Python functions are mutually recursive:

import tensorflow as tf

@tf.function()               
def fun1(num):
    if num == 1:
        return
    print(num)
    fun2(num-1)

@tf.function()
def fun2(num):
    if num == 0:
        return
    print(num)
    fun1(num-1)

fun1(9)

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.

Patches

We have patched the issue in GitHub commit afac8158d43691661ad083f6dd9e56f327c1dcb7.

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.

For more information

Please consult our security guide for more information regarding the security model and how to contact us with issues and questions.

Attribution

This vulnerability has been reported by members of the Aivul Team from Qihoo 360.

NVD (es)

TensorFlow es una plataforma de código abierto para el aprendizaje automático. En las versiones afectadas, el código detrás de la API "tf.function" puede llegar a bloquearse cuando dos funciones de Python decoradas con "tf.function" son recursivas entre sí. Esto ocurre debido a que es usado un objeto Python "Lock" no recursivo. La carga de cualquier modelo que contenga funciones mutuamente recursivas es vulnerable. Un atacante puede causar una denegación de servicio al causar que usuarios carguen dichos modelos y llamen a una función recursiva "tf.function", aunque esto no es un escenario frecuente. La corrección será incluida en TensorFlow versión 2.7.0. También será incluida este commit en TensorFlow versión 2.6.1, TensorFlow versión 2.5.2, y TensorFlow versión 2.4.4, ya que estos también están afectados y todavía están en el rango admitido

References

Sources

SourceRecordLicence
CVE ListCVE-2021-41213 changed 2024-08-04CVE Terms of Use
GitHub Advisory DatabaseGHSA-h67m-xg8f-fxcf changed 2026-07-08CC-BY-4.0
NVDCVE-2021-41213 changed 2026-06-17Public domain
PyPA Advisory DatabasePYSEC-2021-405 changed 2023-12-06CC-BY-4.0
PyPA Advisory DatabasePYSEC-2021-622 changed 2023-12-06CC-BY-4.0
PyPA Advisory DatabasePYSEC-2021-820 changed 2023-12-06CC-BY-4.0
Bitnami Vulnerability DatabaseBIT-TENSORFLOW-2021-41213 changed 2026-09-08Apache-2.0