{"id":"CVE-2021-41220","aliases":["CVE-2021-41220","GHSA-gpfh-jvf9-7wg5","BIT-TENSORFLOW-2021-41220","PYSEC-2021-412","PYSEC-2021-629","PYSEC-2021-827"],"related":[],"kind":"vulnerability","state":"published","title":"Use after free in `CollectiveReduceV2`","summary":"TensorFlow is an open source platform for machine learning. In affected versions the async implementation of `CollectiveReduceV2` suffers from a memory leak and a use after free. This occurs due to the asynchronous computation and the fact that objects that have been `std::move()`d from are still accessed. The fix will be included in TensorFlow 2.7.0. We will also cherrypick this commit on TensorFlow 2.6.1, as this version is the only one that is also affected.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"TensorFlow is an open source platform for machine learning. In affected versions the async implementation of `CollectiveReduceV2` suffers from a memory leak and a use after free. This occurs due to the asynchronous computation and the fact that objects that have been `std::move()`d from are still accessed. The fix will be included in TensorFlow 2.7.0. We will also cherrypick this commit on TensorFlow 2.6.1, as this version is the only one that is also affected.","source":"cvelist"},{"lang":"en","text":"### Impact\nThe [async implementation](https://github.com/tensorflow/tensorflow/blob/8d72537c6abf5a44103b57b9c2e22c14f5f49698/tensorflow/core/kernels/collective_ops.cc#L604-L615) of `CollectiveReduceV2` suffers from a memory leak and a use after free:\n\n```python\nimport tensorflow as tf\n  \ntf.raw_ops.CollectiveReduceV2(\n  input=[],\n  group_size=[-10, -10, -10],\n  group_key=[-10, -10],\n  instance_key=[-10],\n  ordering_token=[],\n  merge_op='Mul',\n  final_op='Div')\n``` \n\nThis occurs due to the asynchronous computation and the fact that objects that have been `std::move()`d from are still accessed:\n\n```cc\nauto done_with_cleanup = [col_params, done = std::move(done)]() {\n  done();\n  col_params->Unref();\n};\nOP_REQUIRES_OK_ASYNC(c,\n                     FillCollectiveParams(col_params, REDUCTION_COLLECTIVE,\n                                          /*group_size*/ c->input(1),\n                                          /*group_key*/ c->input(2),\n                                          /*instance_key*/ c->input(3)),\n                     done);\n```\n\nHere, `done` is already moved from by the time `OP_REQUIRES_OK_ASYNC` macro needs to invoke it in case of errors. In this case, we get an undefined behavior, which can manifest via crashes, `std::bad_alloc` throws or just memory leaks.\n\n### Patches\nWe have patched the issue in GitHub commit [ca38dab9d3ee66c5de06f11af9a4b1200da5ef75](https://github.com/tensorflow/tensorflow/commit/ca38dab9d3ee66c5de06f11af9a4b1200da5ef75).\n\nThe fix will be included in TensorFlow 2.7.0. We will also cherrypick this commit on TensorFlow 2.6.1, as this version is the only one that is also affected.\n\n### For more information\nPlease consult [our security guide](https://github.com/tensorflow/tensorflow/blob/master/SECURITY.md) for more information regarding the security model and how to contact us with issues and questions.\n\n### Attribution\nThis vulnerability has been reported by members of the Aivul Team from Qihoo 360.","format":"markdown","source":"ghsa"},{"lang":"es","text":"TensorFlow es una plataforma de código abierto para el aprendizaje automático. En las versiones afectadas, la implementación asíncrona de \"CollectiveReduceV2\" sufre una perdida de memoria y un uso de memoria previamente liberada. Esto ocurre debido al cálculo asíncrono y al hecho de que se sigue accediendo a los objetos que han sido \"std::move()\"d. La corrección será incluida en TensorFlow versión 2.7.0. También seleccionaremos este commit en TensorFlow versión 2.6.1, ya que esta versión es la única que también está afectada","source":"nvd"}],"published":"2021-11-05T22:20:12.000Z","modified":"2026-09-08T08:48:25.143Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H","score":7.8,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H","score":7.8,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H","score":7.8,"rating":"HIGH"},{"scorer":"NVD","scheme":"CVSS:2.0","vector":"AV:L/AC:L/Au:N/C:P/I:P/A:P","score":4.6,"rating":"MEDIUM"},{"scorer":"Bitnami Vulnerability Database","scheme":"rating","rating":"HIGH"}],"cwes":["CWE-416"],"affected":[{"ranges":[{"version":">= 2.6.0, < 2.6.1","status":"affected"}],"vendor":"tensorflow","product":"tensorflow","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"2.6.0","status":"affected","fixed":"2.6.1"}],"ecosystem":"PyPI","package":"tensorflow","purl":"pkg:pypi/tensorflow","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"2.6.0","status":"affected","fixed":"2.6.1"}],"ecosystem":"PyPI","package":"tensorflow-cpu","purl":"pkg:pypi/tensorflow-cpu","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"2.6.0","status":"affected","fixed":"2.6.1"}],"ecosystem":"PyPI","package":"tensorflow-gpu","purl":"pkg:pypi/tensorflow-gpu","source":"ghsa"},{"ranges":[{"status":"affected","introduced":"2.6.0","fixed":"2.6.1"},{"status":"affected","version":"2.7.0"},{"status":"affected","version":"2.7.0"}],"vendor":"google","product":"tensorflow","cpe":"cpe:2.3:a:google:tensorflow:*:*:*:*:*:*:*:*","source":"nvd"},{"ranges":[{"type":"git","introduced":"0","status":"affected","fixed":"ca38dab9d3ee66c5de06f11af9a4b1200da5ef75"},{"type":"ecosystem","introduced":"2.6.0","status":"affected","fixed":"2.6.1"},{"type":"ecosystem","introduced":"2.7.0rc0","status":"affected","fixed":"2.7.0"}],"ecosystem":"PyPI","package":"tensorflow","purl":"pkg:pypi/tensorflow","repo":"https://github.com/tensorflow/tensorflow","source":"pysec"},{"ranges":[{"type":"git","introduced":"0","status":"affected","fixed":"ca38dab9d3ee66c5de06f11af9a4b1200da5ef75"},{"type":"ecosystem","introduced":"2.6.0","status":"affected","fixed":"2.6.1"},{"type":"ecosystem","introduced":"2.7.0rc0","status":"affected","fixed":"2.7.0"}],"ecosystem":"PyPI","package":"tensorflow-cpu","purl":"pkg:pypi/tensorflow-cpu","repo":"https://github.com/tensorflow/tensorflow","source":"pysec"},{"ranges":[{"type":"git","introduced":"0","status":"affected","fixed":"ca38dab9d3ee66c5de06f11af9a4b1200da5ef75"},{"type":"ecosystem","introduced":"2.6.0","status":"affected","fixed":"2.6.1"},{"type":"ecosystem","introduced":"2.7.0rc0","status":"affected","fixed":"2.7.0"}],"ecosystem":"PyPI","package":"tensorflow-gpu","purl":"pkg:pypi/tensorflow-gpu","repo":"https://github.com/tensorflow/tensorflow","source":"pysec"},{"ranges":[{"type":"semver","introduced":"2.6.0","status":"affected","fixed":"2.6.1"}],"ecosystem":"Bitnami","package":"tensorflow","purl":"pkg:bitnami/tensorflow","source":"bitnami"}],"references":[{"url":"https://github.com/tensorflow/tensorflow/security/advisories/GHSA-gpfh-jvf9-7wg5","tags":["advisory","exploit","patch","third-party-advisory","web","x-refsource-confirm","x-transferred"],"sources":["cvelist","ghsa","nvd","pysec","bitnami"]},{"url":"https://github.com/tensorflow/tensorflow/commit/ca38dab9d3ee66c5de06f11af9a4b1200da5ef75","tags":["advisory","fix","patch","third-party-advisory","web","x-refsource-misc","x-transferred"],"sources":["cvelist","ghsa","nvd","pysec","bitnami"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2021-41220","tags":["advisory","web"],"sources":["ghsa","bitnami"]},{"url":"https://github.com/pypa/advisory-database/tree/main/vulns/tensorflow-cpu/PYSEC-2021-629.yaml","tags":["web"],"sources":["ghsa"]},{"url":"https://github.com/pypa/advisory-database/tree/main/vulns/tensorflow-gpu/PYSEC-2021-827.yaml","tags":["web"],"sources":["ghsa"]},{"url":"https://github.com/pypa/advisory-database/tree/main/vulns/tensorflow/PYSEC-2021-412.yaml","tags":["web"],"sources":["ghsa"]},{"url":"https://github.com/tensorflow/tensorflow","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2021-41220","url":"https://www.cve.org/CVERecord?id=CVE-2021-41220","licence":"CVE Terms of Use","modified":"2024-08-04T03:08:31.404Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-gpfh-jvf9-7wg5","url":"https://github.com/advisories/GHSA-gpfh-jvf9-7wg5","licence":"CC-BY-4.0","modified":"2026-07-08T06:28:10.310Z"},{"source":"nvd","name":"NVD","id":"CVE-2021-41220","url":"https://nvd.nist.gov/vuln/detail/CVE-2021-41220","licence":"Public domain","modified":"2026-06-17T04:08:07.313Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2021-412","url":"https://osv.dev/vulnerability/PYSEC-2021-412","licence":"CC-BY-4.0","modified":"2023-12-06T01:01:34.948Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2021-629","url":"https://osv.dev/vulnerability/PYSEC-2021-629","licence":"CC-BY-4.0","modified":"2023-12-06T01:01:34.948Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2021-827","url":"https://osv.dev/vulnerability/PYSEC-2021-827","licence":"CC-BY-4.0","modified":"2023-12-06T01:01:34.948Z"},{"source":"bitnami","name":"Bitnami Vulnerability Database","id":"BIT-TENSORFLOW-2021-41220","url":"https://osv.dev/vulnerability/BIT-TENSORFLOW-2021-41220","licence":"Apache-2.0","modified":"2026-09-08T08:48:25.143Z"}],"updatedAt":"2026-11-25T22:58:05.399Z","epss":{"score":0.00211,"percentile":0.11969,"date":"2026-12-01T12:00:22.000Z"}}