CVE-2021-41216: TensorFlow heap buffer overflow in Transpose shape inference

CVE-2021-41216 · Severity: low · CVSS 3.1 · Published 2021-11-05

TensorFlow is an open-source machine learning library used for building and training neural networks. The Transpose operation's shape inference function contains a heap buffer overflow vulnerability that can be triggered by providing negative index values in the permutation parameter. An attacker who can supply malicious inputs to a TensorFlow model could cause a crash (denial of service) or potentially achieve code execution.

Technologies: Google TensorFlow, tensorflow (PyPI), tensorflow-cpu (PyPI), tensorflow-gpu (PyPI). Vendors: Google, PyPI.

Quick answers

Is CVE-2021-41216 exploited in the wild?
No. Junglewise Threat Intelligence has no report of CVE-2021-41216 being exploited in the wild.
How severe is CVE-2021-41216?
Low severity, with a CVSS score of 3.1, published 5 November 2021.
Which products and versions are affected?
Google TensorFlow 0.12.0 through 2.4.3, 2.5.0-2.5.1, 2.6.0; tensorflow (PyPI) GIT:introduced=0,fixed=c79ba87153ee343401dbe9d1954d7f79e521eb14|ECOSYSTEM:introduced=0,fixed=2.4.4,introduced=2.5.0,fixed=2.5.2,introduced=2.6.0,fixed=2.6.1,introduced=2.7.0rc0,fixed=2.7.0; tensorflow-cpu (PyPI) GIT:introduced=0,fixed=c79ba87153ee343401dbe9d1954d7f79e521eb14|ECOSYSTEM:introduced=0,fixed=2.4.4,introduced=2.5.0,fixed=2.5.2,introduced=2.6.0,fixed=2.6.1,introduced=2.7.0rc0,fixed=2.7.0; tensorflow-gpu (PyPI) GIT:introduced=0,fixed=c79ba87153ee343401dbe9d1954d7f79e521eb14|ECOSYSTEM:introduced=0,fixed=2.4.4,introduced=2.5.0,fixed=2.5.2,introduced=2.6.0,fixed=2.6.1,introduced=2.7.0rc0,fixed=2.7.0.
Is there a fix for CVE-2021-41216?
Yes. tensorflow (PyPI): upgrade to 2.7.0 or later; tensorflow-cpu (PyPI): upgrade to 2.7.0 or later; tensorflow-gpu (PyPI): upgrade to 2.7.0 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.
How is CVE-2021-41216 attacked?
It is attacked with local access.
Am I affected by CVE-2021-41216?
Check whether you run Google TensorFlow, tensorflow (PyPI), tensorflow-cpu (PyPI) or one of the others listed at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

How to fix

  • tensorflow (PyPI): upgrade to 2.7.0 or later
    pip install "tensorflow>=2.7.0"
  • tensorflow-cpu (PyPI): upgrade to 2.7.0 or later
    pip install "tensorflow-cpu>=2.7.0"
  • tensorflow-gpu (PyPI): upgrade to 2.7.0 or later
    pip install "tensorflow-gpu>=2.7.0"

Technical details

The vulnerability is a heap buffer overflow (CWE-787, CWE-120) in the shape inference function of TensorFlow's Transpose operation. The root cause is insufficient validation: the function checks if permutation indices are greater than or equal to the rank but fails to validate against negative indices before using them. When a negative perm value is passed (e.g., perm=[-10]), the Dim() function accepts -1 as a special value for unknown dimensions, but the code does not properly validate other negative values, leading to out-of-bounds memory access. The vulnerability is triggered by calling tf.raw_ops.Transpose() with a negative perm argument and requires local access or the ability to supply inputs to a running TensorFlow model. The fix validates all indices in perm and was patched in commit c79ba87153ee343401dbe9d1954d7f79e521eb14.

Affected products

  • Google TensorFlow 0.12.0 through 2.4.3, 2.5.0-2.5.1, 2.6.0
  • Google TensorFlow CPU 1.15.0 through 2.4.3, 2.5.0-2.5.1, 2.6.0
  • Google TensorFlow GPU 0.12.0 through 2.4.3, 2.5.0-2.5.1, 2.6.0

Identifiers

  • CVE-2021-41216
  • GHSA-3ff2-r28g-w7h9
  • PYSEC-2021-408
  • PYSEC-2021-625
  • PYSEC-2021-823

Timeline

  • 2021-11-04: disclosed: Advisory published
  • 2021-11-10: patched: Patches released for TensorFlow 2.4.4, 2.5.2, 2.6.1, and included in 2.7.0

References

This page as Markdown. Free to reuse under CC BY 4.0 with a link back.