Use after free / memory leak in `CollectiveReduceV2`
High7.8CVE-2021-41220 · Published Nov 10, 2021 · updated Jul 8, 2026
Affected versions
| Package | Affected | Fixed in |
|---|---|---|
| tensorflow PyPI | >= 2.6.0, < 2.6.1 | 2.6.1 |
Details and references
### Impact The [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: ```python import tensorflow as tf tf.raw_ops.CollectiveReduceV2( input=[], group_size=[-10, -10, -10], group_key=[-10, -10], instance_key=[-10], ordering_token=[], merge_op='Mul', final_op='Div') ``` This occurs due to the asynchronous computation and the fact that objects that have been `std::move()`d from are still accessed: ```cc auto done_with_cleanup = [col_params, done = std::move(done)]() { done(); col_params->Unref(); }; OP_REQUIRES_OK_ASYNC(c, FillCollectiveParams(col_params, REDUCTION_COLLECTIVE, /*group_size*/ c->input(1), /*group_key*/ c->input(2), /*instance_key*/ c->input(3)), done); ``` Here, `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. ### Patches We have patched the issue in GitHub commit [ca38dab9d3ee66c5de06f11af9a4b1200da5ef75](https://github.com/tensorflow/tensorflow/commit/ca38dab9d3ee66c5de06f11af9a4b1200da5ef75). 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. ### For more information Please 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. ### Attribution This vulnerability has been reported by members of the Aivul Team from Qihoo 360.
- CVSS 3.1
- CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
- Severity from
- GitHub (reviewed advisory)
- Weakness
- CWE-416
- Also known as
- BIT-tensorflow-2021-41220, CVE-2021-41220, PYSEC-2021-412, PYSEC-2021-629, PYSEC-2021-827
- github.com/tensorflow/tensorflow/security/advisories/GHSA-gpfh-jvf9-7wg5
- nvd.nist.gov/vuln/detail/CVE-2021-41220
- github.com/tensorflow/tensorflow/commit/ca38dab9d3ee66c5de06f11af9a4b1200da5ef75
- github.com/pypa/advisory-database/tree/main/vulns/tensorflow-cpu/PYSEC-2021-629.yaml
- github.com/pypa/advisory-database/tree/main/vulns/tensorflow-gpu/PYSEC-2021-827.yaml
- github.com/pypa/advisory-database/tree/main/vulns/tensorflow/PYSEC-2021-412.yaml
- github.com/tensorflow/tensorflow
More TensorFlow advisories
All TensorFlow| Date | Advisory | Severity | Fixed in |
|---|---|---|---|
| Nov 102021 | Code injection in `saved_model_cli` CVE-2021-41228Medium7.5fixed in 2.4.4, 2.5.2, 2.6.1 | Medium7.5 | 2.4.4, 2.5.2, 2.6.1 |
| Nov 102021 | Arbitrary memory read in `ImmutableConst` CVE-2021-41227Medium6.6fixed in 2.4.4, 2.5.2, 2.6.1 | Medium6.6 | 2.4.4, 2.5.2, 2.6.1 |
| Nov 102021 | Heap OOB in `SparseBinCount` CVE-2021-41226Medium7.1fixed in 2.4.4, 2.5.2, 2.6.1 | Medium7.1 | 2.4.4, 2.5.2, 2.6.1 |
| Nov 102021 | A use of uninitialized value vulnerability in Tensorflow CVE-2021-41225Medium5.5fixed in 2.4.4, 2.5.2, 2.6.1 | Medium5.5 | 2.4.4, 2.5.2, 2.6.1 |
| Nov 102021 | `SparseFillEmptyRows` heap OOB CVE-2021-41224Medium7.1fixed in 2.4.4, 2.5.2, 2.6.1 | Medium7.1 | 2.4.4, 2.5.2, 2.6.1 |
| Nov 102021 | Heap OOB in `FusedBatchNorm` kernels CVE-2021-41223Medium7.1fixed in 2.4.4, 2.5.2, 2.6.1 | Medium7.1 | 2.4.4, 2.5.2, 2.6.1 |