Skip to content

Use after free / memory leak in `CollectiveReduceV2`

High severity GitHub Reviewed Published Nov 4, 2021 in tensorflow/tensorflow • Updated Nov 7, 2024

Package

pip tensorflow (pip)

Affected versions

= 2.6.0

Patched versions

2.6.1
pip tensorflow-cpu (pip)
= 2.6.0
2.6.1
pip tensorflow-gpu (pip)
= 2.6.0
2.6.1

Description

Impact

The async implementation of CollectiveReduceV2 suffers from a memory leak and a use after free:

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:

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.

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 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.

References

@mihaimaruseac mihaimaruseac published to tensorflow/tensorflow Nov 4, 2021
Published by the National Vulnerability Database Nov 5, 2021
Reviewed Nov 8, 2021
Published to the GitHub Advisory Database Nov 10, 2021
Last updated Nov 7, 2024

Severity

High

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Local
Attack complexity
Low
Privileges required
Low
User interaction
None
Scope
Unchanged
Confidentiality
High
Integrity
High
Availability
High

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H

EPSS score

0.048%
(19th percentile)

Weaknesses

CVE ID

CVE-2021-41220

GHSA ID

GHSA-gpfh-jvf9-7wg5

Source code

Loading Checking history
See something to contribute? Suggest improvements for this vulnerability.